uifw/ganes/src/HgScroller.cpp
branchRCL_3
changeset 25 941195f2d488
parent 23 3d340a0166ff
child 29 a8834a2e9a96
equal deleted inserted replaced
23:3d340a0166ff 25:941195f2d488
    48 #include <aknitemactionmenu.h>
    48 #include <aknitemactionmenu.h>
    49 #include <aknappui.h>
    49 #include <aknappui.h>
    50 
    50 
    51 #include <featdiscovery.h>
    51 #include <featdiscovery.h>
    52 
    52 
    53 const TInt KIntensity = 100; // 100%
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
    53 // ============================ MEMBER FUNCTIONS ===============================
    56 
    54 
    57 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    58 // CHgScroller::ConstructL()
    56 // CHgScroller::ConstructL()
    59 // Symbian 2nd phase constructor can leave.
    57 // Symbian 2nd phase constructor can leave.
   372  :  iDefaultIcon( aDefaultIcon ),
   370  :  iDefaultIcon( aDefaultIcon ),
   373     iItemCount(aItemCount), 
   371     iItemCount(aItemCount), 
   374     iCurrentRow(-1),
   372     iCurrentRow(-1),
   375     iSelectedIndex(KErrNotFound),
   373     iSelectedIndex(KErrNotFound),
   376     iScrollBarType( EHgScrollerScrollBar ),
   374     iScrollBarType( EHgScrollerScrollBar ),
   377     iFirstTime(ETrue)
   375     iFirstTime(ETrue),
       
   376     iOldWinPos(KErrNotFound)
   378     {
   377     {
   379     // No implementation required
   378     // No implementation required
   380     }
   379     }
   381         
   380         
   382 // -----------------------------------------------------------------------------
   381 // -----------------------------------------------------------------------------
   434             TSize(iWidth, iHeight), 
   433             TSize(iWidth, iHeight), 
   435             iLandscapeScrolling);
   434             iLandscapeScrolling);
   436     }
   435     }
   437 
   436 
   438 // -----------------------------------------------------------------------------
   437 // -----------------------------------------------------------------------------
   439 // CHgGrid::Draw()
   438 // CHgScroller::Draw()
   440 // Draws the display.
   439 // Draws the display.
   441 // -----------------------------------------------------------------------------
   440 // -----------------------------------------------------------------------------
   442 //
   441 //
   443 void CHgScroller::Draw ( const TRect& aRect ) const
   442 void CHgScroller::Draw ( const TRect& aRect ) const
   444     {
   443     {
   587 
   586 
   588             if( iDetector 
   587             if( iDetector 
   589                     && iSelectedIndex != KErrNotFound 
   588                     && iSelectedIndex != KErrNotFound 
   590                     && !HasHighlight() 
   589                     && !HasHighlight() 
   591                     && iActionMenu->InitMenuL() )
   590                     && iActionMenu->InitMenuL() )
       
   591                 {
   592                 iDetector->PointerEventL( aEvent );
   592                 iDetector->PointerEventL( aEvent );
       
   593                 }
   593             }
   594             }
   594         // Drag
   595         // Drag
   595         else if( aEvent.iType == TPointerEvent::EDrag && iPointerDown )
   596         else if( aEvent.iType == TPointerEvent::EDrag && iPointerDown )
   596             {
   597             {
   597             HandleDragEventL( aEvent );
   598             HandleDragEventL( aEvent );
   645                 if ( feedback )
   646                 if ( feedback )
   646                     {
   647                     {
   647                     feedback->InstantFeedback( this, ETouchFeedbackSlider, aEvent );
   648                     feedback->InstantFeedback( this, ETouchFeedbackSlider, aEvent );
   648                     }
   649                     }
   649                 }
   650                 }
   650             // Drag
       
   651             else if( aEvent.iType == TPointerEvent::EDrag 
       
   652                     && iScrollbar->IsDragging() )
       
   653                 {
       
   654                 // Smooth continuous tactile feedback is produced
       
   655                 // during thumb dragging. The tactile feedback API 
       
   656                 // filters out possible re-startings of the effect.
       
   657                 if ( feedback )
       
   658                     {
       
   659                     TTimeIntervalMicroSeconds32 timeout( 300000 );
       
   660                     feedback->StartFeedback( this, 
       
   661                                              ETouchContinuousSlider, 
       
   662                                              &aEvent, 
       
   663                                              KIntensity, // intensity
       
   664                                              timeout );
       
   665                     }
       
   666                 }
       
   667             // End drag
       
   668             else if( aEvent.iType == TPointerEvent::EButton1Up )
   651             else if( aEvent.iType == TPointerEvent::EButton1Up )
   669                 {
   652                 {
   670                 // Stop the continuous tactile feedback that may be playing
   653                 // Stop the continuous tactile feedback that may be playing
   671                 // at the time due to possible previous thumb dragging.
   654                 // at the time due to possible previous thumb dragging.
   672                 if ( feedback )
   655                 if ( feedback )
   721         {
   704         {
   722         LaunchHighlightTimer();
   705         LaunchHighlightTimer();
   723         }
   706         }
   724     else if( !iPanning )
   707     else if( !iPanning )
   725         {
   708         {
       
   709         // to get Handle Selected to be called for sure in single touch
       
   710         iSelectedIndex = KErrNotFound; 
   726         SetHighlightL();
   711         SetHighlightL();
   727         }
   712         }
   728     MTouchFeedback* feedback = MTouchFeedback::Instance();
   713     MTouchFeedback* feedback = MTouchFeedback::Instance();
   729     if ( feedback && iSelectedIndex != KErrNotFound )
   714     if ( feedback && iSelectedIndex != KErrNotFound )
   730         {
   715         {
   753         
   738         
   754         delta = delta < 0 ? -delta : delta;
   739         delta = delta < 0 ? -delta : delta;
   755         iPanning = delta >= iPhysics->DragThreshold();
   740         iPanning = delta >= iPhysics->DragThreshold();
   756         }
   741         }
   757 
   742 
       
   743     //if user has dragged onto another item
       
   744     if( !iPanning && GetSelected(iStart) != GetSelected(aEvent.iPosition) )
       
   745         {
       
   746         // after setting iPanning true, longtap is cancelled
       
   747         iPanning = ETrue;    
       
   748         }
       
   749     
   758     if( prevPanning != iPanning )
   750     if( prevPanning != iPanning )
       
   751         {
       
   752         iPrev = aEvent.iPosition;
   759         DrawDeferred(); // to clear highlight
   753         DrawDeferred(); // to clear highlight
       
   754         }
   760     
   755     
   761     if(iPanning)
   756     if(iPanning)
   762         {
   757         {
   763         TPoint delta = iPrev - aEvent.iPosition;
   758         TPoint delta = iPrev - aEvent.iPosition;
   764         if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored())
   759         if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored())
  1269     {
  1264     {
  1270     if(iItemCount)
  1265     if(iItemCount)
  1271         {
  1266         {
  1272         iItems.ResetAndDestroy();
  1267         iItems.ResetAndDestroy();
  1273         iItemCount = 0;
  1268         iItemCount = 0;
  1274         iSelectedIndex = -1;
  1269         iSelectedIndex = KErrNotFound;
  1275         
  1270         
  1276         if( iManager )
  1271         if( iManager )
  1277             {
  1272             {
  1278             iManager->ResetBuffer( iSelectedIndex, iItemCount );
  1273             iManager->ResetBuffer( iSelectedIndex, iItemCount );
  1279             }
  1274             }
  1492 // -----------------------------------------------------------------------------
  1487 // -----------------------------------------------------------------------------
  1493 //
  1488 //
  1494 void CHgScroller::HandleGainingForeground()
  1489 void CHgScroller::HandleGainingForeground()
  1495     {
  1490     {
  1496     iSelectionMode = ENoSelection;
  1491     iSelectionMode = ENoSelection;
  1497     TRect rect( PositionRelativeToScreen(), Size() );
       
  1498     TRAP_IGNORE( InitScreenL( rect ); )
       
  1499     iScrollbar->Reset();
  1492     iScrollbar->Reset();
  1500     }
  1493     }
  1501 
  1494 
  1502 // -----------------------------------------------------------------------------
  1495 // -----------------------------------------------------------------------------
  1503 // CHgScroller::HandleLosingForeground()
  1496 // CHgScroller::HandleLosingForeground()
  1504 // -----------------------------------------------------------------------------
  1497 // -----------------------------------------------------------------------------
  1505 //
  1498 //
  1506 void CHgScroller::HandleLosingForeground()
  1499 void CHgScroller::HandleLosingForeground()
  1507     {
  1500     {
  1508     iPointerDown = EFalse;
  1501     if( iOldWinPos == KErrNotFound 
       
  1502             || iOldWinPos == DrawableWindow()->OrdinalPosition() ) 
       
  1503         {
       
  1504         iPointerDown = EFalse;
       
  1505         }
       
  1506     
  1509     iPopupText1.Zero();
  1507     iPopupText1.Zero();
  1510     iPopupText2.Zero();
  1508     iPopupText2.Zero();
  1511     }
  1509     }
  1512 
  1510 
  1513 // ---------------------------------------------------------------------------
  1511 // ---------------------------------------------------------------------------
  1568 
  1566 
  1569     TInt index = GetSelected(iStart);
  1567     TInt index = GetSelected(iStart);
  1570     if((index != KErrNotFound || !HasHighlight())
  1568     if((index != KErrNotFound || !HasHighlight())
  1571             && iPointerDown )
  1569             && iPointerDown )
  1572         {
  1570         {
  1573         iSelectionToFocusedItem = index == iSelectedIndex;            
  1571         iSelectionToFocusedItem = (index == iSelectedIndex);            
  1574         iSelectedIndex = index;
  1572         iSelectedIndex = index;
  1575         iFocusedIndex = index;
  1573         iFocusedIndex = index;
  1576         // Selection has changed to valid item
  1574         // Selection has changed to valid item
  1577         if( !iSelectionToFocusedItem && iSelectedIndex != KErrNotFound ) 
  1575         if( !iSelectionToFocusedItem && iSelectedIndex != KErrNotFound ) 
  1578             {
  1576             {
  1721             // When skin changes the indicator icons must be reloaded.
  1719             // When skin changes the indicator icons must be reloaded.
  1722         if ( aType == KAknsMessageSkinChange )
  1720         if ( aType == KAknsMessageSkinChange )
  1723             {
  1721             {
  1724             delete iIndicatorManager; iIndicatorManager = NULL;
  1722             delete iIndicatorManager; iIndicatorManager = NULL;
  1725             iIndicatorManager = CHgIndicatorManager::NewL();
  1723             iIndicatorManager = CHgIndicatorManager::NewL();
       
  1724             delete iScrollbar; iScrollbar = NULL;
       
  1725             iScrollbar = CHgScrollbar::NewL(*this);
       
  1726             InitScrollbarL();
  1726             InitGraphicsL();
  1727             InitGraphicsL();
  1727             }
  1728             }
  1728         )
  1729         )
  1729     }
  1730     }
  1730 
  1731 
  1735 void CHgScroller::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/,
  1736 void CHgScroller::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/,
  1736                         const TPoint& aPenEventScreenLocation)
  1737                         const TPoint& aPenEventScreenLocation)
  1737     {
  1738     {
  1738     if( iActionMenu )
  1739     if( iActionMenu )
  1739         {
  1740         {
       
  1741         iOldWinPos = DrawableWindow()->OrdinalPosition();
       
  1742         iActionMenu->ShowMenuL(aPenEventScreenLocation);
  1740         iPointerDown = EFalse;
  1743         iPointerDown = EFalse;
  1741         iActionMenu->ShowMenuL(aPenEventScreenLocation);
       
  1742         }
  1744         }
  1743     }
  1745     }
  1744 
  1746 
  1745 // ---------------------------------------------------------------------------
  1747 // ---------------------------------------------------------------------------
  1746 // CHgScroller::CollectionState()
  1748 // CHgScroller::CollectionState()
  1748 //     
  1750 //     
  1749 TUint CHgScroller::CollectionState() const
  1751 TUint CHgScroller::CollectionState() const
  1750     {
  1752     {
  1751     TUint ret = 0;
  1753     TUint ret = 0;
  1752     
  1754     
  1753     if(IsFocused()) ret |= MAknCollection::EStateCollectionVisible;
  1755     if( IsFocused() ) 
  1754     
  1756         {
  1755     if(HasHighlight()) ret |= MAknCollection::EStateHighlightVisible; 
  1757         ret |= MAknCollection::EStateCollectionVisible;
  1756     
  1758         }
  1757     if( iFlags & EHgScrollerSelectionMode ) ret |= MAknCollection::EStateMultipleSelection;
  1759     if( HasHighlight() ) 
  1758     
  1760         {
       
  1761         ret |= MAknCollection::EStateHighlightVisible;
       
  1762         } 
       
  1763     if( iFlags & EHgScrollerSelectionMode )
       
  1764         {
       
  1765         ret |= MAknCollection::EStateMultipleSelection;
       
  1766         for( TInt i = 0; i < iItems.Count(); ++i )
       
  1767             {
       
  1768             if( iItems[i]->Flags() & CHgItem::EHgItemFlagMarked )
       
  1769                 {
       
  1770                 ret |= MAknCollection::EStateMarkedItems; 
       
  1771                 break; 
       
  1772                 }
       
  1773             }
       
  1774         }
  1759     return ret; 
  1775     return ret; 
  1760     }
  1776     }
  1761 
  1777 
  1762 // ---------------------------------------------------------------------------
  1778 // ---------------------------------------------------------------------------
  1763 // CHgScroller::CollectionState()
  1779 // CHgScroller::CollectionState()
  1764 // ---------------------------------------------------------------------------
  1780 // ---------------------------------------------------------------------------
  1765 //     
  1781 //     
  1766 void CHgScroller::ItemActionMenuClosed()
  1782 void CHgScroller::ItemActionMenuClosed()
  1767     {
  1783     {
       
  1784     iOldWinPos = KErrNotFound;
  1768     DrawDeferred();
  1785     DrawDeferred();
  1769     }
  1786     }
  1770 
  1787 
  1771 // ---------------------------------------------------------------------------
  1788 // ---------------------------------------------------------------------------
  1772 // CHgScroller::CollectionState()
  1789 // CHgScroller::CollectionState()