filemanager/App/src/CFileManagerFileListContainer.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  File list container in file manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <filemanager.rsg>
       
    22 #include <aknlists.h>
       
    23 #include <barsread.h>
       
    24 #include <eikclbd.h>
       
    25 #include <gulicon.h>
       
    26 #include <aknsfld.h>
       
    27 #include <CFileManagerEngine.h>
       
    28 #include <CFileManagerFeatureManager.h>
       
    29 #include <FileManagerPrivateCRKeys.h>
       
    30 #include "CFileManagerFileListContainer.h"
       
    31 #include "CFileManagerDocument.h"
       
    32 #include "CFileManagerAppUi.h"
       
    33 #include "FileManager.hrh"
       
    34 #include "CFileManagerIconArray.h"
       
    35 #include <aknview.h>
       
    36 #include <eikmenub.h>
       
    37 #include <eikmenup.h> // CEikMenuPane
       
    38 // CONSTANTS
       
    39 const TInt KTouchGestureThreshold = 30; // Threshold could be stored in CenRep
       
    40 
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CFileManagerFileListContainer::CFileManagerFileListContainer
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CFileManagerFileListContainer::CFileManagerFileListContainer(
       
    51         const TListType aType ) :
       
    52     iType( aType )
       
    53     {
       
    54     iAppUi = static_cast< CFileManagerAppUi* >( ControlEnv()->AppUi() );
       
    55     iDocument = static_cast< CFileManagerDocument* >( iAppUi->Document() );
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CFileManagerFileListContainer::NewL
       
    60 // 
       
    61 // -----------------------------------------------------------------------------
       
    62 // 
       
    63 CFileManagerFileListContainer* CFileManagerFileListContainer::NewL(
       
    64         const TRect& aRect,
       
    65         const TInt aFocusedIndex,
       
    66         const TListType aType,
       
    67         const TInt aEmptyText,
       
    68         const TDesC& aHelpContext )
       
    69     {
       
    70     CFileManagerFileListContainer* self =
       
    71         new ( ELeave ) CFileManagerFileListContainer( aType );
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL(
       
    74         aRect,
       
    75         aFocusedIndex,
       
    76         aEmptyText,
       
    77         aHelpContext );
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CFileManagerFileListContainer::ConstructL
       
    84 // 
       
    85 // -----------------------------------------------------------------------------
       
    86 // 
       
    87 void CFileManagerFileListContainer::ConstructL(
       
    88         const TRect& aRect,
       
    89         const TInt aFocusedIndex,
       
    90         const TInt aEmptyText,
       
    91         const TDesC& aHelpContext )
       
    92     {
       
    93     CFileManagerFeatureManager& featureManager(
       
    94         iDocument->Engine().FeatureManager() );
       
    95     iRightLeftNaviSupported = featureManager.IsFeatureSupported(
       
    96         EFileManagerFeatureRightLeftNaviSupported );
       
    97     iOwnFastScrollDisabled = featureManager.IsFeatureSupported(
       
    98         EFileManagerFeatureOwnFastScrollDisabled );
       
    99     CFileManagerContainerBase::ConstructL( aRect, aFocusedIndex );
       
   100     SetEmptyTextL( aEmptyText );
       
   101     SetHelpContext( aHelpContext );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CFileManagerFileListContainer::CreateListBoxL
       
   106 // 
       
   107 // -----------------------------------------------------------------------------
       
   108 // 
       
   109 CEikTextListBox* CFileManagerFileListContainer::CreateListBoxL()
       
   110     {
       
   111     switch ( iType )
       
   112         {
       
   113         case EListMain:
       
   114             {
       
   115             CAknDoubleLargeStyleListBox* listBox =
       
   116                 new( ELeave ) CAknDoubleLargeStyleListBox();
       
   117             CleanupStack::PushL( listBox );
       
   118             listBox->SetContainerWindowL( *this );
       
   119             listBox->ConstructL( this, EAknGenericListBoxFlags |
       
   120                 EAknListBoxMenuList | EAknListBoxLoopScrolling );
       
   121             CFormattedCellListBoxData* column = listBox->ItemDrawer()->ColumnData();
       
   122             column->SetIconArray( iDocument->IconArray() );
       
   123             column->SetSkinEnabledL( ETrue );
       
   124             column->EnableMarqueeL( ETrue );
       
   125             CleanupStack::Pop( listBox );
       
   126             return listBox;
       
   127             }
       
   128         case EListMemoryStore: // FALLTHROUGH
       
   129         case EListFolder:
       
   130             {
       
   131             CAknColumnListBox* listBox = new( ELeave )
       
   132                         CFileManagerFileListContainer::CListBox( *this );
       
   133             CleanupStack::PushL( listBox );
       
   134             listBox->SetContainerWindowL( *this );
       
   135             listBox->ConstructL( this, EAknGenericListBoxFlags |
       
   136                 EAknListBoxMenuList | EAknListBoxLoopScrolling |
       
   137                 EAknListBoxStylusMarkableList );
       
   138             CColumnListBoxData* column = listBox->ItemDrawer()->ColumnData();
       
   139             column->SetIconArray( iDocument->IconArray() );
       
   140             column->SetSkinEnabledL( ETrue );
       
   141             // Disable lists MSK observer because the container will be used
       
   142             // as observer
       
   143             listBox->EnableMSKObserver( EFalse );
       
   144             column->EnableMarqueeL( ETrue );
       
   145             // Create search field popup
       
   146             iSearchField = CAknSearchField::NewL(
       
   147                 *this, CAknSearchField::EPopup, NULL, KMaxFileName );
       
   148             iSearchField->MakeVisible( EFalse );
       
   149             iSearchField->SetSkinEnabledL( ETrue );
       
   150             CCoeEnv::Static()->AddFocusObserverL( *this );
       
   151             CleanupStack::Pop( listBox );
       
   152             return listBox;
       
   153             }
       
   154         default:
       
   155             {
       
   156             User::Leave( KErrGeneral );
       
   157             break;
       
   158             }
       
   159         }
       
   160 
       
   161     return NULL;
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CFileManagerFileListContainer::~CFileManagerFileListContainer
       
   166 //
       
   167 // -----------------------------------------------------------------------------
       
   168 // 
       
   169 CFileManagerFileListContainer::~CFileManagerFileListContainer()
       
   170     {
       
   171     CCoeEnv::Static()->RemoveFocusObserver( *this );
       
   172 
       
   173     if ( ListBoxExists() )
       
   174         {
       
   175         // before we destroy listbox in base class,
       
   176         // we have to set icon array to NULL
       
   177         // because we want to let document class own the icon array
       
   178         if ( iType == EListMain )
       
   179             {
       
   180             CAknDoubleLargeStyleListBox& listBox =
       
   181                 static_cast< CAknDoubleLargeStyleListBox& >( ListBox() );
       
   182             listBox.ItemDrawer()->ColumnData()->SetIconArray( NULL );
       
   183             }
       
   184         else
       
   185             {
       
   186             CAknColumnListBox& listBox =
       
   187                 static_cast< CAknColumnListBox& >( ListBox() );
       
   188             listBox.ItemDrawer()->ColumnData()->SetIconArray( NULL );
       
   189             }
       
   190         }
       
   191     delete iSearchField;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CFileManagerFileListContainer::OfferKeyEventL
       
   196 // 
       
   197 // -----------------------------------------------------------------------------
       
   198 // 
       
   199 TKeyResponse CFileManagerFileListContainer::OfferKeyEventL( 
       
   200         const TKeyEvent& aKeyEvent, TEventCode aType )
       
   201     {
       
   202     TKeyResponse response = OfferSearchKeyEventL( aKeyEvent, aType );
       
   203     if ( response == EKeyWasConsumed )
       
   204        {
       
   205        return response;
       
   206        }   
       
   207     
       
   208     TVwsViewId enabledViewId = TVwsViewId( KNullUid, KNullUid );
       
   209     iAppUi->GetActiveViewId( enabledViewId );
       
   210              
       
   211     TUid enabledViewUid = enabledViewId.iViewUid;
       
   212     CAknView* enabledView = iAppUi->View( enabledViewUid );
       
   213     CEikMenuBar* menuBar = NULL;
       
   214     
       
   215     if ( iAppUi->IsFileManagerView( enabledViewUid ) )
       
   216         {
       
   217         menuBar = enabledView->MenuBar();
       
   218         }
       
   219     switch( aKeyEvent.iCode )
       
   220         {
       
   221         case EKeyEnter: // FALLTHROUH
       
   222         case EKeyOK:
       
   223             {
       
   224             if ( ( menuBar != NULL ) && menuBar->ItemSpecificCommandsEnabled() )
       
   225                 {
       
   226                 iAppUi->ProcessCommandL( EFileManagerSelectionKey );
       
   227                 response = EKeyWasConsumed;
       
   228                 }
       
   229             break;
       
   230             }
       
   231         case EKeyDelete:    // FALLTHROUGH
       
   232         case EKeyBackspace:
       
   233             {
       
   234             if ( ( menuBar != NULL ) && menuBar->ItemSpecificCommandsEnabled() )
       
   235                 {
       
   236                 iAppUi->ProcessCommandL( EFileManagerDelete );
       
   237                 response = EKeyWasConsumed;
       
   238                 }
       
   239             break;
       
   240             }
       
   241         case EKeyLeftArrow: // FALLTHROUGH
       
   242         case EKeyRightArrow:
       
   243             {
       
   244             if ( iRightLeftNaviSupported )
       
   245                 {
       
   246                 // Depth navigation using arrows
       
   247                 TInt commandId( EAknSoftkeyBack );
       
   248                 if ( aKeyEvent.iCode == EKeyRightArrow )
       
   249                     {
       
   250                     commandId = EFileManagerOpen;
       
   251                     }
       
   252                 iAppUi->ProcessCommandL( commandId );
       
   253                 response = EKeyWasConsumed;
       
   254                 }
       
   255             break;
       
   256             }
       
   257         case EKeyYes:
       
   258             {
       
   259             if ( AknLayoutUtils::PenEnabled() )
       
   260                 {
       
   261                 // Touch uses just the default functionality
       
   262                 response = ListBox().OfferKeyEventL( aKeyEvent, aType );
       
   263                 }
       
   264             else
       
   265                 {
       
   266                 iAppUi->ProcessCommandL( EFileManagerSend );
       
   267                 response = EKeyWasConsumed;
       
   268                 }
       
   269             break;
       
   270             }
       
   271         default:
       
   272             {
       
   273             response = ListBox().OfferKeyEventL( aKeyEvent, aType );
       
   274             break;
       
   275             }
       
   276         }
       
   277     return response;
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CFileManagerFileListContainer::SetListEmptyL
       
   282 // 
       
   283 // -----------------------------------------------------------------------------
       
   284 // 
       
   285 void CFileManagerFileListContainer::SetListEmptyL()
       
   286     {
       
   287     if ( IsSearchFieldVisible() )
       
   288         {
       
   289         iSearchField->GetSearchText( iSearchText );
       
   290         iSearchFieldAfterRefresh = ETrue;
       
   291         EnableSearchFieldL( EFalse );
       
   292         }
       
   293     CFileManagerContainerBase::SetListEmptyL();
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CFileManagerFileListContainer::RefreshListL
       
   298 // 
       
   299 // -----------------------------------------------------------------------------
       
   300 // 
       
   301 void CFileManagerFileListContainer::RefreshListL( TInt aFocusedIndex )
       
   302     {
       
   303     iDocument->ClearStringCache();
       
   304     SetTextArray( iDocument->FileList() );
       
   305     CFileManagerContainerBase::RefreshListL( aFocusedIndex );
       
   306     if ( iSearchFieldAfterRefresh )
       
   307         {
       
   308         iSearchFieldAfterRefresh = EFalse;
       
   309         EnableSearchFieldL( ETrue, iSearchText );
       
   310         }
       
   311     // Inform user about OOM, suppress other errors
       
   312     TInt err( iDocument->LastError() );
       
   313     if ( err == KErrNoMemory )
       
   314         {
       
   315         ControlEnv()->HandleError( KErrNoMemory );
       
   316         }
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CFileManagerFileListContainer::HandleControlEventL
       
   321 // From MCoeControlObserver, called by current listbox
       
   322 // -----------------------------------------------------------------------------
       
   323 // 
       
   324 void CFileManagerFileListContainer::HandleControlEventL(
       
   325         CCoeControl* /* aControl*/, TCoeEvent aEventType )
       
   326     {
       
   327     if ( aEventType == EEventStateChanged )
       
   328         {
       
   329         iAppUi->ProcessCommandL( EFileManagerCheckMark ); // Inform change
       
   330         }
       
   331     }
       
   332 
       
   333 //-----------------------------------------------------------------------------
       
   334 // CFileManagerFileListContainer::CItemDrawer::CItemDrawer
       
   335 //-----------------------------------------------------------------------------
       
   336 //
       
   337 CFileManagerFileListContainer::CItemDrawer::CItemDrawer(
       
   338     CTextListBoxModel* aTextListBoxModel,
       
   339     const CFont* aFont,
       
   340     CColumnListBoxData* aColumnData,
       
   341     CFileManagerFileListContainer& aContainer ) :
       
   342         CColumnListBoxItemDrawer(
       
   343             aTextListBoxModel, aFont, aColumnData ),
       
   344         iContainer( aContainer )
       
   345     {
       
   346     }
       
   347 
       
   348 //-----------------------------------------------------------------------------
       
   349 // CFileManagerFileListContainer::CItemDrawer::Properties
       
   350 //-----------------------------------------------------------------------------
       
   351 //
       
   352 TListItemProperties CFileManagerFileListContainer::CItemDrawer::Properties( 
       
   353         TInt aItemIndex ) const
       
   354     {
       
   355     aItemIndex = iContainer.SearchFieldToListIndex( aItemIndex );
       
   356     TListItemProperties prop(
       
   357         CColumnListBoxItemDrawer::Properties( aItemIndex ) );
       
   358     // Do not allow folder marking
       
   359     if ( iContainer.iDocument->Engine().IsFolder( aItemIndex ) )
       
   360         {
       
   361         prop.SetHiddenSelection( ETrue );
       
   362         }
       
   363     return prop;
       
   364     }
       
   365 
       
   366 //-----------------------------------------------------------------------------
       
   367 // CFileManagerFileListContainer::CListBox::CListBox
       
   368 //-----------------------------------------------------------------------------
       
   369 //
       
   370 CFileManagerFileListContainer::CListBox::CListBox(
       
   371         CFileManagerFileListContainer& aContainer ) :
       
   372     CAknSingleGraphicStyleListBox(),
       
   373     iContainer( aContainer )
       
   374     {
       
   375     }
       
   376 
       
   377 //-----------------------------------------------------------------------------
       
   378 // CFileManagerFileListContainer::CListBox::CreateItemDrawerL
       
   379 //-----------------------------------------------------------------------------
       
   380 //
       
   381 void CFileManagerFileListContainer::CListBox::CreateItemDrawerL()
       
   382     {
       
   383     CColumnListBoxData* data = CColumnListBoxData::NewL();
       
   384     CleanupStack::PushL( data );
       
   385     iItemDrawer = new ( ELeave ) CFileManagerFileListContainer::CItemDrawer(
       
   386         Model(),
       
   387         iEikonEnv->NormalFont(),
       
   388         data,
       
   389         iContainer );
       
   390     CleanupStack::Pop( data );
       
   391     }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CFileManagerFileListContainer::UpdateCba
       
   395 // 
       
   396 // -----------------------------------------------------------------------------
       
   397 // 
       
   398 void CFileManagerFileListContainer::UpdateCba()
       
   399     {
       
   400     iAppUi->NotifyCbaUpdate();
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CFileManagerFileListContainer::HandlePointerEventL
       
   405 // 
       
   406 // -----------------------------------------------------------------------------
       
   407 // 
       
   408 void CFileManagerFileListContainer::HandlePointerEventL(
       
   409         const TPointerEvent &aPointerEvent )
       
   410     {
       
   411     if ( !iRightLeftNaviSupported )
       
   412         {
       
   413         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   414         return;
       
   415         }
       
   416     if ( !AknLayoutUtils::PenEnabled() )
       
   417         {
       
   418         return;
       
   419         }
       
   420     TBool consumed( EFalse );
       
   421     switch ( aPointerEvent.iType )
       
   422         {
       
   423         case TPointerEvent::EButton1Down:
       
   424             {
       
   425             iDragStartPoint = aPointerEvent.iPosition;
       
   426             iDragging = EFalse;
       
   427             break;
       
   428             }
       
   429         case TPointerEvent::EDrag:
       
   430             {
       
   431             iDragging = ETrue;
       
   432             break;
       
   433             }
       
   434         case TPointerEvent::EButton1Up:
       
   435             {
       
   436             if ( iDragging )
       
   437                 {
       
   438                 iDragging = EFalse;
       
   439                 // Solve drag direction and convert touch gesture to key event
       
   440                 TInt xDelta( iDragStartPoint.iX - aPointerEvent.iPosition.iX );
       
   441                 TInt keyCode( EKeyNull );
       
   442                 if ( xDelta < -KTouchGestureThreshold )
       
   443                     {
       
   444                     keyCode = EKeyRightArrow;
       
   445                     }
       
   446                 else if ( xDelta > KTouchGestureThreshold )
       
   447                     {
       
   448                     keyCode = EKeyLeftArrow;
       
   449                     }
       
   450                 if ( keyCode != EKeyNull )
       
   451                     {
       
   452                     TKeyEvent keyEvent;
       
   453                     keyEvent.iCode = keyCode;
       
   454                     keyEvent.iScanCode = EStdKeyNull;
       
   455                     keyEvent.iModifiers = 0;
       
   456                     keyEvent.iRepeats = 1;
       
   457                     OfferKeyEventL( keyEvent, EEventKey );
       
   458                     consumed = ETrue;
       
   459                     }
       
   460                 }
       
   461             break;
       
   462             }
       
   463         default:
       
   464             {
       
   465             iDragging = EFalse;
       
   466             break;
       
   467             }
       
   468         }
       
   469     if ( !consumed )
       
   470         {
       
   471         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   472         }
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CFileManagerFileListContainer::SizeChanged
       
   477 // 
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CFileManagerFileListContainer::SizeChanged()
       
   481     {
       
   482     if ( iSearchField )
       
   483         {
       
   484         AknFind::HandlePopupFindSizeChanged( this, &ListBox(), iSearchField );
       
   485         }
       
   486     else
       
   487         {
       
   488         CFileManagerContainerBase::SizeChanged();
       
   489         }
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CFileManagerFileListContainer::CountComponentControls
       
   494 // 
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TInt CFileManagerFileListContainer::CountComponentControls() const
       
   498     {
       
   499     TInt ret( CFileManagerContainerBase::CountComponentControls() );
       
   500     if ( iSearchField )
       
   501         {
       
   502         ++ret;
       
   503         }
       
   504     return ret;
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CFileManagerFileListContainer::ComponentControl
       
   509 // 
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 CCoeControl* CFileManagerFileListContainer::ComponentControl( TInt aIndex ) const
       
   513     {
       
   514     if ( aIndex < CFileManagerContainerBase::CountComponentControls() )
       
   515         {
       
   516         return CFileManagerContainerBase::ComponentControl( aIndex );
       
   517         }
       
   518     if ( aIndex < CountComponentControls() )
       
   519         {
       
   520         return iSearchField;
       
   521         }
       
   522     return NULL;
       
   523     }    
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CFileManagerFileListContainer::ListBoxCurrentItemIndex
       
   527 // 
       
   528 // -----------------------------------------------------------------------------
       
   529 // 
       
   530 TInt CFileManagerFileListContainer::ListBoxCurrentItemIndex()
       
   531     {
       
   532     return SearchFieldToListIndex( ListBox().CurrentItemIndex() );
       
   533     }
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // CFileManagerFileListContainer::ListBoxNumberOfItems
       
   537 // 
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 TInt CFileManagerFileListContainer::ListBoxNumberOfItems()
       
   541     {
       
   542     if ( IsSearchFieldVisible() )
       
   543         {
       
   544         return static_cast< CAknFilteredTextListBoxModel* >(
       
   545             ListBox().Model() )->Filter()->FilteredNumberOfItems();
       
   546         }
       
   547     return CFileManagerContainerBase::ListBoxNumberOfItems();
       
   548     }
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CFileManagerFileListContainer::ListBoxSelectionIndexes
       
   552 // 
       
   553 // -----------------------------------------------------------------------------
       
   554 // 
       
   555 const CArrayFix< TInt >* CFileManagerFileListContainer::ListBoxSelectionIndexes()
       
   556     {
       
   557     if ( IsSearchFieldVisible() )
       
   558         {
       
   559         CAknListBoxFilterItems* filter =
       
   560             static_cast< CAknFilteredTextListBoxModel* >(
       
   561                 ListBox().Model() )->Filter();
       
   562 
       
   563         if ( filter )
       
   564             {
       
   565             TRAPD( err, filter->UpdateSelectionIndexesL() );
       
   566             if ( err == KErrNone )
       
   567                 {
       
   568                 return filter->SelectionIndexes();
       
   569                 }
       
   570             }
       
   571         return NULL;
       
   572         }
       
   573     return CFileManagerContainerBase::ListBoxSelectionIndexes();
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CFileManagerFileListContainer::ListBoxSelectionIndexesCount
       
   578 // 
       
   579 // -----------------------------------------------------------------------------
       
   580 // 
       
   581 TInt CFileManagerFileListContainer::ListBoxSelectionIndexesCount()
       
   582     {
       
   583     if ( IsSearchFieldVisible() )
       
   584         {
       
   585         CAknListBoxFilterItems* filter =
       
   586             static_cast< CAknFilteredTextListBoxModel* >(
       
   587                 ListBox().Model() )->Filter();
       
   588 
       
   589         if ( filter )
       
   590             {
       
   591             TRAPD( err, filter->UpdateSelectionIndexesL() );
       
   592             if ( err == KErrNone )
       
   593                 {
       
   594                 return filter->SelectionIndexes()->Count();
       
   595                 }
       
   596             }
       
   597         return 0;
       
   598         }
       
   599     return CFileManagerContainerBase::ListBoxSelectionIndexesCount();
       
   600     }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CFileManagerFileListContainer::ListBoxToggleItemL
       
   604 // 
       
   605 // -----------------------------------------------------------------------------
       
   606 // 
       
   607 void CFileManagerFileListContainer::ListBoxToggleItemL( TInt aIndex )
       
   608     {
       
   609     aIndex = ListToSearchFieldIndex( aIndex );
       
   610     CFileManagerContainerBase::ListBoxToggleItemL( aIndex );
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CFileManagerFileListContainer::ListBoxIsItemSelected
       
   615 // 
       
   616 // -----------------------------------------------------------------------------
       
   617 // 
       
   618 TBool CFileManagerFileListContainer::ListBoxIsItemSelected( TInt aIndex )
       
   619     {
       
   620     aIndex = ListToSearchFieldIndex( aIndex );
       
   621     return CFileManagerContainerBase::ListBoxIsItemSelected( aIndex );
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 // CFileManagerFileListContainer::SearchFieldToListIndex
       
   626 // 
       
   627 // -----------------------------------------------------------------------------
       
   628 // 
       
   629 TInt CFileManagerFileListContainer::SearchFieldToListIndex( TInt aIndex )
       
   630     {
       
   631     if ( IsSearchFieldVisible() && aIndex >= 0 )
       
   632         {
       
   633         aIndex = static_cast< CAknFilteredTextListBoxModel* >(
       
   634             ListBox().Model() )->Filter()->FilteredItemIndex( aIndex );
       
   635         }
       
   636     return aIndex;
       
   637     }
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // CFileManagerFileListContainer::ListToSearchFieldIndex
       
   641 // 
       
   642 // -----------------------------------------------------------------------------
       
   643 // 
       
   644 TInt CFileManagerFileListContainer::ListToSearchFieldIndex( TInt aIndex )
       
   645     {
       
   646     if ( IsSearchFieldVisible() && aIndex >= 0 )
       
   647         {
       
   648         aIndex = static_cast< CAknFilteredTextListBoxModel* >(
       
   649             ListBox().Model() )->Filter()->VisibleItemIndex( aIndex );
       
   650         }
       
   651     return aIndex;
       
   652     }
       
   653 
       
   654 // -----------------------------------------------------------------------------
       
   655 // CFileManagerFileListContainer::ListBoxSetTextL
       
   656 // 
       
   657 // -----------------------------------------------------------------------------
       
   658 // 
       
   659 void CFileManagerFileListContainer::ListBoxSetTextL( const TDesC& aText )
       
   660     {
       
   661     EnableSearchFieldL( EFalse );
       
   662     CFileManagerContainerBase::ListBoxSetTextL( aText );
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CFileManagerFileListContainer::ListBoxSetTextL
       
   667 // 
       
   668 // -----------------------------------------------------------------------------
       
   669 // 
       
   670 void CFileManagerFileListContainer::PageScrollL( TBool aUp )
       
   671     {
       
   672     CEikListBox& listBox( ListBox() );
       
   673     TInt numItems( listBox.Model()->NumberOfItems() );
       
   674 
       
   675     if ( numItems > 0 )
       
   676         {
       
   677         TInt lastIndex( numItems - 1 );
       
   678         if ( !aUp && listBox.View()->BottomItemIndex() == lastIndex )
       
   679             {
       
   680             listBox.SetCurrentItemIndex( lastIndex );
       
   681             }
       
   682         else
       
   683             {
       
   684             CListBoxView::TCursorMovement move( aUp ?
       
   685                 CListBoxView::ECursorPrevScreen :
       
   686                 CListBoxView::ECursorNextScreen );
       
   687             listBox.View()->MoveCursorL( move, CListBoxView::ENoSelection );
       
   688             listBox.SetCurrentItemIndex( listBox.CurrentItemIndex() );
       
   689             }
       
   690         DrawDeferred();
       
   691         }
       
   692     }
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // CFileManagerFileListContainer::IsSearchFieldVisible
       
   696 // 
       
   697 // -----------------------------------------------------------------------------
       
   698 // 
       
   699 TBool CFileManagerFileListContainer::IsSearchFieldVisible() const
       
   700     {
       
   701     return ( iSearchField && iSearchField->IsVisible() );
       
   702     }
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 // CFileManagerFileListContainer::EnableSearchFieldL
       
   706 // 
       
   707 // -----------------------------------------------------------------------------
       
   708 // 
       
   709 void CFileManagerFileListContainer::EnableSearchFieldL(
       
   710         TBool aEnable, const TDesC& aSearchText )
       
   711     {
       
   712     if ( !iSearchField )
       
   713         {
       
   714         return;
       
   715         }
       
   716 
       
   717     CEikListBox& listBox( ListBox() );
       
   718     CAknFilteredTextListBoxModel* filteredModel =
       
   719         static_cast< CAknFilteredTextListBoxModel* >( listBox.Model() );
       
   720 
       
   721     if ( aEnable )
       
   722         {
       
   723         if ( !iSearchField->IsVisible() && listBox.Model()->NumberOfItems() )
       
   724             {
       
   725             iIndexAfterSearch = listBox.CurrentItemIndex();
       
   726             iSearchField->SetSearchTextL( aSearchText );
       
   727             if ( !filteredModel->Filter() )
       
   728                 {
       
   729                 filteredModel->CreateFilterL( &listBox, iSearchField );
       
   730                 }
       
   731             filteredModel->Filter()->HandleItemArrayChangeL();
       
   732             iSearchField->MakeVisible( ETrue );
       
   733             iSearchField->SetFocus( ETrue );
       
   734             iSearchFieldEnabled = ETrue;
       
   735             }
       
   736         }
       
   737     else
       
   738         {
       
   739         iSearchFieldEnabled = EFalse;
       
   740         iSearchField->SetFocus( EFalse );
       
   741         iSearchField->MakeVisible( EFalse );
       
   742         iSearchField->ResetL();
       
   743         filteredModel->RemoveFilter();
       
   744         SetIndex( iIndexAfterSearch );
       
   745         }
       
   746 
       
   747     SizeChanged();
       
   748     UpdateCba();
       
   749     DrawDeferred();
       
   750     }
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CFileManagerFileListContainer::SetCurrentItemIndexAfterSearch
       
   754 // 
       
   755 // -----------------------------------------------------------------------------
       
   756 // 
       
   757 void CFileManagerFileListContainer::SetCurrentItemIndexAfterSearch(
       
   758         TInt aIndex )
       
   759     {
       
   760     iIndexAfterSearch = aIndex;
       
   761     }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 // CFileManagerFileListContainer::HandleChangeInFocus
       
   765 // 
       
   766 // -----------------------------------------------------------------------------
       
   767 // 
       
   768 void CFileManagerFileListContainer::HandleChangeInFocus()
       
   769     {
       
   770     // Update softkeys after search field has been canceled
       
   771     if ( ListBoxExists() &&
       
   772          IsFocused() &&
       
   773          iSearchFieldEnabled &&
       
   774          iSearchField &&
       
   775          !iSearchField->IsVisible() )
       
   776         {
       
   777         CAknFilteredTextListBoxModel* filteredModel =
       
   778             static_cast< CAknFilteredTextListBoxModel* >( ListBox().Model() );
       
   779         iSearchFieldEnabled = EFalse;
       
   780         TRAP_IGNORE( iSearchField->ResetL() );
       
   781         filteredModel->RemoveFilter();
       
   782         SetIndex( iIndexAfterSearch );
       
   783         UpdateCba();
       
   784         DrawDeferred();
       
   785         }
       
   786     }
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CFileManagerFileListContainer::HandleDestructionOfFocusedItem
       
   790 // 
       
   791 // -----------------------------------------------------------------------------
       
   792 // 
       
   793 void CFileManagerFileListContainer::HandleDestructionOfFocusedItem()
       
   794     {
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // CFileManagerFileListContainer::OfferSearchKeyEventL
       
   799 // 
       
   800 // -----------------------------------------------------------------------------
       
   801 // 
       
   802 TKeyResponse CFileManagerFileListContainer::OfferSearchKeyEventL(
       
   803         const TKeyEvent& aKeyEvent, TEventCode aType )
       
   804     {
       
   805     if ( !iSearchField || aKeyEvent.iScanCode == EStdKeyYes )
       
   806         {
       
   807         return EKeyWasNotConsumed;
       
   808         }
       
   809     // Open search field on alpha digit        
       
   810     TBool isVisible( iSearchField->IsVisible() );
       
   811     if ( !isVisible &&
       
   812          aType == EEventKeyDown &&
       
   813          aKeyEvent.iScanCode )
       
   814         {
       
   815         TChar ch( aKeyEvent.iScanCode );
       
   816         if ( ch.IsAlphaDigit() )
       
   817             {
       
   818             EnableSearchFieldL( ETrue );
       
   819             return EKeyWasConsumed;
       
   820             }
       
   821         }
       
   822     // Close search field on clear-button if it's empty
       
   823     else if ( isVisible && aKeyEvent.iCode == EKeyBackspace )
       
   824         {
       
   825         iSearchField->GetSearchText( iSearchText );
       
   826         if ( !iSearchText.Length() )
       
   827             {
       
   828             EnableSearchFieldL( EFalse );
       
   829             return EKeyWasConsumed; 
       
   830             }
       
   831         }
       
   832     if ( isVisible )
       
   833         {
       
   834         TKeyResponse response( iSearchField->OfferKeyEventL( aKeyEvent, aType ) );
       
   835         UpdateCba();
       
   836         if ( response == EKeyWasConsumed )
       
   837             {
       
   838             return response;
       
   839             }
       
   840         }
       
   841     if ( !iOwnFastScrollDisabled )
       
   842         {
       
   843         if ( aKeyEvent.iCode == EKeyUpArrow && aKeyEvent.iRepeats > 0 )
       
   844             {
       
   845             PageScrollL( ETrue );
       
   846             return EKeyWasConsumed; 
       
   847             }
       
   848         if ( aKeyEvent.iCode == EKeyDownArrow && aKeyEvent.iRepeats > 0 )
       
   849             {
       
   850             PageScrollL( EFalse );
       
   851             return EKeyWasConsumed; 
       
   852             }
       
   853         }
       
   854     return EKeyWasNotConsumed;
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // CFileManagerFileListContainer::ListBoxSelectItemL
       
   859 // 
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 void CFileManagerFileListContainer::ListBoxSelectItemL( TInt aIndex )
       
   863     {
       
   864     aIndex = ListToSearchFieldIndex( aIndex );
       
   865     CFileManagerContainerBase::ListBoxSelectItemL( aIndex );
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CFileManagerFileListContainer::ListBoxDeselectItem
       
   870 // 
       
   871 // -----------------------------------------------------------------------------
       
   872 //
       
   873 void CFileManagerFileListContainer::ListBoxDeselectItem( TInt aIndex )
       
   874     {
       
   875     aIndex = ListToSearchFieldIndex( aIndex );
       
   876     CFileManagerContainerBase::ListBoxDeselectItem( aIndex );
       
   877     }
       
   878 	
       
   879 // -----------------------------------------------------------------------------
       
   880 // CFileManagerFileListContainer::SearchFieldToListBoxIndex
       
   881 // 
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 TInt CFileManagerFileListContainer::SearchFieldToListBoxIndex( TInt aIndex )
       
   885     {
       
   886     if ( !iSearchField || !iSearchField->IsVisible() )
       
   887        {
       
   888        return 0;
       
   889        }
       
   890     return SearchFieldToListIndex( aIndex );
       
   891     }
       
   892 //  End of File