uifw/ganes/src/HgScroller.cpp
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     1 /*
       
     2 * Copyright (c) 2009 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ganes/HgScroller.h>
       
    21 
       
    22 #include <aknphysics.h>
       
    23 
       
    24 #include <ganes/HgScrollBufferObserverIface.h>
       
    25 #include <ganes/HgSelectionObserverIface.h>
       
    26 #include <ganes/HgMarkingObserverIface.h>
       
    27 #include <ganes/HgItem.h>
       
    28 #include "HgScrollbar.h"
       
    29 #include "HgScrollBufferManager.h"
       
    30 #include "HgConstants.h"
       
    31 #include "HgPopupDrawer.h"
       
    32 #include "HgMarquee.h"
       
    33 #include "HgDrawUtils.h"
       
    34 #include "HgIndicatorManager.h"
       
    35 #include "HgTextFind.h"
       
    36 #include "HgKeyUtils.h"
       
    37 
       
    38 #include <ganes.mbg>
       
    39 
       
    40 #include <AknIconUtils.h>
       
    41 #include <avkon.mbg>
       
    42 #include <AknsDrawUtils.h>
       
    43 #include <touchfeedback.h>
       
    44 #include <gulicon.h>
       
    45 #include <AknUtils.h>
       
    46 #include <layoutmetadata.cdl.h>
       
    47 #include <AknLayout2ScalableDef.h>
       
    48 #include <aknitemactionmenu.h>
       
    49 #include <aknappui.h>
       
    50 
       
    51 #include <featdiscovery.h>
       
    52 
       
    53 const TInt KIntensity = 50; // 50%
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CHgScroller::ConstructL()
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CHgScroller::ConstructL (const TRect& aRect, RWsSession* aSession )
       
    63     {
       
    64     // Create a window for this application view
       
    65     CreateWindowL ( );
       
    66     EnableDragEvents();
       
    67     ClaimPointerGrab();
       
    68 
       
    69     iUpperCaseTitle.CreateL( KMaxSearchLenght );
       
    70     iPopupText1.CreateL( KMaxPopupTextLength );
       
    71     iPopupText2.CreateL( KMaxPopupTextLength );
       
    72     
       
    73     iScrollbar = CHgScrollbar::NewL(*this);
       
    74     iPopupDrawer = new (ELeave) THgPopupDrawer();
       
    75     
       
    76     TCallBack callback(CHgScroller::MarqueeCallback, this);
       
    77     iDrawUtils = CHgDrawUtils::NewL( callback );
       
    78     
       
    79     iIndicatorManager = CHgIndicatorManager::NewL();
       
    80 
       
    81     /*
       
    82      * TODO: Vasco says it supports qwerty, so the variation cannot be done.
       
    83      *          Commented out for the time being to fix a crash.
       
    84     // Enable key search only in non-touch or hybrid (touch + qwerty) devices
       
    85     if( !AknLayoutUtils::PenEnabled() ||
       
    86         CFeatureDiscovery::IsFeatureSupportedL(TUid::Uid(KFeatureIdQwertyInput)) )
       
    87         {
       
    88         iTextFind = CHgTextFind::NewL( *this );
       
    89         iKeyUtils = CHgKeyUtils::NewL(*this);
       
    90         }
       
    91     */
       
    92     
       
    93     // Init Stuff
       
    94     if( aSession )
       
    95         {
       
    96         InitScreenL( aRect, *aSession );
       
    97         }
       
    98     else
       
    99         {
       
   100         InitScreenL( aRect );
       
   101         }
       
   102     
       
   103     iHighlightTimer = CPeriodic::NewL( CActive::EPriorityStandard );    
       
   104     iKeyScrollingTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   105     
       
   106     CAknAppUi* appUi = static_cast<CAknAppUi*>(iEikonEnv->AppUi());
       
   107     if( appUi && appUi->IsSingleClickCompatible() )
       
   108         {
       
   109         iDetector = CAknLongTapDetector::NewL(this);
       
   110         iActionMenu = CAknItemActionMenu::RegisterCollectionL(*this);
       
   111         }
       
   112 
       
   113     iDrawUtils->EnableMarquee(HasHighlight());
       
   114     
       
   115     InitItemsL();
       
   116 
       
   117     iCoeEnv->AddForegroundObserverL( *this );    
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CHgScroller::InputCapabilities()
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TCoeInputCapabilities CHgScroller::InputCapabilities() const
       
   125     {
       
   126     TCoeInputCapabilities cap( TCoeInputCapabilities::ENone );
       
   127 
       
   128     if(iTextFind)
       
   129         {
       
   130         MCoeFepAwareTextEditor* editor = NULL;
       
   131         
       
   132         if( iSelectionMode == ENoSelection 
       
   133                 && iFlags & EHgScrollerSearchWithQWERTY )
       
   134             editor = iTextFind;
       
   135     
       
   136         cap = TCoeInputCapabilities( TCoeInputCapabilities::EAllText, 
       
   137                 editor, 
       
   138                 NULL );
       
   139         
       
   140         cap.SetObjectProvider( const_cast<CHgScroller*>(this) );
       
   141         }
       
   142     
       
   143     return cap;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CHgScroller::InitScreenL()
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C void CHgScroller::InitScreenL( const TRect& /*aRect*/, RWsSession& /*aSession*/ )
       
   151     {
       
   152     // DSA not supported anymore.
       
   153     User::Leave( KErrNotSupported );
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CHgScroller::InitScreenL()
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C void CHgScroller::InitScreenL( const TRect& aRect )
       
   161     {
       
   162     // Set the windows size
       
   163     SetRect ( aRect );
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CHgScroller::RefreshScreen()
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C void CHgScroller::RefreshScreen( TInt aIndex )
       
   171     {
       
   172     if( IsDisplayed( aIndex ) )
       
   173         DrawDeferred();
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CHgScroller::RefreshScreen()
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C TInt CHgScroller::FirstIndexOnScreen()
       
   181     {
       
   182     return CurrentIndex();
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CHgScroller::RefreshScreen()
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C TInt CHgScroller::ItemsOnScreen()
       
   190     {
       
   191     return iItemsOnScreen;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CHgScroller::RefreshScreen()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C TInt CHgScroller::SelectedIndex()
       
   199     {
       
   200     return iSelectedIndex;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CHgScroller::RefreshScreen()
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C void CHgScroller::SetSelectedIndex( TInt aIndex )
       
   208     {
       
   209     if( aIndex >= 0 && aIndex < iItems.Count() )
       
   210         {
       
   211         iSelectedIndex = aIndex;
       
   212         // Move view position so that it is fully visible.
       
   213         FitSelectionToView();
       
   214         SelectionChanged();
       
   215         }
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CHgScroller::Mark()
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C void CHgScroller::Mark( TInt aIndex )
       
   223     {
       
   224     if( aIndex >= 0 && aIndex < iItems.Count() )
       
   225         {
       
   226         if( !(iItems[aIndex]->Flags() & CHgItem::EHgItemFlagMarked) )
       
   227             {
       
   228             iItems[aIndex]->SetFlags( CHgItem::EHgItemFlagMarked );
       
   229             if( iMarkingObserver )
       
   230                 {
       
   231                 TRAP_IGNORE( iMarkingObserver->HandleMarkingL( aIndex, ETrue ) );
       
   232                 }            
       
   233             }
       
   234         }    
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CHgScroller::UnMark()
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C void CHgScroller::UnMark( TInt aIndex )
       
   242     {
       
   243     if( aIndex >= 0 && aIndex < iItems.Count() )
       
   244         {
       
   245         if( iItems[aIndex]->Flags() & CHgItem::EHgItemFlagMarked )
       
   246             {
       
   247             iItems[aIndex]->ClearFlags( CHgItem::EHgItemFlagMarked );
       
   248             if( iMarkingObserver )
       
   249                 {
       
   250                 TRAP_IGNORE( iMarkingObserver->HandleMarkingL( aIndex, EFalse ) );
       
   251                 }            
       
   252             }
       
   253         }    
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CHgScroller::MarkAll()
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 EXPORT_C void CHgScroller::MarkAll()
       
   261     {
       
   262     for(TInt i = 0; i < iItems.Count(); ++i)
       
   263         {
       
   264         iItems[i]->SetFlags( CHgItem::EHgItemFlagMarked );
       
   265         }
       
   266     
       
   267     DrawDeferred();
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CHgScroller::UnMarkAll()
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C void CHgScroller::UnMarkAll()
       
   275     {
       
   276     for(TInt i = 0; i < iItems.Count(); ++i)
       
   277         {
       
   278         iItems[i]->ClearFlags(CHgItem::EHgItemFlagMarked);
       
   279         }
       
   280     
       
   281     DrawDeferred();
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CHgScroller::GetMarkedItemsL()
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 EXPORT_C void CHgScroller::GetMarkedItemsL( RArray<TInt>& aIndexes )
       
   289     {
       
   290     for(TInt i = 0; i < iItems.Count(); ++i)
       
   291         {
       
   292         if(iItems[i]->Flags() & CHgItem::EHgItemFlagMarked )
       
   293             {
       
   294             aIndexes.AppendL( i );
       
   295             }
       
   296         }
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CHgScroller::EnableScrollBufferL()
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 EXPORT_C void CHgScroller::EnableScrollBufferL( 
       
   304         MHgScrollBufferObserver& aObserver, 
       
   305         TInt aBufferSize,
       
   306         TInt aBufferTreshold  )
       
   307     {
       
   308     delete iManager; iManager = NULL;
       
   309     
       
   310     iManager = CHgScrollBufferManager::NewL(
       
   311             aObserver, 
       
   312             aBufferSize, 
       
   313             aBufferTreshold, 
       
   314             CurrentIndex(), 
       
   315             iItemCount);
       
   316     
       
   317     iManager->SetBufferOwner( *this );
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CHgScroller::EnableNaviStripL()
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 EXPORT_C void CHgScroller::SetScrollBarTypeL( THgScrollBarType aType )
       
   325     {
       
   326     iScrollBarType = aType;
       
   327     DrawDeferred();
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CHgScroller::SetSelectionObserver()
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 EXPORT_C void CHgScroller::SetSelectionObserver( MHgSelectionObserver& aObserver )
       
   335     {
       
   336     iSelectionObserver = &aObserver;
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CHgScroller::SetMarkingObserver()
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 EXPORT_C void CHgScroller::SetMarkingObserver( MHgMarkingObserver& aObserver )
       
   344     {
       
   345     iMarkingObserver = &aObserver;
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CHgScroller::CHgScroller()
       
   350 // C++ default constructor can NOT contain any code, that might leave.
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 CHgScroller::CHgScroller( 
       
   354         TInt aItemCount, 
       
   355         CGulIcon* aDefaultIcon )
       
   356  :  iDefaultIcon( aDefaultIcon ),
       
   357     iItemCount(aItemCount), 
       
   358     iCurrentRow(-1),
       
   359     iSelectedIndex(KErrNotFound),
       
   360     iScrollBarType( EHgScrollerScrollBar ),
       
   361     iFirstTime(ETrue)
       
   362     {
       
   363     // No implementation required
       
   364     }
       
   365         
       
   366 // -----------------------------------------------------------------------------
       
   367 // CHgScroller::~CHgScroller()
       
   368 // Destructor.
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 EXPORT_C CHgScroller::~CHgScroller ( )
       
   372     {
       
   373     iCoeEnv->RemoveForegroundObserver( *this );
       
   374     
       
   375     iItems.ResetAndDestroy();
       
   376 
       
   377     delete iManager;
       
   378     delete iPhysics;
       
   379     delete iScrollbar;
       
   380     delete iEmptyText;    
       
   381     delete iDefaultIcon;
       
   382     delete iPopupDrawer;
       
   383     delete iDrawUtils;
       
   384     delete iHighlightTimer;
       
   385     delete iIndicatorManager;
       
   386     delete iKeyUtils;
       
   387 	delete iTextFind;
       
   388 	delete iKeyScrollingTimer;
       
   389 	delete iDetector;
       
   390 	
       
   391 	if(iActionMenu)
       
   392 	    iActionMenu->RemoveCollection(*this);
       
   393     
       
   394     iUpperCaseTitle.Close();
       
   395     iPopupText1.Close();
       
   396     iPopupText2.Close();
       
   397     
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CHgScroller::InitPhysicsL()
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 void CHgScroller::InitPhysicsL()
       
   405     {
       
   406     if(!iPhysics)
       
   407         {
       
   408         iPhysics = CAknPhysics::NewL(*this, this);
       
   409         }
       
   410     
       
   411     iPhysics->InitPhysicsL( TotalSize(), 
       
   412             TSize(iWidth, iHeight), 
       
   413             iLandscapeScrolling);
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CHgGrid::Draw()
       
   418 // Draws the display.
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void CHgScroller::Draw ( const TRect& aRect ) const
       
   422     {
       
   423     CWindowGc& gc = SystemGc();
       
   424     
       
   425     // Flush screen buffer
       
   426     InitDrawBuffer();
       
   427 
       
   428     DoDraw( aRect );
       
   429 
       
   430     if( iScrollbar && iItemCount )
       
   431         {
       
   432         iScrollbar->Draw( gc );
       
   433         }
       
   434     
       
   435     if( iPopupDrawer )
       
   436         {
       
   437         if(iPopupText2.Length() > 0)
       
   438             {
       
   439             iPopupDrawer->Draw( gc, 
       
   440                     iPopupText1,
       
   441                     iPopupText2
       
   442                     );
       
   443             }
       
   444         else if( iPopupText1.Length( ) > 0 )
       
   445             {
       
   446             if( iScrollBarType == EHgScrollerLetterStrip
       
   447                     || iScrollBarType == EHgScrollerLetterStripLite )
       
   448                 {
       
   449                 iPopupDrawer->DrawNaviChar( gc, iPopupText1 );
       
   450                 }
       
   451             else
       
   452                 {
       
   453                 iPopupDrawer->Draw( gc, iPopupText1 );
       
   454                 }
       
   455             }
       
   456         else if( iTextFind && iTextFind->Text().Length() > 0 )
       
   457             {
       
   458             iPopupDrawer->Draw( gc, iTextFind->Text() );
       
   459             }
       
   460         }
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CHgScroller::InitDrawBuffer()
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CHgScroller::InitDrawBuffer() const
       
   468     {
       
   469     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   470     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   471     AknsDrawUtils::DrawBackground( skin, cc, this, SystemGc(),
       
   472             TPoint(0,0), Rect(), KAknsDrawParamDefault );
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CHgScroller::SizeChanged()
       
   477 // Called by framework when the view size is changed.
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CHgScroller::SizeChanged ( )
       
   481     {
       
   482     iWidth = Rect().Width();
       
   483     iHeight = Rect().Height();
       
   484 
       
   485     HandleItemCountChanged();
       
   486     
       
   487     if( iPopupDrawer )
       
   488         {
       
   489         iPopupDrawer->Init( Rect(), 
       
   490                 &ScreenFont( TCoeFont( KFocusTextFontSize, TCoeFont::EPlain ) ) );
       
   491         }
       
   492     
       
   493     if(iFirstTime)
       
   494         {
       
   495         iViewPosition = TPoint(iWidth/2, iHeight/2);
       
   496         iFirstTime = EFalse;
       
   497         }
       
   498     
       
   499     HandleViewPositionChanged();
       
   500     
       
   501     TRAP_IGNORE( InitGraphicsL(); )
       
   502     DrawDeferred ( );
       
   503     }
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // CHgScroller::HandleItemCountChaged()
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CHgScroller::HandleItemCountChanged()
       
   510     {
       
   511     HandleSizeChanged();
       
   512 
       
   513     if( iSelectedIndex >= iItemCount )
       
   514         {
       
   515         iSelectedIndex = iItemCount - 1;
       
   516         SelectionChanged();
       
   517         }
       
   518 
       
   519     TRAP_IGNORE ( 
       
   520             InitScrollbarL();
       
   521             InitPhysicsL();
       
   522                 )
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CHgScroller::InitScrollbarL()
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CHgScroller::InitScrollbarL()
       
   530     {
       
   531     if( iScrollbar && iItemCount )
       
   532         {
       
   533         iScrollbar->InitScrollBarL( Rect(), 
       
   534                                     TotalSize(), 
       
   535                                     TSize(iWidth, iHeight), 
       
   536                                     iLandscapeScrolling); 
       
   537 
       
   538         iScrollbar->SetViewPosition( iViewPosition - TPoint(iWidth/2, iHeight/2));
       
   539         }
       
   540     }
       
   541 // -----------------------------------------------------------------------------
       
   542 // CHgScroller::HandlePointerEventL()
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 void CHgScroller::HandlePointerEventL( const TPointerEvent& aEvent )
       
   546     {
       
   547     if( !HandleScrollbarEventL( aEvent ) && iItemCount )
       
   548         {
       
   549         iShowHighlight = EFalse;
       
   550         
       
   551         // Start drag
       
   552         if( aEvent.iType == TPointerEvent::EButton1Down )
       
   553             {
       
   554             iPointerDown = ETrue;
       
   555             HandleDownEventL( aEvent );
       
   556 
       
   557             if( iDetector && !HasHighlight() && iActionMenu->InitMenuL() )
       
   558                 iDetector->PointerEventL( aEvent );
       
   559             }
       
   560         // Drag
       
   561         else if( aEvent.iType == TPointerEvent::EDrag && iPointerDown )
       
   562             {
       
   563             HandleDragEventL( aEvent );
       
   564             
       
   565             if( iPanning && iDetector && !HasHighlight()  )
       
   566                 iDetector->CancelAnimationL();
       
   567             }
       
   568         // End drag
       
   569         else if( aEvent.iType == TPointerEvent::EButton1Up && iPointerDown )
       
   570             {
       
   571             if( iDetector && !HasHighlight() )
       
   572                 iDetector->PointerEventL( aEvent );
       
   573             
       
   574             HandleUpEventL( aEvent );
       
   575             iPointerDown = EFalse;
       
   576             }
       
   577         }
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CHgScroller::HandleScrollbarEventL()
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 TBool CHgScroller::HandleScrollbarEventL( const TPointerEvent& aEvent )
       
   585     {
       
   586     TBool sbHandles = EFalse;
       
   587     if( iScrollbar )
       
   588         {
       
   589         sbHandles = iScrollbar->HandlePointerEventL( aEvent );
       
   590         if ( sbHandles && !iScrollbar->IsStatic() )
       
   591             {
       
   592             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   593             // Start drag
       
   594             if( aEvent.iType == TPointerEvent::EButton1Down )
       
   595                 {
       
   596                 if ( feedback )
       
   597                     {
       
   598                     feedback->InstantFeedback( this, ETouchFeedbackBasicSlider, aEvent );
       
   599                     }
       
   600                 }
       
   601             // Drag
       
   602             else if( aEvent.iType == TPointerEvent::EDrag 
       
   603                     && iScrollbar->IsDragging() )
       
   604                 {
       
   605                 // Smooth continuous tactile feedback is produced
       
   606                 // during thumb dragging. The tactile feedback API 
       
   607                 // filters out possible re-startings of the effect.
       
   608                 if ( feedback )
       
   609                     {
       
   610                     TTimeIntervalMicroSeconds32 timeout( 300000 );
       
   611                     feedback->StartFeedback( this, 
       
   612                                              ETouchContinuousSlider, 
       
   613                                              &aEvent, 
       
   614                                              KIntensity, // intensity 50%
       
   615                                              timeout );
       
   616                     }
       
   617                 }
       
   618             // End drag
       
   619             else if( aEvent.iType == TPointerEvent::EButton1Up )
       
   620                 {
       
   621                 // Stop the continuous tactile feedback that may be playing
       
   622                 // at the time due to possible previous thumb dragging.
       
   623                 if ( feedback )
       
   624                     {
       
   625                     feedback->StopFeedback( this );
       
   626                     TTouchFeedbackType type = ETouchFeedbackVibra;
       
   627                     feedback->InstantFeedback( this, ETouchFeedbackBasicSlider, type, aEvent );
       
   628                     }
       
   629                 iPopupText1.Zero();
       
   630                 iPopupText2.Zero();
       
   631                 DrawDeferred();
       
   632                 }
       
   633             }
       
   634         }
       
   635     return sbHandles;
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CHgScroller::HandleDownEventL()
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CHgScroller::HandleDownEventL( const TPointerEvent& aEvent )
       
   643     {
       
   644     if( !HasHighlight() 
       
   645             && (iPhysics->OngoingPhysicsAction() == CAknPhysics::EAknPhysicsActionFlicking) )
       
   646         {
       
   647         iPanning = ETrue;
       
   648         if(iDetector)
       
   649             iDetector->CancelAnimationL();
       
   650         }
       
   651     else
       
   652         {
       
   653         iPanning = EFalse;
       
   654         }
       
   655 
       
   656     iPhysics->StopPhysics();
       
   657     iPhysics->ResetFriction();
       
   658 
       
   659     iStart = aEvent.iPosition;
       
   660     iPrev = iStart;
       
   661     iStartTime.HomeTime();
       
   662 
       
   663     if(iLandscapeScrolling)
       
   664         iViewPosition.iY = iHeight / 2;
       
   665     else
       
   666         iViewPosition.iX = iWidth / 2;
       
   667     
       
   668     iFocusedIndex = KErrNotFound;
       
   669     iSelectionToFocusedItem = EFalse;
       
   670     iDrawUtils->EnableMarquee(HasHighlight());
       
   671     if(HasHighlight())
       
   672         {
       
   673         LaunchHighlightTimer();
       
   674         }
       
   675     else if( !iPanning )
       
   676         {
       
   677         SetHighlightL();
       
   678         }
       
   679     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   680     if ( feedback )
       
   681         {
       
   682         feedback->InstantFeedback( this, ETouchFeedbackBasicItem, aEvent );
       
   683         }
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CHgScroller::HandleDragEventL()
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 void CHgScroller::HandleDragEventL( const TPointerEvent& aEvent )
       
   691     {
       
   692     if(!iPanning)
       
   693         {
       
   694         TInt delta = 0;
       
   695         if(iLandscapeScrolling)
       
   696             {
       
   697             delta = iPrev.iX - aEvent.iPosition.iX;
       
   698             }
       
   699         else
       
   700             {
       
   701             delta = iPrev.iY - aEvent.iPosition.iY;
       
   702             }
       
   703         
       
   704         delta = delta < 0 ? -delta : delta;
       
   705         iPanning = delta >= iPhysics->DragThreshold();
       
   706         }
       
   707 
       
   708     if(iPanning)
       
   709         {
       
   710         TPoint delta = iPrev - aEvent.iPosition;
       
   711         if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored())
       
   712             delta = -delta;
       
   713         iPhysics->RegisterPanningPosition( delta );
       
   714         iPrev = aEvent.iPosition;
       
   715         iHighlightTimer->Cancel();
       
   716         }
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CHgScroller::HandleUpEventL()
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void CHgScroller::HandleUpEventL( const TPointerEvent& aEvent )
       
   724     {
       
   725     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   726     TTouchFeedbackType type = ETouchFeedbackVibra;
       
   727     if( iPanning )
       
   728         {
       
   729         // enable physics
       
   730         TPoint drag = iStart - aEvent.iPosition;
       
   731         if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored())
       
   732             drag = -drag;
       
   733         iPhysics->StartPhysics(drag, iStartTime);
       
   734         if ( feedback )
       
   735             {
       
   736             feedback->InstantFeedback( this, ETouchFeedbackItemScroll, type, aEvent );
       
   737             }
       
   738         }
       
   739     else
       
   740         {
       
   741         HandleSelectionL();
       
   742         if ( feedback )
       
   743             {
       
   744             feedback->InstantFeedback( this, ETouchFeedbackBasicItem, type, aEvent );
       
   745             }
       
   746         }
       
   747     }
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CHgScroller::HandleSelectionL()
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 void CHgScroller::HandleSelectionL()
       
   754     {
       
   755     TInt index = GetSelected(iStart);
       
   756     if(index != KErrNotFound)
       
   757         {
       
   758         if( iFocusedIndex == KErrNotFound )
       
   759             {
       
   760             // Highlight timer hasn't triggered so lets set the highlight.
       
   761             // this is not usually the case since interval is 50ms but just to be sure.
       
   762             SetHighlightL();
       
   763             }
       
   764         
       
   765         if( iFlags & EHgScrollerSelectionMode || iSelectionMode != ENoSelection ) 
       
   766             // Marking mode or shift key pressed ( or hash )
       
   767             {
       
   768             if( iItems[iSelectedIndex]->Flags() & CHgItem::EHgItemFlagMarked )
       
   769                 {
       
   770                 UnMark( iSelectedIndex );
       
   771                 }
       
   772             else
       
   773                 {
       
   774                 Mark( iSelectedIndex );                    
       
   775                 }
       
   776             DrawDeferred();
       
   777             }
       
   778         else // Selection
       
   779             {
       
   780             if( iSelectionToFocusedItem || !HasHighlight() )
       
   781                 {
       
   782                 if(iSelectionObserver)
       
   783                     iSelectionObserver->HandleOpenL(iSelectedIndex);
       
   784                 }
       
   785             }
       
   786         }
       
   787     }
       
   788 
       
   789 // -----------------------------------------------------------------------------
       
   790 // CHgScroller::OfferKeyEventL()
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 TKeyResponse CHgScroller::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   794     {
       
   795     if( iKeyUtils 
       
   796             && !(iFlags & EHgScrollerKeyMarkingDisabled)
       
   797             && iKeyUtils->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
       
   798         return EKeyWasConsumed;
       
   799     
       
   800     switch( aType )
       
   801         {
       
   802         case EEventKeyDown:
       
   803             KeyEventDown();
       
   804             break;
       
   805         case EEventKey:    
       
   806             return HandleKeyEvent( aKeyEvent );
       
   807         case EEventKeyUp:
       
   808             KeyEventUp();
       
   809         default:
       
   810             break;
       
   811         }
       
   812     
       
   813     // Let CCoeControl handle other cases.
       
   814     return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
       
   815     }
       
   816 
       
   817 // -----------------------------------------------------------------------------
       
   818 // CHgScroller::KeyEventDown()
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 void CHgScroller::KeyEventDown()
       
   822     {
       
   823     iKeyRepeats = 0;
       
   824     iKeyScrollingState = ENoKeyScrolling;
       
   825     
       
   826     iPointerDown = EFalse;
       
   827     iPanning = EFalse;
       
   828     iShowHighlight = ETrue;
       
   829     iDrawUtils->EnableMarquee(HasHighlight());
       
   830     }
       
   831 
       
   832 // -----------------------------------------------------------------------------
       
   833 // CHgScroller::KeyEventUp()
       
   834 // -----------------------------------------------------------------------------
       
   835 //
       
   836 void CHgScroller::KeyEventUp()
       
   837     {
       
   838     if( iKeyScrollingState != ENoKeyScrolling )
       
   839         {
       
   840         // Key has been released so stop the key scrolling.
       
   841         StopKeyScrolling();
       
   842         }
       
   843     }
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CHgScroller::SetItem()
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 EXPORT_C void CHgScroller::SetItem(CHgItem* aItem, TInt aIndex)
       
   850     {
       
   851     if( aItem && aIndex >= 0 && aIndex < iItems.Count() )
       
   852         {
       
   853         delete iItems[aIndex];
       
   854         iItems[aIndex] = aItem;
       
   855         }
       
   856     }
       
   857 
       
   858 // -----------------------------------------------------------------------------
       
   859 // CHgScroller::AddItem()
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 EXPORT_C void CHgScroller::AddItem(CHgItem* aItem)
       
   863     {
       
   864     if( aItem )
       
   865         {
       
   866         iItems.Append(aItem);
       
   867         iItemCount++;
       
   868         HandleItemCountChanged();
       
   869         if( iManager )
       
   870             {
       
   871             iManager->ItemCountChanged( iItemCount-1, EFalse, iItemCount );
       
   872             }
       
   873         }
       
   874     }
       
   875 
       
   876 // -----------------------------------------------------------------------------
       
   877 // CHgScroller::InsertItem()
       
   878 // -----------------------------------------------------------------------------
       
   879 //
       
   880 EXPORT_C void CHgScroller::InsertItem(CHgItem* aItem, TInt aIndex)
       
   881     {
       
   882     if( aItem && aIndex >= 0 )
       
   883         {
       
   884         if(aIndex < iItems.Count())
       
   885             {
       
   886             iItems.Insert(aItem, aIndex);
       
   887             }
       
   888         else
       
   889             {
       
   890             iItems.Append(aItem);
       
   891             }
       
   892         iItemCount++;
       
   893         HandleItemCountChanged();
       
   894         
       
   895         if( iManager )
       
   896             {
       
   897             iManager->ItemCountChanged( aIndex, EFalse, iItemCount );
       
   898             }
       
   899         }
       
   900     }
       
   901 
       
   902 // -----------------------------------------------------------------------------
       
   903 // CHgScroller::RemoveItem()
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 EXPORT_C void CHgScroller::RemoveItem(TInt aIndex)
       
   907     {
       
   908     if( aIndex >= 0 && aIndex < iItems.Count() )
       
   909         {
       
   910         delete iItems[aIndex]; iItems[aIndex] = NULL;
       
   911         iItems.Remove(aIndex);
       
   912         iItemCount--;
       
   913         HandleItemCountChanged();
       
   914         
       
   915         if( iManager )
       
   916             {
       
   917             iManager->ItemCountChanged( aIndex, ETrue, iItemCount );
       
   918             }
       
   919         }
       
   920     }
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CHgScroller::ResizeL()
       
   924 // -----------------------------------------------------------------------------
       
   925 //
       
   926 EXPORT_C void CHgScroller::ResizeL( TInt aItemCount )
       
   927     {
       
   928     // Add More
       
   929     if( iItems.Count() < aItemCount )
       
   930         {
       
   931         while( iItems.Count() < aItemCount )
       
   932             {
       
   933             iItems.AppendL( CHgItem::NewL() );
       
   934             }
       
   935         }
       
   936     // remove from the end
       
   937     else if( iItems.Count() > aItemCount )
       
   938         {
       
   939         while( iItems.Count() > aItemCount )
       
   940             {
       
   941             delete iItems[iItems.Count() - 1];
       
   942             iItems.Remove( iItems.Count() - 1 );
       
   943             }
       
   944         }
       
   945     else
       
   946         {
       
   947         return; // no change needed
       
   948         }
       
   949 
       
   950     iItemCount = aItemCount;
       
   951 
       
   952     if( iManager )
       
   953         {
       
   954         iManager->ResetBuffer( iSelectedIndex, iItemCount );
       
   955         }
       
   956 
       
   957     HandleItemCountChanged();
       
   958     }
       
   959 
       
   960 // -----------------------------------------------------------------------------
       
   961 // CHgScroller::ItemL()
       
   962 // -----------------------------------------------------------------------------
       
   963 //
       
   964 EXPORT_C CHgItem& CHgScroller::ItemL(TInt aIndex)
       
   965     {
       
   966     if( aIndex < 0 || aIndex >= iItems.Count() )
       
   967         {
       
   968         User::Leave( KErrArgument );
       
   969         }
       
   970 
       
   971     return *iItems[aIndex];
       
   972     }
       
   973 
       
   974 // -----------------------------------------------------------------------------
       
   975 // CHgScroller::ViewPositionChanged()
       
   976 // -----------------------------------------------------------------------------
       
   977 //
       
   978 void CHgScroller::ViewPositionChanged( const TPoint& aNewPosition,
       
   979                                         TBool aDrawNow,
       
   980                                         TUint /*aFlags*/ )
       
   981     {
       
   982     iViewPosition = aNewPosition;
       
   983     HandleViewPositionChanged();
       
   984     if( aDrawNow )
       
   985         DrawNow();
       
   986     }
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // CHgScroller::ScrollBarPositionChanged()
       
   990 // -----------------------------------------------------------------------------
       
   991 //
       
   992 void CHgScroller::ScrollBarPositionChanged( const TPoint& aNewPosition )
       
   993     {
       
   994     iViewPosition = aNewPosition;
       
   995     iPhysics->StopPhysics();
       
   996     
       
   997     if( iScrollBarType == EHgScrollerTimeStrip )
       
   998         {
       
   999         // Show first item's time.
       
  1000         TInt selectedItem = CurrentIndex();
       
  1001         if( selectedItem >= 0 && selectedItem < iItems.Count() )
       
  1002             {
       
  1003             TRAP_IGNORE(
       
  1004                     iItems[selectedItem]->Time().FormatL( iPopupText1, KGanesMonthString );
       
  1005                     iItems[selectedItem]->Time().FormatL( iPopupText2, KGanesYearString );
       
  1006                 )
       
  1007             // To display year correctly in arabic.
       
  1008             AknTextUtils::LanguageSpecificNumberConversion( iPopupText2 );
       
  1009             }
       
  1010         }
       
  1011     else if( iScrollBarType == EHgScrollerLetterStrip
       
  1012             || iScrollBarType == EHgScrollerLetterStripLite )
       
  1013         {
       
  1014         TInt selectedItem = CurrentIndex();
       
  1015         if( selectedItem >= 0 && selectedItem < iItems.Count() )
       
  1016             {
       
  1017             if(iItems[selectedItem]->Title().Length())
       
  1018                 {
       
  1019                 iPopupText1.Zero();
       
  1020                 iPopupText1.Append( iItems[selectedItem]->Title()[0] );
       
  1021                 }
       
  1022             }
       
  1023         }
       
  1024     HandleViewPositionChanged( EFalse );
       
  1025     DrawNow();
       
  1026     }
       
  1027 
       
  1028 // -----------------------------------------------------------------------------
       
  1029 // CHgScroller::HandleNaviStripChar()
       
  1030 // -----------------------------------------------------------------------------
       
  1031 //
       
  1032 void CHgScroller::HandleNaviStripChar( const TChar& /*aChar*/ )
       
  1033     {
       
  1034     // Feature not used anymore
       
  1035     }
       
  1036 
       
  1037 // -----------------------------------------------------------------------------
       
  1038 // CHgScroller::PhysicEmulationEnded()
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //
       
  1041 void CHgScroller::PhysicEmulationEnded()
       
  1042     {
       
  1043     // Nothing to do.
       
  1044     }
       
  1045 
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CHgScroller::HandleViewPositionChanged()
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 void CHgScroller::HandleViewPositionChanged(TBool aUpdateScrollbar)
       
  1051     {
       
  1052     TInt newRow = iLandscapeScrolling ?
       
  1053         (iViewPosition.iX-(iWidth/2))/((iRowHeight)):
       
  1054         (iViewPosition.iY-(iHeight/2))/(iRowHeight);
       
  1055     
       
  1056     if(iScrollbar && aUpdateScrollbar)
       
  1057         iScrollbar->SetViewPosition( iViewPosition - TPoint(iWidth/2, iHeight/2));
       
  1058 
       
  1059     if(newRow != iCurrentRow)
       
  1060         {
       
  1061         iCurrentRow = newRow;
       
  1062 
       
  1063         if(iManager)
       
  1064             {
       
  1065             iManager->SetPosition( CurrentIndex() );
       
  1066             }
       
  1067         }
       
  1068     }
       
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CHgScroller::HandleViewPositionChanged()
       
  1072 // -----------------------------------------------------------------------------
       
  1073 //
       
  1074 TPoint CHgScroller::ViewPosition() const
       
  1075     {
       
  1076     return iViewPosition;
       
  1077     }
       
  1078 
       
  1079 // -----------------------------------------------------------------------------
       
  1080 // CHgScroller::HandleKeyEvent()
       
  1081 // -----------------------------------------------------------------------------
       
  1082 //
       
  1083 TKeyResponse CHgScroller::HandleKeyEvent(const TKeyEvent& aKeyEvent)
       
  1084     {
       
  1085     iKeyRepeats++;
       
  1086     TInt prevSelected = iSelectedIndex;
       
  1087 
       
  1088     TKeyScrollingState possibleKeyScrollingState = ENoKeyScrolling;
       
  1089     
       
  1090     switch( aKeyEvent.iCode )
       
  1091         {
       
  1092         case EKeyUpArrow:
       
  1093             if( !iLandscapeScrolling )
       
  1094                 possibleKeyScrollingState = EKeyScrollingUp;
       
  1095             break;
       
  1096         case EKeyDownArrow:
       
  1097             if( !iLandscapeScrolling )
       
  1098                 possibleKeyScrollingState = EKeyScrollingDown;
       
  1099             break;
       
  1100         case EKeyLeftArrow:
       
  1101             if( iLandscapeScrolling )
       
  1102                 possibleKeyScrollingState = EKeyScrollingLeft;
       
  1103             break;
       
  1104         case EKeyRightArrow:
       
  1105             if( iLandscapeScrolling )
       
  1106                 possibleKeyScrollingState = EKeyScrollingRight;
       
  1107             break;
       
  1108         case EKeyEnter:
       
  1109             {
       
  1110             if( iSelectedIndex != KErrNotFound && iSelectionObserver )
       
  1111                 {
       
  1112                 TRAP_IGNORE( iSelectionObserver->HandleOpenL( iSelectedIndex ); )
       
  1113                 return EKeyWasConsumed;
       
  1114                 }
       
  1115             return EKeyWasNotConsumed;
       
  1116             }
       
  1117         default:
       
  1118             break;
       
  1119         }
       
  1120 
       
  1121     if( possibleKeyScrollingState != ENoKeyScrolling 
       
  1122         && iKeyRepeats > KPhysLaunchKeyCount
       
  1123         && iSelectionMode == ENoSelection )
       
  1124         {
       
  1125         if( !iKeyScrollingTimer->IsActive() )
       
  1126             {
       
  1127             iKeyScrollingState = possibleKeyScrollingState;
       
  1128             iKeyScrollingTimer->Start(
       
  1129                     TTimeIntervalMicroSeconds32( 0 ),
       
  1130                     TTimeIntervalMicroSeconds32( KKeyScrollingUpdateInterval ), 
       
  1131                     TCallBack( KeyScrollingTimerCallback, this ) );
       
  1132             }
       
  1133         }
       
  1134     
       
  1135     TBool handled = DoHandleKeyEvent(aKeyEvent); 
       
  1136     
       
  1137     if( iSelectedIndex != prevSelected && iSelectionObserver )
       
  1138         {
       
  1139         iDrawUtils->ResetMarquee();
       
  1140         TRAP_IGNORE( iSelectionObserver->HandleSelectL(iSelectedIndex); )
       
  1141         }
       
  1142     
       
  1143     if( !handled )
       
  1144         iKeyRepeats--;
       
  1145     
       
  1146     return handled ? EKeyWasConsumed : EKeyWasNotConsumed;
       
  1147     }
       
  1148 
       
  1149 // -----------------------------------------------------------------------------
       
  1150 // CHgScroller::Release()
       
  1151 // -----------------------------------------------------------------------------
       
  1152 //
       
  1153 void CHgScroller::Release(TInt aReleaseStart, TInt aReleaseEnd)
       
  1154     {
       
  1155     for(; aReleaseStart <= aReleaseEnd; ++aReleaseStart)
       
  1156         {
       
  1157         if( aReleaseStart >= 0 && aReleaseStart < iItems.Count())
       
  1158             {
       
  1159             iItems[aReleaseStart]->SetIcon(NULL, iItems[aReleaseStart]->Flags());
       
  1160             }
       
  1161         }
       
  1162     }
       
  1163 
       
  1164 // -----------------------------------------------------------------------------
       
  1165 // CHgScroller::Reset()
       
  1166 // -----------------------------------------------------------------------------
       
  1167 //
       
  1168 EXPORT_C void CHgScroller::Reset()
       
  1169     {
       
  1170     if(iItemCount)
       
  1171         {
       
  1172         iItems.ResetAndDestroy();
       
  1173         iItemCount = 0;
       
  1174         iSelectedIndex = -1;
       
  1175         
       
  1176         if( iManager )
       
  1177             {
       
  1178             iManager->ResetBuffer( iSelectedIndex, iItemCount );
       
  1179             }
       
  1180     
       
  1181         HandleItemCountChanged();
       
  1182         }
       
  1183     }
       
  1184 
       
  1185 // -----------------------------------------------------------------------------
       
  1186 // CHgScroller::SetFlags()
       
  1187 // -----------------------------------------------------------------------------
       
  1188 //
       
  1189 EXPORT_C void CHgScroller::SetFlags(TInt aFlags)
       
  1190     {
       
  1191     iFlags |= aFlags;
       
  1192     }
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // CHgScroller::ClearFlags()
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 EXPORT_C void CHgScroller::ClearFlags(TInt aFlags)
       
  1199     {
       
  1200     iFlags &= ~aFlags;    
       
  1201     }
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CHgScroller::Flags()
       
  1205 // -----------------------------------------------------------------------------
       
  1206 //
       
  1207 EXPORT_C TInt CHgScroller::Flags()
       
  1208     {
       
  1209     return iFlags;
       
  1210     }
       
  1211 
       
  1212 // -----------------------------------------------------------------------------
       
  1213 // CHgScroller::SetEmptyTextL()
       
  1214 // -----------------------------------------------------------------------------
       
  1215 //
       
  1216 EXPORT_C void CHgScroller::SetEmptyTextL( const TDesC& aEmptyText )
       
  1217     {
       
  1218     delete iEmptyText;
       
  1219     iEmptyText = 0;
       
  1220     iEmptyText = aEmptyText.AllocL();
       
  1221     }
       
  1222 
       
  1223 // -----------------------------------------------------------------------------
       
  1224 // CHgScroller::ItemCount()
       
  1225 // -----------------------------------------------------------------------------
       
  1226 //
       
  1227 EXPORT_C TInt CHgScroller::ItemCount() const
       
  1228     {
       
  1229     return iItems.Count();
       
  1230     }
       
  1231 
       
  1232 // -----------------------------------------------------------------------------
       
  1233 // CHgScroller::HightlightItem()
       
  1234 // -----------------------------------------------------------------------------
       
  1235 //
       
  1236 EXPORT_C TBool CHgScroller::HightlightItem( const TDesC& aHighlightText )
       
  1237     {
       
  1238     TInt searchStartIndex = aHighlightText.Length() == 1 ||
       
  1239         iSelectedIndex == KErrNotFound ? iSelectedIndex + 1 : iSelectedIndex;
       
  1240     
       
  1241     // From selected to end
       
  1242     for(TInt i = searchStartIndex; i < iItems.Count(); ++i)
       
  1243         {
       
  1244         if(iItems[i]->Title().Length() > 0 )
       
  1245             {
       
  1246             iUpperCaseTitle.Copy( iItems[i]->Title().Left( aHighlightText.Length() ) );
       
  1247             iUpperCaseTitle.UpperCase();
       
  1248             TInt result = iUpperCaseTitle.CompareC( aHighlightText );
       
  1249 
       
  1250             if(result == 0)
       
  1251                 {
       
  1252                 iSelectedIndex = i;
       
  1253                 FitSelectionToView();
       
  1254                 DrawDeferred();
       
  1255                 return ETrue;
       
  1256                 }
       
  1257             }
       
  1258         }
       
  1259 
       
  1260     // From beginning to selected - 1
       
  1261     for(TInt i = 0; i < iSelectedIndex; ++i)
       
  1262         {
       
  1263         if(iItems[i]->Title().Length() > 0 )
       
  1264             {
       
  1265             iUpperCaseTitle.Copy( iItems[i]->Title().Left( aHighlightText.Length() ) );
       
  1266             iUpperCaseTitle.UpperCase();
       
  1267             TInt result = iUpperCaseTitle.CompareC( aHighlightText );
       
  1268 
       
  1269             if(result == 0)
       
  1270                 {
       
  1271                 iSelectedIndex = i;
       
  1272                 FitSelectionToView();
       
  1273                 DrawDeferred();
       
  1274                 return ETrue;
       
  1275                 }
       
  1276             else if( result > 0)
       
  1277                 {
       
  1278                 break;
       
  1279                 }
       
  1280             }
       
  1281         }
       
  1282     
       
  1283     return EFalse;
       
  1284     }
       
  1285 
       
  1286 // -----------------------------------------------------------------------------
       
  1287 // CHgScroller::SetDefaultIconL()
       
  1288 // -----------------------------------------------------------------------------
       
  1289 //
       
  1290 EXPORT_C void CHgScroller::SetDefaultIconL( CGulIcon* aDefaultIcon )
       
  1291     {
       
  1292     if( aDefaultIcon )
       
  1293         {
       
  1294         delete iDefaultIcon;
       
  1295         iDefaultIcon = aDefaultIcon;
       
  1296         }
       
  1297     }
       
  1298 
       
  1299 // -----------------------------------------------------------------------------
       
  1300 // CHgScroller::DisableScrollBuffer()
       
  1301 // -----------------------------------------------------------------------------
       
  1302 //
       
  1303 EXPORT_C void CHgScroller::DisableScrollBuffer()
       
  1304     {
       
  1305     delete iManager;
       
  1306     iManager = NULL;
       
  1307     }
       
  1308 
       
  1309 // -----------------------------------------------------------------------------
       
  1310 // CHgScroller::InitGraphicsL()
       
  1311 // -----------------------------------------------------------------------------
       
  1312 //
       
  1313 void CHgScroller::InitGraphicsL()
       
  1314     {
       
  1315     // Non-Skinned icons
       
  1316     // Default icon
       
  1317     if(iIndicatorManager)
       
  1318         {
       
  1319         iIndicatorManager->InitIconL(iDefaultIcon, 
       
  1320                 EMbmGanesQgn_prop_checkbox_on, EMbmGanesQgn_prop_checkbox_on_mask, iImageSize);
       
  1321 
       
  1322         iIndicatorManager->InitIndicatorsL(iIndicatorSize);
       
  1323         }
       
  1324     }
       
  1325 
       
  1326 // -----------------------------------------------------------------------------
       
  1327 // CHgScroller::SelectionChanged()
       
  1328 // -----------------------------------------------------------------------------
       
  1329 //
       
  1330 void CHgScroller::SelectionChanged()
       
  1331     {
       
  1332     }
       
  1333 
       
  1334 // -----------------------------------------------------------------------------
       
  1335 // CHgScroller::FitRowToView()
       
  1336 // -----------------------------------------------------------------------------
       
  1337 //
       
  1338 void CHgScroller::FitRowToView( TInt aRow )
       
  1339     {
       
  1340     if( iLandscapeScrolling )
       
  1341         {
       
  1342         if ( aRow*iRowHeight < iViewPosition.iX-(iWidth/2) )
       
  1343             {
       
  1344             // Item is at top but not fully visible
       
  1345             iViewPosition.iX -= (iViewPosition.iX-(iWidth/2) - ((aRow)*iRowHeight));
       
  1346             HandleViewPositionChanged();                            
       
  1347             }    
       
  1348         else if ( (aRow+1)*iRowHeight > iViewPosition.iX+(iWidth/2) )
       
  1349             {
       
  1350             // Item is at bottom but not fully visible
       
  1351             iViewPosition.iX += ((aRow+1)*iRowHeight - (iViewPosition.iX+(iWidth/2)));
       
  1352             HandleViewPositionChanged();                            
       
  1353             }        
       
  1354         }
       
  1355     else
       
  1356         {
       
  1357         if ( aRow*iRowHeight < iViewPosition.iY-(iHeight/2) )
       
  1358             {
       
  1359             // Item is at top but not fully visible
       
  1360             iViewPosition.iY -= (iViewPosition.iY-(iHeight/2) - ((aRow)*iRowHeight));
       
  1361             HandleViewPositionChanged();                            
       
  1362             }    
       
  1363         else if ( (aRow+1)*iRowHeight > iViewPosition.iY+(iHeight/2) )
       
  1364             {
       
  1365             // Item is at bottom but not fully visible
       
  1366             iViewPosition.iY += ((aRow+1)*iRowHeight - (iViewPosition.iY+(iHeight/2)));
       
  1367             HandleViewPositionChanged();                            
       
  1368             }
       
  1369         }
       
  1370     }
       
  1371 
       
  1372 // -----------------------------------------------------------------------------
       
  1373 // CHgScroller::MarqueeCallback()
       
  1374 // -----------------------------------------------------------------------------
       
  1375 //
       
  1376 TInt CHgScroller::MarqueeCallback( TAny* aSelf )
       
  1377     {
       
  1378     CHgScroller* self = static_cast<CHgScroller*>(aSelf);
       
  1379     if( self->IsDisplayed( self->iSelectedIndex ) )
       
  1380         {
       
  1381         self->DrawDeferred();
       
  1382         return ETrue;
       
  1383         }
       
  1384     else
       
  1385         {
       
  1386         return EFalse;
       
  1387         }
       
  1388     }
       
  1389 
       
  1390 // -----------------------------------------------------------------------------
       
  1391 // CHgScroller::HandleGainingForeground()
       
  1392 // -----------------------------------------------------------------------------
       
  1393 //
       
  1394 void CHgScroller::HandleGainingForeground()
       
  1395     {
       
  1396     iSelectionMode = ENoSelection;
       
  1397     TRect rect( PositionRelativeToScreen(), Size() );
       
  1398     TRAP_IGNORE( InitScreenL( rect ); )
       
  1399     iScrollbar->Reset();
       
  1400     }
       
  1401 
       
  1402 // -----------------------------------------------------------------------------
       
  1403 // CHgScroller::HandleLosingForeground()
       
  1404 // -----------------------------------------------------------------------------
       
  1405 //
       
  1406 void CHgScroller::HandleLosingForeground()
       
  1407     {
       
  1408     iPopupText1.Zero();
       
  1409     iPopupText2.Zero();
       
  1410     }
       
  1411 
       
  1412 // ---------------------------------------------------------------------------
       
  1413 // CHgScroller::LaunchHighlightTimer()
       
  1414 // ---------------------------------------------------------------------------
       
  1415 //     
       
  1416 void CHgScroller::LaunchHighlightTimer()
       
  1417     {
       
  1418     if ( !iHighlightTimer )
       
  1419         {
       
  1420         return;
       
  1421         }
       
  1422 
       
  1423     TInt highlightTimeout( 0 );
       
  1424     if ( iPhysics )
       
  1425         {
       
  1426         highlightTimeout = iPhysics->HighlightTimeout() * 1000;
       
  1427         }
       
  1428     if ( highlightTimeout == 0 )
       
  1429         {
       
  1430         highlightTimeout = KDefaultHighlightTimeout;
       
  1431         }
       
  1432 
       
  1433     iHighlightTimer->Cancel();
       
  1434     iHighlightTimer->Start( 
       
  1435         TTimeIntervalMicroSeconds32( highlightTimeout ),
       
  1436         TTimeIntervalMicroSeconds32( highlightTimeout ), 
       
  1437         TCallBack( HighlightTimerCallback, this ) );
       
  1438     }
       
  1439 
       
  1440 
       
  1441 // ---------------------------------------------------------------------------
       
  1442 // CHgScroller::HighlightTimerCallback()
       
  1443 // ---------------------------------------------------------------------------
       
  1444 //     
       
  1445 TInt CHgScroller::HighlightTimerCallback( TAny* aPtr )
       
  1446     {
       
  1447     CHgScroller* scroller = 
       
  1448         static_cast<CHgScroller*>( aPtr );
       
  1449 
       
  1450     TInt err = KErrNotFound;
       
  1451         
       
  1452     if ( scroller  )
       
  1453         {
       
  1454         TRAP( err, scroller->SetHighlightL() );
       
  1455         }
       
  1456     
       
  1457     return err;
       
  1458     }
       
  1459 
       
  1460 // ---------------------------------------------------------------------------
       
  1461 // CHgScroller::SetHighlightL()
       
  1462 // ---------------------------------------------------------------------------
       
  1463 //     
       
  1464 void CHgScroller::SetHighlightL()
       
  1465     {
       
  1466     iHighlightTimer->Cancel();
       
  1467 
       
  1468     TInt index = GetSelected(iStart);
       
  1469     if(index != KErrNotFound && iPointerDown )
       
  1470         {
       
  1471         iSelectionToFocusedItem = index == iSelectedIndex;            
       
  1472         iSelectedIndex = index;
       
  1473         iFocusedIndex = index;
       
  1474         if( !iSelectionToFocusedItem ) // Selection has changed
       
  1475             {
       
  1476             if( iSelectionObserver )
       
  1477                 iSelectionObserver->HandleSelectL(iSelectedIndex);
       
  1478 
       
  1479             FitSelectionToView();
       
  1480             SelectionChanged();
       
  1481             iDrawUtils->ResetMarquee();
       
  1482             }
       
  1483         DrawDeferred();
       
  1484         }
       
  1485     }
       
  1486 
       
  1487 // ---------------------------------------------------------------------------
       
  1488 // CHgScroller::SetSelectionMode()
       
  1489 // ---------------------------------------------------------------------------
       
  1490 //     
       
  1491 void CHgScroller::SetSelectionMode( TSelectionMode aMode )
       
  1492     {
       
  1493     iSelectionMode = aMode;
       
  1494     if( iSelectionMode == ESelectionPossible
       
  1495             || iSelectionMode == ENoSelection )
       
  1496         {
       
  1497         iCoeEnv->InputCapabilitiesChanged();
       
  1498         }
       
  1499     }
       
  1500 
       
  1501 // ---------------------------------------------------------------------------
       
  1502 // CHgScroller::SelectionMode()
       
  1503 // ---------------------------------------------------------------------------
       
  1504 //     
       
  1505 CHgScroller::TSelectionMode CHgScroller::SelectionMode() const
       
  1506     {
       
  1507     return iSelectionMode;
       
  1508     }
       
  1509 
       
  1510 // ---------------------------------------------------------------------------
       
  1511 // CHgScroller::KeyScrollingTimerCallback()
       
  1512 // ---------------------------------------------------------------------------
       
  1513 //     
       
  1514 TInt CHgScroller::KeyScrollingTimerCallback( TAny* aPtr )
       
  1515     {
       
  1516     CHgScroller* scroller = 
       
  1517         static_cast<CHgScroller*>( aPtr );
       
  1518 
       
  1519     TInt err = KErrNotFound;
       
  1520         
       
  1521     if ( scroller  )
       
  1522         {
       
  1523         scroller->DoKeyScrolling();
       
  1524         err = KErrNone;
       
  1525         }
       
  1526     
       
  1527     return err;
       
  1528     }
       
  1529 
       
  1530 // ---------------------------------------------------------------------------
       
  1531 // CHgScroller::DoKeyScrolling()
       
  1532 // ---------------------------------------------------------------------------
       
  1533 //     
       
  1534 void CHgScroller::DoKeyScrolling()
       
  1535     {
       
  1536     TKeyEvent keyevent;
       
  1537     
       
  1538     switch( iKeyScrollingState )
       
  1539         {
       
  1540         case EKeyScrollingUp:
       
  1541             {
       
  1542             keyevent.iCode = EKeyUpArrow;
       
  1543             HandleKeyEvent( keyevent );
       
  1544             break;
       
  1545             }
       
  1546         case EKeyScrollingDown:
       
  1547             {
       
  1548             keyevent.iCode = EKeyDownArrow;
       
  1549             HandleKeyEvent( keyevent );
       
  1550             break;
       
  1551             }
       
  1552         case EKeyScrollingLeft:
       
  1553             {
       
  1554             keyevent.iCode = EKeyLeftArrow;
       
  1555             HandleKeyEvent( keyevent );
       
  1556             break;
       
  1557             }
       
  1558         case EKeyScrollingRight:        
       
  1559             {
       
  1560             keyevent.iCode = EKeyRightArrow;
       
  1561             HandleKeyEvent( keyevent );
       
  1562             break;
       
  1563             }
       
  1564         case ENoKeyScrolling:
       
  1565         default:
       
  1566             StopKeyScrolling();
       
  1567             break;
       
  1568         }
       
  1569 
       
  1570     DrawNow();
       
  1571     }
       
  1572 
       
  1573 // ---------------------------------------------------------------------------
       
  1574 // CHgScroller::StopKeyScrolling()
       
  1575 // ---------------------------------------------------------------------------
       
  1576 //     
       
  1577 void CHgScroller::StopKeyScrolling()
       
  1578     {    
       
  1579     iKeyScrollingTimer->Cancel();
       
  1580     iKeyScrollingState = ENoKeyScrolling;
       
  1581     }
       
  1582 
       
  1583 // ---------------------------------------------------------------------------
       
  1584 // CHgScroller::FocusChanged()
       
  1585 // ---------------------------------------------------------------------------
       
  1586 //     
       
  1587 void CHgScroller::FocusChanged(TDrawNow aDrawNow)
       
  1588     {
       
  1589     if( iKeyUtils )
       
  1590         {
       
  1591         if( !(iFlags & EHgScrollerKeyMarkingDisabled) )
       
  1592             {
       
  1593             if(IsFocused())
       
  1594                 {
       
  1595                 iKeyUtils->HandleGainingFocus();
       
  1596                 }
       
  1597             else
       
  1598                 {
       
  1599                 iKeyUtils->HandleLosingFocus();
       
  1600                 }
       
  1601             }
       
  1602         else
       
  1603             {
       
  1604             iKeyUtils->HandleLosingFocus();
       
  1605             }
       
  1606         }
       
  1607 
       
  1608     CCoeControl::FocusChanged( aDrawNow );
       
  1609     }
       
  1610 
       
  1611 // ---------------------------------------------------------------------------
       
  1612 // CHgScroller::HandleResourceChange()
       
  1613 // ---------------------------------------------------------------------------
       
  1614 //     
       
  1615 void CHgScroller::HandleResourceChange( TInt aType )
       
  1616     {
       
  1617     TRAP_IGNORE(
       
  1618             // When skin changes the indicator icons must be reloaded.
       
  1619         if ( aType == KAknsMessageSkinChange )
       
  1620             {
       
  1621             delete iIndicatorManager; iIndicatorManager = NULL;
       
  1622             iIndicatorManager = CHgIndicatorManager::NewL();
       
  1623             InitGraphicsL();
       
  1624             }
       
  1625         )
       
  1626     }
       
  1627 
       
  1628 // ---------------------------------------------------------------------------
       
  1629 // CHgScroller::HandleLongTapEventL()
       
  1630 // ---------------------------------------------------------------------------
       
  1631 //     
       
  1632 void CHgScroller::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/,
       
  1633                         const TPoint& aPenEventScreenLocation)
       
  1634     {
       
  1635     if( iActionMenu )
       
  1636         {
       
  1637         iPointerDown = EFalse;
       
  1638         iActionMenu->ShowMenuL(aPenEventScreenLocation);
       
  1639         }
       
  1640     }
       
  1641 
       
  1642 // ---------------------------------------------------------------------------
       
  1643 // CHgScroller::CollectionState()
       
  1644 // ---------------------------------------------------------------------------
       
  1645 //     
       
  1646 TUint CHgScroller::CollectionState() const
       
  1647     {
       
  1648     TUint ret = 0;
       
  1649     
       
  1650     if(IsFocused()) ret |= MAknCollection::EStateCollectionVisible;
       
  1651     
       
  1652     if(HasHighlight()) ret |= MAknCollection::EStateHighlightVisible; 
       
  1653     
       
  1654     if( iFlags & EHgScrollerSelectionMode ) ret |= MAknCollection::EStateMultipleSelection;
       
  1655     
       
  1656     return ret; 
       
  1657     }
       
  1658 
       
  1659 // ---------------------------------------------------------------------------
       
  1660 // CHgScroller::CollectionState()
       
  1661 // ---------------------------------------------------------------------------
       
  1662 //     
       
  1663 void CHgScroller::ItemActionMenuClosed()
       
  1664     {
       
  1665     DrawDeferred();
       
  1666     }
       
  1667 
       
  1668 // ---------------------------------------------------------------------------
       
  1669 // CHgScroller::CollectionState()
       
  1670 // ---------------------------------------------------------------------------
       
  1671 //     
       
  1672 TInt CHgScroller::CollectionExtension( TUint /*aExtensionId*/, TAny*& /*a0*/, TAny* /*a1*/ )
       
  1673     {
       
  1674     return KErrNone;
       
  1675     }
       
  1676 
       
  1677 // ---------------------------------------------------------------------------
       
  1678 // CHgScroller::HasHighlight()
       
  1679 // ---------------------------------------------------------------------------
       
  1680 //     
       
  1681 TBool CHgScroller::HasHighlight() const
       
  1682     {
       
  1683     return (iActionMenu == NULL) || iShowHighlight || (iFlags & EHgScrollerForceDoubleClick);
       
  1684     }
       
  1685 
       
  1686 // End of File