emailuis/uicomponents/src/fstreevisualizerbase.cpp
branchRCL_3
changeset 12 f5907b1a1053
parent 8 e1b6206813b4
child 16 4ce476e64c59
equal deleted inserted replaced
8:e1b6206813b4 12:f5907b1a1053
    81 const TInt KZero = 0;
    81 const TInt KZero = 0;
    82 _LIT8( KPropertyItemId, "PropItemID" );
    82 _LIT8( KPropertyItemId, "PropItemID" );
    83 
    83 
    84 // check from aknphysicsconstants.h
    84 // check from aknphysicsconstants.h
    85 const TInt KFlickMaxDuration( 500000 );
    85 const TInt KFlickMaxDuration( 500000 );
       
    86 const TInt KDefaultFriction( 35 ); // avkon default is 10
    86 
    87 
    87 // ======== LOCAL FUNCTIONS ========
    88 // ======== LOCAL FUNCTIONS ========
    88 
    89 
    89 // ---------------------------------------------------------------------------
    90 // ---------------------------------------------------------------------------
    90 // Deletes and sets pointer to NULL.
    91 // Deletes and sets pointer to NULL.
   348 // ---------------------------------------------------------------------------
   349 // ---------------------------------------------------------------------------
   349 // TWorld::GetItemsL
   350 // TWorld::GetItemsL
   350 // Uses binary search.
   351 // Uses binary search.
   351 // ---------------------------------------------------------------------------
   352 // ---------------------------------------------------------------------------
   352 void TWorld::GetItemsL(RArray<TFsTreeItemId>& aItems, TInt aY, TInt aHeight,
   353 void TWorld::GetItemsL(RArray<TFsTreeItemId>& aItems, TInt aY, TInt aHeight,
   353         TInt& aOffset)
   354         TInt& aOffset, TInt& aBeginIndex)
   354     {
   355     {
   355     // First find first visible item using binary search algorithm
   356     // First find first visible item using binary search algorithm
   356     aItems.Reset();
   357     aItems.Reset();
   357     TInt i(0);
   358     TInt i(0);
   358     aOffset = 0;
   359     aOffset = 0;
   377                 }
   378                 }
   378             else
   379             else
   379                 {
   380                 {
   380                 aOffset = aY - iItems[middle].Top();
   381                 aOffset = aY - iItems[middle].Top();
   381                 aHeight += aOffset;
   382                 aHeight += aOffset;
   382                 i = middle;
   383                 aBeginIndex = i = middle;
   383                 break;
   384                 break;
   384                 }
   385                 }
   385             }
   386             }
   386         }
   387         }
   387     else
   388     else
   447 // ---------------------------------------------------------------------------
   448 // ---------------------------------------------------------------------------
   448 // TWorld::GetItemRect
   449 // TWorld::GetItemRect
   449 // ---------------------------------------------------------------------------
   450 // ---------------------------------------------------------------------------
   450 TInt TWorld::GetItemRect(const TFsTreeItemId aItemId, TRect& aRect) const
   451 TInt TWorld::GetItemRect(const TFsTreeItemId aItemId, TRect& aRect) const
   451     {
   452     {
       
   453     return GetItemRect(aItemId, aRect, 0);
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // TWorld::GetItemRect
       
   458 // ---------------------------------------------------------------------------
       
   459 TInt TWorld::GetItemRect(const TFsTreeItemId aItemId, TRect& aRect, 
       
   460         const TInt aStartIndex ) const
       
   461     {
   452     TInt result(KErrNotFound);
   462     TInt result(KErrNotFound);
   453     for (TInt i = iItems.Count() - 1; i >= 0; i--)
   463     const TInt itemCount(iItems.Count());
       
   464     for (TInt i = aStartIndex; i < itemCount; i++)
   454         {
   465         {
   455         if (iItems[i].iId == aItemId)
   466         if (iItems[i].iId == aItemId)
   456             {
   467             {
   457             result = i;
   468             result = i;
   458             aRect = iItems[i].Rect();
   469             aRect = iItems[i].Rect();
   503 
   514 
   504 // ---------------------------------------------------------------------------
   515 // ---------------------------------------------------------------------------
   505 // TViewPort::TViewPort
   516 // TViewPort::TViewPort
   506 // ---------------------------------------------------------------------------
   517 // ---------------------------------------------------------------------------
   507 TViewPort::TViewPort(MObserver& aObserver, TWorld& aWorld) :
   518 TViewPort::TViewPort(MObserver& aObserver, TWorld& aWorld) :
   508     iObserver(aObserver), iWorld(aWorld)
   519     iObserver(aObserver), iWorld(aWorld), iWorldIndex(KErrNotFound)
   509     {
   520     {
   510     }
   521     }
   511 
   522 
   512 // ---------------------------------------------------------------------------
   523 // ---------------------------------------------------------------------------
   513 // TViewPort::SetPositionL
   524 // TViewPort::SetPositionL
   583         RArray<TFsTreeItemId>& aItemsToBeAdded, TInt& aOffset,
   594         RArray<TFsTreeItemId>& aItemsToBeAdded, TInt& aOffset,
   584         TBool& aFullUpdate)
   595         TBool& aFullUpdate)
   585     {
   596     {
   586     RArray<TFsTreeItemId> tempItems;
   597     RArray<TFsTreeItemId> tempItems;
   587     CleanupClosePushL(tempItems);
   598     CleanupClosePushL(tempItems);
   588     iWorld.GetItemsL(tempItems, iPosition.iY, iSize.iHeight, aOffset);
   599     iWorld.GetItemsL(tempItems, iPosition.iY, iSize.iHeight, aOffset, iWorldIndex);
   589     iCache.UpdateL(tempItems, aItemsToBeRemoved, aItemsToBeAdded, aFullUpdate);
   600     iCache.UpdateL(tempItems, aItemsToBeRemoved, aItemsToBeAdded, aFullUpdate);
   590     CleanupStack::PopAndDestroy(); // tempItems
   601     CleanupStack::PopAndDestroy(); // tempItems
   591     }
   602     }
   592 
   603 
   593 // ---------------------------------------------------------------------------
   604 // ---------------------------------------------------------------------------
   594 // TViewPort::GetVisibleItemsL
   605 // TViewPort::GetVisibleItemsL
   595 // ---------------------------------------------------------------------------
   606 // ---------------------------------------------------------------------------
   596 void TViewPort::GetVisibleItemsL(RArray<TFsTreeItemId>& aVisible, TInt& aOffset)
   607 void TViewPort::GetVisibleItemsL(RArray<TFsTreeItemId>& aVisible, TInt& aOffset)
   597 	{
   608 	{
   598 	iWorld.GetItemsL(aVisible, iPosition.iY, iSize.iHeight, aOffset);
   609 	iWorld.GetItemsL(aVisible, iPosition.iY, iSize.iHeight, aOffset, iWorldIndex);
   599 	}
   610 	}
   600 
   611 
   601 // ---------------------------------------------------------------------------
   612 // ---------------------------------------------------------------------------
   602 // TViewPort::IsScrollBarNeeded
   613 // TViewPort::IsScrollBarNeeded
   603 // ---------------------------------------------------------------------------
   614 // ---------------------------------------------------------------------------
   737 // ---------------------------------------------------------------------------
   748 // ---------------------------------------------------------------------------
   738 // TViewPort::ClearCache
   749 // TViewPort::ClearCache
   739 // ---------------------------------------------------------------------------
   750 // ---------------------------------------------------------------------------
   740 void TViewPort::ClearCache()
   751 void TViewPort::ClearCache()
   741     {
   752     {
       
   753     iWorldIndex = KErrNotFound;
   742     iCache.Clear();
   754     iCache.Clear();
   743     }
   755     }
   744 
   756 
   745 // ---------------------------------------------------------------------------
   757 // ---------------------------------------------------------------------------
   746 // TViewPort::ItemRect
   758 // TViewPort::ItemRect
   748 TRect TViewPort::ItemRect(const TFsTreeItemId aItemId) const
   760 TRect TViewPort::ItemRect(const TFsTreeItemId aItemId) const
   749     {
   761     {
   750     TRect itemRect;
   762     TRect itemRect;
   751     if (!iCache.IsClear() && iCache.ContainsItem(aItemId))
   763     if (!iCache.IsClear() && iCache.ContainsItem(aItemId))
   752         {
   764         {
   753         if (iWorld.GetItemRect(aItemId, itemRect) != KErrNotFound)
   765         const TInt beginIndex(iWorldIndex == KErrNotFound ? 0 : iWorldIndex);
       
   766         if (iWorld.GetItemRect(aItemId, itemRect, beginIndex) != KErrNotFound)
   754             {
   767             {
   755             itemRect.Move(0, -iPosition.iY);
   768             itemRect.Move(0, -iPosition.iY);
   756             }
   769             }
   757         }
   770         }
   758     return itemRect;
   771     return itemRect;
  1540                     {
  1553                     {
  1541                     eventHandled = ETrue;
  1554                     eventHandled = ETrue;
  1542                     iTouchPressed = ETrue;
  1555                     iTouchPressed = ETrue;
  1543                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
  1556                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
  1544                     INFO_2("EButton1Down (%d, %d)", pos.iX, pos.iY);
  1557                     INFO_2("EButton1Down (%d, %d)", pos.iX, pos.iY);
  1545                     if (!iFlags.IsSet(EPhysicsOn))
  1558                     //if (!iFlags.IsSet(EPhysicsOn))
       
  1559                     // Keep this last!
       
  1560                     if (iFlags.IsSet(EPhysicsOn))
  1546                         {
  1561                         {
  1547                         iPhysics->StopPhysics();
  1562                         iPhysics->StopPhysics();
  1548                         iPhysics->ResetFriction();
  1563                         //iPhysics->ResetFriction();
  1549                         UpdatePhysicsL();
  1564                         UpdatePhysicsL();
       
  1565                         iFlags.Set(EIgnorePointerUpAction);
       
  1566                         }
       
  1567                     else
       
  1568                         {
       
  1569                         iFlags.Clear(EIgnorePointerUpAction);
  1550                         }
  1570                         }
  1551                     iDragHandler->PointerDown(aEvent.PointerEvent(), id);
  1571                     iDragHandler->PointerDown(aEvent.PointerEvent(), id);
  1552                     break;
  1572                     break;
  1553                     }
  1573                     }
  1554                 case TPointerEvent::EButton1Up:
  1574                 case TPointerEvent::EButton1Up:
  1560                         iTouchPressed = EFalse;
  1580                         iTouchPressed = EFalse;
  1561                         iVisualizerObserver->TreeVisualizerEventL(
  1581                         iVisualizerObserver->TreeVisualizerEventL(
  1562                             MFsTreeVisualizerObserver::EFsChangeFocusVisibility );
  1582                             MFsTreeVisualizerObserver::EFsChangeFocusVisibility );
  1563                         INFO_2( "EButton1Up (%d, %d)", pos.iX, pos.iY );
  1583                         INFO_2( "EButton1Up (%d, %d)", pos.iX, pos.iY );
  1564                         }
  1584                         }
  1565                     if( !iDragHandler->IsFlicking() )
  1585                     /*if( !iDragHandler->IsFlicking() )
  1566                         {
  1586                         {
  1567                         iPhysics->StopPhysics();
  1587                         iPhysics->StopPhysics();
  1568                         }
  1588                         }*/
  1569                     iDragHandler->PointerUp( aEvent.PointerEvent(), id );
  1589                     iDragHandler->PointerUp( aEvent.PointerEvent(), id );
       
  1590                     iFlags.Clear(EIgnorePointerUpAction);
  1570                     break;
  1591                     break;
  1571                     }
  1592                     }
  1572                 case TPointerEvent::EDrag:
  1593                 case TPointerEvent::EDrag:
  1573                     {
  1594                     {
  1574                     eventHandled = ETrue;
  1595                     eventHandled = ETrue;
  1576                     INFO_2("EDrag (%d, %d)", pos.iX, pos.iY);
  1597                     INFO_2("EDrag (%d, %d)", pos.iX, pos.iY);
  1577                     if (iDragHandler->IsFlicking()
  1598                     if (iDragHandler->IsFlicking()
  1578                             || iDragHandler->DragDelta(aEvent.PointerEvent())
  1599                             || iDragHandler->DragDelta(aEvent.PointerEvent())
  1579                                     >= iPhysics->DragThreshold())
  1600                                     >= iPhysics->DragThreshold())
  1580                         {
  1601                         {
       
  1602                         iFlags.Set(EIgnorePointerUpAction);
  1581                         iDragHandler->PointerDrag(aEvent.PointerEvent(), id);
  1603                         iDragHandler->PointerDrag(aEvent.PointerEvent(), id);
  1582                         iDragHandler->EnableFlicking();
  1604                         iDragHandler->EnableFlicking();
  1583                         }
  1605                         }
  1584                     break;
  1606                     break;
  1585                     }
  1607                     }
  1588                     {
  1610                     {
  1589                     eventHandled = ETrue;
  1611                     eventHandled = ETrue;
  1590                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
  1612                     const TPoint& pos(aEvent.PointerEvent().iParentPosition);
  1591                     INFO_2("EButtonRepeat (%d, %d)", pos.iX, pos.iY);
  1613                     INFO_2("EButtonRepeat (%d, %d)", pos.iX, pos.iY);
  1592                     iDragHandler->PointerRepeat(aEvent.PointerEvent());
  1614                     iDragHandler->PointerRepeat(aEvent.PointerEvent());
       
  1615                     iFlags.Clear(EIgnorePointerUpAction);
  1593                     break;
  1616                     break;
  1594                     }
  1617                     }
  1595 
  1618 
  1596                 default:
  1619                 default:
  1597                     {
  1620                     {
  3642     FUNC_LOG;
  3665     FUNC_LOG;
  3643     if (iScrollBar->ThumbPosition() != iViewPort.Position().iY)
  3666     if (iScrollBar->ThumbPosition() != iViewPort.Position().iY)
  3644         {
  3667         {
  3645         iScrollbarModel.SetFocusPosition(iViewPort.Position().iY);
  3668         iScrollbarModel.SetFocusPosition(iViewPort.Position().iY);
  3646         iScrollBar->SetModelL(&iScrollbarModel);
  3669         iScrollBar->SetModelL(&iScrollbarModel);
  3647         iScrollBar->DrawNow();
  3670         iScrollBar->DrawDeferred();
  3648         }
  3671         }
  3649     }
  3672     }
  3650 
  3673 
  3651 // ---------------------------------------------------------------------------
  3674 // ---------------------------------------------------------------------------
  3652 //  Updates scrollbar.
  3675 //  Updates scrollbar.
  3669     const TInt pageSize(iViewPort.Size().iHeight);
  3692     const TInt pageSize(iViewPort.Size().iHeight);
  3670     iScrollbarModel.SetScrollSpan(Max(iWorld.Height(), pageSize));
  3693     iScrollbarModel.SetScrollSpan(Max(iWorld.Height(), pageSize));
  3671     iScrollbarModel.SetWindowSize(pageSize);
  3694     iScrollbarModel.SetWindowSize(pageSize);
  3672     iScrollbarModel.SetFocusPosition(iViewPort.Position().iY);
  3695     iScrollbarModel.SetFocusPosition(iViewPort.Position().iY);
  3673     iScrollBar->SetModelL(&iScrollbarModel);
  3696     iScrollBar->SetModelL(&iScrollbarModel);
  3674     iScrollBar->DrawNow();
  3697     iScrollBar->DrawDeferred();
  3675 
  3698 
  3676     RArray<TInt> columns;
  3699     RArray<TInt> columns;
  3677     CleanupClosePushL(columns);
  3700     CleanupClosePushL(columns);
  3678     TBool updateLayouts(EFalse);
  3701     TBool updateLayouts(EFalse);
  3679     if (iViewPort.IsScrollBarNeeded() && iVisualizationState
  3702     if (iViewPort.IsScrollBarNeeded() && iVisualizationState
  4635     if (CAknPhysics::FeatureEnabled())
  4658     if (CAknPhysics::FeatureEnabled())
  4636         {
  4659         {
  4637         iPhysics = CAknPhysics::NewL(*this, NULL );
  4660         iPhysics = CAknPhysics::NewL(*this, NULL );
  4638         iDragHandler = CDragHandler::NewL(*this,
  4661         iDragHandler = CDragHandler::NewL(*this,
  4639                 iPhysics->HighlightTimeout(), iFlags);
  4662                 iPhysics->HighlightTimeout(), iFlags);
       
  4663         iPhysics->SetFriction(KDefaultFriction);                        
  4640         }
  4664         }
  4641 
  4665 
  4642     iRootData = CFsTreePlainOneLineItemData::NewL();
  4666     iRootData = CFsTreePlainOneLineItemData::NewL();
  4643     HBufC* empty = StringLoader::LoadL(R_AVKON_EMPTY_POPUP_LIST_TEXT);
  4667     HBufC* empty = StringLoader::LoadL(R_AVKON_EMPTY_POPUP_LIST_TEXT);
  4644     CleanupStack::PushL(empty);
  4668     CleanupStack::PushL(empty);
  4941                     0);
  4965                     0);
  4942             CAlfLayout& visualizerLayout(visualizer->Layout());
  4966             CAlfLayout& visualizerLayout(visualizer->Layout());
  4943             visualizerLayout.SetSize(tpItemSize);
  4967             visualizerLayout.SetSize(tpItemSize);
  4944             visualizerLayout.PropertySetIntegerL(KPropertyItemId(), itemId);
  4968             visualizerLayout.PropertySetIntegerL(KPropertyItemId(), itemId);
  4945             
  4969             
  4946             if(aUpdateByPhysic != EUpdatedByPhisic)
  4970 //            if(aUpdateByPhysic != EUpdatedByPhisic)
  4947             	{
  4971 //            	{
  4948             	visualizer->UpdateL(iTreeData->ItemData(itemId),
  4972             	visualizer->UpdateL(iTreeData->ItemData(itemId),
  4949                     IsItemFocused(itemId) && IsFocusShown(),
  4973                     IsItemFocused(itemId) && IsFocusShown(),
  4950                     iTreeData->Level(itemId), iMarkIcon, iMenuIcon,
  4974                     iTreeData->Level(itemId), iMarkIcon, iMenuIcon,
  4951                     0);
  4975                     0);
  4952             	}
  4976 //            	}
  4953             
  4977             
  4954             visualizerLayout.Brushes()->AppendL(iBorderBrush,
  4978             visualizerLayout.Brushes()->AppendL(iBorderBrush,
  4955                     EAlfDoesNotHaveOwnership);
  4979                     EAlfDoesNotHaveOwnership);
  4956             CAlfBrush* bgBrush(NULL);
  4980             CAlfBrush* bgBrush(NULL);
  4957             if (visualizer->GetBackgroundBrush(bgBrush))
  4981             if (visualizer->GetBackgroundBrush(bgBrush))
  5007     if (moveTime > KFlickMaxDuration)
  5031     if (moveTime > KFlickMaxDuration)
  5008         {
  5032         {
  5009         startTime = now - TTimeIntervalMicroSeconds( KFlickMaxDuration - 1 );
  5033         startTime = now - TTimeIntervalMicroSeconds( KFlickMaxDuration - 1 );
  5010         aDrag.iY = aDrag.iY * KFlickMaxDuration / moveTime;
  5034         aDrag.iY = aDrag.iY * KFlickMaxDuration / moveTime;
  5011         }
  5035         }
  5012     iPhysics->StartPhysics(aDrag, startTime);
  5036     if (iPhysics->StartPhysics(aDrag, startTime))
  5013     iFlags.Set(EPhysicsOn);
  5037         {
       
  5038         iFlags.Set(EPhysicsOn);
       
  5039         }
  5014     }
  5040     }
  5015 
  5041 
  5016 // ---------------------------------------------------------------------------
  5042 // ---------------------------------------------------------------------------
  5017 // Update physics
  5043 // Update physics
  5018 // ---------------------------------------------------------------------------
  5044 // ---------------------------------------------------------------------------
  5026         iPhysics = CAknPhysics::NewL(*this, NULL );
  5052         iPhysics = CAknPhysics::NewL(*this, NULL );
  5027         const TSize viewSize(iViewPort.Size());
  5053         const TSize viewSize(iViewPort.Size());
  5028         const TSize worldSize(viewSize.iWidth, Max(iWorld.Height(),
  5054         const TSize worldSize(viewSize.iWidth, Max(iWorld.Height(),
  5029                 viewSize.iHeight));
  5055                 viewSize.iHeight));
  5030         iPhysics->InitPhysicsL(worldSize, viewSize, EFalse);
  5056         iPhysics->InitPhysicsL(worldSize, viewSize, EFalse);
       
  5057         iPhysics->SetFriction(KDefaultFriction);                        
  5031         }
  5058         }
  5032     }
  5059     }
  5033 
  5060 
  5034 // ---------------------------------------------------------------------------
  5061 // ---------------------------------------------------------------------------
  5035 // Returns viewPort top-left position
  5062 // Returns viewPort top-left position
  5138 				MFsTreeVisualizerObserver::EFsTreeItemTouchLongTap,
  5165 				MFsTreeVisualizerObserver::EFsTreeItemTouchLongTap,
  5139   			    aItemId, aPoint );
  5166   			    aItemId, aPoint );
  5140         }
  5167         }
  5141     else if( aEventType == EPointerUp )
  5168     else if( aEventType == EPointerUp )
  5142         {
  5169         {
  5143         iVisualizerObserver->TreeVisualizerEventL(
  5170         // Ignore pointer up action IF physic emulation was stopped on pointer down
  5144             MFsTreeVisualizerObserver::EFsTreeItemTouchAction, aItemId, aPoint );
  5171         if ( !iFlags.IsSet(EIgnorePointerUpAction) )
       
  5172             {
       
  5173             iVisualizerObserver->TreeVisualizerEventL(
       
  5174                 MFsTreeVisualizerObserver::EFsTreeItemTouchAction, aItemId, aPoint );
       
  5175             }
  5145         }
  5176         }
  5146     }
  5177     }
  5147 
  5178 
  5148 // CFsTreeVisualizerBase::CDragHandler
  5179 // CFsTreeVisualizerBase::CDragHandler
  5149 
  5180 
  5213 // ---------------------------------------------------------------------------
  5244 // ---------------------------------------------------------------------------
  5214 //
  5245 //
  5215 // ---------------------------------------------------------------------------
  5246 // ---------------------------------------------------------------------------
  5216 //
  5247 //
  5217 void CFsTreeVisualizerBase::CDragHandler::PointerDown(
  5248 void CFsTreeVisualizerBase::CDragHandler::PointerDown(
  5218         const TPointerEvent& aEvent, const TFsTreeItemId aItemId)
  5249         const TPointerEvent& aEvent, const TFsTreeItemId aItemId )
  5219     {
  5250     {
  5220     FUNC_LOG;
  5251     FUNC_LOG;
  5221     Reset();
  5252     Reset();
  5222     iItemId = aItemId;
  5253     iItemId = aItemId;
  5223     iPosition = aEvent.iParentPosition;
  5254     iPosition = aEvent.iParentPosition;
  5224     iLastPointerPosition = aEvent.iParentPosition;
  5255     iLastPointerPosition = aEvent.iParentPosition;
  5225     iStartTime.HomeTime();
  5256     iStartTime.HomeTime();
  5226     iFlags.Set( EPointerDownReceived );
  5257     iFlags.Set( EPointerDownReceived );
  5227 
       
  5228     iTree.SetFocusedItemAndSendEvent( iItemId, EPointerDown, iPosition );
  5258     iTree.SetFocusedItemAndSendEvent( iItemId, EPointerDown, iPosition );
  5229     }
  5259     }
  5230 
  5260 
  5231 // ---------------------------------------------------------------------------
  5261 // ---------------------------------------------------------------------------
  5232 //
  5262 //