browserui/browser/FavouritesSrc/BrowserFavouritesListbox.cpp
changeset 0 84ad3b177aa3
child 1 57d5b8e231c4
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *      Implementation of CBrowserFavouritesListbox.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <aknkeys.h>
       
    24 #include <EIKCLBD.H>
       
    25 #include <gulicon.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <FavouritesDb.h>
       
    28 #include <BrowserNG.rsg>
       
    29 #include <ApListItemList.h>
       
    30 #include <FavouritesItem.h>
       
    31 #include <FavouritesItemList.h>
       
    32 #include <AknsConstants.h>
       
    33 
       
    34 #include "BrowserFavouritesListbox.h"
       
    35 #include "BrowserFavouritesListboxState.h"
       
    36 #include "BrowserFavouritesListboxModel.h"
       
    37 #include "BrowserFavouritesListboxView.h"
       
    38 #include "BrowserFavouritesModel.h"
       
    39 #include "CommsModel.h"
       
    40 #include "BrowserFavouritesListboxIconHandler.h"
       
    41 #include "BrowserFavouritesIconIndexArray.h"
       
    42 #include "BrowserUtil.h"
       
    43 #include "BrowserFavouritesListboxCursorObserver.h"
       
    44 #include "BrowserFavouritesListboxState.h"
       
    45 #include "BrowserFavouritesListboxItemDrawer.h"
       
    46 #include "ApiProvider.h"
       
    47 #include "BrowserAppUi.h"
       
    48 
       
    49 #include "BrowserFaviconHandler.h"
       
    50 #include <AknLayout2ScalableDef.h>
       
    51 #include <aknlayoutscalable_avkon.cdl.h>
       
    52 
       
    53 #include "eikon.hrh"
       
    54 
       
    55 
       
    56 // CONSTANTS
       
    57 /// Granularity of the icon index array.
       
    58 LOCAL_C const TInt KGranularity = 4;
       
    59 
       
    60 
       
    61 // ================= LOCAL FUNCTIONS =======================
       
    62 
       
    63 /**
       
    64 * Append elements from aSource to the end of aTarget.
       
    65 * @param aTarget Array which receives copied elements from aSource.
       
    66 * @param aSource Elements from this will be appended to aTarget.
       
    67 */
       
    68 LOCAL_D void AppendArrayL
       
    69 ( CArrayFix<TInt>& aTarget, const CArrayFix<TInt>& aSource )
       
    70     {
       
    71     TInt i;
       
    72     TInt count = aSource.Count();
       
    73     for ( i = 0; i < count; i++ )
       
    74         {
       
    75         aTarget.AppendL( aSource.At( i ) );
       
    76         }
       
    77     }
       
    78 
       
    79 // ================= MEMBER FUNCTIONS =======================
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CBrowserFavouritesListbox::NewL
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CBrowserFavouritesListbox* CBrowserFavouritesListbox::NewL
       
    86         (
       
    87         MApiProvider& aApiProvider,
       
    88         const CCoeControl* aParent,
       
    89         const MBrowserFavouritesListboxIconHandler& aIconHandler
       
    90         )
       
    91     {
       
    92     CBrowserFavouritesListbox* listbox =
       
    93         new (ELeave) CBrowserFavouritesListbox( aApiProvider );
       
    94     CleanupStack::PushL( listbox );
       
    95     listbox->ConstructL( aParent, aIconHandler );
       
    96     CleanupStack::Pop();    // listbox
       
    97     return listbox;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CBrowserFavouritesListbox::~CBrowserFavouritesListbox
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 CBrowserFavouritesListbox::~CBrowserFavouritesListbox()
       
   105     {
       
   106     delete iFaviconHandler;
       
   107     delete iIconIndexes;
       
   108     delete iItems;
       
   109     delete iNewState;
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CBrowserFavouritesListbox::SetListboxCursorObserver
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CBrowserFavouritesListbox::SetListboxCursorObserver
       
   117 (MBrowserFavouritesListboxCursorObserver* aObserver)
       
   118     {
       
   119     iCursorObserver = aObserver;
       
   120     if ( View() )
       
   121         {
       
   122         STATIC_CAST( CBrowserFavouritesListboxView*, View() )->
       
   123             SetCursorObserver( aObserver );
       
   124         }
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CBrowserFavouritesListbox::SetDataL
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CBrowserFavouritesListbox::SetDataL
       
   132 ( CFavouritesItemList* aItems, /*MCommsModel& aCommsModel,*/ TBool aKeepState )
       
   133     {
       
   134     __ASSERT_DEBUG( aItems, Util::Panic( Util::EUnExpected ) );
       
   135 
       
   136     // Ownership of aItems is taken, and will become a member (but not yet
       
   137     // that) - push until then.
       
   138     CleanupStack::PushL( aItems );
       
   139 
       
   140     // Get all favicons asynchronously by iteration on icon array
       
   141     iFaviconHandler->StartGetFaviconsL( aItems );
       
   142 
       
   143     // Get icon indexes into new list. Replace the existing
       
   144     // data only if successfully gotten. This ensures that they don't go out
       
   145     // of sync (there cannot be different number of items in the two list).
       
   146     CBrowserFavouritesIconIndexArray* newIconIndexes =
       
   147         GetIconIndexesLC( /*aCommsModel,*/ *aItems );
       
   148 
       
   149     if ( aKeepState )
       
   150         {
       
   151         // Calculate new state now, while we still have old items.
       
   152         CalcNewStateL( *aItems );
       
   153         }
       
   154 
       
   155     // Got new data. Empty existing data, but keep the empty lists.
       
   156     ClearSelection();
       
   157     iItems->ResetAndDestroy();
       
   158     iIconIndexes->Reset();
       
   159     SetTopItemIndex(0);
       
   160     UpdateFilterL();
       
   161     HandleItemRemovalL();
       
   162     // Replace data with new.
       
   163     delete iIconIndexes;                            // Not NULL-ed, because...
       
   164     delete iItems;                                  // Not NULL-ed, because...
       
   165     iItems = aItems;                                // ... this cannot leave
       
   166     iIconIndexes = newIconIndexes;                  // ... this cannot leave
       
   167 
       
   168     // Let the model know the change.
       
   169     TheModel()->SetData( *iItems, *iIconIndexes );  // ... this cannot leave
       
   170 
       
   171     CleanupStack::Pop( 2 ); // newIconIndexes, aItems: now members.
       
   172     HandleItemAdditionL();
       
   173     UpdateFilterL();
       
   174     if ( aKeepState )
       
   175         {
       
   176         // Now set the new state into listbox, then discard it.
       
   177         __ASSERT_DEBUG( iNewState, Util::Panic( Util::EUnExpected ) );
       
   178         SetStateL( *iNewState );
       
   179         delete iNewState;
       
   180         iNewState = NULL;
       
   181         }
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------
       
   185 // CBrowserFavouritesListbox::DrawFavicons
       
   186 // ---------------------------------------------------------
       
   187 //
       
   188 TInt CBrowserFavouritesListbox::DrawFavicons()
       
   189     {
       
   190     // We have some favicons to draw
       
   191     TInt err = KErrNone;
       
   192 
       
   193     //Update the icon indices
       
   194     TRAP(   err,
       
   195             CBrowserFavouritesIconIndexArray* newIconIndexes =
       
   196                 GetIconIndexesLC( /*aCommsModel,*/ *iItems );
       
   197             iIconIndexes->Reset();
       
   198             delete iIconIndexes;
       
   199             iIconIndexes = newIconIndexes;
       
   200             CleanupStack::Pop( newIconIndexes );
       
   201         );
       
   202 
       
   203     // Don't draw the favicons if there is a leave
       
   204     if ( !err )
       
   205         {
       
   206         // Let the model know the change and update the lisbox.
       
   207         TheModel()->SetData( *iItems, *iIconIndexes );
       
   208         DrawNow();
       
   209         }
       
   210 
       
   211     return err;
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------
       
   215 // CBrowserFavouritesListbox::SelectionStateL
       
   216 // ---------------------------------------------------------
       
   217 //
       
   218 TBrowserFavouritesSelectionState
       
   219 CBrowserFavouritesListbox::SelectionStateL() const
       
   220     {
       
   221     TBrowserFavouritesSelectionState state;
       
   222 
       
   223     // Check marking first.
       
   224     const CArrayFix<TInt>* selection = MarkedRealIndexesLC();
       
   225     TInt i;
       
   226     TInt count = selection->Count();
       
   227     for ( i = 0; i < count; i++ )
       
   228         {
       
   229         state.iMarkFlags |=
       
   230             SelectionFlags( *(iItems->At( selection->At( i ) )) );
       
   231         if ( iItems->At( selection->At( i ) )->IsItem() )
       
   232             {
       
   233             state.iMarkedItemCount++;
       
   234             }
       
   235         else
       
   236             {
       
   237             state.iMarkedFolderCount++;
       
   238             }
       
   239         }
       
   240 
       
   241     if ( count == iItems->Count() )
       
   242         {
       
   243         state.iMarkFlags |= TBrowserFavouritesSelectionState::EAll;
       
   244         }
       
   245 
       
   246     TInt visibleCount;
       
   247     CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   248     visibleCount = filter ? filter->FilteredNumberOfItems() : iItems->Count();
       
   249     for ( i = 0; i < visibleCount; i++ )
       
   250         {
       
   251         if ( iItems->At( RealIndex( i ) )->IsItem() )
       
   252             {
       
   253             state.iVisibleItemCount++;
       
   254             }
       
   255         }
       
   256 
       
   257     TKeyArrayFix key( 0, ECmpTInt32 );
       
   258     TInt dummy;
       
   259     if ( !selection->Find( CurrentItemRealIndex(), key, dummy ) )
       
   260         {
       
   261         state.iMarkFlags |=
       
   262             TBrowserFavouritesSelectionState::ECurrent;
       
   263         }
       
   264 
       
   265     CleanupStack::PopAndDestroy();  // selection
       
   266 
       
   267     // Then comes the current.
       
   268     const CFavouritesItem* current = CurrentItem();
       
   269     if ( current )
       
   270         {
       
   271         state.iCurrentFlags |= SelectionFlags( *current );
       
   272         }
       
   273 
       
   274     return state;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // CBrowserFavouritesListbox::CurrentItem
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 const CFavouritesItem* CBrowserFavouritesListbox::CurrentItem() const
       
   282     {
       
   283     TInt index = CurrentItemRealIndex();
       
   284     if ( index >= 0 )
       
   285         {
       
   286         return iItems->At( index );
       
   287         }
       
   288     return NULL;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------
       
   292 // CBrowserFavouritesListbox::MarkedItemL
       
   293 // ---------------------------------------------------------
       
   294 //
       
   295 const CFavouritesItem* CBrowserFavouritesListbox::MarkedItemL() const
       
   296     {
       
   297     CFavouritesItem* item = NULL;
       
   298     CArrayFix<TInt>* marked = MarkedRealIndexesLC();
       
   299     if ( marked->Count() == 1 )
       
   300         {
       
   301         item = iItems->At( marked->At( 0 ) );
       
   302         }
       
   303     CleanupStack::PopAndDestroy();
       
   304     return item;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------
       
   308 // CBrowserFavouritesListbox::HighlightUidNow
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 TBool CBrowserFavouritesListbox::HighlightUidNow( TInt aUid )
       
   312     {
       
   313     TInt index = 0;
       
   314     if (aUid != 0)
       
   315         {
       
   316         index = UidToViewIndex( aUid );
       
   317         }
       
   318 
       
   319     if ( index >= 0 )
       
   320         {
       
   321         SetCurrentItemIndexAndDraw( index );
       
   322         return ETrue;
       
   323         }
       
   324     return EFalse;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CBrowserFavouritesListbox::HandleMarkableListCommandL
       
   329 // ---------------------------------------------------------
       
   330 //
       
   331 void CBrowserFavouritesListbox::HandleMarkableListCommandL( TInt aCommand )
       
   332     {
       
   333     if ( ListboxFlags() & EAknListBoxMarkableList )
       
   334         {
       
   335         TInt index;
       
   336         switch ( aCommand )
       
   337             {
       
   338             case EWmlCmdMark:
       
   339                 {
       
   340                 index = CurrentItemIndex();
       
   341                 if ( index >= 0 )
       
   342                     {
       
   343                     View()->SelectItemL( index );
       
   344                     }
       
   345                 break;
       
   346                 }
       
   347 
       
   348             case EWmlCmdUnmark:
       
   349                 {
       
   350                 index = CurrentItemIndex();
       
   351                 if ( index >= 0 )
       
   352                     {
       
   353                     View()->DeselectItem( index );
       
   354                     }
       
   355                 break;
       
   356                 }
       
   357 
       
   358             case EWmlCmdMarkAll:
       
   359                 {
       
   360                 ClearSelection();
       
   361                 TInt count = Model()->NumberOfItems();
       
   362                 if ( count )
       
   363                     {
       
   364                     TInt i = 0;
       
   365                     CArrayFixFlat<TInt>* selection =
       
   366                         new(ELeave) CArrayFixFlat<TInt>( 1 );
       
   367                     CleanupStack::PushL( selection );
       
   368                     selection->SetReserveL( count );
       
   369                     for ( i = 0; i < count; i++ )
       
   370                         {
       
   371                         selection->AppendL( i );
       
   372                         }
       
   373                     SetSelectionIndexesL( selection );
       
   374                     CleanupStack::PopAndDestroy();  // selection
       
   375                     }
       
   376                 break;
       
   377                 }
       
   378 
       
   379             case EWmlCmdUnmarkAll:
       
   380                 {
       
   381                 ClearSelection();
       
   382                 break;
       
   383                 }
       
   384 
       
   385             default:
       
   386                 {
       
   387                 Util::Panic( Util::EUnExpected );
       
   388                 }
       
   389             }
       
   390         }
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------
       
   394 // CBrowserFavouritesListbox::MarkedUidsLC
       
   395 // ---------------------------------------------------------
       
   396 //
       
   397 CArrayFix<TInt>* CBrowserFavouritesListbox::MarkedUidsLC() const
       
   398     {
       
   399     CArrayFix<TInt>* array = MarkedRealIndexesLC();
       
   400     RealIndexesToUids( *array );
       
   401     return array;
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------
       
   405 // CBrowserFavouritesListbox::SelectedUidsLC
       
   406 // ---------------------------------------------------------
       
   407 //
       
   408 CArrayFix<TInt>* CBrowserFavouritesListbox::SelectedUidsLC() const
       
   409     {
       
   410     CArrayFix<TInt>* array = SelectedRealIndexesLC();
       
   411     RealIndexesToUids( *array );
       
   412     return array;
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // CBrowserFavouritesListbox::SelectedItemsLC
       
   417 // ---------------------------------------------------------
       
   418 //
       
   419 CArrayPtr<const CFavouritesItem>*
       
   420 CBrowserFavouritesListbox::SelectedItemsLC(TBool aIncludeSpecialItems) const
       
   421     {
       
   422     CArrayPtrFlat<const CFavouritesItem>* itemPtrs =
       
   423         new (ELeave) CArrayPtrFlat<const CFavouritesItem>( KGranularity );
       
   424     CleanupStack::PushL( itemPtrs );
       
   425     CArrayFix<TInt>* indexes = SelectedRealIndexesLC();
       
   426     TInt i;
       
   427     TInt count = indexes->Count();
       
   428     for ( i = 0; i < count; i++ )
       
   429         {
       
   430         CFavouritesItem* item = iItems->At( indexes->At( i ) );
       
   431 
       
   432         if ( !aIncludeSpecialItems )
       
   433             {
       
   434             // Skip special items:
       
   435             // folders, homepage, last visited & start page URLs.
       
   436             // Need a workaround for the start page since CFavouritesItem
       
   437             // does not provide IsStartPage() or something similar.
       
   438             if ( (item->Uid() == KFavouritesHomepageUid ) ||
       
   439                 (item->Uid() == KFavouritesLastVisitedUid ) ||
       
   440                 item->IsFolder() ||
       
   441                 item->Uid() == KFavouritesStartPageUid )
       
   442                     continue;
       
   443             }
       
   444         itemPtrs->AppendL( item );
       
   445         }
       
   446     CleanupStack::PopAndDestroy();  // indexes
       
   447     return itemPtrs;
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CBrowserFavouritesListbox::ItemByUid
       
   452 // ---------------------------------------------------------
       
   453 //
       
   454 const CFavouritesItem* CBrowserFavouritesListbox::ItemByUid
       
   455 ( TInt aUid ) const
       
   456     {
       
   457     return iItems->ItemByUid( aUid );
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------
       
   461 // CBrowserFavouritesListbox::UnfilteredNumberOfItems
       
   462 // ---------------------------------------------------------
       
   463 //
       
   464 TInt CBrowserFavouritesListbox::UnfilteredNumberOfItems()
       
   465     {
       
   466     return iItems->Count();
       
   467     }
       
   468 
       
   469 
       
   470 // ---------------------------------------------------------
       
   471 // CBrowserFavouritesListbox::FilteredNumberOfItems
       
   472 // ---------------------------------------------------------
       
   473 //
       
   474 TInt CBrowserFavouritesListbox::FilteredNumberOfItems()
       
   475     {
       
   476 
       
   477     CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   478     return filter->FilteredNumberOfItems();
       
   479     }
       
   480 
       
   481 
       
   482 // ---------------------------------------------------------
       
   483 // CBrowserFavouritesListbox::UpdateFilterL
       
   484 // ---------------------------------------------------------
       
   485 //
       
   486 void CBrowserFavouritesListbox::UpdateFilterL()
       
   487     {
       
   488     CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   489     if ( filter )
       
   490         {
       
   491         filter->HandleItemArrayChangeL();
       
   492         }
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------
       
   496 // CBrowserFavouritesListbox::AnyFoldersL
       
   497 // ---------------------------------------------------------
       
   498 //
       
   499 TBool CBrowserFavouritesListbox::AnyFoldersL()
       
   500     {
       
   501     TInt i;
       
   502     TInt count = iItems->Count();
       
   503     for ( i = 0; i < count; i++ )
       
   504         {
       
   505         if ( iItems->At( i )->IsFolder() )
       
   506             {
       
   507             if (iItems->At( i )->Uid()!=KFavouritesAdaptiveItemsFolderUid) return ETrue; //exclude Adaptive Bookmarks Folder
       
   508             }
       
   509         }
       
   510     return EFalse;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------
       
   514 // CBrowserFavouritesListbox::OfferKeyEventL
       
   515 // ---------------------------------------------------------
       
   516 //
       
   517 TKeyResponse CBrowserFavouritesListbox::OfferKeyEventL
       
   518 ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   519     {
       
   520     TKeyResponse result = EKeyWasNotConsumed;
       
   521 
       
   522     switch ( aKeyEvent.iCode )
       
   523         {
       
   524         case EKeyLeftUpArrow:     // Northwest
       
   525         case EStdKeyDevice10:     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   526         case EKeyLeftArrow:       // West
       
   527         case EKeyLeftDownArrow:   // Southwest
       
   528         case EStdKeyDevice13:     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   529 
       
   530         case EKeyRightUpArrow:    // Northeast
       
   531         case EStdKeyDevice11:     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   532         case EKeyRightArrow:      // East
       
   533         case EKeyRightDownArrow:  // Southeast
       
   534         case EStdKeyDevice12:     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   535             {
       
   536             // This listbox does not consume left/right or diagonal keypresses.
       
   537             // (The base class always does, even if it doesn't use them )
       
   538             break;
       
   539             }
       
   540 
       
   541         default:
       
   542             {
       
   543             result = CAknSingleGraphicStyleListBox::OfferKeyEventL
       
   544                 ( aKeyEvent, aType );
       
   545             // Call UpdateCBA to update MSK in case of mark/unmark
       
   546             CBrowserAppUi::Static()->UpdateCbaL();
       
   547             }
       
   548 
       
   549         }
       
   550 
       
   551     return result;
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CBrowserFavouritesListbox::FocusChanged
       
   556 // ---------------------------------------------------------
       
   557 //
       
   558 void CBrowserFavouritesListbox::FocusChanged( TDrawNow aDrawNow )
       
   559     {
       
   560     // Do nothing until the listbox is fully constructed
       
   561     // The dialogpage sets the focus before calling ConstructL
       
   562     if ( iView )
       
   563         {
       
   564         CAknSingleGraphicStyleListBox::FocusChanged( aDrawNow );
       
   565         }
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------
       
   569 // CBrowserFavouritesListbox::CreateModelL
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 void CBrowserFavouritesListbox::CreateModelL()
       
   573     {
       
   574     iModel = CBrowserFavouritesListboxModel::NewL( *iItems, *iIconIndexes );
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------
       
   578 // CBrowserFavouritesListbox::MakeViewClassInstanceL
       
   579 // ---------------------------------------------------------
       
   580 //
       
   581 CListBoxView* CBrowserFavouritesListbox::MakeViewClassInstanceL()
       
   582     {
       
   583     return new (ELeave) CBrowserFavouritesListboxView( *this );
       
   584     }
       
   585 
       
   586 
       
   587 // ---------------------------------------------------------
       
   588 // CBrowserFavouritesListbox::CreateItemDrawerL
       
   589 // ---------------------------------------------------------
       
   590 //
       
   591 void CBrowserFavouritesListbox::CreateItemDrawerL()
       
   592     {
       
   593     CAknSingleGraphicStyleListBox::CreateItemDrawerL();
       
   594     }
       
   595 
       
   596 
       
   597 // ---------------------------------------------------------
       
   598 // CBrowserFavouritesListbox::CBrowserFavouritesListbox
       
   599 // ---------------------------------------------------------
       
   600 //
       
   601 CBrowserFavouritesListbox::CBrowserFavouritesListbox
       
   602                             ( MApiProvider& aApiProvider ) :
       
   603     iApiProvider( aApiProvider )
       
   604     {
       
   605     }
       
   606 
       
   607 // ---------------------------------------------------------
       
   608 // CBrowserFavouritesListbox::ConstructL
       
   609 // ---------------------------------------------------------
       
   610 //
       
   611 void CBrowserFavouritesListbox::ConstructL
       
   612         (
       
   613         const CCoeControl* aParent,
       
   614         const MBrowserFavouritesListboxIconHandler& aIconHandler
       
   615         )
       
   616     {
       
   617     iSkinUpdated = EFalse;
       
   618     iIconHandler = &aIconHandler;
       
   619     iItems = new (ELeave) CFavouritesItemList();
       
   620     iIconIndexes =
       
   621         new (ELeave) CBrowserFavouritesIconIndexArray( KGranularity );
       
   622     CAknSingleGraphicStyleListBox::ConstructL( aParent, ListboxFlags() );
       
   623     // MUST call this after the listbox has finished; listbox construction
       
   624     // is buggy and overwrites the model's itemarray ptr.
       
   625     TheModel()->SetItemArray();
       
   626     CreateScrollBarFrameL( ETrue );
       
   627     ScrollBarFrame()->SetScrollBarVisibilityL
       
   628         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   629 
       
   630     // Load icons
       
   631     ItemDrawer()->ColumnData()->SetIconArray
       
   632         ( iIconHandler->CreateIconArrayL() );
       
   633 
       
   634     // Store the size of an icon
       
   635     TAknWindowComponentLayout layout =
       
   636                 AknLayoutScalable_Avkon::list_single_graphic_pane_g1(0);
       
   637 
       
   638     TAknLayoutRect naviPaneGraphicsLayoutRect;
       
   639     TRect listBoxGraphicRect;
       
   640     TRect rect = iAvkonAppUi->ClientRect();
       
   641 
       
   642 
       
   643     naviPaneGraphicsLayoutRect.LayoutRect( rect, layout);
       
   644     listBoxGraphicRect = naviPaneGraphicsLayoutRect.Rect();
       
   645 
       
   646     TSize listBoxGraphicSize( listBoxGraphicRect.iBr.iX - listBoxGraphicRect.iTl.iX,
       
   647                                 listBoxGraphicRect.iBr.iY - listBoxGraphicRect.iTl.iY );
       
   648     // Favicon handler
       
   649     iFaviconHandler = CBrowserFaviconHandler::NewL(
       
   650                                 iApiProvider,
       
   651                                 ItemDrawer()->ColumnData()->IconArray(),
       
   652                                 *this,
       
   653                                 listBoxGraphicSize );
       
   654 
       
   655     ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CBrowserFavouritesListbox::ListboxFlags
       
   660 // ---------------------------------------------------------
       
   661 //
       
   662 TInt CBrowserFavouritesListbox::ListboxFlags()
       
   663     {
       
   664     return EAknListBoxMarkableList;
       
   665     }
       
   666 
       
   667 // ---------------------------------------------------------
       
   668 // CBrowserFavouritesListbox::GetIconIndexesLC
       
   669 // ---------------------------------------------------------
       
   670 //
       
   671 CBrowserFavouritesIconIndexArray*
       
   672 CBrowserFavouritesListbox::GetIconIndexesLC
       
   673 ( /*MCommsModel& aCommsModel, */CFavouritesItemList& aItems )
       
   674     {
       
   675     // Create new empty list.
       
   676     CBrowserFavouritesIconIndexArray* iconIndexes =
       
   677         new (ELeave) CBrowserFavouritesIconIndexArray( KGranularity );
       
   678     CleanupStack::PushL( iconIndexes );
       
   679     // Get list of access points. Not copy, owned by the AP model.
       
   680    // const CApListItemList* apList = aCommsModel.AccessPoints();
       
   681     // Fill the list.
       
   682     TInt i = 0;
       
   683     TInt count = aItems.Count();
       
   684     for ( i = 0; i < count; i++ )
       
   685         {
       
   686         iconIndexes->AppendL
       
   687             ( iIconHandler->IconIndexes( *(aItems.At( i ))/*, apList*/,this ) );
       
   688         }
       
   689     return iconIndexes;
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------
       
   693 // CBrowserFavouritesListbox::CalcNewStateL
       
   694 // ---------------------------------------------------------
       
   695 //
       
   696 void CBrowserFavouritesListbox::CalcNewStateL
       
   697 ( CFavouritesItemList& aNewItems )
       
   698     {
       
   699     delete iNewState;
       
   700     iNewState = NULL;
       
   701     iNewState = new( ELeave ) CBrowserFavouritesListboxState;
       
   702 
       
   703     // 1. Check if we have any new item. If yes, highlight goes to first
       
   704     // new one.
       
   705     TInt i;
       
   706     TInt count = aNewItems.Count();
       
   707     for ( i = 0; i < count; i++ )
       
   708         {
       
   709         if ( iItems->UidToIndex( aNewItems.IndexToUid( i ) ) ==
       
   710                                                             KErrNotFound )
       
   711             {
       
   712             // New item, not found among the old ones.
       
   713             // Set highlight to that, and also becomes top item.
       
   714             iNewState->iHighlightUid = iNewState->iTopItemUid =
       
   715                 aNewItems.IndexToUid( i );
       
   716             break;
       
   717             }
       
   718         }
       
   719 
       
   720     // 2. If there is no new item, get the new highlight. That is the old
       
   721     // one, if still exists, or the next remaining one after the
       
   722     // deleted old one(s).
       
   723     TInt uid;
       
   724     if ( iNewState->iHighlightUid == KFavouritesNullUid )
       
   725         {
       
   726         i = CurrentItemRealIndex();
       
   727         if ( i >= 0 )
       
   728             {
       
   729             // Have current item.
       
   730             // Now go down the old list, beginning from highlighted one;
       
   731             // find first item that still exists.
       
   732             count = iItems->Count();
       
   733             for ( /*current highlight index: i*/; i < count; i++ )
       
   734                 {
       
   735                 uid = iItems->At( i )->Uid();
       
   736                 if ( aNewItems.UidToIndex( uid ) != KErrNotFound )
       
   737                     {
       
   738                     iNewState->iHighlightUid = uid;
       
   739                     break;
       
   740                     }
       
   741                 }
       
   742             // Here we should have higlight uid, unless the deleted element(s)
       
   743             // were last. In that case, set last item highlighted (if there is
       
   744             // anything to highlight).
       
   745             if ( iNewState->iHighlightUid == KFavouritesNullUid &&
       
   746                                                             aNewItems.Count() )
       
   747                 {
       
   748                 iNewState->iHighlightUid = aNewItems.IndexToUid
       
   749                     ( aNewItems.Count() - 1 );
       
   750                 }
       
   751             }
       
   752         }
       
   753 
       
   754     // 3. Get mark uids. Whether these uids exist in the new list or not, is
       
   755     // not checked here; setting marks to the already changed listbox is
       
   756     // fool-proof.
       
   757     iNewState->iMarkUids = MarkedUidsLC();
       
   758     CleanupStack::Pop();    // Uid list; ownership is now in the state.
       
   759     }
       
   760 
       
   761 // ---------------------------------------------------------
       
   762 // CBrowserFavouritesListbox::SetStateL
       
   763 // ---------------------------------------------------------
       
   764 //
       
   765 void CBrowserFavouritesListbox::SetStateL
       
   766 ( const CBrowserFavouritesListboxState& aState )
       
   767     {
       
   768     TInt topIndex;
       
   769 
       
   770     // Set marks.
       
   771     if ( aState.iMarkUids->Count() )
       
   772         {
       
   773         CArrayFix<TInt>* marks = new (ELeave) CArrayFixFlat<TInt>( 4 );
       
   774         CleanupStack::PushL( marks );
       
   775         marks->AppendL
       
   776             ( aState.iMarkUids->Back( 0 ), aState.iMarkUids->Count() );
       
   777         UidsToViewIndexes( *marks );
       
   778         SetSelectionIndexesL( marks );
       
   779         CleanupStack::PopAndDestroy();  // marks
       
   780         }
       
   781 
       
   782     // Set top item index.
       
   783     topIndex = UidToViewIndex ( aState.iTopItemUid );
       
   784     if ( topIndex >= 0 )
       
   785         {
       
   786         // Always try to fill the listbox (if there were empty lines below,
       
   787         // "scroll down", instead of strictly restoring the top item index).
       
   788         TInt topIndexToSeeLastItem = Model()->NumberOfItems() -
       
   789             View()->NumberOfItemsThatFitInRect( View()->ViewRect() );
       
   790         if ( topIndexToSeeLastItem < 0 )
       
   791             {
       
   792             topIndexToSeeLastItem = 0;
       
   793             }
       
   794         topIndex = Min( topIndex, topIndexToSeeLastItem );
       
   795         SetTopItemIndex( topIndex );
       
   796         }
       
   797 
       
   798     // Set higlight.
       
   799     TInt curIndex = UidToViewIndex ( aState.iHighlightUid );
       
   800     if ( curIndex < 0 )
       
   801         {
       
   802         // If cannot restore highlight, set it to top item.
       
   803         curIndex = topIndex;
       
   804         }
       
   805     if ( curIndex >= 0 )
       
   806         {
       
   807         SetCurrentItemIndex( curIndex );
       
   808         }
       
   809 
       
   810     DrawNow();
       
   811 
       
   812     if ( iCursorObserver )
       
   813         {
       
   814         // Cursor now points to some different item. Let the observer know it.
       
   815         iCursorObserver->HandleCursorChangedL( this );
       
   816         }
       
   817     }
       
   818 
       
   819 // ---------------------------------------------------------
       
   820 // CBrowserFavouritesListbox::UidToViewIndex
       
   821 // ---------------------------------------------------------
       
   822 //
       
   823 TInt CBrowserFavouritesListbox::UidToViewIndex( TInt aUid ) const
       
   824     {
       
   825     TInt viewIndex = KErrNotFound;
       
   826     TInt realIndex = iItems->UidToIndex( aUid );
       
   827     if ( realIndex >= 0 )
       
   828         {
       
   829         CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   830         if ( filter )
       
   831             {
       
   832             // Have filter, do the conversion.
       
   833             viewIndex = filter->VisibleItemIndex( realIndex );
       
   834             }
       
   835         else
       
   836             {
       
   837             // No filter, no conversion necessary.
       
   838             viewIndex = realIndex;
       
   839             }
       
   840         }
       
   841     return viewIndex;
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------
       
   845 // CBrowserFavouritesListbox::UidsToViewIndexes
       
   846 // ---------------------------------------------------------
       
   847 //
       
   848 void CBrowserFavouritesListbox::UidsToViewIndexes
       
   849 ( CArrayFix<TInt>& aList ) const
       
   850     {
       
   851     TInt i;
       
   852     TInt j;
       
   853     TInt index;
       
   854     TInt count = aList.Count();
       
   855     for ( i = 0, j = 0; i < count; i++ )
       
   856         {
       
   857         index = UidToViewIndex( aList.At ( i ) );
       
   858         if ( index != KErrNotFound )
       
   859             {
       
   860             aList.At( j++ ) = index;
       
   861             }
       
   862         }
       
   863     if ( j < count )
       
   864         {
       
   865         // Not all Uids were converted. Delete the trailing rubbish.
       
   866         aList.Delete( j, count - j );
       
   867         }
       
   868     }
       
   869 
       
   870 // ---------------------------------------------------------
       
   871 // CBrowserFavouritesListbox::RealIndexesToUids
       
   872 // ---------------------------------------------------------
       
   873 //
       
   874 void CBrowserFavouritesListbox::RealIndexesToUids
       
   875 ( CArrayFix<TInt>& aList ) const
       
   876     {
       
   877     TInt i;
       
   878     TInt uid;
       
   879     TInt count = aList.Count();
       
   880     for ( i = 0; i < count; i++ )
       
   881         {
       
   882         uid = iItems->IndexToUid( aList.At( i ) );
       
   883         __ASSERT_DEBUG( uid != KFavouritesNullUid, \
       
   884             Util::Panic( Util::EFavouritesBadBookmarkUid ) );
       
   885         aList.At( i ) = uid;
       
   886         }
       
   887     }
       
   888 
       
   889 // ---------------------------------------------------------
       
   890 // CBrowserFavouritesListbox::MarkedRealIndexesLC
       
   891 // ---------------------------------------------------------
       
   892 //
       
   893 CArrayFix<TInt>* CBrowserFavouritesListbox::MarkedRealIndexesLC() const
       
   894     {
       
   895     CListBoxView::CSelectionIndexArray* array =
       
   896         new (ELeave) CArrayFixFlat<TInt>( KGranularity );
       
   897     CleanupStack::PushL( array );
       
   898     if ( iItems->Count() )
       
   899         {
       
   900         const CArrayFix<TInt>* marked;
       
   901         CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   902         if ( filter )
       
   903             {
       
   904             // Filter knows all.
       
   905             filter->UpdateSelectionIndexesL();
       
   906             marked = filter->SelectionIndexes();
       
   907 #if 1 /* TODO remove when AVKON bug fixed*/
       
   908             // Overcoming AVKON bug. If filter criteria is empty (i.e. the
       
   909             // user is not typing in the filter), selection indexes between
       
   910             // the filter and the listbox are not synchronized! Unfortunately,
       
   911             // this strange back-way is the only means by we can discover if
       
   912             // we have criteria or not; CAknListBoxFilterItems has the
       
   913             // criteria as private; and the CAknSearchField, which holds the
       
   914             // filter (and has the string) is not accessible here in the
       
   915             // listbox (it's in the container).
       
   916             if ( filter->FilteredNumberOfItems() ==
       
   917                 filter->NonFilteredNumberOfItems() )
       
   918                 {
       
   919                 marked = View()->SelectionIndexes();
       
   920                 }
       
   921 #endif
       
   922             }
       
   923         else
       
   924             {
       
   925             // No filter.
       
   926             marked = View()->SelectionIndexes();
       
   927             }
       
   928         AppendArrayL( /*aTarget=*/*array, /*aSource=*/*marked );
       
   929         }
       
   930     return array;
       
   931     }
       
   932 
       
   933 // ---------------------------------------------------------
       
   934 // CBrowserFavouritesListbox::SelectedRealIndexesLC
       
   935 // ---------------------------------------------------------
       
   936 //
       
   937 CArrayFix<TInt>* CBrowserFavouritesListbox::SelectedRealIndexesLC() const
       
   938     {
       
   939     CListBoxView::CSelectionIndexArray* selection =
       
   940         MarkedRealIndexesLC();
       
   941     if ( selection->Count() == 0 )
       
   942         {
       
   943         // No marks; use the highlighted one.
       
   944         selection->AppendL( CurrentItemRealIndex() );
       
   945         }
       
   946     return selection;
       
   947     }
       
   948 
       
   949 // ---------------------------------------------------------
       
   950 // CBrowserFavouritesListbox::CurrentItemRealIndex
       
   951 // ---------------------------------------------------------
       
   952 //
       
   953 TInt CBrowserFavouritesListbox::CurrentItemRealIndex() const
       
   954     {
       
   955     return RealIndex( CurrentItemIndex() /*that's view index*/ );
       
   956     }
       
   957 
       
   958 // ---------------------------------------------------------
       
   959 // CBrowserFavouritesListbox::RealIndex
       
   960 // ---------------------------------------------------------
       
   961 //
       
   962 TInt CBrowserFavouritesListbox::RealIndex( TInt aViewIndex ) const
       
   963     {
       
   964     TInt index = KErrNotFound;
       
   965     if ( aViewIndex >= 0 )
       
   966         {
       
   967         CAknListBoxFilterItems* filter = TheModel()->Filter();
       
   968         if ( filter )
       
   969             {
       
   970             // If we have the index and the filter also, do the conversion.
       
   971             index = filter->FilteredItemIndex( aViewIndex );
       
   972             }
       
   973         else
       
   974             {
       
   975             index = aViewIndex;
       
   976             }
       
   977         }
       
   978     return index;
       
   979     }
       
   980 
       
   981 // ---------------------------------------------------------
       
   982 // CBrowserFavouritesListbox::RealIndexes
       
   983 // ---------------------------------------------------------
       
   984 //
       
   985 void CBrowserFavouritesListbox::RealIndexes( CArrayFix<TInt>& aList ) const
       
   986     {
       
   987     TInt i;
       
   988     TInt j;
       
   989     TInt index;
       
   990     TInt count = aList.Count();
       
   991     for ( i = 0, j = 0; i < count; i++ )
       
   992         {
       
   993         index = RealIndex( aList.At ( i ) );
       
   994         if ( index != KErrNotFound )
       
   995             {
       
   996             aList.At( j++ ) = index;
       
   997             }
       
   998         }
       
   999     if ( j < count )
       
  1000         {
       
  1001         // Not all indexes were converted. Delete the trailing rubbish.
       
  1002         aList.Delete( j, count - j );
       
  1003         }
       
  1004     }
       
  1005 
       
  1006 // ---------------------------------------------------------
       
  1007 // CBrowserFavouritesListbox::SelectionFlags
       
  1008 // ---------------------------------------------------------
       
  1009 //
       
  1010 TInt CBrowserFavouritesListbox::SelectionFlags
       
  1011 ( const CFavouritesItem& aItem ) const
       
  1012     {
       
  1013     TInt flags = 0;
       
  1014     if ( aItem.IsItem() )
       
  1015         {
       
  1016         switch ( aItem.Uid() )
       
  1017             {
       
  1018             case KFavouritesHomepageUid:
       
  1019                 {
       
  1020                 flags |=
       
  1021                     TBrowserFavouritesSelectionState::EAny |
       
  1022                     TBrowserFavouritesSelectionState::EHomepage |
       
  1023                     TBrowserFavouritesSelectionState::EItem;
       
  1024                 break;
       
  1025                 }
       
  1026 
       
  1027             case KFavouritesStartPageUid:
       
  1028                 {
       
  1029                 flags |=
       
  1030                     TBrowserFavouritesSelectionState::EAny |
       
  1031                     TBrowserFavouritesSelectionState::EStartPage |
       
  1032                     TBrowserFavouritesSelectionState::EItem;
       
  1033                 break;
       
  1034                 }
       
  1035 
       
  1036             case KFavouritesLastVisitedUid:
       
  1037                 {
       
  1038                 flags |=
       
  1039                     TBrowserFavouritesSelectionState::EAny |
       
  1040                     TBrowserFavouritesSelectionState::ELastVisited |
       
  1041                     TBrowserFavouritesSelectionState::EItem;
       
  1042                 break;
       
  1043                 }
       
  1044 
       
  1045             default:
       
  1046                 {
       
  1047                 flags |=
       
  1048                     TBrowserFavouritesSelectionState::EAny |
       
  1049                     TBrowserFavouritesSelectionState::EPlainItem |
       
  1050                     TBrowserFavouritesSelectionState::EItem;
       
  1051                 break;
       
  1052                 }
       
  1053             }
       
  1054         }
       
  1055     else
       
  1056         {
       
  1057         flags |=
       
  1058             TBrowserFavouritesSelectionState::EAny |
       
  1059             TBrowserFavouritesSelectionState::EFolder;
       
  1060         }
       
  1061     return flags;
       
  1062     }
       
  1063 
       
  1064 // ---------------------------------------------------------
       
  1065 // CBrowserFavouritesListbox::TheModel
       
  1066 // ---------------------------------------------------------
       
  1067 //
       
  1068 CBrowserFavouritesListboxModel*
       
  1069 CBrowserFavouritesListbox::TheModel() const
       
  1070     {
       
  1071     return REINTERPRET_CAST( CBrowserFavouritesListboxModel*, Model() );
       
  1072     }
       
  1073 
       
  1074 
       
  1075 // ---------------------------------------------------------
       
  1076 // CBrowserFavouritesListbox::HandleResourceChange
       
  1077 // ---------------------------------------------------------
       
  1078 //
       
  1079 void CBrowserFavouritesListbox::HandleResourceChange( TInt aType )
       
  1080     {
       
  1081     CAknSingleGraphicStyleListBox::HandleResourceChange( aType );
       
  1082     if ( aType == KAknsMessageSkinChange )
       
  1083         {
       
  1084         CArrayPtr<CGulIcon>* array =
       
  1085         ItemDrawer()->ColumnData()->IconArray();
       
  1086 
       
  1087         array->ResetAndDestroy();
       
  1088         delete array;
       
  1089 
       
  1090         CAknIconArray* iconArray = NULL;
       
  1091         TRAPD( err,
       
  1092                 iconArray = iIconHandler->CreateIconArrayL()
       
  1093                 )
       
  1094 
       
  1095         if ( !err )
       
  1096             {
       
  1097             ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
  1098             iFaviconHandler->UpdateIconArray(ItemDrawer()->ColumnData()->IconArray());
       
  1099             SetSkinUpdated(ETrue);
       
  1100             }
       
  1101         }
       
  1102     }
       
  1103 
       
  1104 // ---------------------------------------------------------
       
  1105 // CBrowserFavouritesListbox::SetSkinUpdated
       
  1106 // ---------------------------------------------------------
       
  1107 //
       
  1108 void CBrowserFavouritesListbox::SetSkinUpdated(TBool aSkinUpdated)
       
  1109     {
       
  1110     iSkinUpdated = aSkinUpdated;
       
  1111     }
       
  1112 
       
  1113 
       
  1114 //  End of File