filemanager/App/src/CFileManagerContainerBase.cpp
changeset 0 6a9f87576119
child 10 875fd7f60fdf
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Base class for all file manager containers
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknlists.h>
       
    22 #include <eikclbd.h>
       
    23 #include <StringLoader.h>
       
    24 #include <FileManagerUID.h>
       
    25 #include "CFileManagerContainerBase.h"
       
    26 #include "FileManager.hrh"
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CFileManagerContainerBase::CFileManagerContainerBase
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CFileManagerContainerBase::CFileManagerContainerBase()
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CFileManagerContainerBase::ConstructL
       
    43 // 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CFileManagerContainerBase::ConstructL(
       
    47         const TRect& aRect,
       
    48         const TInt aFocusedIndex )
       
    49     {
       
    50     CreateWindowL();
       
    51     iListBox = CreateListBoxL();
       
    52     if ( !iListBox )
       
    53         {
       
    54         User::Leave( KErrGeneral );
       
    55         }
       
    56     SetListEmptyL();
       
    57     iListBox->CreateScrollBarFrameL( ETrue );
       
    58     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
    59         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
    60     iListBox->SetObserver( this );
       
    61     iListBox->SetListBoxObserver( this );
       
    62     SetIndex( aFocusedIndex );
       
    63     iListBox->SetFocus( ETrue );
       
    64     iListBox->AddSelectionObserverL( this );
       
    65     SetRect( aRect );
       
    66     ActivateL();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CFileManagerContainerBase::~CFileManagerContainerBase
       
    71 //
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CFileManagerContainerBase::~CFileManagerContainerBase()
       
    75     {
       
    76     delete iListBox;
       
    77     delete iEmptyText;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CFileManagerContainerBase::SizeChanged
       
    82 // 
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CFileManagerContainerBase::SizeChanged()
       
    86     {
       
    87     if ( iListBox )
       
    88         {
       
    89         iListBox->SetRect( Rect() );
       
    90         }
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CFileManagerContainerBase::CountComponentControls
       
    95 // 
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CFileManagerContainerBase::CountComponentControls() const
       
    99     {
       
   100     return iListBox ? 1 : 0;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CFileManagerContainerBase::ComponentControl
       
   105 // 
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CCoeControl* CFileManagerContainerBase::ComponentControl(
       
   109         TInt /* aIndex */ ) const
       
   110     {
       
   111     return iListBox;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CFileManagerContainerBase::OfferKeyEventL
       
   116 // 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TKeyResponse CFileManagerContainerBase::OfferKeyEventL(
       
   120         const TKeyEvent& aKeyEvent, TEventCode aType )
       
   121     {
       
   122     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CFileManagerContainerBase::ListBox
       
   127 // 
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CEikListBox& CFileManagerContainerBase::ListBox()
       
   131     {
       
   132     return *iListBox;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CFileManagerContainerBase::RefreshListL
       
   137 // 
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CFileManagerContainerBase::RefreshListL( TInt aFocusedIndex )
       
   141     {
       
   142     if ( !iListBox )
       
   143         {
       
   144         return;
       
   145         }
       
   146 
       
   147     TBool isEmpty( ETrue );
       
   148     if ( iArray )
       
   149         {
       
   150         if ( iArray->MdcaCount() )
       
   151             {
       
   152             isEmpty = EFalse;
       
   153             iListBox->Model()->SetItemTextArray( iArray );
       
   154             // Remove ownership from listbox.
       
   155             iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   156             }
       
   157         }
       
   158     if ( isEmpty )
       
   159         {
       
   160         SetEmptyArrayL();
       
   161         }
       
   162 
       
   163     iListBox->Reset();
       
   164     SetIndex( aFocusedIndex );
       
   165     iListBox->UpdateScrollBarsL();
       
   166     iListBox->SetFocus( ETrue );
       
   167 
       
   168     if ( iEmptyText )
       
   169         {
       
   170         iListBox->View()->SetListEmptyTextL( *iEmptyText );
       
   171         }
       
   172     else
       
   173         {
       
   174         iListBox->View()->SetListEmptyTextL( KNullDesC );
       
   175         }
       
   176     iListBox->DrawDeferred();
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CFileManagerContainerBase::SetListEmptyL
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CFileManagerContainerBase::SetListEmptyL()
       
   185     {
       
   186     if ( !iListBox )
       
   187         {
       
   188         return;
       
   189         }
       
   190     SetEmptyArrayL();
       
   191     iListBox->View()->SetListEmptyTextL( KNullDesC );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CFileManagerContainerBase::SetIndex
       
   196 // 
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CFileManagerContainerBase::SetIndex( TInt aFocusedIndex )
       
   200     {
       
   201     if ( !iListBox )
       
   202         {
       
   203         return;
       
   204         }
       
   205     // Check that given index is valid
       
   206     if ( aFocusedIndex >= 0 && 
       
   207          aFocusedIndex < iListBox->Model()->NumberOfItems() )
       
   208         {
       
   209         iListBox->SetCurrentItemIndex( aFocusedIndex );
       
   210         }
       
   211     else
       
   212         {
       
   213         // if list is empty or value is negative then set focus to 0
       
   214         if ( !iListBox->Model()->NumberOfItems() || aFocusedIndex < 0 )
       
   215             {
       
   216             iListBox->SetCurrentItemIndex( 0 );
       
   217             }
       
   218         else 
       
   219             {
       
   220             // Something has been deleted in the end of the list
       
   221             // set focus to last one so the focus doesn't jump around
       
   222             iListBox->SetCurrentItemIndex(
       
   223                 iListBox->Model()->NumberOfItems() - 1 );
       
   224             }
       
   225         }
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CFileManagerContainerBase::SetTextArray
       
   230 // 
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CFileManagerContainerBase::SetTextArray( MDesCArray* aArray )
       
   234     {
       
   235     iArray = aArray;
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CFileManagerContainerBase::SetEmptyTextL
       
   240 // 
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CFileManagerContainerBase::SetEmptyTextL( TInt aTextId )
       
   244     {
       
   245     delete iEmptyText;
       
   246     iEmptyText = NULL;
       
   247 
       
   248     if ( aTextId )
       
   249         {
       
   250         iEmptyText = StringLoader::LoadL( aTextId );
       
   251         }
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CFileManagerContainerBase::SetHelpContext
       
   256 // 
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CFileManagerContainerBase::SetHelpContext(
       
   260         const TDesC& aHelpContext )
       
   261     {
       
   262     iHelpContext = aHelpContext;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CFileManagerContainerBase::HandleListBoxEventL
       
   267 //
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CFileManagerContainerBase::HandleListBoxEventL(
       
   271         CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   272     {
       
   273     switch ( aEventType )
       
   274         {
       
   275         case EEventItemSingleClicked: // FALLTHROUGH
       
   276         case EEventEnterKeyPressed:
       
   277             {
       
   278             static_cast< CAknAppUi* >( ControlEnv()->AppUi() )->
       
   279                 ProcessCommandL( EFileManagerSelectionKey );
       
   280             break;
       
   281             }
       
   282         default:
       
   283             {
       
   284             break;
       
   285             }
       
   286         }
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CFileManagerContainerBase::HandleControlEventL
       
   291 //
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CFileManagerContainerBase::HandleControlEventL(
       
   295         CCoeControl* /* aControl*/, TCoeEvent /*aEventType*/ )
       
   296     {
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CFileManagerContainerBase::FocusChanged
       
   301 // 
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CFileManagerContainerBase::FocusChanged( TDrawNow aDrawNow )
       
   305     {
       
   306     CCoeControl::FocusChanged( aDrawNow );
       
   307 
       
   308     if ( iListBox )
       
   309         {
       
   310         iListBox->SetFocus( IsFocused(), aDrawNow );
       
   311         }
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CFileManagerContainerBase::GetHelpContext
       
   316 // 
       
   317 // -----------------------------------------------------------------------------
       
   318 // 
       
   319 void CFileManagerContainerBase::GetHelpContext(
       
   320         TCoeHelpContext& aContext ) const
       
   321 	{
       
   322     if ( iHelpContext.Length() )
       
   323         {
       
   324         aContext.iMajor = TUid::Uid( KFileManagerUID3 );
       
   325 	    aContext.iContext = iHelpContext;
       
   326 	    }
       
   327     else
       
   328         {
       
   329         CCoeControl::GetHelpContext( aContext );
       
   330         }
       
   331 	}
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CFileManagerContainerBase::ListBoxExists
       
   335 // 
       
   336 // -----------------------------------------------------------------------------
       
   337 // 
       
   338 TBool CFileManagerContainerBase::ListBoxExists() const
       
   339     {
       
   340     return iListBox ? ETrue : EFalse;
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CFileManagerContainerBase::SetEmptyArrayL
       
   345 // 
       
   346 // -----------------------------------------------------------------------------
       
   347 // 
       
   348 void CFileManagerContainerBase::SetEmptyArrayL()
       
   349     {
       
   350     CDesCArray* empty = new( ELeave ) CDesCArrayFlat( 1 );
       
   351     iListBox->Model()->SetItemTextArray( empty );
       
   352     // Transfer ownership to listbox.
       
   353     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CFileManagerContainerBase::ProcessCommandL
       
   358 // 
       
   359 // -----------------------------------------------------------------------------
       
   360 // 
       
   361 void CFileManagerContainerBase::ProcessCommandL( TInt aCommandId )
       
   362     {
       
   363     switch ( aCommandId )
       
   364         {
       
   365         case EAknSoftkeyShiftMSK:
       
   366             {
       
   367             static_cast< CAknAppUi* >( ControlEnv()->AppUi() )->
       
   368                 ProcessCommandL( EFileManagerToggleMark );
       
   369             break;
       
   370             }
       
   371             
       
   372         default:
       
   373             {
       
   374             break;
       
   375             }
       
   376         }
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CFileManagerContainerBase::SelectionModeChanged
       
   381 // 
       
   382 // -----------------------------------------------------------------------------
       
   383 // 
       
   384 void CFileManagerContainerBase::SelectionModeChanged(
       
   385         CEikListBox* aListBox, TBool aSelectionModeEnabled )
       
   386     {
       
   387     if ( iListBox == aListBox &&
       
   388         iSelectionModeEnabled != aSelectionModeEnabled )
       
   389         {
       
   390         iSelectionModeEnabled = aSelectionModeEnabled;
       
   391         if ( !iSelectionModeEnabled )
       
   392             {
       
   393             // Update cba after selection mode gets done
       
   394             UpdateCba();
       
   395             }
       
   396         }
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CFileManagerContainerBase::SelectionModeEnabled
       
   401 // 
       
   402 // -----------------------------------------------------------------------------
       
   403 // 
       
   404 TBool CFileManagerContainerBase::SelectionModeEnabled() const
       
   405     {
       
   406     return iSelectionModeEnabled;
       
   407     }
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CFileManagerContainerBase::UpdateCba
       
   411 // 
       
   412 // -----------------------------------------------------------------------------
       
   413 // 
       
   414 void CFileManagerContainerBase::UpdateCba()
       
   415     {
       
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CFileManagerContainerBase::ListBoxCurrentItemIndex
       
   420 // 
       
   421 // -----------------------------------------------------------------------------
       
   422 // 
       
   423 TInt CFileManagerContainerBase::ListBoxCurrentItemIndex()
       
   424     {
       
   425     return iListBox->CurrentItemIndex();
       
   426     }
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CFileManagerContainerBase::ListBoxNumberOfItems
       
   430 // 
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 TInt CFileManagerContainerBase::ListBoxNumberOfItems()
       
   434     {
       
   435     return iListBox->Model()->NumberOfItems();
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CFileManagerContainerBase::ListBoxSelectionIndexes
       
   440 // 
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 const CArrayFix< TInt >* CFileManagerContainerBase::ListBoxSelectionIndexes()
       
   444     {
       
   445     return iListBox->SelectionIndexes();
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CFileManagerContainerBase::ListBoxSelectionIndexesCount
       
   450 // 
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 TInt CFileManagerContainerBase::ListBoxSelectionIndexesCount()
       
   454     {
       
   455     return iListBox->SelectionIndexes()->Count();
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CFileManagerContainerBase::ListBoxToggleItemL
       
   460 // 
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void CFileManagerContainerBase::ListBoxToggleItemL( TInt aIndex )
       
   464     {
       
   465     iListBox->View()->ToggleItemL( aIndex );
       
   466     }
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CFileManagerContainerBase::ListBoxIsItemSelected
       
   470 // 
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 TBool CFileManagerContainerBase::ListBoxIsItemSelected( TInt aIndex )
       
   474     {
       
   475     return iListBox->View()->ItemIsSelected( aIndex );
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CFileManagerContainerBase::ListBoxSelectAllL
       
   480 // 
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CFileManagerContainerBase::ListBoxSelectAllL()
       
   484     {
       
   485     TInt count( ListBoxNumberOfItems() );
       
   486     if ( count > 0 )
       
   487         {
       
   488         CArrayFixFlat<TInt>* array =
       
   489             new( ELeave ) CArrayFixFlat< TInt >( count );
       
   490         CleanupStack::PushL( array );
       
   491         for ( TInt i( 0 ); i < count; ++i )
       
   492             {
       
   493             array->AppendL( i );
       
   494             }
       
   495         iListBox->View()->SetSelectionIndexesL( array );
       
   496         CleanupStack::PopAndDestroy( array );
       
   497         }
       
   498     }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CFileManagerContainerBase::ListBoxClearSelection
       
   502 // 
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CFileManagerContainerBase::ListBoxClearSelection()
       
   506     {
       
   507     iListBox->View()->ClearSelection();
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CFileManagerContainerBase::ListBoxSetTextL
       
   512 // 
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CFileManagerContainerBase::ListBoxSetTextL( const TDesC& aText )
       
   516     {
       
   517     iListBox->View()->SetListEmptyTextL( aText );
       
   518     iListBox->DrawDeferred();
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CFileManagerContainerBase::IsSearchFieldVisible
       
   523 // 
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 TBool CFileManagerContainerBase::IsSearchFieldVisible() const
       
   527     {
       
   528     return EFalse;
       
   529     }
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CFileManagerContainerBase::EnableSearchFieldL
       
   533 // 
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CFileManagerContainerBase::EnableSearchFieldL(
       
   537         TBool /*aEnable*/, const TDesC& /*aSearchText^*/ )
       
   538     {
       
   539     }
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CFileManagerContainerBase::SetCurrentItemIndexAfterSearch
       
   543 // 
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 void CFileManagerContainerBase::SetCurrentItemIndexAfterSearch(
       
   547         TInt /*aIndex*/ )
       
   548     {
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CFileManagerContainerBase::ListBoxSelectItemL
       
   553 // 
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 void CFileManagerContainerBase::ListBoxSelectItemL( TInt aIndex )
       
   557     {
       
   558     iListBox->View()->SelectItemL( aIndex );
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CFileManagerContainerBase::ListBoxDeselectItem
       
   563 // 
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 void CFileManagerContainerBase::ListBoxDeselectItem( TInt aIndex )
       
   567     {
       
   568     iListBox->View()->DeselectItem( aIndex );
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CFileManagerContainerBase::ListBoxSetSelectionIndexesL
       
   573 // 
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CFileManagerContainerBase::ListBoxSetSelectionIndexesL(const CArrayFixFlat<TInt>* 
       
   577                                                                 aSelectionIndexes)
       
   578 	{
       
   579 	iListBox->View()->SetSelectionIndexesL( aSelectionIndexes );
       
   580 	}
       
   581 
       
   582 //  End of File