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