browserui/browser/FavouritesSrc/BrowserFavouritesContainer.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     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 CBrowserFavouritesContainer.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <eikimage.h>
       
    23 #include <AknAppUi.h>
       
    24 #include <AknNavi.h>
       
    25 #include <AknNaviDe.h>
       
    26 #include <AknTabGrp.h>
       
    27 #include <AknNaviLabel.h>
       
    28 #include <AknTitle.h>
       
    29 #include <aknsfld.h>
       
    30 #include <calslbs.h>
       
    31 #include <barsread.h>	// for TResourceReader
       
    32 #include <EikSpane.h>
       
    33 #include <Avkon.hrh>
       
    34 #include <BrowserNG.rsg>
       
    35 #include <favouritesdb.h>
       
    36 
       
    37 #include <aknconsts.h>
       
    38 #include <akneditstateindicator.h>
       
    39 #include <AknsListBoxBackgroundControlContext.h>
       
    40 #include <aknlayout.cdl.h>
       
    41 
       
    42 #include "Display.h"
       
    43 #include "Preferences.h"
       
    44 #include "BrowserAppUi.h"
       
    45 #include "BrowserUIVariant.hrh"
       
    46 #include "CommonConstants.h"
       
    47 #include "BrowserFavouritesView.h"
       
    48 #include "BrowserFavouritesContainer.h"
       
    49 #include "BrowserFavouritesListbox.h"
       
    50 #include "BrowserFavouritesListboxModel.h"
       
    51 #include "BrowserFavouritesListboxIconHandler.h"
       
    52 #include "logger.h" 
       
    53 
       
    54 // CONSTANTS
       
    55 LOCAL_D const TInt KTabId = 88888;
       
    56 LOCAL_D const TInt KMaxNaviText = 25;   // format is "<int>/<int>".
       
    57 _LIT( KFormat, "%d/%d" );
       
    58 
       
    59 // ============================= LOCAL FUNCTIONS ===============================
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CBrowserFavouritesContainer::~CBrowserFavouritesContainer
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CBrowserFavouritesContainer::~CBrowserFavouritesContainer()
       
    66 	{
       
    67     delete iListbox;
       
    68     delete iIconHandler;
       
    69 	delete iSkinContext;
       
    70 	delete iNaviPaneTabsFolder;
       
    71 	}
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CBrowserFavouritesContainer::ShowRootNaviPane
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CBrowserFavouritesContainer::ShowRootNaviPane()
       
    79     {
       
    80     // If text is showing, destroy now - this pops off teh Navi Pane.
       
    81 	delete iNaviPaneTabsFolder;
       
    82     iNaviPaneTabsFolder = NULL;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CBrowserFavouritesContainer::ShowFolderNaviPaneL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CBrowserFavouritesContainer::ShowFolderNaviPaneL
       
    90 ( TInt aFolderIndex, TInt aFolderCount )
       
    91     {
       
    92 	CAknNavigationControlContainer* naviPane =
       
    93         iView->ApiProvider().Display().NaviPaneL();
       
    94     if ( !iNaviPaneTabsFolder )
       
    95         {
       
    96         // Folder's tab group not yet created. Make it now.
       
    97         iNaviPaneTabsFolder = naviPane->CreateTabGroupL();
       
    98         iNaviPaneTabsFolder->SetNaviDecoratorObserver(this);
       
    99         }
       
   100 
       
   101     TBuf<KMaxNaviText> buf;
       
   102     // Format Navi Pane text "1/4" style.
       
   103     buf.Format( KFormat, aFolderIndex + 1, aFolderCount );
       
   104     AknTextUtils::LanguageSpecificNumberConversion( buf );
       
   105 
       
   106     CEikImage* folderIcon = new (ELeave) CEikImage;
       
   107     CleanupStack::PushL( folderIcon );
       
   108     TResourceReader rr;
       
   109     iCoeEnv->CreateResourceReaderLC( rr, R_BROWSER_ICON_PROP_FOLDER );
       
   110     folderIcon->ConstructFromResourceL( rr );
       
   111     folderIcon->SetPictureOwnedExternally( EFalse );    // has ownership now
       
   112     CleanupStack::PopAndDestroy(); // rr
       
   113 
       
   114     CAknTabGroup* tabGroup = 
       
   115         STATIC_CAST( CAknTabGroup*, iNaviPaneTabsFolder->DecoratedControl() );
       
   116     if ( tabGroup->TabCount() )
       
   117         {
       
   118         // Already created. Change the contents.
       
   119         tabGroup->ReplaceTabL
       
   120             (
       
   121             KTabId,
       
   122             buf,
       
   123             folderIcon->Bitmap(),                       // ownership passed
       
   124             folderIcon->Mask()                          // ownership passed
       
   125             );
       
   126         }
       
   127     else
       
   128         {
       
   129         // Created just now. Add the contents.
       
   130         tabGroup->AddTabL
       
   131             (
       
   132             KTabId,
       
   133             buf,
       
   134             folderIcon->Bitmap(),                       // ownership passed
       
   135             folderIcon->Mask()                          // ownership passed
       
   136             );
       
   137         }
       
   138     folderIcon->SetPictureOwnedExternally( ETrue );     // ownership passed
       
   139     CleanupStack::PopAndDestroy();  // folderIcon
       
   140 
       
   141     tabGroup->SetTabFixedWidthL( EAknTabWidthWithOneTab );
       
   142     tabGroup->SetActiveTabById( KTabId );
       
   143 
       
   144 	iNaviPaneTabsFolder->SetScrollButtonDimmed
       
   145 		( CAknNavigationDecorator::ELeftButton, aFolderIndex == 0 );
       
   146 	iNaviPaneTabsFolder->SetScrollButtonDimmed
       
   147 		( 
       
   148 		CAknNavigationDecorator::ERightButton,
       
   149 		aFolderIndex == aFolderCount - 1
       
   150 		);
       
   151 
       
   152 	// If not yet pushed, this will do the push; if already there, this brings
       
   153     // it to top and draws.
       
   154     naviPane->PushL( *iNaviPaneTabsFolder );
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CBrowserFavouritesContainer::ComponentControl
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 CCoeControl* CBrowserFavouritesContainer::ComponentControl
       
   162 ( TInt aIndex ) const
       
   163 	{
       
   164     switch (aIndex)
       
   165         {
       
   166         case 0:
       
   167             return iListbox;
       
   168 
       
   169         default:
       
   170             return 0;
       
   171         }
       
   172 	}
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CBrowserFavouritesContainer::CountComponentControls
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 TInt CBrowserFavouritesContainer::CountComponentControls() const
       
   179 	{
       
   180     return (iListbox ? 1 : 0) ;
       
   181 	}
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CBrowserFavouritesContainer::SizeChanged
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CBrowserFavouritesContainer::SizeChanged()
       
   188 	{
       
   189     // Listbox is empty; listbox takes the whole area.
       
   190     iListbox->SetRect( Rect() );
       
   191 	}
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CBrowserFavouritesContainer::OfferKeyEventL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TKeyResponse CBrowserFavouritesContainer::OfferKeyEventL
       
   198 ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   199 	{
       
   200 	CBrowserAppUi* ui = CBrowserAppUi::Static();
       
   201     TKeyResponse result = EKeyWasNotConsumed;
       
   202     
       
   203 	if (ui->OfferApplicationSpecificKeyEventL(aKeyEvent, aType) == EKeyWasConsumed)
       
   204 		{
       
   205 		return EKeyWasConsumed;
       
   206 		}
       
   207 
       
   208 
       
   209     if ( result == EKeyWasNotConsumed )
       
   210         {
       
   211         // Otherwise, give the view a chance to handle arrow presses
       
   212         // (moving between subfolders).
       
   213         result = iView->OfferKeyEventL( aKeyEvent, aType );
       
   214         }
       
   215 
       
   216     if ( result == EKeyWasNotConsumed && iListbox )
       
   217         {
       
   218         // Otherwise, let the listbox fiddle with it. This will NOT consume
       
   219         // arrow presses (base class overridden).
       
   220         result = iListbox->OfferKeyEventL( aKeyEvent, aType );
       
   221         
       
   222         if( (aKeyEvent.iCode == EKeyDownArrow) || (aKeyEvent.iCode == EKeyUpArrow) )  
       
   223                 {  
       
   224                 BROWSER_LOG( ( _L("Need to update tool bar buttons") ) );  
       
   225                 iView->UpdateToolbarButtonsState();  
       
   226                 }  
       
   227 
       
   228         }
       
   229 
       
   230     return result;
       
   231 	}
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CBrowserFavouritesContainer::HandleCursorChangedL
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CBrowserFavouritesContainer::HandleCursorChangedL
       
   238 ( CEikListBox* /*aListBox*/ )
       
   239     {
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CBrowserFavouritesContainer::HandleNaviDecoratorEventL
       
   244 //
       
   245 // Called when user touches the left or right arrow in navipane
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CBrowserFavouritesContainer::HandleNaviDecoratorEventL( TInt aEventID )
       
   249     {
       
   250     // used to swap the arrow key functionality for Arabic, etc...
       
   251     TBool forward(!(AknLayoutUtils::PenEnabled() && AknLayoutUtils::LayoutMirrored()));
       
   252     
       
   253     switch (aEventID)
       
   254         {
       
   255         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow:
       
   256             iView->ShowNextFolerL(forward);
       
   257             break;
       
   258         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventLeftTabArrow:
       
   259             iView->ShowNextFolerL(!forward);
       
   260             break;
       
   261         default:
       
   262             break;
       
   263         }
       
   264     }
       
   265 
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CBrowserFavouritesContainer::ConstructComponentControlsL
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CBrowserFavouritesContainer::ConstructComponentControlsL(
       
   272         const TRect& /*aRect*/,
       
   273         CBrowserFavouritesView& aView )
       
   274 	{
       
   275     // Construct listbox.
       
   276     iIconHandler = CreateListboxIconHandlerL();
       
   277     iListbox = CBrowserFavouritesListbox::NewL( iView->ApiProvider(), this, *iIconHandler );
       
   278     iListbox->SetListBoxObserver( &aView );
       
   279     iListbox->SetListboxCursorObserver( this );
       
   280     HBufC* buf = iCoeEnv->AllocReadResourceLC( ListboxEmptyTextResourceId() );
       
   281     iListbox->View()->SetListEmptyTextL( *buf );
       
   282     CleanupStack::PopAndDestroy();  // buf
       
   283 
       
   284 	}
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CBrowserFavouritesContainer::ConstructL
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CBrowserFavouritesContainer::ConstructL
       
   291 ( const TRect& aRect, CBrowserFavouritesView& aView )
       
   292 	{
       
   293     iView = &aView;
       
   294 
       
   295 	CAknNavigationControlContainer* naviPane =
       
   296         iView->ApiProvider().Display().NaviPaneL();
       
   297 
       
   298     CreateWindowL();
       
   299     SetMopParent( iView );
       
   300 
       
   301     ConstructComponentControlsL( aRect, *iView );
       
   302 
       
   303     TAknsItemID tileIID = KAknsIIDSkinBmpListPaneNarrowA;
       
   304     TAknLayoutRect listGenPane;
       
   305     listGenPane.LayoutRect(iAvkonAppUi->ClientRect() , 
       
   306         AknLayout::list_gen_pane( 0 ));
       
   307 
       
   308     TAknLayoutRect column;
       
   309     column.LayoutRect(iAvkonAppUi->ClientRect() , 
       
   310         AknLayout::A_column());
       
   311 
       
   312     iSkinContext = CAknsListBoxBackgroundControlContext::NewL(
       
   313         KAknsIIDSkinBmpMainPaneUsual, 
       
   314         listGenPane.Rect(), //TODOVRa: Should come from LAF!
       
   315         EFalse, tileIID,
       
   316         column.Rect() ); //TODOVRa: Should come from LAF!
       
   317     SetRect( aRect );
       
   318     ActivateL();
       
   319     }
       
   320 
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CBrowserFavouritesContainer::MopSupplyObject
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TTypeUid::Ptr CBrowserFavouritesContainer::MopSupplyObject( TTypeUid aId )
       
   327     {
       
   328     if( aId.iUid == MAknsControlContext::ETypeId  )
       
   329         {
       
   330         return MAknsControlContext::SupplyMopObject( aId, iSkinContext );
       
   331         }
       
   332 
       
   333 	return SupplyMopObject( aId, (MAknEditingStateIndicator*)NULL );
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CBrowserFavouritesContainer::HandleResourceChange
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CBrowserFavouritesContainer::HandleResourceChange( TInt aType )
       
   341     {
       
   342     // goes through all the subcomponents
       
   343     CCoeControl::HandleResourceChange( aType );
       
   344     
       
   345     if (aType == KEikDynamicLayoutVariantSwitch)
       
   346         {
       
   347         SetRect(iView->ClientRect());
       
   348         DrawDeferred();
       
   349         }
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CBrowserFavouritesContainer::FocusChanged
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CBrowserFavouritesContainer::FocusChanged( TDrawNow aDrawNow )
       
   357     {
       
   358 	if ( iListbox && iListbox->IsVisible() )
       
   359         {
       
   360         Listbox()->SetFocus( IsFocused(), aDrawNow );
       
   361         }
       
   362     }
       
   363 
       
   364 // End of File