emailuis/uicomponents/src/fstreevisualizerbase.cpp
branchRCL_3
changeset 25 3533d4323edc
child 26 968773a0b6ef
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2  * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  *  Description : Freestyle tree list visualizer implementation
       
    15  *
       
    16  *
       
    17  */
       
    18 
       
    19 //////SYSTEM INCLUDES
       
    20 #include "emailtrace.h"
       
    21 #include <AknUtils.h>
       
    22 #include <StringLoader.h>
       
    23 #include <avkon.rsg> // R_AVKON_EMPTY_POPUP_LIST_TEXT
       
    24 #include <centralrepository.h>
       
    25 
       
    26 //////TOOLKIT INCLUDES
       
    27 // <cmail> SF
       
    28 #include <alf/alfstatic.h>
       
    29 #include <alf/alfownership.h>
       
    30 #include <alf/alfevent.h>
       
    31 #include <alf/alfimage.h>
       
    32 #include <alf/alfenv.h>
       
    33 #include <alf/alfcontrolgroup.h>
       
    34 //layouts
       
    35 #include <alf/alfflowlayout.h>
       
    36 #include <alf/alfdecklayout.h>
       
    37 #include <alf/alfgridlayout.h>
       
    38 #include <alf/alfanchorlayout.h>
       
    39 //brushes
       
    40 #include <alf/alfbrusharray.h>
       
    41 #include <alf/alfbrush.h>
       
    42 #include <alf/alfborderbrush.h>
       
    43 #include <alf/alfimagebrush.h>
       
    44 #include <alf/alfgradientbrush.h>
       
    45 #include <alf/alfframebrush.h>
       
    46 #include <alf/alfshadowborderbrush.h>
       
    47 //metrics
       
    48 #include <alf/alfmetric.h>
       
    49 #include <alf/alftimedvalue.h>
       
    50 //visuals
       
    51 #include <alf/alfvisual.h>
       
    52 #include <alf/alfimagevisual.h>
       
    53 // </cmail>
       
    54 
       
    55 
       
    56 //////PROJECT INCLUDES
       
    57 #include "fstreevisualizerbase.h"
       
    58 #include "fstreeplainrootvisualizer.h"
       
    59 #include "fstree.h"
       
    60 #include "fstreeiterator.h"
       
    61 #include "fsgenericpanic.h"
       
    62 #include "fsfadeeffect.h"
       
    63 #include "fstreeplainonelineitemdata.h"
       
    64 #include "fsslideeffect.h"
       
    65 #include "fstreeplainonelineitemvisualizer.h"
       
    66 #include "fstreelist.h"
       
    67 #include "fstreevisualizerobserver.h"
       
    68 #include "fscenrepkeys.h"
       
    69 #include "fswatermark.h"
       
    70 #include "fslayoutmanager.h"
       
    71 #include "fsseparatordata.h"
       
    72 ////alf specific
       
    73 #include "fsalfscrollbarlayout.h"
       
    74 #include "fsalftextstylemanager.h"
       
    75 #include "fsinteractioninterval.h"
       
    76 #include "muicscrollbar.h"
       
    77 #include "cuicaknscrollbaradapter.h"
       
    78 #include "cuicscrollbar.h"
       
    79 
       
    80 #include <aknphysics.h>
       
    81 #include <touchfeedback.h> // for MTouchFeedback
       
    82 
       
    83 
       
    84 //CONSTANTS
       
    85 const TInt KDefaultShadowWidth = 4;
       
    86 const TInt KFSListDefaultSelectorBorderWidth = 0;
       
    87 const TInt KZero = 0;
       
    88 _LIT8( KPropertyItemId, "PropItemID" );
       
    89 
       
    90 // check from aknphysicsconstants.h
       
    91 const TInt KFlickMaxDuration( 500000 );
       
    92 //const TInt KDefaultFriction( 25 ); // avkon default is 10
       
    93 const TInt KDefaultFriction( 5 ); // avkon default is 10
       
    94 
       
    95 // ======== LOCAL FUNCTIONS ========
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Deletes and sets pointer to NULL.
       
    99 // ---------------------------------------------------------------------------
       
   100 template<class T> void SafeDelete(T*& aPtr)
       
   101     {
       
   102     delete aPtr;
       
   103     aPtr = NULL;
       
   104     }
       
   105 
       
   106 // ======== MEMBER FUNCTIONS ========
       
   107 
       
   108 // TWorld::TItem
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // TWorld::TItem::TItem
       
   112 // ---------------------------------------------------------------------------
       
   113 TWorld::TItem::TItem(const TFsTreeItemId aId, const TRect& aRect) :
       
   114     iId(aId)
       
   115     {
       
   116     SetRect(aRect);
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // TWorld::TItem::Rect
       
   121 // ---------------------------------------------------------------------------
       
   122 TRect TWorld::TItem::Rect() const
       
   123     {
       
   124     return TRect(TPoint(0, iY), TPoint(0, iY + iHeight));
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // TWorld::TItem::SetRect
       
   129 // ---------------------------------------------------------------------------
       
   130 void TWorld::TItem::SetRect(const TRect& aRect)
       
   131     {
       
   132     iY = aRect.iTl.iY;
       
   133     iHeight = aRect.Height();
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // TWorld::TItem::Move
       
   138 // ---------------------------------------------------------------------------
       
   139 void TWorld::TItem::Move(TInt aDy)
       
   140     {
       
   141     iY += aDy;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // TWorld::TItem::Top
       
   146 // ---------------------------------------------------------------------------
       
   147 TInt TWorld::TItem::Top() const
       
   148     {
       
   149     return iY;
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // TWorld::TItem::TopLeft
       
   154 // ---------------------------------------------------------------------------
       
   155 TPoint TWorld::TItem::TopLeft() const
       
   156     {
       
   157     return TPoint(0, iY);
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // TWorld::TItem::Height
       
   162 // ---------------------------------------------------------------------------
       
   163 TInt TWorld::TItem::Height() const
       
   164     {
       
   165     return iHeight;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // TWorld::TItem::Bottom
       
   170 // ---------------------------------------------------------------------------
       
   171 TInt TWorld::TItem::Bottom() const
       
   172     {
       
   173     return iY + iHeight;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // TWorld::TItem::Bottom
       
   178 // ---------------------------------------------------------------------------
       
   179 TPoint TWorld::TItem::BottomRight() const
       
   180     {
       
   181     return TPoint(0, iY + iHeight);
       
   182     }
       
   183 
       
   184 // TWorld
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // TWorld::TWorld
       
   188 // ---------------------------------------------------------------------------
       
   189 TWorld::TWorld() :
       
   190     iBatchUpdateOngoing(EFalse)
       
   191     {
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // TWorld::~TWorld
       
   196 // ---------------------------------------------------------------------------
       
   197 TWorld::~TWorld()
       
   198     {
       
   199     iItems.Reset();
       
   200     iObservers.Reset();
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // TWorld::AddObserverL
       
   205 // ---------------------------------------------------------------------------
       
   206 void TWorld::AddObserverL(MObserver& aObserver)
       
   207     {
       
   208     iObservers.AppendL(&aObserver);
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // TWorld::RemoveObserver
       
   213 // ---------------------------------------------------------------------------
       
   214 void TWorld::RemoveObserver(MObserver& aObserver)
       
   215     {
       
   216     const TInt index(iObservers.Find(&aObserver));
       
   217     if (index != KErrNotFound)
       
   218         {
       
   219         iObservers.Remove(index);
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // TWorld::AppendL
       
   225 // ---------------------------------------------------------------------------
       
   226 void TWorld::AppendL(const TFsTreeItemId aId, const TSize& aSize)
       
   227     {
       
   228     const TInt count(iItems.Count());
       
   229     TPoint tl;
       
   230     if (count > 0)
       
   231         {
       
   232         tl.iY = iItems[count - 1].Bottom();
       
   233         }
       
   234     const TRect modifiedRect(TRect(tl, aSize));
       
   235     iItems.AppendL(TItem(aId, modifiedRect));
       
   236     iHeight += aSize.iHeight;
       
   237     UpdatedL();
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // TWorld::InsertL
       
   242 // ---------------------------------------------------------------------------
       
   243 void TWorld::InsertL(const TFsTreeItemId aId, const TSize& aSize,
       
   244         const TInt aSlot)
       
   245     {
       
   246     if (aSlot >= iItems.Count())
       
   247         {
       
   248         AppendL(aId, aSize);
       
   249         }
       
   250     else
       
   251         {
       
   252         const TPoint topLeft(iItems[aSlot].TopLeft());
       
   253         iItems.InsertL(TItem(aId, TRect(topLeft, aSize)), aSlot);
       
   254         MoveBy(aSlot + 1, aSize.iHeight);
       
   255         iHeight += aSize.iHeight;
       
   256         UpdatedL();
       
   257         }
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // TWorld::RemoveL
       
   262 // ---------------------------------------------------------------------------
       
   263 void TWorld::RemoveL(const TFsTreeItemId aId)
       
   264     {
       
   265     for (TInt i = iItems.Count() - 1; i >= 0; i--)
       
   266         {
       
   267         const TFsTreeItemId itemId(iItems[i].iId);
       
   268         if (itemId == aId)
       
   269             {
       
   270             const TItem item(iItems[i]);
       
   271             iItems.Remove(i);
       
   272             const TInt delta(-item.Height());
       
   273             MoveBy(i, delta);
       
   274             iHeight += delta;
       
   275             UpdatedL();
       
   276             break;
       
   277             }
       
   278         }
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // TWorld::RemoveAllL
       
   283 // ---------------------------------------------------------------------------
       
   284 void TWorld::RemoveAllL()
       
   285     {
       
   286     iHeight = 0;
       
   287     iItems.Reset();
       
   288     UpdatedL();
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // TWorld::Height
       
   293 // ---------------------------------------------------------------------------
       
   294 TInt TWorld::Height() const
       
   295     {
       
   296     return iHeight;
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // TWorld::ItemCount
       
   301 // ---------------------------------------------------------------------------
       
   302 TInt TWorld::ItemCount() const
       
   303     {
       
   304     return iItems.Count();
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // TWorld::Item
       
   309 // ---------------------------------------------------------------------------
       
   310 TFsTreeItemId TWorld::Item(TInt aIndex) const
       
   311     {
       
   312     return iItems[aIndex].iId;
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // TWorld::IndexOfItem
       
   317 // ---------------------------------------------------------------------------
       
   318 TInt TWorld::IndexOfItem(TFsTreeItemId aItem) const
       
   319     {
       
   320     for (TInt i = 0; i < iItems.Count(); i++)
       
   321         {
       
   322         if (iItems[i].iId == aItem)
       
   323             {
       
   324             return i;
       
   325             }
       
   326         }
       
   327     return KErrNotFound;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // TWorld::MoveBy
       
   332 // ---------------------------------------------------------------------------
       
   333 void TWorld::MoveBy(const TInt aSlot, const TInt aDelta)
       
   334     {
       
   335     const TInt count(iItems.Count());
       
   336     for (TInt i = aSlot; i < count; i++)
       
   337         {
       
   338         iItems[i].Move(aDelta);
       
   339         }
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // TWorld::UpdatedL
       
   344 // ---------------------------------------------------------------------------
       
   345 void TWorld::UpdatedL()
       
   346     {
       
   347     if (!iBatchUpdateOngoing)
       
   348         {
       
   349         for (TInt i = iObservers.Count() - 1; i >= 0; i--)
       
   350             {
       
   351             iObservers[i]->WorldUpdatedL(*this);
       
   352             }
       
   353         }
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // TWorld::GetItemsL
       
   358 // Uses binary search.
       
   359 // ---------------------------------------------------------------------------
       
   360 void TWorld::GetItemsL(RArray<TFsTreeItemId>& aItems, TInt aY, TInt aHeight,
       
   361         TInt& aOffset, TInt& aBeginIndex)
       
   362     {
       
   363     // First find first visible item using binary search algorithm
       
   364     aItems.Reset();
       
   365     TInt i(0);
       
   366     aOffset = 0;
       
   367     if (aY > Height())
       
   368         {
       
   369         aHeight = -1;
       
   370         }
       
   371     else if (aY > 0)
       
   372         {
       
   373         TInt min(0);
       
   374         TInt max(iItems.Count() - 1);
       
   375         while (min <= max)
       
   376             {
       
   377             const TInt middle(min + (max - min) / 2);
       
   378             if (aY < iItems[middle].Top())
       
   379                 {
       
   380                 max = middle - 1;
       
   381                 }
       
   382             else if (aY > iItems[middle].Bottom())
       
   383                 {
       
   384                 min = middle + 1;
       
   385                 }
       
   386             else
       
   387                 {
       
   388                 aOffset = aY - iItems[middle].Top();
       
   389                 aHeight += aOffset;
       
   390                 aBeginIndex = i = middle;
       
   391                 break;
       
   392                 }
       
   393             }
       
   394         }
       
   395     else
       
   396         {
       
   397         aOffset = aY;
       
   398         aHeight += aY;
       
   399         }
       
   400 
       
   401     // If item was found, collect enough items to fill the view
       
   402     while (aHeight >= 0 && i < iItems.Count())
       
   403         {
       
   404         aItems.AppendL(iItems[i].iId);
       
   405         aHeight -= iItems[i++].Height();
       
   406         }
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // TWorld::BeginUpdate
       
   411 // ---------------------------------------------------------------------------
       
   412 void TWorld::BeginUpdate()
       
   413     {
       
   414     iBatchUpdateOngoing = ETrue;
       
   415     }
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 // TWorld::EndUpdateL
       
   419 // ---------------------------------------------------------------------------
       
   420 void TWorld::EndUpdateL()
       
   421     {
       
   422     if (iBatchUpdateOngoing)
       
   423         {
       
   424         iBatchUpdateOngoing = EFalse;
       
   425         UpdatedL();
       
   426         }
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // TWorld::IsUpdating
       
   431 // ---------------------------------------------------------------------------
       
   432 TBool TWorld::IsUpdating() const
       
   433     {
       
   434     return iBatchUpdateOngoing;
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // TWorld::Recalculate
       
   439 // ---------------------------------------------------------------------------
       
   440 void TWorld::Recalculate(const CFsTree& aTree)
       
   441     {
       
   442     TPoint tl;
       
   443     iHeight = 0;
       
   444     for (TInt i = 0; i < iItems.Count(); i++)
       
   445         {
       
   446         TItem& item(iItems[i]);
       
   447         MFsTreeItemVisualizer* visualizer(aTree.ItemVisualizer(item.iId));
       
   448         TSize size(visualizer->Size());
       
   449         item.SetRect(TRect(tl, size));
       
   450         tl.iY += size.iHeight;
       
   451         iHeight += size.iHeight;
       
   452         }
       
   453     }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // TWorld::GetItemRect
       
   457 // ---------------------------------------------------------------------------
       
   458 TInt TWorld::GetItemRect(const TFsTreeItemId aItemId, TRect& aRect) const
       
   459     {
       
   460     return GetItemRect(aItemId, aRect, 0);
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 // TWorld::GetItemRect
       
   465 // ---------------------------------------------------------------------------
       
   466 TInt TWorld::GetItemRect(const TFsTreeItemId aItemId, TRect& aRect,
       
   467         const TInt aStartIndex ) const
       
   468     {
       
   469     TInt result(KErrNotFound);
       
   470     const TInt itemCount(iItems.Count());
       
   471     for (TInt i = aStartIndex; i < itemCount; i++)
       
   472         {
       
   473         if (iItems[i].iId == aItemId)
       
   474             {
       
   475             result = i;
       
   476             aRect = iItems[i].Rect();
       
   477             break;
       
   478             }
       
   479         }
       
   480     return result;
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // TWorld::GetItemRectByIndex
       
   485 // ---------------------------------------------------------------------------
       
   486 TInt TWorld::GetItemRectByIndex(const TInt aIndex, TRect& aRect) const
       
   487     {
       
   488     TInt result(KErrNotFound);
       
   489     if (aIndex < iItems.Count() && aIndex >= 0)
       
   490         {
       
   491         aRect = iItems[aIndex].Rect();
       
   492         result = KErrNone;
       
   493         }
       
   494     return result;
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // TWorld::CheckIntegrity
       
   499 // ---------------------------------------------------------------------------
       
   500 TBool TWorld::CheckIntegrity() const
       
   501     {
       
   502     TBool result(ETrue);
       
   503     if (iItems.Count() > 1)
       
   504         {
       
   505         TRect prev(iItems[0].Rect());
       
   506         for (TInt i = 1; i < iItems.Count() - 1; i++)
       
   507             {
       
   508             const TRect& curr(iItems[i].Rect());
       
   509             if (prev.Intersects(curr))
       
   510                 {
       
   511                 result = EFalse;
       
   512                 break;
       
   513                 }
       
   514             prev.iBr.iY += curr.Height();
       
   515             }
       
   516         }
       
   517     return result;
       
   518     }
       
   519 
       
   520 // TViewPort
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // TViewPort::TViewPort
       
   524 // ---------------------------------------------------------------------------
       
   525 TViewPort::TViewPort(MObserver& aObserver, TWorld& aWorld) :
       
   526     iObserver(aObserver), iWorld(aWorld), iWorldIndex(KErrNotFound)
       
   527     {
       
   528     }
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // TViewPort::SetPositionL
       
   532 // ---------------------------------------------------------------------------
       
   533 void TViewPort::SetPositionL(const TPoint& aPosition, TBool aInformUpdate)
       
   534     {
       
   535     iPosition = aPosition;
       
   536     // Do validation!
       
   537     if (aInformUpdate)
       
   538         {
       
   539         UpdatedL();
       
   540         }
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // TViewPort::SetCenterPositionL
       
   545 // ---------------------------------------------------------------------------
       
   546 void TViewPort::SetCenterPositionL(const TPoint& aPosition,
       
   547         TBool aInformUpdate, TUpdatedByPhysic aUpdateByPhysic)
       
   548     {
       
   549     iPosition = TPoint(aPosition.iX - iSize.iWidth / 2, aPosition.iY
       
   550             - iSize.iHeight / 2);
       
   551     // Do validation!
       
   552     if (aInformUpdate)
       
   553         {
       
   554         UpdatedL(aUpdateByPhysic);
       
   555         }
       
   556     }
       
   557 
       
   558 // ---------------------------------------------------------------------------
       
   559 // TViewPort::Position
       
   560 // ---------------------------------------------------------------------------
       
   561 const TPoint& TViewPort::Position() const
       
   562     {
       
   563     return iPosition;
       
   564     }
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // TViewPort::CenterPosition
       
   568 // ---------------------------------------------------------------------------
       
   569 TPoint TViewPort::CenterPosition() const
       
   570     {
       
   571     TPoint result(iPosition.iX + iSize.iWidth / 2, iPosition.iY
       
   572             + iSize.iHeight / 2);
       
   573     return result;
       
   574     }
       
   575 
       
   576 // ---------------------------------------------------------------------------
       
   577 // TViewPort::SetSizeL
       
   578 // ---------------------------------------------------------------------------
       
   579 void TViewPort::SetSizeL(const TSize& aSize)
       
   580     {
       
   581     iSize = aSize;
       
   582     // Do validation!
       
   583     if (!iWorld.IsUpdating())
       
   584         {
       
   585         UpdatedL();
       
   586         }
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // TViewPort::Size
       
   591 // ---------------------------------------------------------------------------
       
   592 const TSize& TViewPort::Size() const
       
   593     {
       
   594     return iSize;
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // TViewPort::GetVisibleItemsL
       
   599 // ---------------------------------------------------------------------------
       
   600 void TViewPort::GetVisibleItemsL(RArray<TFsTreeItemId>& aItemsToBeRemoved,
       
   601         RArray<TFsTreeItemId>& aItemsToBeAdded, TInt& aOffset,
       
   602         TBool& aFullUpdate)
       
   603     {
       
   604     RArray<TFsTreeItemId> tempItems;
       
   605     CleanupClosePushL(tempItems);
       
   606     iWorld.GetItemsL(tempItems, iPosition.iY, iSize.iHeight, aOffset, iWorldIndex);
       
   607     iCache.UpdateL(tempItems, aItemsToBeRemoved, aItemsToBeAdded, aFullUpdate);
       
   608     CleanupStack::PopAndDestroy(); // tempItems
       
   609     }
       
   610 
       
   611 // ---------------------------------------------------------------------------
       
   612 // TViewPort::GetVisibleItemsL
       
   613 // ---------------------------------------------------------------------------
       
   614 void TViewPort::GetVisibleItemsL(RArray<TFsTreeItemId>& aVisible, TInt& aOffset)
       
   615 	{
       
   616 	iWorld.GetItemsL(aVisible, iPosition.iY, iSize.iHeight, aOffset, iWorldIndex);
       
   617 	}
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 // TViewPort::IsScrollBarNeeded
       
   621 // ---------------------------------------------------------------------------
       
   622 TBool TViewPort::IsScrollBarNeeded() const
       
   623     {
       
   624     return iWorld.Height() > iSize.iHeight;
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // TViewPort::UpdatedL
       
   629 // ---------------------------------------------------------------------------
       
   630 void TViewPort::UpdatedL(TUpdatedByPhysic aUpdateByPhysic)
       
   631     {
       
   632     iObserver.ViewPortUpdatedL(*this, aUpdateByPhysic);
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // TViewPort::WorldUpdatedL
       
   637 // ---------------------------------------------------------------------------
       
   638 void TViewPort::WorldUpdatedL(const TWorld& aWorld)
       
   639     {
       
   640     // recreate viewable set if needed
       
   641     if (iPosition.iY > aWorld.Height() || (iPosition.iY + iSize.iHeight
       
   642             > aWorld.Height() && iSize.iHeight <= aWorld.Height()))
       
   643         {
       
   644         iPosition.iY = Max(0, aWorld.Height() - iSize.iHeight);
       
   645         }
       
   646     else if (iSize.iHeight > aWorld.Height() && iPosition.iY > 0)
       
   647         {
       
   648         iPosition.iY = 0;
       
   649         }
       
   650     iObserver.ViewPortUpdatedL(*this);
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // TViewPort::ScrollToItemL
       
   655 // ---------------------------------------------------------------------------
       
   656 void TViewPort::ScrollToItemL(const TFsTreeItemId aItemId,
       
   657         TBool aInformUpdate)
       
   658     {
       
   659     TRect itemRect;
       
   660     if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
       
   661         {
       
   662         SetPositionL(itemRect.iTl, aInformUpdate);
       
   663         }
       
   664     }
       
   665 
       
   666 // ---------------------------------------------------------------------------
       
   667 // TViewPort::CenterToItemL
       
   668 // ---------------------------------------------------------------------------
       
   669 void TViewPort::CenterToItemL(const TFsTreeItemId aItemId,
       
   670         TBool aInformUpdate)
       
   671     {
       
   672     TRect itemRect;
       
   673     if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
       
   674         {
       
   675         TInt top(itemRect.iTl.iY);
       
   676         top -= (iSize.iHeight - itemRect.Height()) / 2;
       
   677         LimitTop(top);
       
   678         SetPositionL(TPoint(iPosition.iX, top), aInformUpdate);
       
   679         }
       
   680     }
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // TViewPort::ItemToPositionL
       
   684 // Tries to scroll view so that given item is in given position aPosition.
       
   685 // ---------------------------------------------------------------------------
       
   686 void TViewPort::ItemToPositionL(const TFsTreeItemId aItemId,
       
   687         const TPoint& aPosition, const TBool aInformUpdate,
       
   688         const TPositionHint aHint)
       
   689     {
       
   690     TRect itemRect;
       
   691     if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
       
   692         {
       
   693         TInt top(itemRect.iTl.iY);
       
   694         top -= aPosition.iY;
       
   695         LimitTop(top);
       
   696         if (aHint == EPositionAfterExpand)
       
   697             {
       
   698             const TInt error( iWorld.GetItemRectByIndex(
       
   699                     iWorld.IndexOfItem(aItemId) + 1, itemRect) );
       
   700             if (!error)
       
   701                 {
       
   702                 if (itemRect.iBr.iY - top > iSize.iHeight)
       
   703                     {
       
   704                     top += itemRect.iBr.iY - top - iSize.iHeight;
       
   705                     LimitTop(top);
       
   706                     }
       
   707                 }
       
   708             }
       
   709         SetPositionL(TPoint(iPosition.iX, top), aInformUpdate);
       
   710         }
       
   711     }
       
   712 
       
   713 // ---------------------------------------------------------------------------
       
   714 // TViewPort::ScrollItemToViewL
       
   715 // Scrolls item to view. Item is set as top most item, if it is above the current
       
   716 // display area or bottom most item if it is below the current display area.
       
   717 // ---------------------------------------------------------------------------
       
   718 void TViewPort::ScrollItemToViewL(const TFsTreeItemId aItemId,
       
   719         TBool aInformUpdate)
       
   720     {
       
   721     TRect itemRect;
       
   722     if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
       
   723         {
       
   724         if (itemRect.iTl.iY < iPosition.iY)
       
   725             {
       
   726             SetPositionL(itemRect.iTl, aInformUpdate);
       
   727             }
       
   728         if (itemRect.iBr.iY > iPosition.iY + iSize.iHeight)
       
   729             {
       
   730             SetPositionL(
       
   731                     TPoint(iPosition.iX, itemRect.iBr.iY - iSize.iHeight),
       
   732                     aInformUpdate);
       
   733             }
       
   734         }
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // TViewPort::MakeViewFullyOccupiedL
       
   739 // ---------------------------------------------------------------------------
       
   740 void TViewPort::MakeViewFullyOccupiedL(TBool aInformUpdate)
       
   741     {
       
   742     TInt top(iPosition.iY);
       
   743     LimitTop(top);
       
   744     SetPositionL(TPoint(iPosition.iX, top), aInformUpdate);
       
   745     }
       
   746 
       
   747 // ---------------------------------------------------------------------------
       
   748 // TViewPort::TopItem
       
   749 // ---------------------------------------------------------------------------
       
   750 TFsTreeItemId TViewPort::TopItem() const
       
   751     {
       
   752     return iCache.TopItem();
       
   753     }
       
   754 
       
   755 // ---------------------------------------------------------------------------
       
   756 // TViewPort::ClearCache
       
   757 // ---------------------------------------------------------------------------
       
   758 void TViewPort::ClearCache()
       
   759     {
       
   760     iWorldIndex = KErrNotFound;
       
   761     iCache.Clear();
       
   762     }
       
   763 
       
   764 // ---------------------------------------------------------------------------
       
   765 // TViewPort::ItemRect
       
   766 // ---------------------------------------------------------------------------
       
   767 TRect TViewPort::ItemRect(const TFsTreeItemId aItemId) const
       
   768     {
       
   769     TRect itemRect;
       
   770     if (!iCache.IsClear() && iCache.ContainsItem(aItemId))
       
   771         {
       
   772         const TInt beginIndex(iWorldIndex == KErrNotFound ? 0 : iWorldIndex);
       
   773         if (iWorld.GetItemRect(aItemId, itemRect, beginIndex) != KErrNotFound)
       
   774             {
       
   775             itemRect.Move(0, -iPosition.iY);
       
   776             }
       
   777         }
       
   778     return itemRect;
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // TViewPort::ItemFullyVisible
       
   783 // ---------------------------------------------------------------------------
       
   784 TBool TViewPort::ItemFullyVisible(const TFsTreeItemId aItemId) const
       
   785     {
       
   786     TBool result(EFalse);
       
   787     if (!iCache.IsClear() && iCache.ContainsItem(aItemId))
       
   788         {
       
   789         TRect itemRect;
       
   790         if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
       
   791             {
       
   792             if (itemRect.Height())
       
   793                 {
       
   794                 const TRect viewRect(iPosition, iSize);
       
   795                 result = viewRect.Contains(itemRect.iTl)
       
   796                         && viewRect.Contains(itemRect.iBr);
       
   797                 }
       
   798             }
       
   799         }
       
   800     return result;
       
   801     }
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // TViewPort::ItemRect
       
   805 // ---------------------------------------------------------------------------
       
   806 void TViewPort::LimitTop(TInt& aTop) const
       
   807     {
       
   808     aTop = Min(iWorld.Height() - iSize.iHeight, aTop);
       
   809     aTop = Max(0, aTop);
       
   810     }
       
   811 
       
   812 // ---------------------------------------------------------------------------
       
   813 // TViewPort::TCache::TCache
       
   814 // ---------------------------------------------------------------------------
       
   815 TViewPort::TCache::TCache() :
       
   816     iClear(ETrue)
       
   817     {
       
   818     }
       
   819 
       
   820 // ---------------------------------------------------------------------------
       
   821 // TViewPort::TCache::~TCache
       
   822 // ---------------------------------------------------------------------------
       
   823 TViewPort::TCache::~TCache()
       
   824     {
       
   825     iCachedItems.Reset();
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // TViewPort::TCache::Clear
       
   830 // ---------------------------------------------------------------------------
       
   831 void TViewPort::TCache::Clear()
       
   832     {
       
   833     iClear = ETrue;
       
   834     iCachedItems.Reset();
       
   835     }
       
   836 
       
   837 // ---------------------------------------------------------------------------
       
   838 // TViewPort::TCache::IsClear
       
   839 // ---------------------------------------------------------------------------
       
   840 TBool TViewPort::TCache::IsClear() const
       
   841     {
       
   842     return iClear;
       
   843     }
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // TViewPort::TCache::ContainsItem
       
   847 // ---------------------------------------------------------------------------
       
   848 TBool TViewPort::TCache::ContainsItem(const TFsTreeItemId aItemId) const
       
   849     {
       
   850     return iCachedItems.Find(aItemId) != KErrNotFound;
       
   851     }
       
   852 
       
   853 // ---------------------------------------------------------------------------
       
   854 // TViewPort::TCache::UpdateL
       
   855 // ---------------------------------------------------------------------------
       
   856 void TViewPort::TCache::UpdateL(const RArray<TFsTreeItemId>& aItems, RArray<
       
   857         TFsTreeItemId>& aItemsToBeRemoved,
       
   858         RArray<TFsTreeItemId>& aItemsToBeAdded, TBool& aFullUpdate)
       
   859     {
       
   860     aFullUpdate = iClear;
       
   861     if (!iClear)
       
   862         {
       
   863         // find items in cache, missing in new set => items to be removed
       
   864         aItemsToBeRemoved.Reset();
       
   865         for (TInt i = 0; i < iCachedItems.Count(); i++)
       
   866             {
       
   867             if (aItems.Find(iCachedItems[i]) == KErrNotFound)
       
   868                 {
       
   869                 aItemsToBeRemoved.AppendL(iCachedItems[i]);
       
   870                 }
       
   871             }
       
   872 
       
   873         // find items in new set, missing in cache => items to be added
       
   874         aItemsToBeAdded.Reset();
       
   875         for (TInt i = 0; i < aItems.Count(); i++)
       
   876             {
       
   877             if (iCachedItems.Find(aItems[i]) == KErrNotFound)
       
   878                 {
       
   879                 aItemsToBeAdded.AppendL(aItems[i]);
       
   880                 }
       
   881             else
       
   882                 {
       
   883                 aItemsToBeAdded.AppendL(KFsTreeNoneID);
       
   884                 }
       
   885             }
       
   886         }
       
   887     else
       
   888         {
       
   889         // find items in new set, missing in cache => items to be added
       
   890         aItemsToBeAdded.Reset();
       
   891         for (TInt i = 0; i < aItems.Count(); i++)
       
   892             {
       
   893             aItemsToBeAdded.AppendL(aItems[i]);
       
   894             }
       
   895         }
       
   896     // finally update cache
       
   897     iCachedItems.Reset();
       
   898     for (TInt i = 0; i < aItems.Count(); i++)
       
   899         {
       
   900         iCachedItems.AppendL(aItems[i]);
       
   901         }
       
   902     iClear = EFalse;
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------------------------
       
   906 // TViewPort::TCache::TopItem
       
   907 // ---------------------------------------------------------------------------
       
   908 TFsTreeItemId TViewPort::TCache::TopItem() const
       
   909     {
       
   910     if (iClear || !iCachedItems.Count())
       
   911         {
       
   912         return KFsTreeNoneID;
       
   913         }
       
   914     return iCachedItems[0];
       
   915     }
       
   916 
       
   917 // ---------------------------------------------------------------------------
       
   918 // Two-phased constructor.
       
   919 // ---------------------------------------------------------------------------
       
   920 //
       
   921 EXPORT_C CFsTreeVisualizerBase* CFsTreeVisualizerBase::NewL(
       
   922         CAlfControl* aOwnerControl, CAlfLayout& aParent,
       
   923         const TBool aPopUpMode)
       
   924     {
       
   925     FUNC_LOG;
       
   926     CFsTreeVisualizerBase* self = new (ELeave) CFsTreeVisualizerBase(
       
   927             aOwnerControl, aParent, aPopUpMode);
       
   928     CleanupStack::PushL(self);
       
   929     self->ConstructL();
       
   930     CleanupStack::Pop(self);
       
   931     return self;
       
   932     }
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 // C++ destructor.
       
   936 // ---------------------------------------------------------------------------
       
   937 //
       
   938 CFsTreeVisualizerBase::~CFsTreeVisualizerBase()
       
   939     {
       
   940     FUNC_LOG;
       
   941     delete iDragHandler;
       
   942     delete iPhysics;
       
   943     if (iOwnerControl)
       
   944         {
       
   945         iOwnerControl->Env().RemoveActionObserver(this);
       
   946         }
       
   947     delete iBorderBrush;
       
   948     iVisibleItems.Close();
       
   949     iVisibleItemsBackground.Close();
       
   950     iCustomPageUpKeys.Close();
       
   951     iCustomPageDownKeys.Close();
       
   952     delete iFadeEffect;
       
   953     delete iSlideEffect;
       
   954     delete iWatermark;
       
   955     delete iTextStyleManager;
       
   956     delete iIntx;
       
   957     if ( iScrollBar )
       
   958         {
       
   959         iScrollBar->Destroy();
       
   960         }
       
   961     }
       
   962 
       
   963 // ---------------------------------------------------------------------------
       
   964 //Sets data model for the visualizer.
       
   965 // ---------------------------------------------------------------------------
       
   966 //
       
   967 void CFsTreeVisualizerBase::SetTreeData(CFsTree& aTreeData)
       
   968     {
       
   969     FUNC_LOG;
       
   970     iTreeData = &aTreeData;
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 // Adds custom key which triggers page-up event.
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 void CFsTreeVisualizerBase::AddCustomPageUpKey(TInt aKeyCode)
       
   978     {
       
   979     FUNC_LOG;
       
   980     iCustomPageUpKeys.InsertInOrder(aKeyCode);
       
   981     }
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 // Removes given key code from custom page-up event key codes.
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 TBool CFsTreeVisualizerBase::RemoveCustomPageUpKey(TInt aKeyCode)
       
   988     {
       
   989     FUNC_LOG;
       
   990     TBool keyRemoved = EFalse;
       
   991 
       
   992     TInt index = iCustomPageUpKeys.FindInOrder(aKeyCode);
       
   993     if (index != KErrNotFound)
       
   994         {
       
   995         iCustomPageUpKeys.Remove(index);
       
   996         keyRemoved = ETrue;
       
   997         }
       
   998 
       
   999     return keyRemoved;
       
  1000     }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 // Checks whether given key is a custom key for page-up event.
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 TBool CFsTreeVisualizerBase::IsCustomPageUpKey(TInt aKeyCode)
       
  1007     {
       
  1008     FUNC_LOG;
       
  1009     TBool keyExists = EFalse;
       
  1010     TInt index = iCustomPageUpKeys.FindInOrder(aKeyCode);
       
  1011     if (index != KErrNotFound)
       
  1012         {
       
  1013         keyExists = ETrue;
       
  1014         }
       
  1015     return keyExists;
       
  1016     }
       
  1017 
       
  1018 // ---------------------------------------------------------------------------
       
  1019 // Adds custom key which triggers page-down event.
       
  1020 // ---------------------------------------------------------------------------
       
  1021 //
       
  1022 void CFsTreeVisualizerBase::AddCustomPageDownKey(TInt aKeyCode)
       
  1023     {
       
  1024     FUNC_LOG;
       
  1025     iCustomPageDownKeys.InsertInOrder(aKeyCode);
       
  1026     }
       
  1027 
       
  1028 // ---------------------------------------------------------------------------
       
  1029 // Removes given key code from custom page-down event key codes.
       
  1030 // ---------------------------------------------------------------------------
       
  1031 //
       
  1032 TBool CFsTreeVisualizerBase::RemoveCustomPageDownKey(TInt aKeyCode)
       
  1033     {
       
  1034     FUNC_LOG;
       
  1035     TBool keyRemoved = EFalse;
       
  1036 
       
  1037     TInt index = iCustomPageDownKeys.FindInOrder(aKeyCode);
       
  1038     if (index != KErrNotFound)
       
  1039         {
       
  1040         iCustomPageDownKeys.Remove(index);
       
  1041         keyRemoved = ETrue;
       
  1042         }
       
  1043 
       
  1044     return keyRemoved;
       
  1045     }
       
  1046 
       
  1047 // ---------------------------------------------------------------------------
       
  1048 //  Checks whether given key is a custom key for page-down event.
       
  1049 // ---------------------------------------------------------------------------
       
  1050 //
       
  1051 TBool CFsTreeVisualizerBase::IsCustomPageDownKey(TInt aKeyCode)
       
  1052     {
       
  1053     FUNC_LOG;
       
  1054     TBool keyExists = EFalse;
       
  1055     TInt index = iCustomPageDownKeys.FindInOrder(aKeyCode);
       
  1056     if (index != KErrNotFound)
       
  1057         {
       
  1058         keyExists = ETrue;
       
  1059         }
       
  1060     return keyExists;
       
  1061     }
       
  1062 
       
  1063 // ---------------------------------------------------------------------------
       
  1064 //  Sets icon for a mark sign.
       
  1065 // ---------------------------------------------------------------------------
       
  1066 //
       
  1067 void CFsTreeVisualizerBase::SetMarkIcon(CAlfTexture& aMarkIcon)
       
  1068     {
       
  1069     FUNC_LOG;
       
  1070     iMarkIcon = &aMarkIcon;
       
  1071     }
       
  1072 
       
  1073 // ---------------------------------------------------------------------------
       
  1074 //  Returns icon used to mark items.
       
  1075 // ---------------------------------------------------------------------------
       
  1076 //
       
  1077 CAlfTexture* CFsTreeVisualizerBase::MarkIcon()
       
  1078     {
       
  1079     FUNC_LOG;
       
  1080     return iMarkIcon;
       
  1081     }
       
  1082 
       
  1083 // ---------------------------------------------------------------------------
       
  1084 //
       
  1085 // ---------------------------------------------------------------------------
       
  1086 //
       
  1087 TBool CFsTreeVisualizerBase::IsMarked(const TFsTreeItemId aItemId) const
       
  1088     {
       
  1089     FUNC_LOG;
       
  1090     MFsTreeItemVisualizer* vis = NULL;
       
  1091     vis = iTreeData->ItemVisualizer(aItemId);
       
  1092     return vis->IsMarked();
       
  1093     }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 //
       
  1097 // ---------------------------------------------------------------------------
       
  1098 //
       
  1099 void CFsTreeVisualizerBase::MarkItemL(const TFsTreeItemId aItemId,
       
  1100         TBool aMarked)
       
  1101     {
       
  1102     FUNC_LOG;
       
  1103     MFsTreeItemVisualizer* vis = NULL;
       
  1104     vis = iTreeData->ItemVisualizer(aItemId);
       
  1105     vis->SetMarked(aMarked);
       
  1106     if (iVisibleItems.Find(aItemId) != KErrNotFound)
       
  1107         {
       
  1108         MFsTreeItemData* data = NULL;
       
  1109         data = &(iTreeData->ItemData(aItemId));
       
  1110 
       
  1111         vis->UpdateL(*data, IsItemFocused(aItemId) && IsFocusShown(),
       
  1112                 iTreeData->Level(aItemId), iMarkIcon, iMenuIcon);
       
  1113         }
       
  1114     }
       
  1115 
       
  1116 // ---------------------------------------------------------------------------
       
  1117 //
       
  1118 // ---------------------------------------------------------------------------
       
  1119 //
       
  1120 void CFsTreeVisualizerBase::GetMarkedItemsL(RFsTreeItemIdList& aMarkedItems) const
       
  1121     {
       
  1122     FUNC_LOG;
       
  1123     TFsTreeIterator treeIter = iTreeData->Iterator(KFsTreeRootID,
       
  1124             KFsTreeRootID);
       
  1125     TFsTreeItemId itemId;
       
  1126     MFsTreeItemVisualizer* vis = NULL;
       
  1127     while (treeIter.HasNext())
       
  1128         {
       
  1129         itemId = treeIter.Next();
       
  1130         vis = iTreeData->ItemVisualizer(itemId);
       
  1131         if (vis->IsMarked())
       
  1132             {
       
  1133             aMarkedItems.AppendL(itemId);
       
  1134             }
       
  1135         }
       
  1136     }
       
  1137 
       
  1138 // ---------------------------------------------------------------------------
       
  1139 //  Function marks/unmarks all items in the list.
       
  1140 // ---------------------------------------------------------------------------
       
  1141 //
       
  1142 void CFsTreeVisualizerBase::MarkAllItemsL(TBool aMarkAll)
       
  1143     {
       
  1144     FUNC_LOG;
       
  1145     TFsTreeIterator treeIter = iTreeData->Iterator(KFsTreeRootID,
       
  1146             KFsTreeRootID);
       
  1147     TFsTreeItemId itemId;
       
  1148     MFsTreeItemVisualizer* vis = NULL;
       
  1149     while (treeIter.HasNext())
       
  1150         {
       
  1151         itemId = treeIter.Next();
       
  1152         vis = iTreeData->ItemVisualizer(itemId);
       
  1153         vis->SetMarked(aMarkAll);
       
  1154         }
       
  1155     RefreshListViewL();
       
  1156     }
       
  1157 
       
  1158 // ---------------------------------------------------------------------------
       
  1159 //  Sets item indentation per hierarchy level.
       
  1160 // ---------------------------------------------------------------------------
       
  1161 void CFsTreeVisualizerBase::SetIndentationL(TInt aIndentation)
       
  1162     {
       
  1163     FUNC_LOG;
       
  1164     iLevelIndentation = aIndentation;
       
  1165 
       
  1166     MFsTreeItemVisualizer* vis = NULL;
       
  1167     TFsTreeItemId itemId = KFsTreeNoneID;
       
  1168     //loop through the list and set items to always-extended state.
       
  1169     TFsTreeIterator iter = iTreeData->Iterator(KFsTreeRootID, KFsTreeRootID);
       
  1170     while (iter.HasNext())
       
  1171         {
       
  1172         itemId = iter.Next();
       
  1173         //get item's visualizer
       
  1174         vis = iTreeData->ItemVisualizer(itemId);
       
  1175         //set indentation in pixels
       
  1176         vis->SetIndentation(iLevelIndentation);
       
  1177         }
       
  1178 
       
  1179     //refresh the list view
       
  1180     RefreshListViewL();
       
  1181     }
       
  1182 
       
  1183 // ---------------------------------------------------------------------------
       
  1184 //  Returns indentation per hierarchy level in pixels.
       
  1185 // ---------------------------------------------------------------------------
       
  1186 //
       
  1187 TInt CFsTreeVisualizerBase::Indentation() const
       
  1188     {
       
  1189     FUNC_LOG;
       
  1190     return iLevelIndentation;
       
  1191     }
       
  1192 
       
  1193 // ---------------------------------------------------------------------------
       
  1194 //  Sets icon for a menu sign.
       
  1195 // ---------------------------------------------------------------------------
       
  1196 void CFsTreeVisualizerBase::SetMenuIcon(CAlfTexture& aMenuIcon)
       
  1197     {
       
  1198     FUNC_LOG;
       
  1199     iMenuIcon = &aMenuIcon;
       
  1200     }
       
  1201 
       
  1202 // ---------------------------------------------------------------------------
       
  1203 //  Returns menu icon.
       
  1204 // ---------------------------------------------------------------------------
       
  1205 CAlfTexture* CFsTreeVisualizerBase::MenuIcon() const
       
  1206     {
       
  1207     FUNC_LOG;
       
  1208     return iMenuIcon;
       
  1209     }
       
  1210 
       
  1211 // ---------------------------------------------------------------------------
       
  1212 //  Used internally by the list. To make the list focused/not focused use
       
  1213 //  CFsTreeList::SetFocusedL() instead.
       
  1214 // ---------------------------------------------------------------------------
       
  1215 //
       
  1216 void CFsTreeVisualizerBase::SetFocusedL(const TBool aFocused)
       
  1217     {
       
  1218     FUNC_LOG;
       
  1219     if (iDragHandler && !aFocused)
       
  1220         {
       
  1221         iDragHandler->Reset();
       
  1222         }
       
  1223     if (iFlags.IsSet(EListFocused) != aFocused)
       
  1224         {
       
  1225         iFlags.Assign(EListFocused, aFocused);
       
  1226         if (iTreeData->Count())
       
  1227             {
       
  1228             if (iFlags.IsSet(EListFocused))
       
  1229                 {
       
  1230                 //list will receive focus
       
  1231                 if (iFocusedItem == KFsTreeNoneID)
       
  1232                     {
       
  1233                     TFsTreeIterator treeIter = iTreeData->Iterator(
       
  1234                             KFsTreeRootID, KFsTreeRootID,
       
  1235                             KFsTreeIteratorSkipCollapsedFlag
       
  1236                                     | KFsTreeIteratorSkipHiddenFlag);
       
  1237 
       
  1238                     TFsTreeItemId id(KFsTreeNoneID);
       
  1239                     MFsTreeItemVisualizer* visualizer(NULL);
       
  1240                     id = treeIter.First();
       
  1241                     visualizer = iTreeData->ItemVisualizer(id);
       
  1242                     if (visualizer)
       
  1243                         {
       
  1244                         if (visualizer->IsFocusable())
       
  1245                             {
       
  1246                             iFocusedItem = id;
       
  1247                             }
       
  1248                         }
       
  1249                     }
       
  1250                 // a workaround to make SetFocusedItemL work with timeout
       
  1251                 SetFocusedItemL(iFocusedItem);
       
  1252                 MakeSelectorVisibleL(ETrue);
       
  1253                 }
       
  1254             else
       
  1255                 {
       
  1256                 if (iFocusedItem != KFsTreeNoneID)
       
  1257                     {
       
  1258                     //list will loose focus
       
  1259                     MFsTreeItemVisualizer* visualizer =
       
  1260                             iTreeData->ItemVisualizer(iFocusedItem);
       
  1261                     if (visualizer)
       
  1262                         {
       
  1263                         TInt index(iListLayout->FindVisual(
       
  1264                                 &visualizer->Layout()));
       
  1265                         if (index != KErrNotFound)
       
  1266                             {
       
  1267                             MFsTreeItemData* data = &iTreeData->ItemData(
       
  1268                                     iFocusedItem);
       
  1269                             MakeSelectorVisibleL(EFalse);
       
  1270                             visualizer->UpdateL(*data, EFalse,
       
  1271                                     iTreeData->Level(iFocusedItem),
       
  1272                                     iMarkIcon, iMenuIcon, iCurrentScrollSpeed);
       
  1273                             }
       
  1274                         }
       
  1275                     }
       
  1276                 }
       
  1277             iListLayout->UpdateChildrenLayout();
       
  1278             }
       
  1279         }
       
  1280     }
       
  1281 
       
  1282 // ---------------------------------------------------------------------------
       
  1283 // The function sets some properties of the selector like bitmap, type
       
  1284 // of movement.
       
  1285 // ---------------------------------------------------------------------------
       
  1286 //
       
  1287 void CFsTreeVisualizerBase::SetSelectorPropertiesL(CAlfTexture* aTexture,
       
  1288         TFsSelectorMovement aMovementType, TInt aLeftBorderWidth,
       
  1289         TInt aRightBorderWidth, TInt aTopBorderHeight,
       
  1290         TInt aBottomBorderHeight)
       
  1291     {
       
  1292     FUNC_LOG;
       
  1293     iSelectorTexture = aTexture;
       
  1294     iSelectorBrush = NULL;
       
  1295     iSelectorMovementType = aMovementType;
       
  1296     iSelectorOpacity = 1.0;
       
  1297 
       
  1298     iLeftSelectorBorderWidth = aLeftBorderWidth;
       
  1299     iRightSelectorBorderWidth = aRightBorderWidth;
       
  1300     iTopSelectorBorderHeight = aTopBorderHeight;
       
  1301     iBottomSelectorBorderHeight = aBottomBorderHeight;
       
  1302 
       
  1303     DestroySelectorVisualL();
       
  1304     MakeSelectorVisibleL(ETrue);
       
  1305     }
       
  1306 
       
  1307 // ---------------------------------------------------------------------------
       
  1308 // The function sets some properties of the selector.
       
  1309 // ---------------------------------------------------------------------------
       
  1310 //
       
  1311 void CFsTreeVisualizerBase::SetSelectorPropertiesL(CAlfBrush* aSelectorBrush,
       
  1312         TReal32 aOpacity, TFsSelectorMovement aMovementType)
       
  1313     {
       
  1314     FUNC_LOG;
       
  1315     iSelectorTexture = NULL;
       
  1316     iSelectorBrush = aSelectorBrush;
       
  1317     iSelectorMovementType = aMovementType;
       
  1318     //check value, selector cannot be fully transparent ( <= 0.0 )
       
  1319     if (aOpacity <= 0.0 || aOpacity > 1.0)
       
  1320         {
       
  1321         iSelectorOpacity = 1.0;
       
  1322         }
       
  1323     else
       
  1324         {
       
  1325         iSelectorOpacity = aOpacity;
       
  1326         }
       
  1327 
       
  1328     iLeftSelectorBorderWidth = 0;
       
  1329     iRightSelectorBorderWidth = 0;
       
  1330     iTopSelectorBorderHeight = 0;
       
  1331     iBottomSelectorBorderHeight = 0;
       
  1332 
       
  1333     DestroySelectorVisualL();
       
  1334     MakeSelectorVisibleL(ETrue);
       
  1335     }
       
  1336 
       
  1337 // ---------------------------------------------------------------------------
       
  1338 // The function returnes selector's properties.
       
  1339 // ---------------------------------------------------------------------------
       
  1340 //
       
  1341 void CFsTreeVisualizerBase::GetSelectorProperties(CAlfTexture*& aTexture,
       
  1342         TFsSelectorMovement& aMovementType, TInt& aLeftBorderWidth,
       
  1343         TInt& aRightBorderWidth, TInt& aTopBorderHeight,
       
  1344         TInt& aBottomBorderHeight)
       
  1345     {
       
  1346     FUNC_LOG;
       
  1347     aTexture = iSelectorTexture;
       
  1348     aMovementType = iSelectorMovementType;
       
  1349 
       
  1350     aLeftBorderWidth = iLeftSelectorBorderWidth;
       
  1351     aRightBorderWidth = iRightSelectorBorderWidth;
       
  1352     aTopBorderHeight = iTopSelectorBorderHeight;
       
  1353     aBottomBorderHeight = iBottomSelectorBorderHeight;
       
  1354     }
       
  1355 
       
  1356 // ---------------------------------------------------------------------------
       
  1357 // The function sets a text for empty list's view.
       
  1358 // ---------------------------------------------------------------------------
       
  1359 //
       
  1360 void CFsTreeVisualizerBase::SetEmptyListTextL(const TDesC& aText)
       
  1361     {
       
  1362     FUNC_LOG;
       
  1363     if (iRootData)
       
  1364         {
       
  1365         iRootData->SetDataL(aText);
       
  1366         }
       
  1367     }
       
  1368 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 // The function returns a text for empty list's view.
       
  1371 // ---------------------------------------------------------------------------
       
  1372 //
       
  1373 TDesC& CFsTreeVisualizerBase::GetEmptyListText() const
       
  1374     {
       
  1375     FUNC_LOG;
       
  1376     return iRootData->Data();
       
  1377     }
       
  1378 
       
  1379 // ---------------------------------------------------------------------------
       
  1380 //  Handles key event forwarded by the controller.
       
  1381 // ---------------------------------------------------------------------------
       
  1382 //
       
  1383 TBool CFsTreeVisualizerBase::HandleKeyEventL(const TAlfEvent& aEvent)
       
  1384     {
       
  1385     //ignore  KeyUp events
       
  1386     TBool eventHandled = aEvent.Code() == EEventKeyUp;
       
  1387 
       
  1388     if (iTreeData->Count() && (!eventHandled))
       
  1389         {
       
  1390         TInt nowOffset = iListLayout->ScrollOffset().iY.ValueNow();
       
  1391         TInt targetOffset = iListLayout->ScrollOffset().iY.Target();
       
  1392 
       
  1393         if (!(iFlags.IsSet(EIsPageUpDownActive)
       
  1394                 && (nowOffset != targetOffset)))
       
  1395             {
       
  1396             iFlags.Clear(EIsPageUpDownActive);
       
  1397 
       
  1398             switch (aEvent.KeyEvent().iScanCode)
       
  1399                 {
       
  1400                 case EStdKeyUpArrow:
       
  1401                     {
       
  1402                     if (iFocusedItem != KFsTreeNoneID)
       
  1403                         {
       
  1404                         SetCurrentScrollSpeed(aEvent.KeyEvent().iRepeats);
       
  1405                         MoveSelectionL(EFsTreeVisualizerMoveLineUp);
       
  1406                         //iCurrentScrollSpeed = iScrollSpeed;
       
  1407                         }
       
  1408                     eventHandled = ETrue;
       
  1409                     break;
       
  1410                     }
       
  1411                 case EStdKeyDownArrow:
       
  1412                     {
       
  1413                     if (iFocusedItem != KFsTreeNoneID)
       
  1414                         {
       
  1415                         SetCurrentScrollSpeed(aEvent.KeyEvent().iRepeats);
       
  1416                         MoveSelectionL(EFsTreeVisualizerMoveLineDown);
       
  1417                         //iCurrentScrollSpeed = iScrollSpeed;
       
  1418                         }
       
  1419                     eventHandled = ETrue;
       
  1420                     break;
       
  1421                     }
       
  1422                 case EStdKeyLeftArrow:
       
  1423                     {
       
  1424                     if (iVisualizerObserver)
       
  1425                         {
       
  1426                         iVisualizerObserver->TreeVisualizerEventL(
       
  1427                                 MFsTreeVisualizerObserver::EFsTreeKeyLeftArrow,
       
  1428                                 iFocusedItem);
       
  1429                         }
       
  1430                     eventHandled = ETrue;
       
  1431                     break;
       
  1432                     }
       
  1433                 case EStdKeyRightArrow:
       
  1434                     {
       
  1435                     if (iVisualizerObserver)
       
  1436                         {
       
  1437                         iVisualizerObserver->TreeVisualizerEventL(
       
  1438                                 MFsTreeVisualizerObserver::EFsTreeKeyRightArrow,
       
  1439                                 iFocusedItem);
       
  1440                         }
       
  1441                     eventHandled = ETrue;
       
  1442                     break;
       
  1443                     }
       
  1444                 case EStdKeyDevice3:
       
  1445                     {
       
  1446                     if (iTreeData->IsNode(iFocusedItem))
       
  1447                         {
       
  1448                         if (iTreeData->NodeVisualizer(iFocusedItem)->IsExpanded())
       
  1449                             {
       
  1450                             CollapseNodeL(iFocusedItem);
       
  1451                             }
       
  1452                         else
       
  1453                             {
       
  1454                             ExpandNodeL(iFocusedItem);
       
  1455                             }
       
  1456                         }
       
  1457                     else
       
  1458                         {
       
  1459                         if (iVisualizerObserver)
       
  1460                             {
       
  1461                             if (iTreeData->ItemVisualizer(iFocusedItem)->Menu())
       
  1462                                 {
       
  1463                                 iVisualizerObserver->TreeVisualizerEventL(
       
  1464                                         MFsTreeVisualizerObserver::EFsTreeItemWithMenuSelected,
       
  1465                                         iFocusedItem);
       
  1466                                 }
       
  1467                             else
       
  1468                                 {
       
  1469                                 iVisualizerObserver->TreeVisualizerEventL(
       
  1470                                         MFsTreeVisualizerObserver::EFsTreeItemSelected,
       
  1471                                         iFocusedItem);
       
  1472                                 }
       
  1473                             }
       
  1474                         }
       
  1475                     eventHandled = ETrue;
       
  1476                     break;
       
  1477                     }
       
  1478                 default:
       
  1479                     {
       
  1480                     // the visualizer ignores all other events
       
  1481                     break;
       
  1482                     }
       
  1483                 }
       
  1484             //page up/down
       
  1485             if (!eventHandled)
       
  1486                 {
       
  1487                 if (IsCustomPageUpKey(aEvent.KeyEvent().iScanCode))
       
  1488                     {
       
  1489                     SetCurrentScrollSpeed(aEvent.KeyEvent().iRepeats);
       
  1490                     MoveSelectionL(EFsTreeVisualizerMovePageUp);
       
  1491                     iFlags.Set(EIsPageUpDownActive);
       
  1492                     eventHandled = ETrue;
       
  1493                     //iCurrentScrollSpeed = iScrollSpeed;
       
  1494                     }
       
  1495                 else if (IsCustomPageDownKey(aEvent.KeyEvent().iScanCode))
       
  1496                     {
       
  1497                     SetCurrentScrollSpeed(aEvent.KeyEvent().iRepeats);
       
  1498                     MoveSelectionL(EFsTreeVisualizerMovePageDown);
       
  1499                     iFlags.Set(EIsPageUpDownActive);
       
  1500                     eventHandled = ETrue;
       
  1501                     //iCurrentScrollSpeed = iScrollSpeed;
       
  1502                     }
       
  1503                 }
       
  1504             }
       
  1505         else
       
  1506             {
       
  1507             eventHandled = EFalse;
       
  1508             }
       
  1509         }
       
  1510     else
       
  1511         {
       
  1512         eventHandled = EFalse;
       
  1513         }
       
  1514 
       
  1515     return eventHandled;
       
  1516     }
       
  1517 
       
  1518 // ---------------------------------------------------------------------------
       
  1519 // CFsTreeVisualizerBase::SetFlipState
       
  1520 // ---------------------------------------------------------------------------
       
  1521 //
       
  1522 void CFsTreeVisualizerBase::SetFlipState( TBool aOpen )
       
  1523     {
       
  1524     iFlipOpen = aOpen;
       
  1525     }
       
  1526 
       
  1527 // ---------------------------------------------------------------------------
       
  1528 // CFsTreeVisualizerBase::SetFocusVisibility
       
  1529 // ---------------------------------------------------------------------------
       
  1530 //
       
  1531 void CFsTreeVisualizerBase::SetFocusVisibility( TBool aShow )
       
  1532     {
       
  1533     if ( ( iFocusVisible && !aShow ) || ( !iFocusVisible && aShow ) )
       
  1534         {
       
  1535         iFocusVisible = aShow;
       
  1536         TRAP_IGNORE(
       
  1537             MakeSelectorVisibleL( aShow );
       
  1538             UpdateItemL( iFocusedItem ); );
       
  1539         }
       
  1540     }
       
  1541 
       
  1542 // ---------------------------------------------------------------------------
       
  1543 // CFsTreeVisualizerBase::HandlePointerEventL
       
  1544 // ---------------------------------------------------------------------------
       
  1545 //
       
  1546 TBool CFsTreeVisualizerBase::HandlePointerEventL(const TAlfEvent& aEvent)
       
  1547     {
       
  1548     TBool eventHandled(EFalse);
       
  1549     if (iDragHandler && iOwnerControl->ControlGroup()->AcceptInput())
       
  1550         {
       
  1551         TPointerEvent::TType type = aEvent.PointerEvent().iType;
       
  1552         const TFsTreeItemId id(EventItemId(aEvent));
       
  1553         INFO_1("visual: $%x", aEvent.Visual());
       
  1554         if ( KFsTreeNoneID != id || type == TPointerEvent::EDrag ||
       
  1555                 type  == TPointerEvent::EButtonRepeat ||
       
  1556                 type  == TPointerEvent::EButton1Up ||
       
  1557                 type  == TPointerEvent::EButton1Down)
       
  1558             {
       
  1559             switch (type)
       
  1560                 {
       
  1561                 case TPointerEvent::EButton1Down:
       
  1562                     {
       
  1563                     eventHandled = ETrue;
       
  1564                     iTouchPressed = ETrue;
       
  1565                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
       
  1566                     INFO_2("EButton1Down (%d, %d)", pos.iX, pos.iY);
       
  1567                     //if (!iFlags.IsSet(EPhysicsOn))
       
  1568                     // Keep this last!
       
  1569                     if (iFlags.IsSet(EPhysicsOn))
       
  1570                         {
       
  1571                         iPhysics->StopPhysics();
       
  1572                         //iPhysics->ResetFriction();
       
  1573                         UpdatePhysicsL();
       
  1574                         iFlags.Set(EIgnorePointerUpAction);
       
  1575                         }
       
  1576                     else
       
  1577                         {
       
  1578                         iFlags.Clear(EIgnorePointerUpAction);
       
  1579                         }
       
  1580                     iDragHandler->PointerDown(aEvent.PointerEvent(), id);
       
  1581                     break;
       
  1582                     }
       
  1583                 case TPointerEvent::EButton1Up:
       
  1584                     {
       
  1585                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
       
  1586                     if( iTouchPressed )
       
  1587                         {
       
  1588                         eventHandled = ETrue;
       
  1589                         iTouchPressed = EFalse;
       
  1590                         iVisualizerObserver->TreeVisualizerEventL(
       
  1591                             MFsTreeVisualizerObserver::EFsChangeFocusVisibility );
       
  1592                         INFO_2( "EButton1Up (%d, %d)", pos.iX, pos.iY );
       
  1593                         }
       
  1594                     /*if( !iDragHandler->IsFlicking() )
       
  1595                         {
       
  1596                         iPhysics->StopPhysics();
       
  1597                         }*/
       
  1598                     iDragHandler->PointerUp( aEvent.PointerEvent(), id );
       
  1599                     iFlags.Clear(EIgnorePointerUpAction);
       
  1600                     iFlags.Clear( EListPanning );
       
  1601                     break;
       
  1602                     }
       
  1603                 case TPointerEvent::EDrag:
       
  1604                     {
       
  1605                     eventHandled = ETrue;
       
  1606                     const TPoint& pos(aEvent.PointerEvent().iPosition);
       
  1607                     INFO_2("EDrag (%d, %d)", pos.iX, pos.iY);
       
  1608                     if (iDragHandler->IsFlicking()
       
  1609                             || iDragHandler->DragDelta(aEvent.PointerEvent())
       
  1610                                     >= iPhysics->DragThreshold())
       
  1611                         {
       
  1612                         iFlags.Set(EIgnorePointerUpAction);
       
  1613                         iDragHandler->PointerDrag(aEvent.PointerEvent(), id);
       
  1614                         iDragHandler->EnableFlicking();
       
  1615                         }
       
  1616                     break;
       
  1617                     }
       
  1618 
       
  1619                 case TPointerEvent::EButtonRepeat:
       
  1620                     {
       
  1621                     eventHandled = ETrue;
       
  1622                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
       
  1623                     INFO_2("EButtonRepeat (%d, %d)", pos.iX, pos.iY);
       
  1624                     iDragHandler->PointerRepeat(aEvent.PointerEvent());
       
  1625                     iFlags.Clear(EIgnorePointerUpAction);
       
  1626                     break;
       
  1627                     }
       
  1628 
       
  1629                 default:
       
  1630                     {
       
  1631                     //Unknown event, ignore.
       
  1632                     break;
       
  1633                     }
       
  1634                 }
       
  1635             }
       
  1636         else
       
  1637         	{
       
  1638         	iVisualizerObserver->TreeVisualizerEventL(
       
  1639 					MFsTreeVisualizerObserver::EFsChangeFocusVisibility );
       
  1640         	}
       
  1641         }
       
  1642     return eventHandled;
       
  1643     }
       
  1644 // ---------------------------------------------------------------------------
       
  1645 //  CFsTreeVisualizerBase::EventItemId
       
  1646 // ---------------------------------------------------------------------------
       
  1647 //
       
  1648 TFsTreeItemId CFsTreeVisualizerBase::EventItemId(const TAlfEvent& aEvent) const
       
  1649     {
       
  1650     FUNC_LOG;
       
  1651     if (aEvent.Type() == TPointerEvent::EDrag)
       
  1652         {
       
  1653         return VisualItemId(FindVisualUnderDrag(
       
  1654                 aEvent.PointerEvent().iPosition));
       
  1655         }
       
  1656     else
       
  1657         {
       
  1658         return VisualItemId(aEvent.Visual());
       
  1659         }
       
  1660     }
       
  1661 
       
  1662 // ---------------------------------------------------------------------------
       
  1663 //  CFsTreeVisualizerBase::FindVisualUnderDrag
       
  1664 // ---------------------------------------------------------------------------
       
  1665 //
       
  1666 const CAlfVisual* CFsTreeVisualizerBase::FindVisualUnderDrag(
       
  1667         const TPoint& aPosition) const
       
  1668     {
       
  1669     FUNC_LOG;
       
  1670     for (TInt i = 0; i < iListLayout->Count(); i++)
       
  1671         {
       
  1672         const TRect displayRect(iListLayout->Visual(i).DisplayRectTarget());
       
  1673         if (displayRect.Contains(aPosition))
       
  1674             {
       
  1675             return &iListLayout->Visual(i);
       
  1676             }
       
  1677         }
       
  1678     return NULL;
       
  1679     }
       
  1680 
       
  1681 // ---------------------------------------------------------------------------
       
  1682 //  CFsTreeVisualizerBase::VisualItemId
       
  1683 // ---------------------------------------------------------------------------
       
  1684 //
       
  1685 TFsTreeItemId CFsTreeVisualizerBase::VisualItemId(const CAlfVisual* aVisual) const
       
  1686     {
       
  1687     FUNC_LOG;
       
  1688     TFsTreeItemId itemId( KFsTreeNoneID );
       
  1689     if (aVisual)
       
  1690         {
       
  1691         aVisual->PropertyFindInteger(KPropertyItemId(), &itemId);
       
  1692         }
       
  1693     return itemId;
       
  1694     }
       
  1695 
       
  1696 // ---------------------------------------------------------------------------
       
  1697 // Sets the specified item as focused.
       
  1698 // ---------------------------------------------------------------------------
       
  1699 //
       
  1700 void CFsTreeVisualizerBase::SetFocusedItemL( const TFsTreeItemId aItemId,
       
  1701 		TBool /*aCheckFocus*/ )
       
  1702     {
       
  1703     FUNC_LOG;
       
  1704     MFsTreeItemVisualizer* visualizer = NULL;
       
  1705 
       
  1706     if ( aItemId != iFocusedItem )
       
  1707         {
       
  1708         visualizer = iTreeData->ItemVisualizer( iFocusedItem );
       
  1709 
       
  1710         if ( visualizer )
       
  1711             {
       
  1712             visualizer->UpdateL( iTreeData->ItemData( iFocusedItem ), EFalse,
       
  1713             		iTreeData->Level( iFocusedItem ), iMarkIcon, iMenuIcon, 0 );
       
  1714             }
       
  1715 
       
  1716         iFocusedItem = aItemId;
       
  1717         }
       
  1718 
       
  1719     visualizer = iTreeData->ItemVisualizer( iFocusedItem );
       
  1720 
       
  1721     if ( visualizer )
       
  1722         {
       
  1723         visualizer->UpdateL( iTreeData->ItemData( iFocusedItem ), IsFocusShown(),
       
  1724                 iTreeData->Level( iFocusedItem ), iMarkIcon, iMenuIcon, 0 );
       
  1725         }
       
  1726 
       
  1727     if ( iFocusedItem != KFsTreeNoneID )
       
  1728         {
       
  1729         UpdateSelectorVisualL();
       
  1730 
       
  1731         if ( !iViewPort.ItemFullyVisible( iFocusedItem ) )
       
  1732             {
       
  1733             iViewPort.ScrollItemToViewL( iFocusedItem );
       
  1734             }
       
  1735         }
       
  1736     }
       
  1737 
       
  1738 // ---------------------------------------------------------------------------
       
  1739 // Gets item vertical position in the list
       
  1740 // ---------------------------------------------------------------------------
       
  1741 //
       
  1742 TInt CFsTreeVisualizerBase::GetItemWorldPosition( const TInt aIdx )
       
  1743     {
       
  1744     TRect rect;
       
  1745     iWorld.GetItemRectByIndex( aIdx, rect);
       
  1746     return rect.iTl.iY;
       
  1747     }
       
  1748 
       
  1749 // ---------------------------------------------------------------------------
       
  1750 // Checks if the specified item is focused.
       
  1751 // ---------------------------------------------------------------------------
       
  1752 //
       
  1753 TFsTreeItemId CFsTreeVisualizerBase::FocusedItem() const
       
  1754     {
       
  1755     FUNC_LOG;
       
  1756     return iFocusedItem;
       
  1757     }
       
  1758 
       
  1759 // ---------------------------------------------------------------------------
       
  1760 // Checks if the specified item is focused.
       
  1761 // ---------------------------------------------------------------------------
       
  1762 //
       
  1763 TBool CFsTreeVisualizerBase::IsFocused(const TFsTreeItemId aItemId) const
       
  1764     {
       
  1765     FUNC_LOG;
       
  1766     return iFocusedItem == aItemId ? ETrue : EFalse;
       
  1767     }
       
  1768 
       
  1769 // ---------------------------------------------------------------------------
       
  1770 // Sets an item as first visible one in the list.
       
  1771 // ---------------------------------------------------------------------------
       
  1772 //
       
  1773 // <cmail>
       
  1774 void CFsTreeVisualizerBase::SetFirstVisibleItemL(const TFsTreeItemId /*aItemId*/)
       
  1775     {
       
  1776     FUNC_LOG;
       
  1777     }
       
  1778 
       
  1779 // ---------------------------------------------------------------------------
       
  1780 // Get an id of the first visible item.
       
  1781 // ---------------------------------------------------------------------------
       
  1782 //
       
  1783 TFsTreeItemId CFsTreeVisualizerBase::FirstVisibleItem()
       
  1784     {
       
  1785     FUNC_LOG;
       
  1786     TFsTreeItemId retId = KFsTreeNoneID;
       
  1787     if (iVisibleItems.Count())
       
  1788         {
       
  1789         // <cmail>
       
  1790         //        TRAP_IGNORE( ClearVisibleItemsListL(EFalse) );
       
  1791         // </cmail>
       
  1792         retId = iVisibleItems[0];
       
  1793         }
       
  1794     else
       
  1795         {
       
  1796         retId = KFsTreeNoneID;
       
  1797         }
       
  1798     return retId;
       
  1799     }
       
  1800 
       
  1801 // ---------------------------------------------------------------------------
       
  1802 // Gets a pointer to the root's item data object.
       
  1803 // ---------------------------------------------------------------------------
       
  1804 //
       
  1805 MFsTreeItemData* CFsTreeVisualizerBase::RootItemData()
       
  1806     {
       
  1807     FUNC_LOG;
       
  1808     return iRootData;
       
  1809     }
       
  1810 
       
  1811 // ---------------------------------------------------------------------------
       
  1812 // Gets a pointer to the root's item visualizer object.
       
  1813 // ---------------------------------------------------------------------------
       
  1814 //
       
  1815 MFsTreeNodeVisualizer* CFsTreeVisualizerBase::RootNodeVisualizer()
       
  1816     {
       
  1817     FUNC_LOG;
       
  1818     return iRootVisualizer;
       
  1819     }
       
  1820 
       
  1821 // ---------------------------------------------------------------------------
       
  1822 // Displays the list.
       
  1823 // ---------------------------------------------------------------------------
       
  1824 //
       
  1825 // <cmail>
       
  1826 void CFsTreeVisualizerBase::ShowListL(const TBool aFadeIn,
       
  1827         const TBool aSlideIn)
       
  1828     {
       
  1829     FUNC_LOG;
       
  1830     iVisualizationState = EFsTreeVisible;
       
  1831     if (iTreeData->Count() == 0)
       
  1832         {
       
  1833         iRootVisualizer->ShowL(*iRootLayout);
       
  1834         iRootVisualizer->UpdateL(*iRootData, EFalse, 0, iMarkIcon, iMenuIcon);
       
  1835         }
       
  1836     else
       
  1837         {
       
  1838         const TBool showFocus = IsFocusShown();
       
  1839         for (TUint i = 0; i < iVisibleItems.Count(); ++i)
       
  1840             {
       
  1841             TFsTreeItemId itemId(iVisibleItems[i]);
       
  1842             MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(
       
  1843                     itemId);
       
  1844 
       
  1845             TBool itemFocused( showFocus && IsItemFocused(itemId) );
       
  1846 			if ( visualizer )
       
  1847 				{
       
  1848 	        	visualizer->UpdateL(iTreeData->ItemData(itemId), itemFocused,
       
  1849 	                iTreeData->Level(itemId), iMarkIcon, iMenuIcon,
       
  1850 	                0);
       
  1851 				}
       
  1852             }
       
  1853         }
       
  1854     UpdateViewPortL();
       
  1855 
       
  1856     TInt fadeInTime(KZero), slideInTime(KZero);
       
  1857     CFsSlideEffect::TSlideEffectDirection slideInDir(
       
  1858             CFsSlideEffect::ESlideNone);
       
  1859 
       
  1860 
       
  1861     if (aFadeIn)
       
  1862         {
       
  1863         fadeInTime = iFadeInEffectTime;
       
  1864         if (aSlideIn)
       
  1865             {
       
  1866             iVisualizationState = EFsTreeFadingInSlidingIn;
       
  1867             }
       
  1868         else
       
  1869             {
       
  1870             iVisualizationState = EFsTreeFadingIn;
       
  1871             }
       
  1872         }
       
  1873     else
       
  1874         {
       
  1875         fadeInTime = KZero;
       
  1876         }
       
  1877 
       
  1878     if (aSlideIn)
       
  1879         {
       
  1880         slideInTime = iSlideInDuration;
       
  1881         switch (iSlideInDirection)
       
  1882             {
       
  1883             case MFsTreeVisualizer::ESlideFromTop:
       
  1884                 {
       
  1885                 slideInDir = CFsSlideEffect::ESlideFromTop;
       
  1886                 break;
       
  1887                 }
       
  1888             case MFsTreeVisualizer::ESlideFromBottom:
       
  1889                 {
       
  1890                 slideInDir = CFsSlideEffect::ESlideFromBottom;
       
  1891                 break;
       
  1892                 }
       
  1893             case MFsTreeVisualizer::ESlideFromLeft:
       
  1894                 {
       
  1895                 slideInDir = CFsSlideEffect::ESlideFromLeft;
       
  1896                 break;
       
  1897                 }
       
  1898             case MFsTreeVisualizer::ESlideFromRight:
       
  1899                 {
       
  1900                 slideInDir = CFsSlideEffect::ESlideFromRight;
       
  1901                 break;
       
  1902                 }
       
  1903             case MFsTreeVisualizer::ESlideNone:
       
  1904             default:
       
  1905                 {
       
  1906                 slideInDir = CFsSlideEffect::ESlideNone;
       
  1907                 break;
       
  1908                 }
       
  1909             }
       
  1910         iVisualizationState = EFsTreeFadingInSlidingIn;
       
  1911         }
       
  1912     else
       
  1913         {
       
  1914         slideInTime = KZero;
       
  1915         slideInDir = CFsSlideEffect::ESlideNone;
       
  1916         }
       
  1917 
       
  1918     iFadeEffect->SetTime(fadeInTime);
       
  1919     iSlideEffect->SetTime(slideInTime);
       
  1920 
       
  1921     iFadeEffect->FadeIn();
       
  1922     iSlideEffect->SlideIn(slideInDir);
       
  1923 
       
  1924     UpdateScrollBarL();
       
  1925     }
       
  1926 // </cmail>
       
  1927 
       
  1928 // ---------------------------------------------------------------------------
       
  1929 // The function assures that the list view is correct.
       
  1930 // ---------------------------------------------------------------------------
       
  1931 //
       
  1932 void CFsTreeVisualizerBase::ValidateListLayoutL(TInt /*aTime*/)
       
  1933     {
       
  1934     FUNC_LOG;
       
  1935     }
       
  1936 
       
  1937 // ---------------------------------------------------------------------------
       
  1938 // Hides the list.
       
  1939 // ---------------------------------------------------------------------------
       
  1940 //
       
  1941 void CFsTreeVisualizerBase::HideList(const TBool aFadeOut,
       
  1942         const TBool aSlideOut)
       
  1943     {
       
  1944     FUNC_LOG;
       
  1945     iScrollBar->Show( EFalse );
       
  1946     if (iDragHandler)
       
  1947         {
       
  1948         iDragHandler->Reset();
       
  1949         }
       
  1950 
       
  1951     if (aFadeOut)
       
  1952         {
       
  1953         iFadeEffect->SetTime(iFadeOutEffectTime);
       
  1954         iVisualizationState = EFsTreeFadingOut;
       
  1955         iFadeEffect->FadeOut();
       
  1956         }
       
  1957 
       
  1958     if (aSlideOut)
       
  1959         {
       
  1960         iSlideEffect->SetTime(iSlideOutDuration);
       
  1961         if (iVisualizationState == EFsTreeFadingOut)
       
  1962             {
       
  1963             iVisualizationState = EFsTreeFadingOutSlidingOut;
       
  1964             }
       
  1965         else
       
  1966             {
       
  1967             iVisualizationState = EFsTreeSlidingOut;
       
  1968             }
       
  1969         switch (iSlideOutDirection)
       
  1970             {
       
  1971             case MFsTreeVisualizer::ESlideFromTop:
       
  1972                 {
       
  1973                 iSlideEffect->SlideOut(CFsSlideEffect::ESlideFromTop);
       
  1974                 break;
       
  1975                 }
       
  1976             case MFsTreeVisualizer::ESlideFromBottom:
       
  1977                 {
       
  1978                 iSlideEffect->SlideOut(CFsSlideEffect::ESlideFromBottom);
       
  1979                 break;
       
  1980                 }
       
  1981             case MFsTreeVisualizer::ESlideFromLeft:
       
  1982                 {
       
  1983                 iSlideEffect->SlideOut(CFsSlideEffect::ESlideFromLeft);
       
  1984                 break;
       
  1985                 }
       
  1986             case MFsTreeVisualizer::ESlideFromRight:
       
  1987                 {
       
  1988                 iSlideEffect->SlideOut(CFsSlideEffect::ESlideFromRight);
       
  1989                 break;
       
  1990                 }
       
  1991             case MFsTreeVisualizer::ESlideNone:
       
  1992             default:
       
  1993                 {
       
  1994                 iSlideEffect->SlideOut(CFsSlideEffect::ESlideNone);
       
  1995                 break;
       
  1996                 }
       
  1997             }
       
  1998         }
       
  1999 
       
  2000     if (!aFadeOut && !aSlideOut)
       
  2001         {
       
  2002         iVisualizationState = EFsTreeFadingOut;
       
  2003         iFadeEffect->SetTime(KZero);
       
  2004         iFadeEffect->FadeOut();
       
  2005         }
       
  2006     }
       
  2007 
       
  2008 // ---------------------------------------------------------------------------
       
  2009 //  The function sets duration of the slide-in effect.
       
  2010 // ---------------------------------------------------------------------------
       
  2011 //
       
  2012 void CFsTreeVisualizerBase::SetSlideInDuration(TInt aTimeMiliseconds)
       
  2013     {
       
  2014     FUNC_LOG;
       
  2015     iSlideInDuration = aTimeMiliseconds;
       
  2016     if (iSlideInDuration < KZero)
       
  2017         {
       
  2018         iSlideInDuration = KZero;
       
  2019         }
       
  2020     }
       
  2021 
       
  2022 // ---------------------------------------------------------------------------
       
  2023 //  The function returns slide in effect's duration.
       
  2024 // ---------------------------------------------------------------------------
       
  2025 //
       
  2026 TInt CFsTreeVisualizerBase::SlideInDuration() const
       
  2027     {
       
  2028     FUNC_LOG;
       
  2029     return iSlideInDuration;
       
  2030     }
       
  2031 
       
  2032 // ---------------------------------------------------------------------------
       
  2033 //  The function sets direction of the slide in effect.
       
  2034 // ---------------------------------------------------------------------------
       
  2035 //
       
  2036 void CFsTreeVisualizerBase::SetSlideInDirection(TFsSlideEffect aDirection)
       
  2037     {
       
  2038     FUNC_LOG;
       
  2039     iSlideInDirection = aDirection;
       
  2040     }
       
  2041 
       
  2042 // ---------------------------------------------------------------------------
       
  2043 //  The function returns direction of the slide in effect.
       
  2044 // ---------------------------------------------------------------------------
       
  2045 //
       
  2046 MFsTreeVisualizer::TFsSlideEffect CFsTreeVisualizerBase::SlideInDirection() const
       
  2047     {
       
  2048     FUNC_LOG;
       
  2049     return iSlideInDirection;
       
  2050     }
       
  2051 
       
  2052 // ---------------------------------------------------------------------------
       
  2053 //  The function sets duration of the slide-out effect.
       
  2054 // ---------------------------------------------------------------------------
       
  2055 //
       
  2056 void CFsTreeVisualizerBase::SetSlideOutDuration(TInt aTimeMiliseconds)
       
  2057     {
       
  2058     FUNC_LOG;
       
  2059     iSlideOutDuration = aTimeMiliseconds;
       
  2060     if (iSlideOutDuration < 0)
       
  2061         {
       
  2062         iSlideOutDuration = 0;
       
  2063         }
       
  2064     }
       
  2065 
       
  2066 // ---------------------------------------------------------------------------
       
  2067 //  The function returns slide out effect's duration.
       
  2068 // ---------------------------------------------------------------------------
       
  2069 //
       
  2070 TInt CFsTreeVisualizerBase::SlideOutDuration() const
       
  2071     {
       
  2072     FUNC_LOG;
       
  2073     return iSlideOutDuration;
       
  2074     }
       
  2075 
       
  2076 // ---------------------------------------------------------------------------
       
  2077 //  The function sets direction of the slide out effect.
       
  2078 // ---------------------------------------------------------------------------
       
  2079 //
       
  2080 void CFsTreeVisualizerBase::SetSlideOutDirection(TFsSlideEffect aDirection)
       
  2081     {
       
  2082     FUNC_LOG;
       
  2083     iSlideOutDirection = aDirection;
       
  2084     }
       
  2085 
       
  2086 // ---------------------------------------------------------------------------
       
  2087 //  The function returns direction of the slide out effect.
       
  2088 // ---------------------------------------------------------------------------
       
  2089 //
       
  2090 MFsTreeVisualizer::TFsSlideEffect CFsTreeVisualizerBase::SlideOutDirection() const
       
  2091     {
       
  2092     return iSlideOutDirection;
       
  2093     }
       
  2094 
       
  2095 // ---------------------------------------------------------------------------
       
  2096 // Returns information about looping type of the list.
       
  2097 // ---------------------------------------------------------------------------
       
  2098 //
       
  2099 TFsTreeListLoopingType CFsTreeVisualizerBase::LoopingType() const
       
  2100     {
       
  2101     FUNC_LOG;
       
  2102     return iLooping;
       
  2103     }
       
  2104 
       
  2105 // ---------------------------------------------------------------------------
       
  2106 // Sets type of list's looping.
       
  2107 // ---------------------------------------------------------------------------
       
  2108 //
       
  2109 void CFsTreeVisualizerBase::SetLoopingType(
       
  2110         const TFsTreeListLoopingType aLoopingType)
       
  2111     {
       
  2112     FUNC_LOG;
       
  2113     iLooping = aLoopingType;
       
  2114     }
       
  2115 
       
  2116 // ---------------------------------------------------------------------------
       
  2117 // Sets item expansion delay.
       
  2118 // ---------------------------------------------------------------------------
       
  2119 //
       
  2120 void CFsTreeVisualizerBase::SetItemExpansionDelay(const TInt aDelay)
       
  2121     {
       
  2122     FUNC_LOG;
       
  2123     iScrollSpeed = aDelay;
       
  2124     if (iScrollSpeed < 0)
       
  2125         {
       
  2126         iScrollSpeed = 0;
       
  2127         }
       
  2128 
       
  2129     iCurrentScrollSpeed = iScrollSpeed;
       
  2130     iScrollAccelerationRate = 0.5;
       
  2131     }
       
  2132 
       
  2133 // ---------------------------------------------------------------------------
       
  2134 // Sets an item separator color.
       
  2135 // ---------------------------------------------------------------------------
       
  2136 //
       
  2137 void CFsTreeVisualizerBase::SetItemSeparatorColor(const TRgb& aColor)
       
  2138     {
       
  2139     FUNC_LOG;
       
  2140     static_cast<CAlfBorderBrush*> (iBorderBrush)->SetColor(aColor);
       
  2141     }
       
  2142 
       
  2143 // ---------------------------------------------------------------------------
       
  2144 // Sets an item separator size.
       
  2145 // ---------------------------------------------------------------------------
       
  2146 //
       
  2147 void CFsTreeVisualizerBase::SetItemSeparatorSize(const TSize aSize)
       
  2148     {
       
  2149     FUNC_LOG;
       
  2150     static_cast<CAlfBorderBrush*> (iBorderBrush)->SetThickness(
       
  2151             TAlfTimedPoint(aSize.iWidth, aSize.iHeight));
       
  2152     }
       
  2153 
       
  2154 // ---------------------------------------------------------------------------
       
  2155 // Sets an item separator size.
       
  2156 // ---------------------------------------------------------------------------
       
  2157 //
       
  2158 void CFsTreeVisualizerBase::SetItemSeparatorSize(
       
  2159         const TAlfTimedPoint& aThickness)
       
  2160     {
       
  2161     FUNC_LOG;
       
  2162     static_cast<CAlfBorderBrush*> (iBorderBrush)->SetThickness(aThickness);
       
  2163     }
       
  2164 
       
  2165 // ---------------------------------------------------------------------------
       
  2166 // The functions sets fade-in's effect duration.
       
  2167 // ---------------------------------------------------------------------------
       
  2168 //
       
  2169 void CFsTreeVisualizerBase::SetFadeInEffectTime(TInt aFadeTime)
       
  2170     {
       
  2171     FUNC_LOG;
       
  2172     if (aFadeTime < 0)
       
  2173         {
       
  2174         iFadeInEffectTime = 0;
       
  2175         }
       
  2176     else
       
  2177         {
       
  2178         iFadeInEffectTime = aFadeTime;
       
  2179         }
       
  2180     }
       
  2181 
       
  2182 // ---------------------------------------------------------------------------
       
  2183 // The functions returns fade-in's effect duration.
       
  2184 // ---------------------------------------------------------------------------
       
  2185 //
       
  2186 TInt CFsTreeVisualizerBase::FadeInEffectTime()
       
  2187     {
       
  2188     FUNC_LOG;
       
  2189     return iFadeInEffectTime;
       
  2190     }
       
  2191 
       
  2192 // ---------------------------------------------------------------------------
       
  2193 // The functions sets fade-out's effect duration.
       
  2194 // ---------------------------------------------------------------------------
       
  2195 //
       
  2196 void CFsTreeVisualizerBase::SetFadeOutEffectTime(TInt aFadeTime)
       
  2197     {
       
  2198     FUNC_LOG;
       
  2199     if (aFadeTime < 0)
       
  2200         {
       
  2201         iFadeOutEffectTime = 0;
       
  2202         }
       
  2203     else
       
  2204         {
       
  2205         iFadeOutEffectTime = aFadeTime;
       
  2206         }
       
  2207     }
       
  2208 
       
  2209 // ---------------------------------------------------------------------------
       
  2210 // The functions returns fade-out's effect duration.
       
  2211 // ---------------------------------------------------------------------------
       
  2212 //
       
  2213 TInt CFsTreeVisualizerBase::FadeOutEffectTime()
       
  2214     {
       
  2215     FUNC_LOG;
       
  2216     return iFadeOutEffectTime;
       
  2217     }
       
  2218 
       
  2219 // ---------------------------------------------------------------------------
       
  2220 // Function sets the time of list scroll per item and the scroll
       
  2221 // acceleration rate.
       
  2222 // ---------------------------------------------------------------------------
       
  2223 //
       
  2224 void CFsTreeVisualizerBase::SetScrollTime(TInt aScrollTime,
       
  2225         TReal aScrollAcceleration)
       
  2226     {
       
  2227     FUNC_LOG;
       
  2228     iScrollSpeed = aScrollTime;
       
  2229     if (iScrollSpeed < 0)
       
  2230         {
       
  2231         iScrollSpeed = 0;
       
  2232         }
       
  2233 
       
  2234     iCurrentScrollSpeed = iScrollSpeed;
       
  2235     iScrollAccelerationRate = aScrollAcceleration;
       
  2236     if (iScrollAccelerationRate < 0.0)
       
  2237         {
       
  2238         iScrollAccelerationRate = 0.0;
       
  2239         }
       
  2240     else if (iScrollAccelerationRate > 1.0)
       
  2241         {
       
  2242         iScrollAccelerationRate = 1.0;
       
  2243         }
       
  2244     }
       
  2245 
       
  2246 // ---------------------------------------------------------------------------
       
  2247 // Gets the item expansion delay.
       
  2248 // ---------------------------------------------------------------------------
       
  2249 //
       
  2250 TInt CFsTreeVisualizerBase::ItemExpansionDelay() const
       
  2251     {
       
  2252     FUNC_LOG;
       
  2253     return iScrollSpeed;
       
  2254     }
       
  2255 
       
  2256 // ---------------------------------------------------------------------------
       
  2257 // Function gets the values of scroll speed and its acceleration rate.
       
  2258 // ---------------------------------------------------------------------------
       
  2259 //
       
  2260 void CFsTreeVisualizerBase::GetScrollTime(TInt& aScrollTime,
       
  2261         TReal& aScrollAcceleration)
       
  2262     {
       
  2263     FUNC_LOG;
       
  2264     aScrollTime = iScrollSpeed;
       
  2265     aScrollAcceleration = iScrollAccelerationRate;
       
  2266     }
       
  2267 
       
  2268 // ---------------------------------------------------------------------------
       
  2269 // Expand the node.
       
  2270 // ---------------------------------------------------------------------------
       
  2271 //
       
  2272 void CFsTreeVisualizerBase::ExpandNodeL(const TFsTreeItemId aNodeId)
       
  2273     {
       
  2274     FUNC_LOG;
       
  2275     MFsTreeNodeVisualizer* nodeVisualizer =
       
  2276             iTreeData->NodeVisualizer(aNodeId);
       
  2277     TRect rc;
       
  2278     TInt index = iWorld.GetItemRect(aNodeId, rc);
       
  2279     if (!nodeVisualizer->IsExpanded() && index != KErrNotFound )
       
  2280         {
       
  2281         nodeVisualizer->SetExpanded(ETrue, &iTreeData->ItemData(aNodeId));
       
  2282 
       
  2283         TFsTreeIterator treeIter = iTreeData->Iterator(aNodeId, aNodeId,
       
  2284                 KFsTreeIteratorSkipHiddenFlag);
       
  2285         if (treeIter.HasNext())
       
  2286             {
       
  2287             TPoint position;
       
  2288             if (iFocusedItem != KFsTreeNoneID)
       
  2289                 {
       
  2290                 position = iViewPort.ItemRect(iFocusedItem).iTl;
       
  2291                 }
       
  2292             iWorld.BeginUpdate();
       
  2293             TFsTreeItemId itemId;
       
  2294             TSize size;
       
  2295             do
       
  2296                 {
       
  2297                 itemId = treeIter.Next();
       
  2298                 ++index;
       
  2299                 MFsTreeItemVisualizer* itemviz =
       
  2300                         iTreeData->ItemVisualizer(itemId);
       
  2301                 ApplyListSpecificValuesToItem(itemviz);
       
  2302                 size = itemviz->Size();
       
  2303                 iWorld.InsertL(itemId, size, index);
       
  2304                 } while (treeIter.HasNext());
       
  2305             if (iFocusedItem != KFsTreeNoneID)
       
  2306                 {
       
  2307                 iViewPort.ItemToPositionL(iFocusedItem, position, EFalse,
       
  2308                         TViewPort::EPositionAfterExpand);
       
  2309                 }
       
  2310             iWorld.EndUpdateL();
       
  2311 
       
  2312             if ( iVisualizerObserver )
       
  2313                 {
       
  2314                 iVisualizerObserver->TreeVisualizerEventL(
       
  2315                         MFsTreeVisualizerObserver::EFsTreeListItemExpanded,
       
  2316                         aNodeId );
       
  2317                 }
       
  2318             }
       
  2319         }
       
  2320     }
       
  2321 
       
  2322 // ---------------------------------------------------------------------------
       
  2323 // Collapse the node.
       
  2324 // ---------------------------------------------------------------------------
       
  2325 //
       
  2326 void CFsTreeVisualizerBase::CollapseNodeL(const TFsTreeItemId aNodeId)
       
  2327     {
       
  2328     FUNC_LOG;
       
  2329     MFsTreeNodeVisualizer* nodeVisualizer =
       
  2330             iTreeData->NodeVisualizer(aNodeId);
       
  2331     if (nodeVisualizer->IsExpanded())
       
  2332         {
       
  2333         TFsTreeIterator treeIter = iTreeData->Iterator(aNodeId, aNodeId,
       
  2334                 KFsTreeIteratorSkipHiddenFlag);
       
  2335         nodeVisualizer->SetExpanded(EFalse, &iTreeData->ItemData(aNodeId));
       
  2336         if (treeIter.HasNext())
       
  2337             {
       
  2338             iWorld.BeginUpdate();
       
  2339             TFsTreeItemId itemId;
       
  2340             TSize size;
       
  2341             do
       
  2342                 {
       
  2343                 itemId = treeIter.Next();
       
  2344                 if (itemId != KFsTreeNoneID)
       
  2345                     {
       
  2346                     iWorld.RemoveL(itemId);
       
  2347                     }
       
  2348                 } while (treeIter.HasNext());
       
  2349             iWorld.EndUpdateL();
       
  2350 
       
  2351             if ( iVisualizerObserver )
       
  2352                 {
       
  2353                 iVisualizerObserver->TreeVisualizerEventL(
       
  2354                         MFsTreeVisualizerObserver::EFsTreeListItemCollapsed,
       
  2355                         aNodeId );
       
  2356                 }
       
  2357             }
       
  2358         }
       
  2359     }
       
  2360 
       
  2361 // ---------------------------------------------------------------------------
       
  2362 // Expand all nodes in the tree.
       
  2363 // ---------------------------------------------------------------------------
       
  2364 //
       
  2365 void CFsTreeVisualizerBase::ExpandAllL()
       
  2366     {
       
  2367     FUNC_LOG;
       
  2368     iWorld.BeginUpdate();
       
  2369     TPoint position;
       
  2370 
       
  2371     if( iFocusedItem != KFsTreeNoneID )
       
  2372         {
       
  2373         position = iViewPort.ItemRect(iFocusedItem).iTl;
       
  2374         }
       
  2375     iWorld.RemoveAllL();
       
  2376     TFsTreeIterator treeIter = iTreeData->Iterator(
       
  2377         KFsTreeRootID, KFsTreeRootID );
       
  2378     TFsTreeItemId itemId = KFsTreeNoneID;
       
  2379     TSize size;
       
  2380     while( treeIter.HasNext() )
       
  2381         {
       
  2382         itemId = treeIter.Next();
       
  2383         if( itemId != KFsTreeNoneID )
       
  2384             {
       
  2385             if( iTreeData->IsNode( itemId ) )
       
  2386                 {
       
  2387                 MFsTreeNodeVisualizer* nodeviz = iTreeData->NodeVisualizer(
       
  2388                         itemId);
       
  2389                 nodeviz->SetExpanded( ETrue, &iTreeData->ItemData( itemId ) );
       
  2390                 size = nodeviz->Size();
       
  2391                 }
       
  2392             else
       
  2393                 {
       
  2394                 MFsTreeItemVisualizer* itemviz =
       
  2395                     iTreeData->ItemVisualizer( itemId );
       
  2396                 size = itemviz->Size();
       
  2397                 }
       
  2398             iWorld.AppendL( itemId, size );
       
  2399             }
       
  2400         }
       
  2401 
       
  2402     if( iFocusedItem != KFsTreeNoneID )
       
  2403         {
       
  2404         iViewPort.ItemToPositionL(iFocusedItem, position, EFalse,
       
  2405                 TViewPort::EPositionAfterExpand );
       
  2406         }
       
  2407     iWorld.EndUpdateL();
       
  2408 
       
  2409     if ( iVisualizerObserver )
       
  2410         {
       
  2411         iVisualizerObserver->TreeVisualizerEventL(
       
  2412                 MFsTreeVisualizerObserver::EFsTreeListExpandedAll );
       
  2413         }
       
  2414     }
       
  2415 
       
  2416 // ---------------------------------------------------------------------------
       
  2417 // Collapse all nodes in the tree.
       
  2418 // ---------------------------------------------------------------------------
       
  2419 //
       
  2420 void CFsTreeVisualizerBase::CollapseAllL()
       
  2421     {
       
  2422     FUNC_LOG;
       
  2423     iWorld.BeginUpdate();
       
  2424     TPoint position;
       
  2425 
       
  2426     if( iFocusedItem != KFsTreeNoneID )
       
  2427         {
       
  2428         position = iViewPort.ItemRect( iFocusedItem ).iTl;
       
  2429         }
       
  2430     iWorld.RemoveAllL();
       
  2431     if( iTreeData->Count() > 0 )
       
  2432         {
       
  2433         const TUint childcount = iTreeData->CountChildren( KFsTreeRootID );
       
  2434         for( TUint i( 0 ); i < childcount; ++i )
       
  2435             {
       
  2436             TFsTreeItemId itemId = iTreeData->Child( KFsTreeRootID, i );
       
  2437             TSize itemSize;
       
  2438             if( iTreeData->IsNode( itemId ) )
       
  2439                 {
       
  2440                 MFsTreeNodeVisualizer* nodeVis =
       
  2441                     iTreeData->NodeVisualizer( itemId );
       
  2442                 nodeVis->SetExpanded( EFalse, &iTreeData->ItemData( itemId ) );
       
  2443                 itemSize = nodeVis->Size();
       
  2444                 }
       
  2445             else
       
  2446                 {
       
  2447                 itemSize = iTreeData->ItemVisualizer( itemId )->Size();
       
  2448                 }
       
  2449             iWorld.AppendL(itemId, itemSize);
       
  2450             }
       
  2451         }
       
  2452 
       
  2453     if( iFocusedItem != KFsTreeNoneID )
       
  2454         {
       
  2455         // If item, which was selected, wasn't node, then make its parent node
       
  2456         // focused, if it doesn't have parent node or its parent is not a node
       
  2457         // then leave focus as it was.
       
  2458         if( !iTreeData->IsNode( iFocusedItem ) )
       
  2459             {
       
  2460             TFsTreeItemId parentId = iTreeData->Parent( iFocusedItem );
       
  2461             if( iTreeData->IsNode( parentId ) )
       
  2462                 {
       
  2463                 SetFocusedItemL( parentId );
       
  2464                 position = iViewPort.ItemRect( iFocusedItem ).iTl;
       
  2465                 }
       
  2466             }
       
  2467         iViewPort.ItemToPositionL( iFocusedItem, position, EFalse );
       
  2468         }
       
  2469 
       
  2470     iWorld.EndUpdateL();
       
  2471 
       
  2472     if ( iVisualizerObserver )
       
  2473         {
       
  2474         iVisualizerObserver->TreeVisualizerEventL(
       
  2475                 MFsTreeVisualizerObserver::EFsTreeListCollapsedAll );
       
  2476         }
       
  2477     }
       
  2478 
       
  2479 // ---------------------------------------------------------------------------
       
  2480 //
       
  2481 //
       
  2482 // ---------------------------------------------------------------------------
       
  2483 //
       
  2484 TBool CFsTreeVisualizerBase::AllNodesCollapsed() const
       
  2485     {
       
  2486     FUNC_LOG;
       
  2487     TFsTreeIterator treeIter = iTreeData->Iterator(KFsTreeRootID,
       
  2488             KFsTreeRootID, KFsTreeIteratorSkipCollapsedFlag
       
  2489                     | KFsTreeIteratorSkipHiddenFlag);
       
  2490     TFsTreeItemId itemId = KFsTreeNoneID;
       
  2491     while (treeIter.HasNext())
       
  2492         {
       
  2493         itemId = treeIter.Next();
       
  2494         if (!iTreeData->IsNode(itemId))
       
  2495             {
       
  2496             return EFalse;
       
  2497             }
       
  2498         }
       
  2499     return ETrue;
       
  2500     }
       
  2501 
       
  2502 // ---------------------------------------------------------------------------
       
  2503 //
       
  2504 //
       
  2505 // ---------------------------------------------------------------------------
       
  2506 //
       
  2507 TBool CFsTreeVisualizerBase::AllNodesExpanded() const
       
  2508     {
       
  2509     FUNC_LOG;
       
  2510     return iWorld.ItemCount() == iTreeData->Count();
       
  2511     }
       
  2512 
       
  2513 // ---------------------------------------------------------------------------
       
  2514 // Update visual of the item given by id.
       
  2515 // ---------------------------------------------------------------------------
       
  2516 //
       
  2517 void CFsTreeVisualizerBase::UpdateItemL(const TFsTreeItemId aItemId)
       
  2518     {
       
  2519     FUNC_LOG;
       
  2520     TInt i = iVisibleItems.Find(aItemId);
       
  2521     if (i != KErrNotFound)
       
  2522         {
       
  2523         MFsTreeItemVisualizer* vis = iTreeData->ItemVisualizer(aItemId);
       
  2524         if (vis)
       
  2525             {
       
  2526             vis->UpdateL(iTreeData->ItemData(aItemId),
       
  2527                     IsItemFocused(aItemId) && IsFocusShown(),
       
  2528                     iTreeData->Level(aItemId),
       
  2529                     iMarkIcon, iMenuIcon, 0);
       
  2530             }
       
  2531         }
       
  2532     }
       
  2533 
       
  2534 // ---------------------------------------------------------------------------
       
  2535 //  The functions sets wether all item in the list should be always in
       
  2536 //  extended state or in normal state.
       
  2537 // ---------------------------------------------------------------------------
       
  2538 //
       
  2539 void CFsTreeVisualizerBase::SetItemsAlwaysExtendedL(TBool aAlwaysExtended)
       
  2540     {
       
  2541     FUNC_LOG;
       
  2542     // Do not change this to: IsItemsAlwaysExtended() != aAlwaysExtended, because
       
  2543     // it will not work. TBool is defined as TInt and thus this comparison
       
  2544     // comes out as TInt != TInt, which always evaluates true in this case.
       
  2545     if ( ( IsItemsAlwaysExtended() && !aAlwaysExtended ) || 
       
  2546          ( !IsItemsAlwaysExtended() && aAlwaysExtended ) )
       
  2547         {
       
  2548         iFlags.Assign(EItemsAlwaysExtended, aAlwaysExtended);
       
  2549         TFsTreeIterator treeIter(
       
  2550                 iTreeData->Iterator(KFsTreeRootID, KFsTreeRootID));
       
  2551         while (treeIter.HasNext())
       
  2552             {
       
  2553             TFsTreeItemId itemId(treeIter.Next());
       
  2554             if (itemId != KFsTreeNoneID && !iTreeData->IsNode(itemId))
       
  2555                 {
       
  2556                 MFsTreeItemVisualizer* itemviz(iTreeData->ItemVisualizer(itemId));
       
  2557                 ApplyListSpecificValuesToItem(itemviz);
       
  2558                 }
       
  2559             }
       
  2560             const TBool isUpdating(iWorld.IsUpdating());
       
  2561         if (!isUpdating)
       
  2562             {
       
  2563             iWorld.BeginUpdate();
       
  2564             }
       
  2565         iWorld.RemoveAllL();
       
  2566         treeIter = iTreeData->Iterator(KFsTreeRootID, KFsTreeRootID,
       
  2567                 KFsTreeIteratorSkipCollapsedFlag);
       
  2568         while (treeIter.HasNext())
       
  2569             {
       
  2570             TFsTreeItemId itemId(treeIter.Next());
       
  2571             if (itemId != KFsTreeNoneID)
       
  2572                 {
       
  2573                 MFsTreeItemVisualizer* itemviz(iTreeData->ItemVisualizer(itemId));
       
  2574                 iWorld.AppendL(itemId, itemviz->Size());
       
  2575                 }
       
  2576             }
       
  2577             // Below line commetned out. ViewPort is now not moved to the top of mail list
       
  2578             //iViewPort.SetPositionL(TPoint(), EFalse);
       
  2579         iViewPort.ClearCache();
       
  2580         if (!isUpdating)
       
  2581             {
       
  2582             iWorld.EndUpdateL();
       
  2583             }
       
  2584         }
       
  2585     }
       
  2586 
       
  2587 // ---------------------------------------------------------------------------
       
  2588 //  The function returns if items are always in extended state or in normal.
       
  2589 // ---------------------------------------------------------------------------
       
  2590 //
       
  2591 TBool CFsTreeVisualizerBase::IsItemsAlwaysExtended()
       
  2592     {
       
  2593     FUNC_LOG;
       
  2594     return iFlags.IsSet(EItemsAlwaysExtended);
       
  2595     }
       
  2596 
       
  2597 // ---------------------------------------------------------------------------
       
  2598 // Set the background texture, clears the background color.
       
  2599 // ---------------------------------------------------------------------------
       
  2600 //
       
  2601 EXPORT_C void CFsTreeVisualizerBase::SetBackgroundTextureL(CAlfTexture& /*aBgTexture*/)
       
  2602     {
       
  2603     FUNC_LOG;
       
  2604     }
       
  2605 
       
  2606 // ---------------------------------------------------------------------------
       
  2607 // Sets the background color, clears the background texture.
       
  2608 // ---------------------------------------------------------------------------
       
  2609 //
       
  2610 EXPORT_C void CFsTreeVisualizerBase::SetBackgroundColorL(TRgb aColor)
       
  2611     {
       
  2612     FUNC_LOG;
       
  2613     if (iWatermarkLayout && iWatermarkLayout->Brushes())
       
  2614         {
       
  2615         TInt count = iWatermarkLayout->Brushes()->Count();
       
  2616         if (count > 0)
       
  2617             {//there is only background brush attached to this layout
       
  2618             iWatermarkLayout->Brushes()->Remove(KZero);
       
  2619             iWatermarkLayout->Brushes()->Reset();
       
  2620             iWatermarkLayout->SetFlag(EAlfVisualChanged);
       
  2621             }
       
  2622 
       
  2623     CAlfGradientBrush* backgroundBrush = CAlfGradientBrush::NewL(
       
  2624             iOwnerControl->Env());
       
  2625     backgroundBrush->SetLayer(EAlfBrushLayerBackground);
       
  2626     backgroundBrush->SetColor(aColor);
       
  2627 
       
  2628     iWatermarkLayout->Brushes()->AppendL(backgroundBrush, EAlfHasOwnership);
       
  2629         }
       
  2630     }
       
  2631 
       
  2632 // ---------------------------------------------------------------------------
       
  2633 // Sets a given brush as a list background.
       
  2634 // ---------------------------------------------------------------------------
       
  2635 //
       
  2636 EXPORT_C void CFsTreeVisualizerBase::SetBackgroundBrushL(CAlfBrush* aBrush)
       
  2637     {
       
  2638     FUNC_LOG;
       
  2639 
       
  2640     if (iWatermarkLayout && iWatermarkLayout->Brushes())
       
  2641         {
       
  2642         TInt count = iWatermarkLayout->Brushes()->Count();
       
  2643         if (count > 0)
       
  2644             {//there is only background brush attached to this layout
       
  2645             iWatermarkLayout->Brushes()->Remove(KZero);
       
  2646             iWatermarkLayout->Brushes()->Reset();
       
  2647             iWatermarkLayout->SetFlag(EAlfVisualChanged);
       
  2648             }
       
  2649         }
       
  2650 
       
  2651     aBrush->SetLayer(EAlfBrushLayerBackground);
       
  2652     iWatermarkLayout->Brushes()->AppendL(aBrush, EAlfHasOwnership);
       
  2653     }
       
  2654 
       
  2655 // ---------------------------------------------------------------------------
       
  2656 // The function clears list's background.
       
  2657 // ---------------------------------------------------------------------------
       
  2658 //
       
  2659 EXPORT_C void CFsTreeVisualizerBase::ClearBackground()
       
  2660     {
       
  2661     FUNC_LOG;
       
  2662     if (iWatermarkLayout && iWatermarkLayout->Brushes())
       
  2663         {
       
  2664         TInt count = iWatermarkLayout->Brushes()->Count();
       
  2665         if (count > 0)
       
  2666             {//there is only background brush attached to this layout
       
  2667             iWatermarkLayout->Brushes()->Remove(KZero);
       
  2668             iWatermarkLayout->Brushes()->Reset();
       
  2669             iWatermarkLayout->SetFlag(EAlfVisualChanged);
       
  2670             }
       
  2671         }
       
  2672     }
       
  2673 
       
  2674 // ---------------------------------------------------------------------------
       
  2675 // Sets watermark position.
       
  2676 // ---------------------------------------------------------------------------
       
  2677 //
       
  2678 EXPORT_C void CFsTreeVisualizerBase::SetWatermarkPos(const TPoint& aPosition)
       
  2679     {
       
  2680     FUNC_LOG;
       
  2681     if (iWatermark)
       
  2682         {
       
  2683         TAlfTimedPoint position;
       
  2684         position.SetTarget(TAlfRealPoint(aPosition));
       
  2685         iWatermark->SetPos(position);
       
  2686         }
       
  2687     }
       
  2688 
       
  2689 // ---------------------------------------------------------------------------
       
  2690 // Sets watermark's size.
       
  2691 // ---------------------------------------------------------------------------
       
  2692 //
       
  2693 EXPORT_C void CFsTreeVisualizerBase::SetWatermarkSize(const TSize& aSize)
       
  2694     {
       
  2695     FUNC_LOG;
       
  2696     if (iWatermark)
       
  2697         {
       
  2698         TAlfTimedPoint size;
       
  2699         size.SetTarget(TAlfRealPoint(aSize.AsPoint()));
       
  2700         iWatermark->SetSize(size);
       
  2701         }
       
  2702     }
       
  2703 
       
  2704 // ---------------------------------------------------------------------------
       
  2705 // Sets watermark opacity.
       
  2706 // ---------------------------------------------------------------------------
       
  2707 //
       
  2708 EXPORT_C void CFsTreeVisualizerBase::SetWatermarkOpacity(const float aOpacity)
       
  2709     {
       
  2710     FUNC_LOG;
       
  2711     if (iWatermark)
       
  2712         {
       
  2713         TAlfTimedValue opacity;
       
  2714         opacity.SetTarget(aOpacity, 0);
       
  2715         iWatermark->SetOpacity(opacity);
       
  2716         }
       
  2717     }
       
  2718 
       
  2719 // ---------------------------------------------------------------------------
       
  2720 // Sets watermark texture.
       
  2721 // ---------------------------------------------------------------------------
       
  2722 //
       
  2723 EXPORT_C void CFsTreeVisualizerBase::SetWatermarkL(CAlfTexture* aTexture)
       
  2724     {
       
  2725     FUNC_LOG;
       
  2726     if (aTexture)
       
  2727         {
       
  2728         if (!iWatermark)
       
  2729             {
       
  2730             iWatermark
       
  2731                     = CFsWatermark::NewL(*iOwnerControl, *iWatermarkLayout);
       
  2732             }
       
  2733         // <cmail>
       
  2734         iWatermark->SetWatermarkTextureL(*aTexture);
       
  2735         // </cmail>
       
  2736         }
       
  2737     else
       
  2738         {
       
  2739         delete iWatermark;
       
  2740         iWatermark = NULL;
       
  2741         }
       
  2742     }
       
  2743 
       
  2744 // ---------------------------------------------------------------------------
       
  2745 //
       
  2746 // ---------------------------------------------------------------------------
       
  2747 //
       
  2748 void CFsTreeVisualizerBase::TreeEventL(
       
  2749     const TFsTreeEvent aEvent,
       
  2750     const MFsTreeObserver::TFsTreeEventParams& aParams)
       
  2751     {
       
  2752     FUNC_LOG;
       
  2753     switch (aEvent)
       
  2754         {
       
  2755         case EFsTreeItemAdded:
       
  2756         case EFsTreeNodeAdded:
       
  2757             {
       
  2758             MFsTreeItemVisualizer* itemVisualizer(iTreeData->ItemVisualizer(
       
  2759                     aParams.iItemId));
       
  2760             const TBool isHidden(itemVisualizer->IsHidden());
       
  2761             if (!isHidden)
       
  2762                 {
       
  2763                 if (!iListLayout->Count())
       
  2764                     {
       
  2765                     // Hide empty list marker
       
  2766                     iRootVisualizer->Hide();
       
  2767                     iComponentLayout->UpdateChildrenLayout();
       
  2768                     iListLayout->UpdateChildrenLayout();
       
  2769                     }
       
  2770                 if (aParams.iTargetNodeId != KFsTreeRootID)
       
  2771                     {
       
  2772                     MFsTreeNodeVisualizer* nodeVisualizer =
       
  2773                             iTreeData->NodeVisualizer(aParams.iTargetNodeId);
       
  2774                     if (nodeVisualizer->IsExpanded())
       
  2775                         {
       
  2776                         // look for parent's index
       
  2777                         TInt indexAdd = 0;
       
  2778                         while (iWorld.Item(indexAdd) != aParams.iTargetNodeId)
       
  2779                             {
       
  2780                             indexAdd++;
       
  2781                             }
       
  2782 
       
  2783                         // look for how many children parent already has in
       
  2784                         // the tree model
       
  2785                         TInt childCount( 0 );
       
  2786                         if ( aParams.iIndex >= 0 )
       
  2787                             {
       
  2788                             childCount = aParams.iIndex;
       
  2789                             }
       
  2790                         else
       
  2791                             {
       
  2792                             // -1 is for excluding the item that is now being
       
  2793                             // inserted to visualiser
       
  2794                             // (it has already been inserted to the tree model)
       
  2795                             childCount = iTreeData->CountChildrenRecursively(
       
  2796                                 aParams.iTargetNodeId ) - 1;
       
  2797                             }
       
  2798 
       
  2799                         InsertItemL( aParams.iItemId, indexAdd + 1 + childCount );
       
  2800                         }
       
  2801                     }
       
  2802                 else if (iWorld.ItemCount() > 0)
       
  2803                     {
       
  2804                     if (aParams.iIndex >= 0)
       
  2805                         {
       
  2806                         TInt indexAdd = 0;
       
  2807                         TInt nodeCount = 0;
       
  2808                         while (indexAdd < iWorld.ItemCount() - 1 && nodeCount
       
  2809                                 != aParams.iIndex)
       
  2810                             {
       
  2811                             indexAdd++;
       
  2812                             if (iTreeData->Parent(iWorld.Item(indexAdd))
       
  2813                                     == KFsTreeRootID)
       
  2814                                 {
       
  2815                                 nodeCount++;
       
  2816                                 }
       
  2817                             }
       
  2818                         InsertItemL(aParams.iItemId, indexAdd);
       
  2819                         }
       
  2820                     else
       
  2821                         {
       
  2822                         InsertItemL(aParams.iItemId, KErrNotFound);
       
  2823                         }
       
  2824                     }
       
  2825                 else
       
  2826                     {
       
  2827                     InsertItemL(aParams.iItemId, aParams.iIndex);
       
  2828                     }
       
  2829                 }
       
  2830             }
       
  2831             break;
       
  2832         case EFsTreeItemRemoved:
       
  2833         case EFsTreeNodeRemoved:
       
  2834             {
       
  2835             RemoveItemL(aParams.iItemId);
       
  2836             }
       
  2837             break;
       
  2838         case EFsTreeRemovedAll:
       
  2839             {
       
  2840             if ( iPhysics )
       
  2841                 {
       
  2842                 iPhysics->StopPhysics();
       
  2843                 }
       
  2844             if (!iWorld.IsUpdating())
       
  2845                 {
       
  2846                 iRootVisualizer->ShowL(*iRootLayout);
       
  2847                 iRootVisualizer->UpdateL(*iRootData, EFalse, 0, iMarkIcon,
       
  2848                         iMenuIcon);
       
  2849                 }
       
  2850             iVisibleItems.Reset();
       
  2851             iWorld.RemoveAllL();
       
  2852             iFocusedItem = KFsTreeNoneID;
       
  2853             }
       
  2854             break;
       
  2855         case EFsTreeItemVisualizerChanged:
       
  2856             //the selector visual will be destroyed only when changing visualizer
       
  2857             if (aParams.iItemId == iFocusedItem)
       
  2858                 {
       
  2859                 iSelectorVisual = NULL;
       
  2860                 }
       
  2861         case EFsTreeItemDataChanged:
       
  2862             {
       
  2863             const TFsTreeItemId itemId(aParams.iItemId);
       
  2864             MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(
       
  2865                     itemId);
       
  2866             if (visualizer)
       
  2867                 {
       
  2868                 visualizer->UpdateL(iTreeData->ItemData(itemId),
       
  2869                         IsItemFocused(itemId), iTreeData->Level(itemId),
       
  2870                         iMarkIcon, iMenuIcon, 0);
       
  2871                 }
       
  2872             }
       
  2873             break;
       
  2874 
       
  2875         default:
       
  2876             break;
       
  2877         }
       
  2878     }
       
  2879 
       
  2880 // ---------------------------------------------------------------------------
       
  2881 // The function implements tree observer's reaction to removing a list item
       
  2882 // from the model. If the item was visible then it's removed from the visible
       
  2883 // area. If the focused item was removed then the focus is moved to the next
       
  2884 // item in the tree hierarchy (if the next item is not present, then the focus
       
  2885 // is moved to the previous one).
       
  2886 // ---------------------------------------------------------------------------
       
  2887 //
       
  2888 void CFsTreeVisualizerBase::RemoveItemL(TFsTreeItemId aItemId)
       
  2889     {
       
  2890     FUNC_LOG;
       
  2891     const TInt removedindex(iWorld.IndexOfItem(aItemId));
       
  2892     iWorld.RemoveL(aItemId);
       
  2893     if (iFocusedItem == aItemId)
       
  2894         {
       
  2895         if ( iWorld.ItemCount() > removedindex && removedindex != KErrNotFound )
       
  2896             {
       
  2897             SetFocusedItemL(iWorld.Item(removedindex), EFalse);
       
  2898             }
       
  2899         else if ( iWorld.ItemCount() > 0 && removedindex != KErrNotFound )
       
  2900             {
       
  2901             SetFocusedItemL(iWorld.Item(removedindex - 1), EFalse);
       
  2902             }
       
  2903         else
       
  2904             {
       
  2905             iFocusedItem = KFsTreeNoneID;
       
  2906             }
       
  2907         }
       
  2908     }
       
  2909 
       
  2910 // ---------------------------------------------------------------------------
       
  2911 //  The function checks whether the focused item is not outside the visible
       
  2912 //  area and if needed scrolls the list so that selected item is fully visible.
       
  2913 // ---------------------------------------------------------------------------
       
  2914 //
       
  2915 void CFsTreeVisualizerBase::MakeFocusedItemFullyVisible()
       
  2916     {
       
  2917     FUNC_LOG;
       
  2918     }
       
  2919 
       
  2920 // ---------------------------------------------------------------------------
       
  2921 //
       
  2922 // ---------------------------------------------------------------------------
       
  2923 //
       
  2924 void CFsTreeVisualizerBase::RefreshListViewL()
       
  2925     {
       
  2926     FUNC_LOG;
       
  2927     if (iTreeData->Count() == 0)
       
  2928         {
       
  2929         iRootVisualizer->ShowL(*iRootLayout);
       
  2930         iRootVisualizer->UpdateL(*iRootData, EFalse, 0, iMarkIcon, iMenuIcon);
       
  2931         }
       
  2932     else
       
  2933         {
       
  2934         }
       
  2935     }
       
  2936 
       
  2937 // ---------------------------------------------------------------------------
       
  2938 // Hides item.
       
  2939 // ---------------------------------------------------------------------------
       
  2940 //
       
  2941 void CFsTreeVisualizerBase::HideItemL(const TFsTreeItemId /*aItemId*/)
       
  2942 
       
  2943     {
       
  2944     FUNC_LOG;
       
  2945     }
       
  2946 
       
  2947 // ---------------------------------------------------------------------------
       
  2948 // Unhides item.
       
  2949 // ---------------------------------------------------------------------------
       
  2950 //
       
  2951 void CFsTreeVisualizerBase::UnhideItemL(const TFsTreeItemId /*aItemId*/)
       
  2952     {
       
  2953     FUNC_LOG;
       
  2954 
       
  2955     }
       
  2956 
       
  2957 // ---------------------------------------------------------------------------
       
  2958 //
       
  2959 // ---------------------------------------------------------------------------
       
  2960 //
       
  2961 void CFsTreeVisualizerBase::SetPadding(const TAlfBoxMetric& aPadding)
       
  2962     {
       
  2963     FUNC_LOG;
       
  2964 
       
  2965     iWatermarkLayout->SetPadding(aPadding);
       
  2966 
       
  2967     }
       
  2968 
       
  2969 // ---------------------------------------------------------------------------
       
  2970 // List pane's padding taken from Layout Manager or switched off.
       
  2971 // ---------------------------------------------------------------------------
       
  2972 //
       
  2973 void CFsTreeVisualizerBase::EnableListPanePadding(TBool aEnable)
       
  2974     {
       
  2975     FUNC_LOG;
       
  2976     if (aEnable)
       
  2977         {
       
  2978         TRect listPane;
       
  2979         CFsLayoutManager::LayoutMetricsRect(TRect(
       
  2980                 iComponentLayout->Size().Target().AsSize()),
       
  2981                 CFsLayoutManager::EFsLmMainSpFsListPane, listPane);
       
  2982 
       
  2983         if (CFsLayoutManager::IsMirrored())
       
  2984             {
       
  2985             iListLayout->SetPadding(TPoint(
       
  2986                     iComponentLayout->Size().Target().AsSize().iWidth
       
  2987                             - listPane.iBr.iX, 0));
       
  2988             iListItemBackgroundLayout->SetPadding(TPoint(
       
  2989                     iComponentLayout->Size().Target().AsSize().iWidth
       
  2990                             - listPane.iBr.iX, 0));
       
  2991             }
       
  2992         else
       
  2993             {
       
  2994             TInt xPadd;
       
  2995             xPadd = listPane.iTl.iX;
       
  2996             iListLayout->SetPadding(TPoint(xPadd, 0));
       
  2997             iListItemBackgroundLayout->SetPadding(TPoint(xPadd, 0));
       
  2998             }
       
  2999         }
       
  3000     else
       
  3001         {
       
  3002         //no padding
       
  3003         TInt padd(0);
       
  3004         iListLayout->SetPadding(TPoint(padd, padd));
       
  3005         iListItemBackgroundLayout->SetPadding(TPoint(padd, padd));
       
  3006         }
       
  3007     }
       
  3008 
       
  3009 // ---------------------------------------------------------------------------
       
  3010 //  Sets the type of text marquee.
       
  3011 // ---------------------------------------------------------------------------
       
  3012 //
       
  3013 void CFsTreeVisualizerBase::SetTextMarqueeType(
       
  3014         const TFsTextMarqueeType aMarqueeType)
       
  3015     {
       
  3016     FUNC_LOG;
       
  3017     iMarqueeType = aMarqueeType;
       
  3018     }
       
  3019 
       
  3020 // ---------------------------------------------------------------------------
       
  3021 //  Gets the type of text marquee.
       
  3022 // ---------------------------------------------------------------------------
       
  3023 //
       
  3024 TFsTextMarqueeType CFsTreeVisualizerBase::TextMarqueeType() const
       
  3025     {
       
  3026     FUNC_LOG;
       
  3027     return iMarqueeType;
       
  3028     }
       
  3029 
       
  3030 // ---------------------------------------------------------------------------
       
  3031 //  Sets the speed of marquee.
       
  3032 // ---------------------------------------------------------------------------
       
  3033 //
       
  3034 void CFsTreeVisualizerBase::SetTextMarqueeSpeed(const TInt aPixelsPerSec)
       
  3035     {
       
  3036     FUNC_LOG;
       
  3037     iMarqueeSpeed = aPixelsPerSec;
       
  3038     }
       
  3039 
       
  3040 // ---------------------------------------------------------------------------
       
  3041 //  Gets the speed of marquee.
       
  3042 // ---------------------------------------------------------------------------
       
  3043 //
       
  3044 TInt CFsTreeVisualizerBase::TextMarqueeSpeed() const
       
  3045     {
       
  3046     FUNC_LOG;
       
  3047     return iMarqueeSpeed;
       
  3048     }
       
  3049 
       
  3050 // ---------------------------------------------------------------------------
       
  3051 //  Sets delay for text marquee start.
       
  3052 // ---------------------------------------------------------------------------
       
  3053 //
       
  3054 void CFsTreeVisualizerBase::SetTextMarqueeStartDelay(const TInt aStartDelay)
       
  3055     {
       
  3056     FUNC_LOG;
       
  3057     iMarqueStartDelay = aStartDelay;
       
  3058     }
       
  3059 
       
  3060 // ---------------------------------------------------------------------------
       
  3061 //  Gets delay for text marquee.
       
  3062 // ---------------------------------------------------------------------------
       
  3063 //
       
  3064 TInt CFsTreeVisualizerBase::TextMarqueeStartDelay() const
       
  3065     {
       
  3066     FUNC_LOG;
       
  3067     return iMarqueStartDelay;
       
  3068     }
       
  3069 
       
  3070 // ---------------------------------------------------------------------------
       
  3071 //  Sets a delay for each cycle start.
       
  3072 // ---------------------------------------------------------------------------
       
  3073 //
       
  3074 void CFsTreeVisualizerBase::SetTextMarqueeCycleStartDelay(
       
  3075         const TInt aCycleStartDelay)
       
  3076     {
       
  3077     FUNC_LOG;
       
  3078     iMarqueCycleStartDelay = aCycleStartDelay;
       
  3079     }
       
  3080 
       
  3081 // ---------------------------------------------------------------------------
       
  3082 //  Returns a delay for each cycle start.
       
  3083 // ---------------------------------------------------------------------------
       
  3084 //
       
  3085 TInt CFsTreeVisualizerBase::TextMarqueeCycleStartDelay() const
       
  3086     {
       
  3087     FUNC_LOG;
       
  3088     return iMarqueCycleStartDelay;
       
  3089     }
       
  3090 
       
  3091 // ---------------------------------------------------------------------------
       
  3092 //  Sets number of marquee cycles.
       
  3093 // ---------------------------------------------------------------------------
       
  3094 //
       
  3095 void CFsTreeVisualizerBase::SetTextMarqueeRepetitions(
       
  3096         const TInt aMarqueeRepetitions)
       
  3097     {
       
  3098     FUNC_LOG;
       
  3099     iMarqueeRepetitions = aMarqueeRepetitions;
       
  3100     }
       
  3101 
       
  3102 // ---------------------------------------------------------------------------
       
  3103 //  Gets number of marquee cycles.
       
  3104 // ---------------------------------------------------------------------------
       
  3105 //
       
  3106 TInt CFsTreeVisualizerBase::TextMarqueeRepetitions() const
       
  3107     {
       
  3108     FUNC_LOG;
       
  3109     return iMarqueeRepetitions;
       
  3110     }
       
  3111 
       
  3112 // ---------------------------------------------------------------------------
       
  3113 //
       
  3114 // ---------------------------------------------------------------------------
       
  3115 //
       
  3116 TInt CFsTreeVisualizerBase::GetItemDisplayRectTarget(
       
  3117         const TFsTreeItemId aItemId, TAlfRealRect& aRect)
       
  3118     {
       
  3119     FUNC_LOG;
       
  3120     TInt retVal(KErrNotFound);
       
  3121     MFsTreeItemVisualizer* itemVis(NULL);
       
  3122     CAlfLayout* lay(NULL);
       
  3123 
       
  3124     aRect.iTl = TAlfRealPoint(0.0, 0.0);
       
  3125     aRect.iBr = TAlfRealPoint(0.0, 0.0);
       
  3126 
       
  3127     retVal = iVisibleItems.Find(aItemId);
       
  3128     if (retVal != KErrNotFound)
       
  3129         {//item visible
       
  3130         itemVis = iTreeData->ItemVisualizer(aItemId);
       
  3131         if (itemVis)
       
  3132             {
       
  3133             lay = &itemVis->Layout();
       
  3134             if (lay)
       
  3135                 {
       
  3136                 aRect = lay->DisplayRectTarget();
       
  3137                 retVal = KErrNone;
       
  3138                 }
       
  3139             else
       
  3140                 {
       
  3141                 retVal = KErrNotFound;
       
  3142                 }
       
  3143             }
       
  3144         else
       
  3145             {
       
  3146             retVal = KErrNotFound;
       
  3147             }
       
  3148         }
       
  3149     else
       
  3150         {
       
  3151         retVal = KErrNotFound;
       
  3152         }
       
  3153 
       
  3154     return retVal;
       
  3155     }
       
  3156 
       
  3157 // ---------------------------------------------------------------------------
       
  3158 //  Internall to TreeList. Do not use directly.
       
  3159 //  Used to block update during addition of many items/nodes. Currently only
       
  3160 //  scrollbar is blocked from beign updated.Gets number of marquee cycles.
       
  3161 // ---------------------------------------------------------------------------
       
  3162 //
       
  3163 void CFsTreeVisualizerBase::SetAutoRefreshAtInsert(TBool aAllowRefresh)
       
  3164     {
       
  3165     FUNC_LOG;
       
  3166     if (!aAllowRefresh && iFlags.IsSet(EAutoRefresh))
       
  3167         {
       
  3168         iWorld.BeginUpdate();
       
  3169         }
       
  3170     else if (aAllowRefresh && !iFlags.IsSet(EAutoRefresh))
       
  3171         {
       
  3172         TInt error( KErrNone );
       
  3173         TRAP( error, iWorld.EndUpdateL() );
       
  3174         ERROR_1( error, "iWorld.EndUpdateL failed with error: %d", error );
       
  3175         }
       
  3176     iFlags.Assign(EAutoRefresh, aAllowRefresh);
       
  3177     }
       
  3178 
       
  3179 // ---------------------------------------------------------------------------
       
  3180 //  Internall to TreeList. Do not use directly.
       
  3181 //  Used to block update during addition of many items/nodes. Currently only
       
  3182 //  scrollbar is blocked from beign updated.Gets number of marquee cycles.
       
  3183 // ---------------------------------------------------------------------------
       
  3184 //
       
  3185 TBool CFsTreeVisualizerBase::IsAutoRefreshAtInsert()
       
  3186     {
       
  3187     FUNC_LOG;
       
  3188     return iFlags.IsSet(EAutoRefresh);
       
  3189     }
       
  3190 
       
  3191 // ---------------------------------------------------------------------------
       
  3192 //  CFsTreeVisualizerBase::SetDirectTouchMode
       
  3193 // ---------------------------------------------------------------------------
       
  3194 //
       
  3195 void CFsTreeVisualizerBase::SetDirectTouchMode(const TBool aDirectTouchMode)
       
  3196     {
       
  3197     FUNC_LOG;
       
  3198     iFlags.Assign(EDirectTouchMode, aDirectTouchMode);
       
  3199     }
       
  3200 
       
  3201 // ---------------------------------------------------------------------------
       
  3202 //  CFsTreeVisualizerBase::SetExpandCollapseAllOnLongTap
       
  3203 // ---------------------------------------------------------------------------
       
  3204 //
       
  3205 void CFsTreeVisualizerBase::SetExpandCollapseAllOnLongTap( TBool aExpandCollapse )
       
  3206     {
       
  3207     FUNC_LOG;
       
  3208     iFlags.Assign( EExpandCollapseOnLongTap, aExpandCollapse );
       
  3209     }
       
  3210 
       
  3211 // ---------------------------------------------------------------------------
       
  3212 //  CFsTreeVisualizerBase::IsExpandCollapseAllOnLongTap
       
  3213 // ---------------------------------------------------------------------------
       
  3214 //
       
  3215 TBool CFsTreeVisualizerBase::IsExpandCollapseAllOnLongTap()
       
  3216     {
       
  3217     FUNC_LOG;
       
  3218     return iFlags.IsSet( EExpandCollapseOnLongTap );
       
  3219     }
       
  3220 
       
  3221 // ---------------------------------------------------------------------------
       
  3222 // From MFsFadeEffectObserver
       
  3223 // Function which will receive notifications about fade effect state changes.
       
  3224 // ---------------------------------------------------------------------------
       
  3225 //
       
  3226 void CFsTreeVisualizerBase::FadeEffectEvent(
       
  3227         MFsFadeEffectObserver::TFadeEffectState aState)
       
  3228     {
       
  3229     FUNC_LOG;
       
  3230     switch (aState)
       
  3231         {
       
  3232         case MFsFadeEffectObserver::EFadeInFinished:
       
  3233             {
       
  3234             if (iVisualizationState == EFsTreeFadingInSlidingIn)
       
  3235                 {//slide in effect still on
       
  3236                 iVisualizationState = EFsTreeSlidingIn;
       
  3237                 }
       
  3238             else if (iVisualizationState == EFsTreeFadingIn)
       
  3239                 {
       
  3240                 iVisualizationState = EFsTreeVisible;
       
  3241                 UpdateScrollBar();
       
  3242                 }
       
  3243             break;
       
  3244             }
       
  3245         case MFsFadeEffectObserver::EFadeOutFinished:
       
  3246             {
       
  3247             if (iVisualizationState == EFsTreeFadingOutSlidingOut)
       
  3248                 {//slide out effect still on
       
  3249                 iVisualizationState = EFsTreeSlidingOut;
       
  3250                 }
       
  3251             else if (iVisualizationState == EFsTreeFadingOut)
       
  3252                 {
       
  3253                 iScrollBar->Show( EFalse );
       
  3254                 iVisualizationState = EFsTreeHidden;
       
  3255                 }
       
  3256             break;
       
  3257             }
       
  3258         default:
       
  3259             {
       
  3260             break;
       
  3261             }
       
  3262         }
       
  3263 
       
  3264     if (iVisualizationState == EFsTreeVisible && iVisualizerObserver)
       
  3265         {
       
  3266             // <cmail> Touch
       
  3267             TRAP_IGNORE(iVisualizerObserver->TreeVisualizerEventL(
       
  3268                             MFsTreeVisualizerObserver::EFsTreeListVisualizerShown,
       
  3269                             KFsTreeNoneID ));
       
  3270         // </cmail>
       
  3271         }
       
  3272 
       
  3273     if (iVisualizationState == EFsTreeHidden && iVisualizerObserver)
       
  3274         {
       
  3275             // <cmail> Touch
       
  3276             TRAP_IGNORE(iVisualizerObserver->TreeVisualizerEventL(
       
  3277                             MFsTreeVisualizerObserver::EFsTreeListVisualizerHidden,
       
  3278                             KFsTreeNoneID ));
       
  3279         // </cmail>
       
  3280         }
       
  3281     }
       
  3282 
       
  3283 // ---------------------------------------------------------------------------
       
  3284 // From MFsSlideEffectObserver
       
  3285 // Function which will receive notifications about slide effect state changes.
       
  3286 // ---------------------------------------------------------------------------
       
  3287 //
       
  3288 void CFsTreeVisualizerBase::SlideEffectEvent(
       
  3289         MFsSlideEffectObserver::TSlideEffectState aState)
       
  3290     {
       
  3291     FUNC_LOG;
       
  3292     switch (aState)
       
  3293         {
       
  3294         case MFsSlideEffectObserver::ESlideInFinished:
       
  3295             {
       
  3296             if (iVisualizationState == EFsTreeFadingInSlidingIn)
       
  3297                 {//fade in effect still on
       
  3298                 iVisualizationState = EFsTreeFadingIn;
       
  3299                 }
       
  3300             else if (iVisualizationState == EFsTreeSlidingIn)
       
  3301                 {
       
  3302                 iVisualizationState = EFsTreeVisible;
       
  3303                 UpdateScrollBar();
       
  3304                 }
       
  3305             break;
       
  3306             }
       
  3307         case MFsSlideEffectObserver::ESlideOutFinished:
       
  3308             {
       
  3309             if (iVisualizationState == EFsTreeFadingOutSlidingOut)
       
  3310                 {//fade out effect still on
       
  3311                 iVisualizationState = EFsTreeFadingOut;
       
  3312                 }
       
  3313             else if (iVisualizationState == EFsTreeSlidingOut)
       
  3314                 {
       
  3315                 iScrollBar->Show( EFalse );
       
  3316                 iVisualizationState = EFsTreeHidden;
       
  3317                 }
       
  3318             break;
       
  3319             }
       
  3320         default:
       
  3321             {
       
  3322             break;
       
  3323             }
       
  3324         }
       
  3325 
       
  3326     if (iVisualizationState == EFsTreeVisible && iVisualizerObserver)
       
  3327         {
       
  3328             // <cmail> Touch
       
  3329             TRAP_IGNORE(iVisualizerObserver->TreeVisualizerEventL(
       
  3330                             MFsTreeVisualizerObserver::EFsTreeListVisualizerShown,
       
  3331                             KFsTreeNoneID ));
       
  3332 
       
  3333         }
       
  3334 
       
  3335     if (iVisualizationState == EFsTreeHidden && iVisualizerObserver)
       
  3336         {
       
  3337             TRAP_IGNORE(iVisualizerObserver->TreeVisualizerEventL(
       
  3338                             MFsTreeVisualizerObserver::EFsTreeListVisualizerHidden,
       
  3339                             KFsTreeNoneID ));
       
  3340         // </cmail>
       
  3341         }
       
  3342     }
       
  3343 
       
  3344 // ---------------------------------------------------------------------------
       
  3345 // From MAlfActionObserver
       
  3346 // Called by the server when an action command is executed.
       
  3347 // ---------------------------------------------------------------------------
       
  3348 //
       
  3349 void CFsTreeVisualizerBase::HandleActionL(
       
  3350         const TAlfActionCommand& aActionCommand)
       
  3351     {
       
  3352     if (KAknsMessageSkinChange == aActionCommand.Id())
       
  3353         {
       
  3354         iScrollBar->NotifyThemeChanged();
       
  3355         }
       
  3356     }
       
  3357 
       
  3358 // ---------------------------------------------------------------------------
       
  3359 // Hides visible list items. Clears the visible items table.
       
  3360 // ---------------------------------------------------------------------------
       
  3361 //
       
  3362 void CFsTreeVisualizerBase::ClearVisibleItemsListL(TBool /*aRemoveAll*/,
       
  3363         TBool /*aScrollList*/)
       
  3364     {
       
  3365     FUNC_LOG;
       
  3366     }
       
  3367 
       
  3368 // ---------------------------------------------------------------------------
       
  3369 // Applies focus brush to the selected item.
       
  3370 // ---------------------------------------------------------------------------
       
  3371 //
       
  3372 void CFsTreeVisualizerBase::ChangeFocusL(const TFsTreeItemId /*aPrevious*/)
       
  3373     {
       
  3374     FUNC_LOG;
       
  3375 
       
  3376     }
       
  3377 
       
  3378 // ---------------------------------------------------------------------------
       
  3379 // CFsTreeVisualizerBase::AdjustVisibleItemsL
       
  3380 // ---------------------------------------------------------------------------
       
  3381 //
       
  3382 void CFsTreeVisualizerBase::AdjustVisibleItemsL()
       
  3383     {
       
  3384     FUNC_LOG;
       
  3385 
       
  3386     }
       
  3387 
       
  3388 // ---------------------------------------------------------------------------
       
  3389 // CFsTreeVisualizerBase::InsertItemL
       
  3390 // ---------------------------------------------------------------------------
       
  3391 //
       
  3392 void CFsTreeVisualizerBase::InsertItemL(TFsTreeItemId aItemId,
       
  3393         const TInt aSlot)
       
  3394     {
       
  3395     MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(aItemId);
       
  3396     ApplyListSpecificValuesToItem(visualizer);
       
  3397     //TUint32 oldflags = visualizer->Flags();
       
  3398     //visualizer->SetFlags(oldflags | KFsTreeListItemManagedLayout);
       
  3399     const TSize size(visualizer->Size());
       
  3400     //visualizer->SetFlags(oldflags);
       
  3401     if (aSlot != KErrNotFound)
       
  3402         {
       
  3403         iWorld.InsertL(aItemId, size, aSlot);
       
  3404         }
       
  3405     else
       
  3406         {
       
  3407         iWorld.AppendL(aItemId, size);
       
  3408         }
       
  3409     }
       
  3410 
       
  3411 // ---------------------------------------------------------------------------
       
  3412 // Move selection in the list.
       
  3413 // ---------------------------------------------------------------------------
       
  3414 //
       
  3415 void CFsTreeVisualizerBase::MoveSelectionL(
       
  3416         const TFsTreeVisualizerMove aMoveType)
       
  3417     {
       
  3418     FUNC_LOG;
       
  3419     TInt focusedIndex = iWorld.IndexOfItem(iFocusedItem);
       
  3420     switch (aMoveType)
       
  3421         {
       
  3422         case EFsTreeVisualizerMoveLineUp:
       
  3423             {
       
  3424             while (focusedIndex > 0)
       
  3425                 {
       
  3426                 focusedIndex -= 1;
       
  3427                 if (iTreeData->ItemData(iWorld.Item(focusedIndex)).Type()
       
  3428                         != KFsSeparatorDataType)
       
  3429                     {
       
  3430                     SetFocusedItemL(iWorld.Item(focusedIndex));
       
  3431                     break;
       
  3432                     }
       
  3433                 }
       
  3434             break;
       
  3435             }
       
  3436         case EFsTreeVisualizerMoveLineDown:
       
  3437             {
       
  3438             while (focusedIndex < iWorld.ItemCount() - 1)
       
  3439                 {
       
  3440                 focusedIndex += 1;
       
  3441                 if (iTreeData->ItemData(iWorld.Item(focusedIndex)).Type()
       
  3442                         != KFsSeparatorDataType)
       
  3443                     {
       
  3444                     SetFocusedItemL(iWorld.Item(focusedIndex));
       
  3445                     break;
       
  3446                     }
       
  3447                 }
       
  3448             break;
       
  3449             }
       
  3450         case EFsTreeVisualizerMovePageUp:
       
  3451             {
       
  3452             focusedIndex -= iVisibleItems.Count() - 2;
       
  3453             while (focusedIndex > 0)
       
  3454                 {
       
  3455                 if (iTreeData->ItemData(iWorld.Item(focusedIndex)).Type()
       
  3456                         != KFsSeparatorDataType)
       
  3457                     {
       
  3458                     break;
       
  3459                     }
       
  3460                 else
       
  3461                     {
       
  3462                     focusedIndex--;
       
  3463                     }
       
  3464                 }
       
  3465             if (focusedIndex < 0)
       
  3466                 {
       
  3467                 focusedIndex = 0;
       
  3468                 }
       
  3469             if (iWorld.ItemCount() > 0)
       
  3470                 {
       
  3471                 SetFocusedItemL(iWorld.Item(focusedIndex));
       
  3472                 }
       
  3473             break;
       
  3474             }
       
  3475         case EFsTreeVisualizerMovePageDown:
       
  3476             {
       
  3477             focusedIndex += iVisibleItems.Count() - 2;
       
  3478             while (focusedIndex < iWorld.ItemCount() - 1)
       
  3479                 {
       
  3480                 if (iTreeData->ItemData(iWorld.Item(focusedIndex)).Type()
       
  3481                         != KFsSeparatorDataType)
       
  3482                     {
       
  3483                     break;
       
  3484                     }
       
  3485                 else
       
  3486                     {
       
  3487                     focusedIndex++;
       
  3488                     }
       
  3489                 }
       
  3490             if (focusedIndex > iWorld.ItemCount() - 1)
       
  3491                 {
       
  3492                 focusedIndex = iWorld.ItemCount() - 1;
       
  3493                 }
       
  3494             if (iWorld.ItemCount() > 0)
       
  3495                 {
       
  3496                 SetFocusedItemL(iWorld.Item(focusedIndex));
       
  3497                 }
       
  3498             break;
       
  3499             }
       
  3500         }
       
  3501     iViewPort.ScrollItemToViewL(iFocusedItem, ETrue);
       
  3502     }
       
  3503 
       
  3504 // ---------------------------------------------------------------------------
       
  3505 // Moves selection in the list by one item upwards.
       
  3506 // ---------------------------------------------------------------------------
       
  3507 //
       
  3508 TInt CFsTreeVisualizerBase::MoveSelectionByLineUpL(const TBool /*aChangeFocus*/)
       
  3509     {
       
  3510     FUNC_LOG;
       
  3511     return 0;
       
  3512     }
       
  3513 
       
  3514 // ---------------------------------------------------------------------------
       
  3515 // Moves selection in the list by one item downwards.
       
  3516 // ---------------------------------------------------------------------------
       
  3517 //
       
  3518 TInt CFsTreeVisualizerBase::MoveSelectionByLineDownL(const TBool /*aChangeFocus*/)
       
  3519     {
       
  3520     FUNC_LOG;
       
  3521     return 0;
       
  3522     }
       
  3523 
       
  3524 // ---------------------------------------------------------------------------
       
  3525 // Scrolling
       
  3526 // ---------------------------------------------------------------------------
       
  3527 //
       
  3528 void CFsTreeVisualizerBase::Scroll(const TFsTreeItemId aPrevious,
       
  3529         TBool aAlignTop)
       
  3530     {
       
  3531     FUNC_LOG;
       
  3532     TInt currScrollOffset = iListLayout->ScrollOffset().iY.Target();
       
  3533     TInt listItemsHeight = 0;
       
  3534     TInt visibleHeight = iComponentLayout->Size().iY.Target();
       
  3535     TInt scrollOffset = 0;
       
  3536 
       
  3537     listItemsHeight = VisibleItemsHeight(aPrevious);
       
  3538 
       
  3539     if (aAlignTop)
       
  3540         {
       
  3541         scrollOffset = 0;
       
  3542         }
       
  3543     else
       
  3544         {
       
  3545         if (listItemsHeight > visibleHeight)
       
  3546             {
       
  3547             scrollOffset = listItemsHeight - visibleHeight;
       
  3548             }
       
  3549         else
       
  3550             {
       
  3551             scrollOffset = currScrollOffset;
       
  3552             }
       
  3553         }
       
  3554 
       
  3555     ScrollListLayouts(scrollOffset, iCurrentScrollSpeed);
       
  3556     }
       
  3557 
       
  3558 // ---------------------------------------------------------------------------
       
  3559 // Counts height items from iVisibleItems array which will
       
  3560 // be drawn on the screen
       
  3561 // ---------------------------------------------------------------------------
       
  3562 //
       
  3563 TInt CFsTreeVisualizerBase::VisibleItemsHeight(const TFsTreeItemId aPrevious)
       
  3564     {
       
  3565     FUNC_LOG;
       
  3566     TInt listItemsHeight = 0;
       
  3567     MFsTreeItemVisualizer* visualizer = 0;
       
  3568     TFsTreeItemId itemId;
       
  3569     TInt itemCount = iVisibleItems.Count();
       
  3570 
       
  3571     for (TInt index = 0; index < itemCount; ++index)
       
  3572         {
       
  3573         itemId = iVisibleItems[index];
       
  3574         visualizer = iTreeData->ItemVisualizer(itemId);
       
  3575 
       
  3576 
       
  3577         if (visualizer)
       
  3578             {
       
  3579             if (itemId == iFocusedItem)
       
  3580                 {
       
  3581                 if (visualizer->IsExtendable())
       
  3582                     {
       
  3583                     listItemsHeight += visualizer->ExtendedSize().iHeight;
       
  3584                     }
       
  3585                 else
       
  3586                     {
       
  3587                     listItemsHeight += visualizer->Size().iHeight;
       
  3588                     }
       
  3589                 }
       
  3590             else if (itemId == aPrevious && iFocusedItem != aPrevious)
       
  3591                 {
       
  3592                 listItemsHeight += visualizer->Size().iHeight;
       
  3593                 }
       
  3594             else if (visualizer->IsExtended() && visualizer->IsExtendable())
       
  3595                 {
       
  3596                 listItemsHeight += visualizer->ExtendedSize().iHeight;
       
  3597                 }
       
  3598             else
       
  3599                 {
       
  3600                 listItemsHeight += visualizer->Size().iHeight;
       
  3601                 }
       
  3602             }
       
  3603         }
       
  3604 
       
  3605     return listItemsHeight;
       
  3606     }
       
  3607 
       
  3608 // ---------------------------------------------------------------------------
       
  3609 // Check if item is in expanded node
       
  3610 // ---------------------------------------------------------------------------
       
  3611 TBool CFsTreeVisualizerBase::IsInExpanded(TFsTreeItemId aItemId)
       
  3612     {
       
  3613     FUNC_LOG;
       
  3614     TBool result(ETrue);
       
  3615     TFsTreeItemId parentId = iTreeData->Parent(aItemId);
       
  3616     while (parentId != KFsTreeRootID && parentId != KFsTreeNoneID)
       
  3617         {
       
  3618         if (iTreeData->IsNode(parentId))
       
  3619             {
       
  3620             if (iTreeData->NodeVisualizer(parentId)->IsExpanded())
       
  3621                 {
       
  3622                 result = ETrue;
       
  3623                 parentId = iTreeData->Parent(parentId);
       
  3624                 }
       
  3625             else
       
  3626                 {
       
  3627                 result = EFalse;
       
  3628                 break;
       
  3629                 }
       
  3630             }
       
  3631         else
       
  3632             {
       
  3633             parentId = iTreeData->Parent(parentId);
       
  3634             }
       
  3635         }
       
  3636 
       
  3637     return result;
       
  3638     }
       
  3639 
       
  3640 // ---------------------------------------------------------------------------
       
  3641 //  CFsTreeVisualizerBase::UpdateViewPortL
       
  3642 // ---------------------------------------------------------------------------
       
  3643 //
       
  3644 void CFsTreeVisualizerBase::UpdateViewPortL()
       
  3645     {
       
  3646     FUNC_LOG;
       
  3647     TRect mainPaneRect;
       
  3648     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
  3649     TRect listRect(iRootLayout->DisplayRectTarget());
       
  3650     listRect.Move(mainPaneRect.iTl);
       
  3651     TRect listPane;
       
  3652     CFsLayoutManager::LayoutMetricsRect(listRect,
       
  3653             CFsLayoutManager::EFsLmMainSpFsListPane, listPane);
       
  3654     iWorld.BeginUpdate();
       
  3655     TBool keepFocusedItemInView(EFalse);
       
  3656     if (iFocusedItem != KFsTreeNoneID)
       
  3657         {
       
  3658         keepFocusedItemInView = iViewPort.ItemRect(iFocusedItem).Height() > 0;
       
  3659         }
       
  3660     iViewPort.SetSizeL(listPane.Size());
       
  3661     iWorld.Recalculate(*iTreeData);
       
  3662     if (keepFocusedItemInView)
       
  3663         {
       
  3664         iViewPort.ScrollItemToViewL(iFocusedItem, EFalse);
       
  3665         }
       
  3666     else
       
  3667         {
       
  3668         iViewPort.MakeViewFullyOccupiedL();
       
  3669         }
       
  3670     iViewPort.ClearCache();
       
  3671     iWorld.EndUpdateL();
       
  3672     }
       
  3673 
       
  3674 // ---------------------------------------------------------------------------
       
  3675 //  Updates scrollbar, only if update is needed.
       
  3676 // ---------------------------------------------------------------------------
       
  3677 //
       
  3678 void CFsTreeVisualizerBase::UpdateScrollBarIfNeededL()
       
  3679     {
       
  3680     FUNC_LOG;
       
  3681     if (iScrollBar->ThumbPosition() != iViewPort.Position().iY)
       
  3682         {
       
  3683         SetScrollBarModelValues();
       
  3684         iScrollBar->UpdateModelL(iScrollBarModel);
       
  3685         iScrollBar->Redraw();
       
  3686         }
       
  3687     }
       
  3688 
       
  3689 // ---------------------------------------------------------------------------
       
  3690 //  Sets scrollbar model values.
       
  3691 // ---------------------------------------------------------------------------
       
  3692 //
       
  3693 void CFsTreeVisualizerBase::SetScrollBarModelValues()
       
  3694     {
       
  3695     const TInt pageSize(iViewPort.Size().iHeight);
       
  3696     iScrollBarModel.SetHeight(Max(iWorld.Height(), pageSize));
       
  3697     iScrollBarModel.SetWindowHeight(pageSize);
       
  3698     iScrollBarModel.SetWindowPosition(iViewPort.Position().iY);    
       
  3699     }
       
  3700 
       
  3701 // ---------------------------------------------------------------------------
       
  3702 //  Updates scrollbar.
       
  3703 // ---------------------------------------------------------------------------
       
  3704 //
       
  3705 void CFsTreeVisualizerBase::UpdateScrollBarL(const TInt /*aTimeout*/)
       
  3706     {
       
  3707     FUNC_LOG;
       
  3708 
       
  3709     TRect mainPaneRect;
       
  3710     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
  3711     TRect listRect(iRootLayout->DisplayRectTarget());
       
  3712     if (!(iScrollBar->LayoutHints() & MUiCScrollBar::ELayoutRelativeToList))
       
  3713         {
       
  3714         listRect.Move(mainPaneRect.iTl);
       
  3715         }
       
  3716     else
       
  3717         {
       
  3718         const TPoint& tl( listRect.iTl );
       
  3719         listRect.Move( -tl.iX, -tl.iY );
       
  3720         }
       
  3721     TRect scrollPane, listPane;
       
  3722     CFsLayoutManager::LayoutMetricsRect(listRect,
       
  3723             CFsLayoutManager::EFsLmSpFsScrollPane, scrollPane);
       
  3724     CFsLayoutManager::LayoutMetricsRect(listRect,
       
  3725             CFsLayoutManager::EFsLmMainSpFsListPane, listPane);
       
  3726     SetScrollBarModelValues();
       
  3727     iScrollBar->UpdateModelL(iScrollBarModel);
       
  3728     iScrollBar->Redraw();
       
  3729 
       
  3730     RArray<TInt> columns;
       
  3731     CleanupClosePushL(columns);
       
  3732     TBool updateLayouts(EFalse);
       
  3733     if (iViewPort.IsScrollBarNeeded() && iVisualizationState
       
  3734             == EFsTreeVisible)
       
  3735         {
       
  3736         iScrollBar->SetRect(scrollPane);
       
  3737         if (AknLayoutUtils::LayoutMirrored())
       
  3738             {
       
  3739             if (iScrollBar->LayoutHints() & MUiCScrollBar::ELayoutOnTopOfList)
       
  3740                 {
       
  3741                 columns.AppendL(0);
       
  3742                 columns.AppendL(listRect.Width());
       
  3743                 }
       
  3744             else
       
  3745                 {
       
  3746                 columns.AppendL(scrollPane.Width());
       
  3747                 columns.AppendL(listPane.Width());
       
  3748                 }
       
  3749             }
       
  3750         else
       
  3751             {
       
  3752             if (iScrollBar->LayoutHints() & MUiCScrollBar::ELayoutOnTopOfList)
       
  3753                 {
       
  3754                 columns.AppendL(listRect.Width());
       
  3755                 columns.AppendL(0);
       
  3756                 }
       
  3757             else
       
  3758                 {
       
  3759                 columns.AppendL(listPane.Width());
       
  3760                 columns.AppendL(scrollPane.Width());
       
  3761                 }
       
  3762             }
       
  3763         iComponentLayout->SetColumnsL(columns);
       
  3764         iScrollBar->Show(ETrue);
       
  3765         updateLayouts = ETrue;
       
  3766         }
       
  3767     else if (!iViewPort.IsScrollBarNeeded())
       
  3768         {
       
  3769         if (AknLayoutUtils::LayoutMirrored())
       
  3770             {
       
  3771             columns.AppendL(0);
       
  3772             columns.AppendL(listRect.Width());
       
  3773             }
       
  3774         else
       
  3775             {
       
  3776             columns.AppendL(listRect.Width());
       
  3777             columns.AppendL(0);
       
  3778             }
       
  3779         iComponentLayout->SetColumnsL(columns);
       
  3780         iScrollBar->Show(EFalse);
       
  3781         updateLayouts = ETrue;
       
  3782         }
       
  3783     CleanupStack::PopAndDestroy(); // columns.Close()
       
  3784     if (updateLayouts)
       
  3785         {
       
  3786         iComponentLayout->UpdateChildrenLayout();
       
  3787 
       
  3788         for (TUint i = 0; i < iVisibleItems.Count(); ++i)
       
  3789             {
       
  3790             TFsTreeItemId itemId(iVisibleItems[i]);
       
  3791             MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(itemId);
       
  3792             if (visualizer)
       
  3793                 {
       
  3794                 visualizer->UpdateL(iTreeData->ItemData(itemId),
       
  3795 					IsItemFocused(itemId) && IsFocusShown(),
       
  3796                     iTreeData->Level(itemId), iMarkIcon, iMenuIcon, 0, EFalse);
       
  3797                 }
       
  3798             }
       
  3799         UpdateSelectorVisualL();
       
  3800         }
       
  3801 
       
  3802     }
       
  3803 
       
  3804 // ---------------------------------------------------------------------------
       
  3805 //
       
  3806 // ---------------------------------------------------------------------------
       
  3807 //
       
  3808 TInt CFsTreeVisualizerBase::UpdateScrollBar(const TInt aTimeout)
       
  3809     {
       
  3810     FUNC_LOG;
       
  3811     TRAPD( error, UpdateScrollBarL( aTimeout ) );
       
  3812     return error;
       
  3813     }
       
  3814 
       
  3815 // ---------------------------------------------------------------------------
       
  3816 //  Old API to be removed. Turns on or off vertical scrollbar.
       
  3817 // ---------------------------------------------------------------------------
       
  3818 //
       
  3819 void CFsTreeVisualizerBase::SetVScrollBarL(TBool /*aSetOn*/)
       
  3820     {
       
  3821     FUNC_LOG;
       
  3822     UpdateScrollBarL(iCurrentScrollSpeed);
       
  3823     }
       
  3824 
       
  3825 // ---------------------------------------------------------------------------
       
  3826 //  Turns on or off vertical scrollbar.
       
  3827 // ---------------------------------------------------------------------------
       
  3828 //
       
  3829 void CFsTreeVisualizerBase::SetScrollBarVisibilityL(
       
  3830         const TFsScrollbarVisibility aVisibility)
       
  3831     {
       
  3832     iScrollbarVisibility = aVisibility;
       
  3833     UpdateScrollBarL(iCurrentScrollSpeed);
       
  3834     }
       
  3835 
       
  3836 // ---------------------------------------------------------------------------
       
  3837 //  Gets scrollbar visibility.
       
  3838 // ---------------------------------------------------------------------------
       
  3839 //
       
  3840 TFsScrollbarVisibility CFsTreeVisualizerBase::ScrollbarVisibility() const
       
  3841     {
       
  3842     FUNC_LOG;
       
  3843     return iScrollbarVisibility;
       
  3844     }
       
  3845 
       
  3846 // ---------------------------------------------------------------------------
       
  3847 // Sets border status
       
  3848 // ---------------------------------------------------------------------------
       
  3849 //
       
  3850 void CFsTreeVisualizerBase::SetBorderL(const TBool aVisible,
       
  3851         CAlfTexture* aBorderTexture)
       
  3852     {
       
  3853     FUNC_LOG;
       
  3854     if (!aBorderTexture)
       
  3855         {
       
  3856         FsGenericPanic(EFsListPanicBorderNotSet);
       
  3857         }
       
  3858 
       
  3859     if (aVisible)
       
  3860         {
       
  3861         CAlfImageBrush* border = CAlfImageBrush::NewL(iOwnerControl->Env(),
       
  3862                 TAlfImage(*aBorderTexture));
       
  3863         border->SetLayer(EAlfBrushLayerBackground);
       
  3864 
       
  3865         border->SetBorders(-8, -8, -8, -8);
       
  3866         //<cmail>
       
  3867         // layout values needed here (not: only used from FS action menu)
       
  3868         //</cmail>
       
  3869         iBorderLayout->SetPadding(TPoint(5, 5));
       
  3870 
       
  3871         if (iBorderLayout->Brushes()->Count() > 0)
       
  3872             {
       
  3873             iBorderLayout->Brushes()->Remove(0);
       
  3874             iBorderLayout->Brushes()->Reset();
       
  3875             }
       
  3876 
       
  3877         iBorderLayout->Brushes()->AppendL(border, EAlfHasOwnership);
       
  3878         }
       
  3879     else
       
  3880         {
       
  3881         if (iBorderLayout->Brushes()->Count() > 0)
       
  3882             {
       
  3883             iBorderLayout->Brushes()->Remove(0);
       
  3884             iBorderLayout->Brushes()->Reset();
       
  3885             iBorderLayout->SetPadding(0);
       
  3886             }
       
  3887         }
       
  3888 
       
  3889     iBorderLayout->SetFlag(EAlfVisualChanged);
       
  3890     iBorderLayout->UpdateChildrenLayout();
       
  3891     RefreshListViewL();
       
  3892     }
       
  3893 
       
  3894 // ---------------------------------------------------------------------------
       
  3895 // Sets shadow status
       
  3896 // ---------------------------------------------------------------------------
       
  3897 //
       
  3898 void CFsTreeVisualizerBase::SetShadowL(const TBool aVisible)
       
  3899     {
       
  3900     FUNC_LOG;
       
  3901     if (aVisible)
       
  3902         {
       
  3903         //remove shadow if it's already set
       
  3904         if (iShadowLayout && iShadowLayout->Brushes())
       
  3905             {
       
  3906             TInt count = iShadowLayout->Brushes()->Count();
       
  3907             if (count > 0)
       
  3908                 {//there is only a shadow brush attached to this layout
       
  3909                 iShadowLayout->Brushes()->Remove(KZero);
       
  3910                 iShadowLayout->Brushes()->Reset();
       
  3911                 iShadowLayout->SetFlag(EAlfVisualChanged);
       
  3912                 }
       
  3913             }
       
  3914         //attach shadow brush to layout
       
  3915         CAlfShadowBorderBrush* shadow = CAlfShadowBorderBrush::NewLC(
       
  3916                 iOwnerControl->Env(), KDefaultShadowWidth);
       
  3917         shadow->SetOpacity(.25f);
       
  3918 
       
  3919         //set paddind to root layout so the shadow can be visible
       
  3920         TAlfBoxMetric m;
       
  3921         m.iBottom.iMagnitude = KDefaultShadowWidth;
       
  3922         m.iLeft.iMagnitude = KZero;
       
  3923         m.iRight.iMagnitude = KDefaultShadowWidth;
       
  3924         m.iTop.iMagnitude = KZero;
       
  3925         iRootLayout->SetPadding(m);
       
  3926 
       
  3927         iShadowLayout->EnableBrushesL(ETrue);
       
  3928         iShadowLayout->Brushes()->AppendL(shadow, EAlfHasOwnership);
       
  3929         CleanupStack::Pop(shadow);
       
  3930 
       
  3931         iShadowLayout->SetFlag(EAlfVisualChanged);
       
  3932         iRootLayout->UpdateChildrenLayout(KZero);
       
  3933         }
       
  3934     else
       
  3935         {
       
  3936         //remove shadow if it's already set
       
  3937         if (iShadowLayout && iShadowLayout->Brushes())
       
  3938             {
       
  3939             TInt count = iShadowLayout->Brushes()->Count();
       
  3940             if (count > 0)
       
  3941                 {//there is only a shadow brush attached to this layout
       
  3942                 iShadowLayout->Brushes()->Remove(KZero);
       
  3943                 iShadowLayout->Brushes()->Reset();
       
  3944                 iShadowLayout->SetFlag(EAlfVisualChanged);
       
  3945 
       
  3946                 //remove paddind from root layout
       
  3947                 TAlfBoxMetric m;
       
  3948                 m.iBottom.iMagnitude = KZero;
       
  3949                 m.iLeft.iMagnitude = KZero;
       
  3950                 m.iRight.iMagnitude = KZero;
       
  3951                 m.iTop.iMagnitude = KZero;
       
  3952                 iRootLayout->SetPadding(m);
       
  3953                 iRootLayout->UpdateChildrenLayout(KZero);
       
  3954                 }
       
  3955             }
       
  3956         }
       
  3957     }
       
  3958 
       
  3959 // ---------------------------------------------------------------------------
       
  3960 //  Sets visualizer observer
       
  3961 // ---------------------------------------------------------------------------
       
  3962 //
       
  3963 void CFsTreeVisualizerBase::SetVisualizerObserver(
       
  3964         MFsTreeVisualizerObserver* aObserver)
       
  3965     {
       
  3966     FUNC_LOG;
       
  3967     iVisualizerObserver = aObserver;
       
  3968     }
       
  3969 
       
  3970 // ---------------------------------------------------------------------------
       
  3971 //  Returns parent layout.
       
  3972 // ---------------------------------------------------------------------------
       
  3973 //
       
  3974 CAlfLayout& CFsTreeVisualizerBase::ParentLayout() const
       
  3975     {
       
  3976     FUNC_LOG;
       
  3977     return iParentLayout;
       
  3978     }
       
  3979 
       
  3980 // ---------------------------------------------------------------------------
       
  3981 //  Function shows selector or hides it.
       
  3982 // ---------------------------------------------------------------------------
       
  3983 //
       
  3984 EXPORT_C void CFsTreeVisualizerBase::MakeSelectorVisibleL(TBool aVisible)
       
  3985     {
       
  3986     MakeSelectorVisibleL( aVisible, 0 );
       
  3987     }
       
  3988 
       
  3989 // ---------------------------------------------------------------------------
       
  3990 //  Function shows selector or hides it.
       
  3991 // ---------------------------------------------------------------------------
       
  3992 //
       
  3993 void CFsTreeVisualizerBase::MakeSelectorVisibleL(TBool aVisible, TInt aDelay)
       
  3994     {
       
  3995     FUNC_LOG;
       
  3996     TAlfTimedValue opacity;
       
  3997 
       
  3998     if (aVisible)
       
  3999         {
       
  4000         if (!iSelectorVisual)
       
  4001             {
       
  4002             CreateSelectorVisualL();
       
  4003             }
       
  4004 
       
  4005         TBool isFocused = IsItemFocused(iFocusedItem);
       
  4006 
       
  4007         if (iSelectorVisual)
       
  4008             {
       
  4009             if (isFocused && IsFocusShown())
       
  4010                 {
       
  4011                 if( aDelay )
       
  4012                     opacity.SetTarget(iSelectorOpacity, aDelay);
       
  4013                 else
       
  4014                     opacity.SetValueNow(iSelectorOpacity);
       
  4015                 }
       
  4016             else
       
  4017                 {
       
  4018                 if( aDelay )
       
  4019                     opacity.SetTarget(0.0, aDelay);
       
  4020                 else
       
  4021                     opacity.SetValueNow(0.0);
       
  4022                 }
       
  4023 
       
  4024             iSelectorVisual->SetOpacity(opacity);
       
  4025             }
       
  4026         UpdateSelectorVisualL();
       
  4027         }
       
  4028     else
       
  4029         {
       
  4030         if (iSelectorVisual)
       
  4031             {
       
  4032             opacity.SetValueNow(0);
       
  4033             iSelectorVisual->SetOpacity(opacity);
       
  4034             }
       
  4035         }
       
  4036     }
       
  4037 
       
  4038 // ---------------------------------------------------------------------------
       
  4039 //
       
  4040 // ---------------------------------------------------------------------------
       
  4041 //
       
  4042 void CFsTreeVisualizerBase::UpdateSelectorVisualL(TInt /*aTime*/)
       
  4043     {
       
  4044     FUNC_LOG;
       
  4045 
       
  4046     if ( iSelectorVisual )
       
  4047         {
       
  4048         if ( iFocusedItem == KFsTreeNoneID ||
       
  4049         	 !iFlags.IsSet( EListFocused ) || !IsFocusShown() )
       
  4050             {
       
  4051             TAlfTimedValue opacity;
       
  4052             opacity.SetValueNow( 0.0f );
       
  4053             iSelectorVisual->SetOpacity( opacity );
       
  4054             }
       
  4055         else
       
  4056             {
       
  4057             //check if item is visible
       
  4058             MFsTreeItemVisualizer* vis( NULL );
       
  4059 
       
  4060             iListLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
  4061             iListItemBackgroundLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
  4062 
       
  4063             TRect itemRect( iViewPort.ItemRect( iFocusedItem ) );
       
  4064 
       
  4065             if ( itemRect.Height() )
       
  4066                 {
       
  4067                 TSize currSize;
       
  4068                 currSize.iWidth = iListLayout->Size().iX.Target() - 2
       
  4069                         * iListLayout->PaddingInPixels().iTl.iX;
       
  4070                 currSize.iHeight = itemRect.Height();
       
  4071                 iSelectorVisual->SetSize( currSize, 0 );
       
  4072                 TAlfRealPoint pNow;
       
  4073                 pNow.iY = itemRect.iTl.iY;
       
  4074                 pNow.iX = iListLayout->PaddingInPixels().iTl.iX;
       
  4075                 iSelectorVisual->SetPos( pNow, 0 );
       
  4076 
       
  4077                 TAlfTimedValue opacity( iSelectorOpacity, 0 );
       
  4078                 iSelectorVisual->SetOpacity( opacity );
       
  4079                 iFocusVisible = ETrue;
       
  4080 
       
  4081                 if ( iMarqueeType != EFsTextMarqueeNone )
       
  4082                     {
       
  4083                     vis = iTreeData->ItemVisualizer( iFocusedItem );
       
  4084                     if (vis)
       
  4085                         {
       
  4086                         vis->MarqueeL( iMarqueeType, iMarqueeSpeed,
       
  4087                     	        iMarqueStartDelay, iMarqueCycleStartDelay,
       
  4088                                 iMarqueeRepetitions );
       
  4089                         }
       
  4090                     }
       
  4091                 }
       
  4092             else
       
  4093                 {
       
  4094                 TAlfTimedValue opacity;
       
  4095                 opacity.SetValueNow( 0.0f );
       
  4096                 iSelectorVisual->SetOpacity( opacity );
       
  4097                 }
       
  4098 
       
  4099             iListLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
  4100             iListItemBackgroundLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
  4101             }
       
  4102         }
       
  4103     else if ( iFocusedItem != KFsTreeNoneID && iFlags.IsSet( EListFocused ) )
       
  4104         {
       
  4105         MakeSelectorVisibleL( ETrue );
       
  4106         }
       
  4107     }
       
  4108 
       
  4109 // ---------------------------------------------------------------------------
       
  4110 //  The function deletes selector visual.
       
  4111 // ---------------------------------------------------------------------------
       
  4112 //
       
  4113 void CFsTreeVisualizerBase::DestroySelectorVisualL()
       
  4114     {
       
  4115     FUNC_LOG;
       
  4116 
       
  4117     if (iSelectorVisual && iSelectorLayout)
       
  4118         {
       
  4119         iSelectorLayout->Remove(iSelectorVisual);
       
  4120         //destroy
       
  4121         iSelectorVisual->RemoveAndDestroyAllD();
       
  4122         iSelectorVisual = NULL;
       
  4123         }
       
  4124     }
       
  4125 
       
  4126 // ---------------------------------------------------------------------------
       
  4127 //  The function creates selector visual.
       
  4128 // ---------------------------------------------------------------------------
       
  4129 //
       
  4130 void CFsTreeVisualizerBase::CreateSelectorVisualL()
       
  4131     {
       
  4132     FUNC_LOG;
       
  4133     TAlfTimedValue opacity;
       
  4134 
       
  4135     if (!iSelectorVisual)
       
  4136         {
       
  4137         if (iFocusedItem != KFsTreeNoneID)
       
  4138             {
       
  4139             MFsTreeItemVisualizer* vis =
       
  4140                     iTreeData->ItemVisualizer( iFocusedItem );
       
  4141             MFsTreeItemData* data = &iTreeData->ItemData( iFocusedItem );
       
  4142 
       
  4143             iListLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
  4144             iListItemBackgroundLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
  4145 
       
  4146             iSelectorVisual = CAlfImageVisual::AddNewL(*iOwnerControl, iSelectorLayout);
       
  4147             opacity.SetValueNow(0.0f);
       
  4148             iSelectorVisual->SetOpacity(opacity);
       
  4149             iSelectorVisual->SetScaleMode( CAlfImageVisual::EScaleFit);
       
  4150             iSelectorVisual->EnableBrushesL();
       
  4151 
       
  4152             // Set the selector visual size and pos.
       
  4153             iSelectorVisual->SetFlags(EAlfVisualFlagManualLayout |
       
  4154                     EAlfVisualFlagIgnorePointer);
       
  4155 
       
  4156             TRect itemRect(iViewPort.ItemRect(iFocusedItem));
       
  4157             itemRect.SetWidth(iListLayout->Size().iX.Target() - 2 * iListLayout->PaddingInPixels().iTl.iX);
       
  4158             if ( itemRect.Height() )
       
  4159                 {
       
  4160                 iSelectorVisual->SetPos(itemRect.iTl);
       
  4161                 iSelectorVisual->SetSize(itemRect.Size());
       
  4162                 }
       
  4163 
       
  4164             //create a selector from skin or from a supplied bitmap
       
  4165             if ( iSelectorTexture )
       
  4166                 {
       
  4167                 CAlfImageBrush* brush = CAlfImageBrush::NewLC(
       
  4168                         iOwnerControl->Env(),TAlfImage(*iSelectorTexture));
       
  4169 
       
  4170                 brush->SetBorders(iLeftSelectorBorderWidth,
       
  4171                                   iRightSelectorBorderWidth,
       
  4172                                   iTopSelectorBorderHeight,
       
  4173                                   iBottomSelectorBorderHeight);
       
  4174 
       
  4175                 iSelectorVisual->Brushes()->AppendL(brush, EAlfHasOwnership);
       
  4176                 CleanupStack::Pop(brush);
       
  4177                 }
       
  4178             else if ( iSelectorBrush )
       
  4179                 {
       
  4180                 //append brush supplied by the user to the selector visual
       
  4181                 iSelectorVisual->Brushes()->AppendL(
       
  4182                         iSelectorBrush, EAlfDoesNotHaveOwnership);
       
  4183 
       
  4184                 if ( iSelectorOpacity <= 0.0 || iSelectorOpacity > 1.0 )
       
  4185                         {
       
  4186                         iSelectorOpacity = 1.0;
       
  4187                         }
       
  4188 
       
  4189                 opacity.SetValueNow(iSelectorOpacity);
       
  4190                 iSelectorVisual->SetOpacity(opacity);
       
  4191                 }
       
  4192             else //no bitmap/brush given - create selector from skin
       
  4193                 {
       
  4194                 // apply a image brush to the visual
       
  4195                 CAlfFrameBrush* brush = CAlfFrameBrush::NewLC(iOwnerControl->Env(),
       
  4196                                         KAknsIIDQsnFrList);
       
  4197 
       
  4198                 iSelectorVisual->Brushes()->AppendL(brush, EAlfHasOwnership);
       
  4199                 CleanupStack::Pop(brush);
       
  4200 
       
  4201                 CAlfBrush& skinbrush( iSelectorVisual->Brushes()->At(
       
  4202                         iSelectorVisual->Brushes()->Count() - 1 ) );
       
  4203                 CAlfFrameBrush*
       
  4204                     selectorBrush( static_cast<CAlfFrameBrush*>( &skinbrush ) );
       
  4205 
       
  4206                 const TRect outerRect( itemRect.Size() ); //outer rect has the size of item
       
  4207                 TRect innerRect( outerRect );
       
  4208 
       
  4209                 innerRect.Shrink( 5, 5 );
       
  4210                 if ( outerRect.Width() > 0 && outerRect.Height() > 0 &&
       
  4211                         innerRect.Width() > 0 && innerRect.Height() > 0   )
       
  4212                     {
       
  4213                     // aInnerRect, const TRect& aOuterRect
       
  4214                     selectorBrush->SetFrameRectsL( innerRect, outerRect );
       
  4215                     }
       
  4216                 }
       
  4217 
       
  4218             iListLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
  4219             iListItemBackgroundLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
  4220             }
       
  4221         }
       
  4222     }
       
  4223 
       
  4224 // ---------------------------------------------------------------------------
       
  4225 //
       
  4226 // ---------------------------------------------------------------------------
       
  4227 //
       
  4228 void CFsTreeVisualizerBase::UpdateListItemSizes()
       
  4229     {
       
  4230     FUNC_LOG;
       
  4231     TInt focused = iVisibleItems.Find(iFocusedItem);
       
  4232     if (focused == KErrNotFound)
       
  4233         {
       
  4234         return;
       
  4235         }
       
  4236     TInt count = iVisibleItemsBackground.Count();
       
  4237     for (TInt i = 0; i < count; ++i)
       
  4238         {
       
  4239         if (i == focused)
       
  4240             {//focused item already updated
       
  4241             continue;
       
  4242             }
       
  4243         else
       
  4244             {
       
  4245             UpdateListItemSize(i);
       
  4246             }
       
  4247         }
       
  4248     }
       
  4249 
       
  4250 // ---------------------------------------------------------------------------
       
  4251 //
       
  4252 // ---------------------------------------------------------------------------
       
  4253 //
       
  4254 void CFsTreeVisualizerBase::UpdateListItemSize(TInt aIndex)
       
  4255     {
       
  4256     FUNC_LOG;
       
  4257     TSize size;
       
  4258     TReal32 diff(0);
       
  4259     TReal32 speed(0);
       
  4260     TAlfTimedPoint sizeTarg;
       
  4261     TAlfTimedPoint sizeNow;
       
  4262     CAlfDeckLayout* lay;
       
  4263 
       
  4264     lay = iVisibleItemsBackground[aIndex];
       
  4265 
       
  4266     sizeNow.iY.SetTarget(lay->Size().iY.ValueNow(), 0);
       
  4267     sizeNow.iX.SetTarget(lay->Size().iX.ValueNow(), 0);
       
  4268     sizeTarg.iY.SetTarget(lay->Size().iY.Target(), 0);
       
  4269     sizeTarg.iX.SetTarget(lay->Size().iX.Target(), 0);
       
  4270 
       
  4271     if (sizeNow.iY.Target() != sizeTarg.iY.Target())
       
  4272         {
       
  4273         diff = sizeNow.iY.Target() - sizeTarg.iY.Target();
       
  4274         if (diff < 0)
       
  4275             {
       
  4276             diff *= -1;
       
  4277             }
       
  4278 
       
  4279         if (iCurrentScrollSpeed != 0)
       
  4280             {
       
  4281             speed = diff / iCurrentScrollSpeed * 1000;
       
  4282             }
       
  4283 
       
  4284         TAlfTimedPoint p;
       
  4285         p.iY.SetTargetWithSpeed(sizeTarg.iY.Target(), speed);
       
  4286         p.iX.SetTarget(sizeTarg.iX.Target(), 0);
       
  4287         p.SetStyle(EAlfTimedValueStyleLinear);
       
  4288 
       
  4289         lay->SetSize(p);
       
  4290         iListLayout->Visual(aIndex).SetSize(p);
       
  4291 
       
  4292         }
       
  4293     }
       
  4294 
       
  4295 // ---------------------------------------------------------------------------
       
  4296 //
       
  4297 // ---------------------------------------------------------------------------
       
  4298 //
       
  4299 void CFsTreeVisualizerBase::ScrollListLayoutsL(TInt aScrollOffset, TInt /*aScrollTime*/)
       
  4300     {
       
  4301     FUNC_LOG;
       
  4302     TPoint position(iViewPort.Position());
       
  4303     if (position.iY != aScrollOffset)
       
  4304         {
       
  4305         position.iY = aScrollOffset;
       
  4306         iViewPort.SetPositionL(position);
       
  4307         }
       
  4308     }
       
  4309 
       
  4310 // ---------------------------------------------------------------------------
       
  4311 //
       
  4312 // ---------------------------------------------------------------------------
       
  4313 //
       
  4314 TInt CFsTreeVisualizerBase::ScrollListLayouts(TInt aScrollOffset,
       
  4315         TInt aScrollTime)
       
  4316     {
       
  4317     TRAPD( error, ScrollListLayoutsL(aScrollOffset, aScrollTime) );
       
  4318     return error;
       
  4319     }
       
  4320 
       
  4321 // ---------------------------------------------------------------------------
       
  4322 //
       
  4323 // ---------------------------------------------------------------------------
       
  4324 //
       
  4325 TFsTreeItemId CFsTreeVisualizerBase::NextFocusableItem(
       
  4326         const TFsTreeItemId aItemId)
       
  4327     {
       
  4328     FUNC_LOG;
       
  4329     TFsTreeItemId treeItem = KFsTreeNoneID;
       
  4330     TFsTreeItemId foundItem = KFsTreeNoneID;
       
  4331 
       
  4332     TFsTreeIterator treeIter = iTreeData->Iterator(KFsTreeRootID, aItemId,
       
  4333             KFsTreeIteratorSkipCollapsedFlag | KFsTreeIteratorSkipHiddenFlag);
       
  4334 
       
  4335     while (treeIter.HasNext())
       
  4336         {
       
  4337         treeItem = treeIter.Next();
       
  4338         if (iTreeData->ItemVisualizer(treeItem)->IsFocusable())
       
  4339             {
       
  4340             foundItem = treeItem;
       
  4341             break;
       
  4342             }
       
  4343         }
       
  4344 
       
  4345     return foundItem;
       
  4346     }
       
  4347 
       
  4348 // ---------------------------------------------------------------------------
       
  4349 //
       
  4350 // ---------------------------------------------------------------------------
       
  4351 //
       
  4352 TFsTreeItemId CFsTreeVisualizerBase::PrevFocusableItem(
       
  4353         const TFsTreeItemId aItemId)
       
  4354     {
       
  4355     FUNC_LOG;
       
  4356     TFsTreeItemId treeItem = KFsTreeNoneID;
       
  4357     TFsTreeItemId foundItem = KFsTreeNoneID;
       
  4358 
       
  4359     TFsTreeIterator treeIter = iTreeData->Iterator(KFsTreeRootID, aItemId,
       
  4360             KFsTreeIteratorSkipCollapsedFlag | KFsTreeIteratorSkipHiddenFlag);
       
  4361 
       
  4362     while (treeIter.HasPrevious())
       
  4363         {
       
  4364         treeItem = treeIter.Previous();
       
  4365         if (iTreeData->ItemVisualizer(treeItem)->IsFocusable())
       
  4366             {
       
  4367             foundItem = treeItem;
       
  4368             break;
       
  4369             }
       
  4370         }
       
  4371 
       
  4372     return foundItem;
       
  4373     }
       
  4374 
       
  4375 // ---------------------------------------------------------------------------
       
  4376 //  Function sets current scroll speed based on the up/down key repeats.
       
  4377 // ---------------------------------------------------------------------------
       
  4378 //
       
  4379 void CFsTreeVisualizerBase::SetCurrentScrollSpeed(TInt aKeyRepeats)
       
  4380     {
       
  4381     FUNC_LOG;
       
  4382     TInt time(0);
       
  4383     if (iScrollSpeed > 0)
       
  4384         {
       
  4385         time = iIntx->Interval(iScrollSpeed);
       
  4386         if (time != iScrollSpeed)
       
  4387             {
       
  4388             iCurrentScrollSpeed = time;
       
  4389             if (aKeyRepeats > 0)
       
  4390                 {
       
  4391                 iCurrentScrollSpeed = iCurrentScrollSpeed * (1 - aKeyRepeats
       
  4392                         * iScrollAccelerationRate);
       
  4393                 if (iCurrentScrollSpeed < 0)
       
  4394                     {
       
  4395                     iCurrentScrollSpeed = 1;
       
  4396                     }
       
  4397                 }
       
  4398             }
       
  4399         else
       
  4400             {
       
  4401             iCurrentScrollSpeed = iScrollSpeed;
       
  4402             }
       
  4403 
       
  4404         if (iCurrentScrollSpeed < iScrollSpeed)
       
  4405             {
       
  4406             iCurrentScrollSpeed = KZero;
       
  4407             }
       
  4408         //        TInt part(0);
       
  4409         //        part = iScrollSpeed * 0.9;
       
  4410 
       
  4411         //        if ( iCurrentScrollSpeed <= part )
       
  4412         //            {
       
  4413         //            iCurrentScrollSpeed = 0;
       
  4414         //            }
       
  4415         //        if (iCurrentScrollSpeed < 200)
       
  4416         //            {
       
  4417         //            iCurrentScrollSpeed = 200;
       
  4418         //            }
       
  4419         }
       
  4420     }
       
  4421 
       
  4422 // ---------------------------------------------------------------------------
       
  4423 //  Gets default settings from Central Repository.
       
  4424 // ---------------------------------------------------------------------------
       
  4425 //
       
  4426 void CFsTreeVisualizerBase::ReadDefaultValuesFromCenRep()
       
  4427     {
       
  4428     FUNC_LOG;
       
  4429     CRepository *crep(NULL);
       
  4430         TRAP_IGNORE( crep = CRepository::NewL( KCRUidFSGenericUI ) );
       
  4431 
       
  4432     //scroll time
       
  4433     if (!crep || crep->Get(KFSGenericUIDefScrollSpeed, iScrollSpeed)
       
  4434             != KErrNone)
       
  4435         {
       
  4436         iScrollSpeed = KFsListDefaultScrollSpeed;
       
  4437         }
       
  4438     if (iScrollSpeed < 0)
       
  4439         {
       
  4440         iScrollSpeed = 0;
       
  4441         }
       
  4442 
       
  4443     //duration of the fade-in effect
       
  4444     if (!crep || crep->Get(KFSGenericUIFadeIn, iFadeInEffectTime) != KErrNone)
       
  4445         {
       
  4446         iFadeInEffectTime = KFsListDefaultFadeInTime;
       
  4447         }
       
  4448     if (iFadeInEffectTime < 0)
       
  4449         {
       
  4450         iFadeInEffectTime = 0;
       
  4451         }
       
  4452 
       
  4453     //duration of the fade-out effect
       
  4454     if (!crep || crep->Get(KFSGenericUIFadeOut, iFadeOutEffectTime)
       
  4455             != KErrNone)
       
  4456         {
       
  4457         iFadeOutEffectTime = KFsListDefaultFadeOutTime;
       
  4458         }
       
  4459     if (iFadeOutEffectTime < 0)
       
  4460         {
       
  4461         iFadeOutEffectTime = 0;
       
  4462         }
       
  4463 
       
  4464     //duration of the slide-in effect
       
  4465     if (!crep || crep->Get(KFSGenericUISlideInTime, iSlideInDuration)
       
  4466             != KErrNone)
       
  4467         {
       
  4468         iSlideInDuration = KFsListDefaultSlideInTime;
       
  4469         }
       
  4470     if (iSlideInDuration < 0)
       
  4471         {
       
  4472         iSlideInDuration = KFsListDefaultSlideInTime;
       
  4473         }
       
  4474 
       
  4475     //duration of the slide-out effect
       
  4476     if (!crep || crep->Get(KFSGenericUISlideOutTime, iSlideOutDuration)
       
  4477             != KErrNone)
       
  4478         {
       
  4479         iSlideOutDuration = KFsListDefaultSlideOutTime;
       
  4480         }
       
  4481     if (iSlideOutDuration < 0)
       
  4482         {
       
  4483         iSlideOutDuration = 0;
       
  4484         }
       
  4485 
       
  4486     //direction of the slide-in effect
       
  4487     TInt slideInDir;
       
  4488     if (!crep || crep->Get(KFSGenericUISlideInDir, slideInDir) != KErrNone)
       
  4489         {
       
  4490         slideInDir = KFsListDefaultSlideInDir;
       
  4491         }
       
  4492     if (slideInDir < 0 || slideInDir > 4)
       
  4493         {
       
  4494         slideInDir = 0;
       
  4495         }
       
  4496     iSlideInDirection
       
  4497             = static_cast<MFsTreeVisualizer::TFsSlideEffect> (slideInDir);
       
  4498 
       
  4499     //direction of the slide-out effect
       
  4500     TInt slideOutDir;
       
  4501     if (!crep || crep->Get(KFSGenericUISlideOutDir, slideOutDir) != KErrNone)
       
  4502         {
       
  4503         slideOutDir = KFsListDefaultSlideOutDir;
       
  4504         }
       
  4505     if (slideOutDir < 0 || slideOutDir > 4)
       
  4506         {
       
  4507         slideOutDir = 0;
       
  4508         }
       
  4509     iSlideOutDirection =
       
  4510                    static_cast<MFsTreeVisualizer::TFsSlideEffect>(slideOutDir);
       
  4511 
       
  4512     //item expansion time
       
  4513     if ( !crep || crep->Get( KFSGenericUIListExpTimeOut, iCurrentScrollSpeed ) !=
       
  4514         KErrNone  )
       
  4515         {
       
  4516         iCurrentScrollSpeed = KFsListDefaultListExpTimeOut;
       
  4517         }
       
  4518     if (iCurrentScrollSpeed < 1)
       
  4519         {
       
  4520         iCurrentScrollSpeed = 1;
       
  4521         }
       
  4522 
       
  4523     //list looping type
       
  4524     TInt listLooping;
       
  4525     if ( !crep || crep->Get( KFSGenericUIListLooping, listLooping) !=
       
  4526         KErrNone )
       
  4527         {
       
  4528         listLooping = KFsListDefaultListLooping;
       
  4529         }
       
  4530     if (listLooping < 0 || listLooping > 2)
       
  4531         {
       
  4532         listLooping = 0;
       
  4533         }
       
  4534     iLooping = static_cast<TFsTreeListLoopingType> (listLooping);
       
  4535 
       
  4536     delete crep;
       
  4537     }
       
  4538 
       
  4539 // ---------------------------------------------------------------------------
       
  4540 //  Sets values to an item which are default for the whole list (e.g. if
       
  4541 //  items are always extended.
       
  4542 // ---------------------------------------------------------------------------
       
  4543 //
       
  4544 void CFsTreeVisualizerBase::ApplyListSpecificValuesToItem(
       
  4545         MFsTreeItemVisualizer *aItemVis)
       
  4546     {
       
  4547     FUNC_LOG;
       
  4548     //list can have all items in extended or in a normal state
       
  4549     aItemVis->SetAlwaysExtended(IsItemsAlwaysExtended());
       
  4550 
       
  4551     //global indentation in pixels for a list component
       
  4552     aItemVis->SetIndentation(iLevelIndentation);
       
  4553 
       
  4554     //global indentation in pixels for a list component
       
  4555     aItemVis->SetTextStyleManager(*iTextStyleManager);
       
  4556     }
       
  4557 
       
  4558 // ---------------------------------------------------------------------------
       
  4559 // The function calculates tree height up to the specified item.
       
  4560 // ---------------------------------------------------------------------------
       
  4561 //
       
  4562 TInt CFsTreeVisualizerBase::CalculateTreeHeightUpToItem(
       
  4563         const TFsTreeItemId aItemId, TInt& aHeight) const
       
  4564     {
       
  4565     FUNC_LOG;
       
  4566     TFsTreeItemId tmpItem(KFsTreeNoneID);
       
  4567     TFsTreeItemId itemToFind(KFsTreeNoneID);
       
  4568     itemToFind = aItemId;
       
  4569     TInt retVal(KErrNone);
       
  4570     //validate given item id
       
  4571     if (!iTreeData->Contains(itemToFind))
       
  4572         {
       
  4573         retVal = KErrNotFound;
       
  4574         }
       
  4575     if (retVal == KErrNone)
       
  4576         {
       
  4577         //create an iterator
       
  4578         TFsTreeIterator iter = iTreeData->Iterator(KFsTreeRootID,
       
  4579                 KFsTreeRootID, KFsTreeIteratorSkipCollapsedFlag
       
  4580                         | KFsTreeIteratorSkipHiddenFlag);
       
  4581 
       
  4582         TBool notFound(ETrue);
       
  4583         TInt height(0);
       
  4584         MFsTreeItemVisualizer* vis = NULL;
       
  4585 
       
  4586         //iterate up to the given item id and calculate the tree height
       
  4587         while (notFound && iter.HasNext())
       
  4588             {
       
  4589             tmpItem = iter.Next();
       
  4590             if (tmpItem == itemToFind)
       
  4591                 {
       
  4592                 notFound = EFalse;
       
  4593                 continue;
       
  4594                 }
       
  4595             else
       
  4596                 {//add item's height
       
  4597                 vis = iTreeData->ItemVisualizer(tmpItem);
       
  4598                 if (vis->IsExtendable() && vis->IsExtended())
       
  4599                     {
       
  4600                     height += vis->ExtendedSize().iHeight;
       
  4601                     }
       
  4602                 else
       
  4603                     {
       
  4604                     height += vis->Size().iHeight;
       
  4605                     }
       
  4606                 }
       
  4607             }
       
  4608 
       
  4609         if (notFound)
       
  4610             {
       
  4611             retVal = KErrNotFound;
       
  4612             }
       
  4613         else
       
  4614             {
       
  4615             retVal = KErrNone;
       
  4616             aHeight = height;
       
  4617             }
       
  4618         }
       
  4619     return retVal;
       
  4620     }
       
  4621 
       
  4622 // ---------------------------------------------------------------------------
       
  4623 //  Update list's visual content by appending items into empty gap in list.
       
  4624 // ---------------------------------------------------------------------------
       
  4625 //
       
  4626 void CFsTreeVisualizerBase::FillGapWithItemsL(const TInt /*aHeight*/)
       
  4627     {
       
  4628     FUNC_LOG;
       
  4629     }
       
  4630 
       
  4631 // ---------------------------------------------------------------------------
       
  4632 //  The function checks if the given item id matches the focused one.
       
  4633 // ---------------------------------------------------------------------------
       
  4634 //
       
  4635 TBool CFsTreeVisualizerBase::IsItemFocused(TFsTreeItemId aItemId) const
       
  4636     {
       
  4637     FUNC_LOG;
       
  4638     TBool isFocused(EFalse);
       
  4639 
       
  4640     if (iFocusedItem != KFsTreeNoneID)
       
  4641         {
       
  4642         if (iFlags.IsSet(EListFocused) && (aItemId == iFocusedItem))
       
  4643             {
       
  4644             isFocused = ETrue;
       
  4645             }
       
  4646         }
       
  4647     return isFocused;
       
  4648     }
       
  4649 
       
  4650 // <cmail> "Base class modifications for using touch"
       
  4651 
       
  4652 // ---------------------------------------------------------------------------
       
  4653 //  C++ constructor.
       
  4654 // ---------------------------------------------------------------------------
       
  4655 //
       
  4656 CFsTreeVisualizerBase::CFsTreeVisualizerBase( CAlfControl* aOwnerControl,
       
  4657         CAlfLayout& aParent, const TBool aPopUpMode )
       
  4658     : iVisualizationState(EFsTreeHidden),
       
  4659       iOwnerControl ( aOwnerControl ),
       
  4660       iParentLayout ( aParent ),
       
  4661       iTreeData ( NULL ),
       
  4662       iFocusedItem ( KFsTreeNoneID ),
       
  4663       iListLayout ( NULL ),
       
  4664       iLooping ( EFsTreeListLoopingDisabled ),
       
  4665       iSelectorTexture(NULL),
       
  4666       iSelectorBrush(NULL),
       
  4667       iSelectorOpacity(1.0),
       
  4668       iLeftSelectorBorderWidth(KFSListDefaultSelectorBorderWidth),
       
  4669       iRightSelectorBorderWidth(KFSListDefaultSelectorBorderWidth),
       
  4670       iTopSelectorBorderHeight(KFSListDefaultSelectorBorderWidth),
       
  4671       iBottomSelectorBorderHeight(KFSListDefaultSelectorBorderWidth),
       
  4672       iSelectorMovementType(EFsSelectorMoveImmediately),
       
  4673       iMarqueeSpeed(30),
       
  4674       iScrollSpeed( 0 ),
       
  4675       iCurrentScrollSpeed(0),
       
  4676       iScrollAccelerationRate(0.4),
       
  4677       iFadeInEffectTime(0),
       
  4678       iFadeOutEffectTime(0),
       
  4679       iWatermark(NULL),
       
  4680       iLevelIndentation ( KFsDefaultIndentation ),
       
  4681       iSlideInDuration ( 0 ),
       
  4682       iSlideInDirection ( ESlideFromTop ),
       
  4683       iSlideOutDuration ( 0 ),
       
  4684       iSlideOutDirection ( ESlideFromTop ),
       
  4685       iScrollOffset(0),
       
  4686       iMarqueeType(EFsTextMarqueeForth),
       
  4687       iMarqueStartDelay( 1000 ), //one sec of delay
       
  4688       iMarqueCycleStartDelay ( 500 ), //half a sec cycle delay
       
  4689       iMarqueeRepetitions (-1), //infinite loop
       
  4690       iViewPort( *this, iWorld )
       
  4691     {
       
  4692     FUNC_LOG;
       
  4693     iFlags.Set( EAutoRefresh );
       
  4694     iFlags.Assign( EPopupMode, aPopUpMode );
       
  4695     iFlags.Set( EExpandCollapseOnLongTap );
       
  4696     }
       
  4697 // </cmail>
       
  4698 
       
  4699 // ---------------------------------------------------------------------------
       
  4700 //  Second phase constructor.
       
  4701 // ---------------------------------------------------------------------------
       
  4702 //
       
  4703 void CFsTreeVisualizerBase::ConstructL()
       
  4704     {
       
  4705     FUNC_LOG;
       
  4706     ReadDefaultValuesFromCenRep();
       
  4707 
       
  4708     if (CAknPhysics::FeatureEnabled())
       
  4709         {
       
  4710         iPhysics = CAknPhysics::NewL(*this, NULL );
       
  4711         iDragHandler = CDragHandler::NewL(*this,
       
  4712                 iPhysics->HighlightTimeout(), iFlags);
       
  4713         iPhysics->SetFriction(KDefaultFriction);
       
  4714         }
       
  4715 
       
  4716     iRootData = CFsTreePlainOneLineItemData::NewL();
       
  4717     HBufC* empty = StringLoader::LoadL(R_AVKON_EMPTY_POPUP_LIST_TEXT);
       
  4718     CleanupStack::PushL(empty);
       
  4719     iRootData->SetDataL(*empty);
       
  4720     CleanupStack::PopAndDestroy(empty);
       
  4721 
       
  4722     iParentLayout.UpdateChildrenLayout();
       
  4723 
       
  4724     iRootVisualizer = CFsTreePlainRootVisualizer::NewL(*iOwnerControl);
       
  4725 
       
  4726     iRootLayout = CAlfDeckLayout::AddNewL(*iOwnerControl, &iParentLayout);
       
  4727     iRootLayout->EnableBrushesL();
       
  4728     iRootLayout->SetClipping(ETrue);
       
  4729     iRootLayout->UpdateChildrenLayout();
       
  4730 
       
  4731     iTextStyleManager = CFsAlfTextStyleManager::NewL(
       
  4732             iRootLayout->Env().TextStyleManager());
       
  4733 
       
  4734     iRootVisualizer->SetTextStyleManager(*iTextStyleManager);
       
  4735 
       
  4736     iShadowLayout = CAlfDeckLayout::AddNewL(*iOwnerControl, iRootLayout);
       
  4737     iShadowLayout->EnableBrushesL();
       
  4738     iShadowLayout->UpdateChildrenLayout();
       
  4739 
       
  4740     iBorderLayout = CAlfDeckLayout::AddNewL(*iOwnerControl, iShadowLayout);
       
  4741     iBorderLayout->EnableBrushesL();
       
  4742     iBorderLayout->UpdateChildrenLayout();
       
  4743 
       
  4744     iWatermarkLayout = CAlfDeckLayout::AddNewL(*iOwnerControl, iBorderLayout);
       
  4745     iWatermarkLayout->EnableBrushesL();
       
  4746     iWatermarkLayout->UpdateChildrenLayout();
       
  4747 
       
  4748     iComponentLayout = CAlfGridLayout::AddNewL(*iOwnerControl, 1, 1,
       
  4749             iWatermarkLayout);
       
  4750     iComponentLayout->SetClipping(ETrue);
       
  4751     iComponentLayout->EnableBrushesL();
       
  4752     iComponentLayout->UpdateChildrenLayout();
       
  4753 
       
  4754     if (AknLayoutUtils::LayoutMirrored())
       
  4755         {
       
  4756         iDummyScrollbar = CAlfImageVisual::AddNewL(*iOwnerControl);
       
  4757         iComponentLayout->Append(iDummyScrollbar);
       
  4758         iListDeck = CAlfDeckLayout::AddNewL(*iOwnerControl, iComponentLayout);
       
  4759         }
       
  4760     else
       
  4761         {
       
  4762         iListDeck = CAlfDeckLayout::AddNewL(*iOwnerControl, iComponentLayout);
       
  4763         iDummyScrollbar = CAlfImageVisual::AddNewL(*iOwnerControl);
       
  4764         iComponentLayout->Append(iDummyScrollbar);
       
  4765         }
       
  4766     iListItemBackgroundLayout = CAlfFlowLayout::AddNewL(*iOwnerControl,
       
  4767             iListDeck);
       
  4768     iListItemBackgroundLayout->SetFlowDirection(CAlfFlowLayout::EFlowVertical);
       
  4769     iListItemBackgroundLayout->SetClipping(ETrue);
       
  4770     iListItemBackgroundLayout->EnableScrollingL(ETrue);
       
  4771     TAlfTimedPoint tpListScrollOffset;
       
  4772     tpListScrollOffset.SetStyle(EAlfTimedValueStyleLinear);
       
  4773     iListItemBackgroundLayout->SetScrollOffset(tpListScrollOffset);
       
  4774 
       
  4775     iSelectorLayout = CAlfDeckLayout::AddNewL(*iOwnerControl, iListDeck);
       
  4776     iSelectorLayout->SetClipping(ETrue);
       
  4777 
       
  4778     iListLayout = CAlfFlowLayout::AddNewL(*iOwnerControl, iListDeck);
       
  4779     iListLayout->SetFlowDirection(CAlfFlowLayout::EFlowVertical);
       
  4780 
       
  4781     iListLayout->EnableBrushesL();
       
  4782     iListLayout->EnableScrollingL(ETrue);
       
  4783     iListLayout->SetScrollOffset(tpListScrollOffset);
       
  4784 
       
  4785     //list pane's padding taken from layout manager
       
  4786     EnableListPanePadding(ETrue);
       
  4787 
       
  4788     iListLayout->UpdateChildrenLayout();
       
  4789     iListItemBackgroundLayout->UpdateChildrenLayout();
       
  4790 
       
  4791     iBorderBrush = CAlfBorderBrush::NewL(iOwnerControl->Env(), 0, 1, 0, 0);
       
  4792     static_cast<CAlfBorderBrush*> (iBorderBrush)->SetColor(KRgbGray);
       
  4793     static_cast<CAlfBorderBrush*> (iBorderBrush)->SetThickness(
       
  4794             TAlfTimedPoint(0.0f, 0.5f));
       
  4795     iBorderBrush->SetLayer(EAlfBrushLayerForeground);
       
  4796 
       
  4797     iScrollbarVisibility = EFsScrollbarShowAlways;
       
  4798 
       
  4799     iScrollBarLayout = CAlfAnchorLayout::AddNewL( *iOwnerControl, iListDeck );
       
  4800     iScrollBarLayout->SetFlags( EAlfVisualFlagIgnorePointer );
       
  4801 
       
  4802     if ( iFlags.IsSet( EPopupMode ) )
       
  4803         {
       
  4804         iScrollBar = CUiCAknScrollBarAdapter::NewL( *this );
       
  4805         }
       
  4806     else
       
  4807         {
       
  4808         iScrollBar = CUiCScrollBar::NewL( iOwnerControl->Env(), iScrollBarLayout );
       
  4809         }
       
  4810 
       
  4811     iScrollBarModel.SetHeight(iComponentLayout->Size().Target().iY);
       
  4812     iScrollBarModel.SetWindowPosition(iViewPort.Position().iY);
       
  4813     iScrollBarModel.SetWindowHeight(iListLayout->Size().iY.Target());
       
  4814 
       
  4815     iScrollBar->Show( EFalse );
       
  4816     iScrollBar->UpdateModelL( iScrollBarModel );
       
  4817 
       
  4818     iFadeEffect = CFsFadeEffect::NewL(iOwnerControl, this, iRootLayout, 0);
       
  4819     iSlideEffect = CFsSlideEffect::NewL(iOwnerControl, this, iRootLayout, 0);
       
  4820 
       
  4821     iFadeInEffectTime = KFsListDefaultFadeInTime;
       
  4822     iFadeOutEffectTime = KFsListDefaultFadeOutTime;
       
  4823 
       
  4824     iIntx = new (ELeave) CFsInteractionInterval;
       
  4825 
       
  4826     iOwnerControl->Env().AddActionObserverL(this);
       
  4827 
       
  4828     iWorld.AddObserverL(iViewPort);
       
  4829     iWorld.AddObserverL(*this);
       
  4830     UpdateViewPortL();
       
  4831     }
       
  4832 
       
  4833 // ---------------------------------------------------------------------------
       
  4834 //  Handle scrollbar events
       
  4835 // ---------------------------------------------------------------------------
       
  4836 //
       
  4837 void CFsTreeVisualizerBase::HandleScrollEventL( const MUiCScrollBar& aScrollBar,
       
  4838         MUiCScrollBar::TEvent aEvent )
       
  4839     {
       
  4840     FUNC_LOG;
       
  4841     switch (aEvent)
       
  4842         {
       
  4843         case MUiCScrollBar::EScrollHome:
       
  4844             // Home
       
  4845             break;
       
  4846         case MUiCScrollBar::EScrollEnd:
       
  4847             // End
       
  4848             break;
       
  4849         default:
       
  4850             TPoint position(iViewPort.Position());
       
  4851             position.iY = aScrollBar.ThumbPosition();
       
  4852             iViewPort.SetPositionL(position);
       
  4853             break;
       
  4854         }
       
  4855     }
       
  4856 
       
  4857 // ---------------------------------------------------------------------------
       
  4858 //  Handle visibility change
       
  4859 // ---------------------------------------------------------------------------
       
  4860 //
       
  4861 void CFsTreeVisualizerBase::NotifyControlVisibilityChange(TBool aIsVisible)
       
  4862     {
       
  4863     FUNC_LOG;
       
  4864 
       
  4865     if (aIsVisible && iVisualizationState == EFsTreeVisible)
       
  4866         {
       
  4867         UpdateScrollBar();
       
  4868         }
       
  4869     else
       
  4870         {
       
  4871         iScrollBar->Show( EFalse );
       
  4872         }
       
  4873     }
       
  4874 
       
  4875 // ---------------------------------------------------------------------------
       
  4876 //
       
  4877 // ---------------------------------------------------------------------------
       
  4878 //
       
  4879 void CFsTreeVisualizerBase::DisableKineticScrolling( TBool aDisable )
       
  4880     {
       
  4881     FUNC_LOG;
       
  4882     iKineticScrollingDisabled = aDisable;
       
  4883     }
       
  4884 
       
  4885 
       
  4886 // ---------------------------------------------------------------------------
       
  4887 //
       
  4888 // ---------------------------------------------------------------------------
       
  4889 //
       
  4890 TBool CFsTreeVisualizerBase::IsKineticScrollingDisabled() const
       
  4891     {
       
  4892     FUNC_LOG;
       
  4893     return iKineticScrollingDisabled;
       
  4894     }
       
  4895 
       
  4896 // ---------------------------------------------------------------------------
       
  4897 // World updated
       
  4898 // ---------------------------------------------------------------------------
       
  4899 //
       
  4900 void CFsTreeVisualizerBase::WorldUpdatedL(const TWorld& /*aWorld*/)
       
  4901     {
       
  4902     FUNC_LOG;
       
  4903     if (iFlags.IsSet(EPhysicsOn))
       
  4904         {
       
  4905         iFlags.Set(EUpdatePhysicsAfterSimulationFinished);
       
  4906         }
       
  4907     else
       
  4908         {
       
  4909         UpdatePhysicsL();
       
  4910         }
       
  4911     UpdateScrollBarL();
       
  4912     }
       
  4913 
       
  4914 // ---------------------------------------------------------------------------
       
  4915 // ViewPort updated
       
  4916 // ---------------------------------------------------------------------------
       
  4917 //
       
  4918 void CFsTreeVisualizerBase::ViewPortUpdatedL(TViewPort& aViewPort, TUpdatedByPhysic aUpdateByPhysic)
       
  4919     {
       
  4920     FUNC_LOG;
       
  4921 
       
  4922     // Only upadte view if the list is visible
       
  4923     if (iVisualizationState != EFsTreeVisible)
       
  4924         {
       
  4925         return;
       
  4926         }
       
  4927 
       
  4928     RArray<TFsTreeItemId> visibleItems;
       
  4929     RArray<TFsTreeItemId> removableItems;
       
  4930     TInt scrollOffset;
       
  4931     TBool fullUpdate;
       
  4932     CleanupClosePushL(visibleItems);
       
  4933     CleanupClosePushL(removableItems);
       
  4934     aViewPort.GetVisibleItemsL(removableItems, visibleItems, scrollOffset,
       
  4935             fullUpdate);
       
  4936     TAlfRefreshMode rm(EAlfRefreshModeAutomatic);
       
  4937     rm = CAlfStatic::Env().RefreshMode();
       
  4938     CAlfStatic::Env().SetRefreshMode(EAlfRefreshModeManual);
       
  4939     iListLayout->SetFlag(EAlfVisualFlagFreezeLayout);
       
  4940 
       
  4941 	if(aUpdateByPhysic == EUpdatedByPhisicEnd)
       
  4942 		{
       
  4943     	RArray<TFsTreeItemId> myVisibleItems;
       
  4944     	TInt myOffset;
       
  4945     	CleanupClosePushL(myVisibleItems);
       
  4946     	aViewPort.GetVisibleItemsL(myVisibleItems, myOffset);
       
  4947 
       
  4948     	for (TInt i = 0; i < myVisibleItems.Count(); i++)
       
  4949     		{
       
  4950     		const TFsTreeItemId itemId(myVisibleItems[i]);
       
  4951     		if (itemId != KFsTreeNoneID)
       
  4952     			{
       
  4953     			MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(
       
  4954     											itemId);
       
  4955     			visualizer->UpdateL(iTreeData->ItemData(itemId),
       
  4956     							IsItemFocused(itemId) && IsFocusShown(),
       
  4957     							iTreeData->Level(itemId), iMarkIcon, iMenuIcon,
       
  4958     							0);
       
  4959     			}
       
  4960     		}
       
  4961     	CleanupStack::PopAndDestroy();
       
  4962     	}
       
  4963 
       
  4964     // clear list
       
  4965     TInt removed(0);
       
  4966     if (fullUpdate)
       
  4967         {
       
  4968         removed += iListLayout->Count();
       
  4969         for (TInt i = removed - 1; i >= 0; i--)
       
  4970             {
       
  4971             iTreeData->ItemVisualizer(VisualItemId(&iListLayout->Visual(i)))->Hide();
       
  4972             }
       
  4973         iVisibleItems.Reset();
       
  4974         }
       
  4975     else
       
  4976         {
       
  4977         for (TInt i = 0; i < removableItems.Count(); i++)
       
  4978             {
       
  4979             MFsTreeItemVisualizer* itemVisualizer(iTreeData->ItemVisualizer(removableItems[i]));
       
  4980             if (itemVisualizer)
       
  4981                 {
       
  4982                 CAlfVisual* visual(&itemVisualizer->Layout());
       
  4983                 if (iListLayout->FindVisual(visual) != KErrNotFound)
       
  4984                     {
       
  4985                     removed++;
       
  4986                     }
       
  4987                 itemVisualizer->Hide();
       
  4988                 const TInt index(iVisibleItems.Find(removableItems[i]));
       
  4989                 if (index != KErrNotFound)
       
  4990                     {
       
  4991                     iVisibleItems.Remove(index);
       
  4992                     }
       
  4993                 }
       
  4994             }
       
  4995         }
       
  4996 
       
  4997     // update items to list
       
  4998     TInt added(0);
       
  4999     for (TInt i = 0; i < visibleItems.Count(); i++)
       
  5000         {
       
  5001         const TFsTreeItemId itemId(visibleItems[i]);
       
  5002         if (itemId != KFsTreeNoneID)
       
  5003             {
       
  5004             MFsTreeItemVisualizer* visualizer = iTreeData->ItemVisualizer(
       
  5005                     itemId);
       
  5006             visualizer->ShowL(*iListLayout);
       
  5007             TSize size(visualizer->Size());
       
  5008             TInt listInnerWidth(iListLayout->Size().IntTarget().iX);
       
  5009             TAlfTimedPoint tpItemSize( listInnerWidth, size.iHeight );
       
  5010             CAlfLayout& visualizerLayout(visualizer->Layout());
       
  5011             visualizerLayout.SetSize(tpItemSize);
       
  5012         	visualizer->UpdateL(iTreeData->ItemData(itemId),
       
  5013                 IsItemFocused(itemId) && IsFocusShown(),
       
  5014                 iTreeData->Level(itemId), iMarkIcon, iMenuIcon,
       
  5015                 0);
       
  5016             visualizerLayout.PropertySetIntegerL(KPropertyItemId(), itemId);
       
  5017             visualizerLayout.Brushes()->AppendL(iBorderBrush,
       
  5018                     EAlfDoesNotHaveOwnership);
       
  5019             CAlfBrush* bgBrush(NULL);
       
  5020             if (visualizer->GetBackgroundBrush(bgBrush))
       
  5021                 {
       
  5022                 bgBrush->SetLayer(EAlfBrushLayerBackground);
       
  5023                 visualizerLayout.Brushes()->AppendL(bgBrush,
       
  5024                         EAlfDoesNotHaveOwnership);
       
  5025                 }
       
  5026             const TInt orderPosition(
       
  5027                     i < iListLayout->Count() ? i : iListLayout->Count() - 1);
       
  5028             iListLayout->Reorder(visualizerLayout, orderPosition);
       
  5029             iVisibleItems.AppendL(itemId);
       
  5030             added++;
       
  5031             }
       
  5032         }
       
  5033 
       
  5034     INFO_2("totalItems: %d, visibleItems: %d", iWorld.ItemCount(), visibleItems.Count());
       
  5035     CleanupStack::PopAndDestroy(2); // visibleItems.Close(), removableItems.Close()
       
  5036     // scroll list layout by offset
       
  5037     TAlfTimedPoint alfOffset;
       
  5038     alfOffset.iY.SetTarget(scrollOffset, 0);
       
  5039     iListLayout->SetScrollOffset(alfOffset);
       
  5040     iListLayout->ClearFlag(EAlfVisualFlagFreezeLayout);
       
  5041     iListLayout->UpdateChildrenLayout();
       
  5042     UpdateSelectorVisualL();
       
  5043     UpdateScrollBarIfNeededL();
       
  5044     CAlfStatic::Env().RefreshCallBack(&CAlfStatic::Env());
       
  5045     CAlfStatic::Env().SetRefreshMode(rm);
       
  5046     }
       
  5047 
       
  5048 // ---------------------------------------------------------------------------
       
  5049 // Set panning position
       
  5050 // ---------------------------------------------------------------------------
       
  5051 //
       
  5052 void CFsTreeVisualizerBase::SetPanningPosition(const TPoint& aDelta)
       
  5053     {
       
  5054     FUNC_LOG;
       
  5055     iPhysics->RegisterPanningPosition(aDelta);    
       
  5056     iFlags.Set( EListPanning );
       
  5057     SetFocusVisibility( EFalse );
       
  5058     }
       
  5059 
       
  5060 // ---------------------------------------------------------------------------
       
  5061 // Starts flicking.
       
  5062 // ---------------------------------------------------------------------------
       
  5063 //
       
  5064 void CFsTreeVisualizerBase::StartPhysics(TPoint& aDrag,
       
  5065         const TTime& aStartTime)
       
  5066     {
       
  5067     FUNC_LOG;
       
  5068     TTime startTime( aStartTime );
       
  5069     TTime now;
       
  5070     now.HomeTime();
       
  5071     TInt moveTime( now.MicroSecondsFrom( aStartTime ).Int64() );
       
  5072     if (moveTime > KFlickMaxDuration)
       
  5073         {
       
  5074         startTime = now - TTimeIntervalMicroSeconds( KFlickMaxDuration - 1 );
       
  5075         aDrag.iY = aDrag.iY * KFlickMaxDuration / moveTime;
       
  5076         }
       
  5077     if (iPhysics->StartPhysics(aDrag, startTime))
       
  5078         {
       
  5079         iFlags.Set(EPhysicsOn);
       
  5080         }
       
  5081     }
       
  5082 
       
  5083 // ---------------------------------------------------------------------------
       
  5084 // Update physics
       
  5085 // ---------------------------------------------------------------------------
       
  5086 //
       
  5087 void CFsTreeVisualizerBase::UpdatePhysicsL()
       
  5088     {
       
  5089     FUNC_LOG;
       
  5090     if (iPhysics)
       
  5091         {
       
  5092         SafeDelete(iPhysics);
       
  5093         iPhysics = CAknPhysics::NewL(*this, NULL );
       
  5094         const TSize viewSize(iViewPort.Size());
       
  5095         const TSize worldSize(viewSize.iWidth, Max(iWorld.Height(),
       
  5096                 viewSize.iHeight));
       
  5097         iPhysics->InitPhysicsL(worldSize, viewSize, EFalse);
       
  5098         iPhysics->SetFriction(KDefaultFriction);
       
  5099         }
       
  5100     }
       
  5101 
       
  5102 // ---------------------------------------------------------------------------
       
  5103 // Returns viewPort top-left position
       
  5104 // ---------------------------------------------------------------------------
       
  5105 //
       
  5106 TPoint CFsTreeVisualizerBase::ViewPortTopPosition() const
       
  5107 {
       
  5108     FUNC_LOG;
       
  5109     return iViewPort.Position();
       
  5110 }
       
  5111 
       
  5112 // ---------------------------------------------------------------------------
       
  5113 // Physic updated view position
       
  5114 // ---------------------------------------------------------------------------
       
  5115 //
       
  5116 void CFsTreeVisualizerBase::ViewPositionChanged(const TPoint& aNewPosition,
       
  5117         TBool /*aDrawNow*/, TUint aFlags )
       
  5118     {
       
  5119     FUNC_LOG;
       
  5120     TInt error(KErrNone);
       
  5121     TRAP( error, iViewPort.SetCenterPositionL(aNewPosition, ETrue,
       
  5122                 aFlags == 0 ? EUpdatedByPhisic : ENotUpdatedByPhisic ) );
       
  5123     ERROR_1( error, "iViewPort.SetCenterPositionL failed with error: %d", error );
       
  5124     }
       
  5125 
       
  5126 // ---------------------------------------------------------------------------
       
  5127 // Physic emulation has finished
       
  5128 // ---------------------------------------------------------------------------
       
  5129 //
       
  5130 void CFsTreeVisualizerBase::PhysicEmulationEnded()
       
  5131     {
       
  5132     FUNC_LOG;
       
  5133 
       
  5134     TRAP_IGNORE( iViewPort.SetCenterPositionL(iViewPort.CenterPosition(), ETrue, EUpdatedByPhisicEnd));
       
  5135 
       
  5136     iFlags.Clear(EPhysicsOn);
       
  5137     if (iFlags.IsSet(EUpdatePhysicsAfterSimulationFinished))
       
  5138         {
       
  5139         iFlags.Clear(EUpdatePhysicsAfterSimulationFinished);
       
  5140             TRAP_IGNORE( UpdatePhysicsL() );
       
  5141         }
       
  5142     }
       
  5143 
       
  5144 // ---------------------------------------------------------------------------
       
  5145 //
       
  5146 // ---------------------------------------------------------------------------
       
  5147 //
       
  5148 TPoint CFsTreeVisualizerBase::ViewPosition() const
       
  5149     {
       
  5150     FUNC_LOG;
       
  5151     return iViewPort.CenterPosition();
       
  5152     }
       
  5153 
       
  5154 // ---------------------------------------------------------------------------
       
  5155 // Wrapper for SetFocusedItemAndSendEventL to trap the error and return it
       
  5156 // instead of leaving.
       
  5157 // ---------------------------------------------------------------------------
       
  5158 //
       
  5159 TInt CFsTreeVisualizerBase::SetFocusedItemAndSendEvent(
       
  5160     const TFsTreeItemId aItemId, TPointerEventType aEventType, const TPoint& aPoint )
       
  5161     {
       
  5162     FUNC_LOG;
       
  5163     TRAPD(error, SetFocusedItemAndSendEventL( aItemId, aEventType, aPoint ) );
       
  5164     return error;
       
  5165     }
       
  5166 
       
  5167 // ---------------------------------------------------------------------------
       
  5168 // Sets the specified item as focused and sends event about touch focusing if
       
  5169 // the same item is already focused, action event will be sent instead.
       
  5170 // ---------------------------------------------------------------------------
       
  5171 //
       
  5172 void CFsTreeVisualizerBase::SetFocusedItemAndSendEventL(
       
  5173         const TFsTreeItemId aItemId, TPointerEventType aEventType, const TPoint& aPoint )
       
  5174     {
       
  5175     FUNC_LOG;
       
  5176 
       
  5177     // Handles all other than pointer up events.
       
  5178     // Focus is drawn when:
       
  5179     //  - new item is selected (FocusedItem() != aItemId)
       
  5180     //  - pointer is pressed down and focus is not visible by default
       
  5181     //    (aEventType == EPointerDown ) && IsFocusShown())
       
  5182     if( ( aEventType < EPointerUp ) &&
       
  5183         ( !iFlags.IsSet( EListFocused ) || FocusedItem() != aItemId ||
       
  5184             ( ( aEventType == EPointerDown ) && IsFocusShown() ) ) )
       
  5185         {
       
  5186         SetFocusedItemL( aItemId );
       
  5187         iVisualizerObserver->TreeVisualizerEventL(
       
  5188             MFsTreeVisualizerObserver::EFsTreeItemTouchFocused,
       
  5189             FocusedItem(), aPoint );
       
  5190 
       
  5191         // If DirectTouchMode (actions happens in pointer down events)
       
  5192         if( iFlags.IsSet( EDirectTouchMode ) && aEventType == EPointerDown )
       
  5193             {
       
  5194             iTouchPressed = EFalse;
       
  5195             iVisualizerObserver->TreeVisualizerEventL(
       
  5196                 MFsTreeVisualizerObserver::EFsTreeItemTouchAction,
       
  5197                 aItemId, aPoint );
       
  5198             }
       
  5199         }
       
  5200     else if( aEventType == ELongTap )
       
  5201         {
       
  5202         // HandlePointerEventL do not get pointer up event after long tap event
       
  5203         // so <code>iTouchPressed</code> flag needs to be reset here.
       
  5204         iTouchPressed = EFalse;
       
  5205 		iVisualizerObserver->TreeVisualizerEventL(
       
  5206 				MFsTreeVisualizerObserver::EFsTreeItemTouchLongTap,
       
  5207   			    aItemId, aPoint );
       
  5208         }
       
  5209     else if( aEventType == EPointerUp )
       
  5210         {
       
  5211         // Ignore pointer up action IF physic emulation was stopped on pointer down
       
  5212         if ( !iFlags.IsSet(EIgnorePointerUpAction) )
       
  5213             {
       
  5214             iVisualizerObserver->TreeVisualizerEventL(
       
  5215                 MFsTreeVisualizerObserver::EFsTreeItemTouchAction, aItemId, aPoint );
       
  5216             }
       
  5217         }
       
  5218     // Added for tactile feedback
       
  5219     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  5220     if( feedback )
       
  5221         {
       
  5222         feedback->InstantFeedback( ETouchFeedbackBasic );
       
  5223         }
       
  5224     }
       
  5225 
       
  5226 // CFsTreeVisualizerBase::CDragHandler
       
  5227 
       
  5228 // ---------------------------------------------------------------------------
       
  5229 //
       
  5230 // ---------------------------------------------------------------------------
       
  5231 //
       
  5232 CFsTreeVisualizerBase::CDragHandler* CFsTreeVisualizerBase::CDragHandler::NewL(
       
  5233         CFsTreeVisualizerBase& aTree, const TInt aHighlightTimeout,
       
  5234         const TBitFlags& aFlags)
       
  5235     {
       
  5236     FUNC_LOG;
       
  5237     CDragHandler* self = new (ELeave) CDragHandler(aTree, aHighlightTimeout,
       
  5238             aFlags);
       
  5239     CleanupStack::PushL(self);
       
  5240     self->ConstructL();
       
  5241     CleanupStack::Pop(self);
       
  5242     return self;
       
  5243     }
       
  5244 
       
  5245 // ---------------------------------------------------------------------------
       
  5246 //
       
  5247 // ---------------------------------------------------------------------------
       
  5248 //
       
  5249 CFsTreeVisualizerBase::CDragHandler::~CDragHandler()
       
  5250     {
       
  5251     FUNC_LOG;
       
  5252     delete iHighlightTimer;
       
  5253     }
       
  5254 
       
  5255 // ---------------------------------------------------------------------------
       
  5256 //
       
  5257 // ---------------------------------------------------------------------------
       
  5258 //
       
  5259 void CFsTreeVisualizerBase::CDragHandler::Reset()
       
  5260     {
       
  5261     FUNC_LOG;
       
  5262     iFlags.ClearAll();
       
  5263     iHighlightTimer->Cancel();
       
  5264     iItemId = KFsTreeNoneID;
       
  5265     iDragDirection = EDraggingNone;
       
  5266     }
       
  5267 
       
  5268 // ---------------------------------------------------------------------------
       
  5269 //
       
  5270 // ---------------------------------------------------------------------------
       
  5271 //
       
  5272 CFsTreeVisualizerBase::CDragHandler::TDragDirection
       
  5273     CFsTreeVisualizerBase::CDragHandler::DragDirection(
       
  5274         const TPoint& aCurrent, const TPoint aPrevious ) const
       
  5275     {
       
  5276     FUNC_LOG;
       
  5277     if (aCurrent.iY > aPrevious.iY)
       
  5278         {
       
  5279         return EDraggingDown;
       
  5280         }
       
  5281     else if (aCurrent.iY < aPrevious.iY)
       
  5282         {
       
  5283         return EDraggingUp;
       
  5284         }
       
  5285     else
       
  5286         {
       
  5287         return iDragDirection;
       
  5288         }
       
  5289     }
       
  5290 
       
  5291 // ---------------------------------------------------------------------------
       
  5292 //
       
  5293 // ---------------------------------------------------------------------------
       
  5294 //
       
  5295 void CFsTreeVisualizerBase::CDragHandler::PointerDown(
       
  5296         const TPointerEvent& aEvent, const TFsTreeItemId aItemId )
       
  5297     {
       
  5298     FUNC_LOG;
       
  5299     Reset();
       
  5300     iItemId = aItemId;
       
  5301     iPosition = aEvent.iParentPosition;
       
  5302     iLastPointerPosition = aEvent.iParentPosition;
       
  5303     iStartTime.HomeTime();
       
  5304     iFlags.Set( EPointerDownReceived );
       
  5305     iTree.SetFocusedItemAndSendEvent( iItemId, EPointerDown, iPosition );
       
  5306     }
       
  5307 
       
  5308 // ---------------------------------------------------------------------------
       
  5309 //
       
  5310 // ---------------------------------------------------------------------------
       
  5311 //
       
  5312 void CFsTreeVisualizerBase::CDragHandler::PointerRepeat(
       
  5313         const TPointerEvent& aEvent )
       
  5314     {
       
  5315     if( iItemId != KFsTreeNoneID && !IsFlicking() )
       
  5316         {
       
  5317         iFlags.Set( EWasRepeat );
       
  5318         iTree.SetFocusedItemAndSendEvent( iItemId, ELongTap, aEvent.iParentPosition );
       
  5319         }
       
  5320     }
       
  5321 
       
  5322 // ---------------------------------------------------------------------------
       
  5323 //
       
  5324 // ---------------------------------------------------------------------------
       
  5325 //
       
  5326 void CFsTreeVisualizerBase::CDragHandler::PointerUp(
       
  5327         const TPointerEvent& aEvent, const TFsTreeItemId aItemId )
       
  5328     {
       
  5329     FUNC_LOG;
       
  5330     // If kinetic scrolling is disabled
       
  5331     if( iTree.IsKineticScrollingDisabled() )
       
  5332         {
       
  5333         if( ( aItemId != KFsTreeNoneID ) &&
       
  5334             ( iTree.FocusedItem() == aItemId  ) )
       
  5335             {
       
  5336             iTree.SetFocusedItemAndSendEvent( iItemId, EPointerUp, aEvent.iParentPosition );
       
  5337             }
       
  5338         }
       
  5339     else if ( IsFlicking() )
       
  5340         {
       
  5341         TPoint drag(iPosition - aEvent.iParentPosition);
       
  5342         iTree.StartPhysics( drag, iStartTime );
       
  5343         }
       
  5344     else if( !iFlags.IsSet( EWasRepeat ) && iItemId != KFsTreeNoneID )
       
  5345         {
       
  5346         iTree.SetFocusedItemAndSendEvent( iItemId, EPointerUp, aEvent.iParentPosition );
       
  5347         }
       
  5348     iLastPointerPosition = iPosition = TPoint();
       
  5349     iFlags.Clear( EPointerDownReceived );
       
  5350     iDragDirection = EDraggingNone;
       
  5351     }
       
  5352 
       
  5353 // ---------------------------------------------------------------------------
       
  5354 //
       
  5355 // ---------------------------------------------------------------------------
       
  5356 //
       
  5357 TInt CFsTreeVisualizerBase::CDragHandler::DragDelta(
       
  5358         const TPointerEvent& aEvent) const
       
  5359     {
       
  5360     FUNC_LOG;
       
  5361     return Abs(iPosition.iY - aEvent.iPosition.iY);
       
  5362     }
       
  5363 
       
  5364 // ---------------------------------------------------------------------------
       
  5365 //
       
  5366 // ---------------------------------------------------------------------------
       
  5367 //
       
  5368 TPoint CFsTreeVisualizerBase::CDragHandler::PointerDrag(
       
  5369         const TPointerEvent& aEvent, const TFsTreeItemId /*aItemId*/)
       
  5370     {
       
  5371     FUNC_LOG;
       
  5372     // If kinetic scrolling is disabled
       
  5373     if( iTree.IsKineticScrollingDisabled() )
       
  5374         {
       
  5375         iLastPointerPosition = iPosition;
       
  5376         return aEvent.iPosition;
       
  5377         }
       
  5378 
       
  5379     if (!iFlags.IsSet(EPointerDownReceived))
       
  5380         {
       
  5381         iLastPointerPosition = iPosition = aEvent.iPosition;
       
  5382         iFlags.Set(EPointerDownReceived);
       
  5383         }
       
  5384     else
       
  5385         {
       
  5386         iHighlightTimer->Cancel();
       
  5387         if (!iTreeVisualizerFlags.IsSet(EPhysicsOn))
       
  5388             {
       
  5389             iTree.SetPanningPosition(TPoint(0, iLastPointerPosition.iY
       
  5390                     - aEvent.iPosition.iY));
       
  5391             }
       
  5392         TDragDirection dragDirection(DragDirection(aEvent.iPosition, iLastPointerPosition));
       
  5393         const TBool dragDirectionChanged(
       
  5394                 (dragDirection == EDraggingUp && iDragDirection == EDraggingDown ) ||
       
  5395                 (dragDirection == EDraggingDown && iDragDirection == EDraggingUp ) );
       
  5396         if (dragDirectionChanged)
       
  5397             {
       
  5398             iPosition = aEvent.iPosition;
       
  5399             iStartTime.HomeTime();
       
  5400             }
       
  5401         iDragDirection = dragDirection;
       
  5402         iLastPointerPosition = aEvent.iPosition;
       
  5403         }
       
  5404     return iPosition - aEvent.iPosition;
       
  5405     }
       
  5406 
       
  5407 // ---------------------------------------------------------------------------
       
  5408 //
       
  5409 // ---------------------------------------------------------------------------
       
  5410 //
       
  5411 void CFsTreeVisualizerBase::CDragHandler::EnableFlicking()
       
  5412     {
       
  5413     FUNC_LOG;
       
  5414     iFlags.Set(EFlicking);
       
  5415     }
       
  5416 
       
  5417 // ---------------------------------------------------------------------------
       
  5418 //
       
  5419 // ---------------------------------------------------------------------------
       
  5420 //
       
  5421 TBool CFsTreeVisualizerBase::CDragHandler::IsFlicking() const
       
  5422     {
       
  5423     FUNC_LOG;
       
  5424     return iFlags.IsSet(EFlicking);
       
  5425     }
       
  5426 
       
  5427 // ---------------------------------------------------------------------------
       
  5428 //
       
  5429 // ---------------------------------------------------------------------------
       
  5430 //
       
  5431 CFsTreeVisualizerBase::CDragHandler::CDragHandler(
       
  5432         CFsTreeVisualizerBase& aTree, const TInt aHighlightTimeout,
       
  5433         const TBitFlags& aFlags) :
       
  5434     iTree(aTree), iHighlightTimeout(aHighlightTimeout * 1000),
       
  5435             iTreeVisualizerFlags(aFlags)
       
  5436     {
       
  5437     FUNC_LOG;
       
  5438     }
       
  5439 
       
  5440 // ---------------------------------------------------------------------------
       
  5441 //
       
  5442 // ---------------------------------------------------------------------------
       
  5443 //
       
  5444 void CFsTreeVisualizerBase::CDragHandler::ConstructL()
       
  5445     {
       
  5446     FUNC_LOG;
       
  5447     iHighlightTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
  5448     }
       
  5449 
       
  5450 // ---------------------------------------------------------------------------
       
  5451 //
       
  5452 // ---------------------------------------------------------------------------
       
  5453 //
       
  5454 TInt CFsTreeVisualizerBase::CDragHandler::HighlightTimerCallback( TAny* aPtr )
       
  5455     {
       
  5456     FUNC_LOG;
       
  5457     CDragHandler* self = reinterpret_cast<CDragHandler*>( aPtr );
       
  5458     self->iHighlightTimer->Cancel();
       
  5459     return self->iTree.SetFocusedItemAndSendEvent( self->iItemId, ELongTap, self->iPosition );
       
  5460     }
       
  5461 
       
  5462 // ---------------------------------------------------------------------------
       
  5463 // CFsTreeVisualizerBase::IsFocusShown
       
  5464 // ---------------------------------------------------------------------------
       
  5465 //
       
  5466 TBool CFsTreeVisualizerBase::IsFocusShown()
       
  5467     {
       
  5468     return ( iTouchPressed || iFocusVisible ) && iFlags.IsClear( EListPanning );
       
  5469     }
       
  5470 
       
  5471 
       
  5472 // </cmail>