browserui/browser/FavouritesSrc/BrowserFavouritesContainer.cpp
branchRCL_3
changeset 65 8e6fa1719340
equal deleted inserted replaced
64:6385c4c93049 65:8e6fa1719340
       
     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                 iView->UpdateToolbarButtonsState();  
       
   225                 }  
       
   226 
       
   227         }
       
   228 
       
   229     return result;
       
   230 	}
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CBrowserFavouritesContainer::HandleCursorChangedL
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CBrowserFavouritesContainer::HandleCursorChangedL
       
   237 ( CEikListBox* /*aListBox*/ )
       
   238     {
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CBrowserFavouritesContainer::HandleNaviDecoratorEventL
       
   243 //
       
   244 // Called when user touches the left or right arrow in navipane
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CBrowserFavouritesContainer::HandleNaviDecoratorEventL( TInt aEventID )
       
   248     {
       
   249     // used to swap the arrow key functionality for Arabic, etc...
       
   250     TBool forward(!(AknLayoutUtils::PenEnabled() && AknLayoutUtils::LayoutMirrored()));
       
   251     
       
   252     switch (aEventID)
       
   253         {
       
   254         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow:
       
   255             iView->ShowNextFolerL(forward);
       
   256             break;
       
   257         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventLeftTabArrow:
       
   258             iView->ShowNextFolerL(!forward);
       
   259             break;
       
   260         default:
       
   261             break;
       
   262         }
       
   263     }
       
   264 
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CBrowserFavouritesContainer::ConstructComponentControlsL
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CBrowserFavouritesContainer::ConstructComponentControlsL(
       
   271         const TRect& /*aRect*/,
       
   272         CBrowserFavouritesView& aView )
       
   273 	{
       
   274     // Construct listbox.
       
   275     iIconHandler = CreateListboxIconHandlerL();
       
   276     iListbox = CBrowserFavouritesListbox::NewL( iView->ApiProvider(), this, *iIconHandler );
       
   277     iListbox->SetListBoxObserver( &aView );
       
   278     iListbox->SetListboxCursorObserver( this );
       
   279     HBufC* buf = iCoeEnv->AllocReadResourceLC( ListboxEmptyTextResourceId() );
       
   280     iListbox->View()->SetListEmptyTextL( *buf );
       
   281     CleanupStack::PopAndDestroy();  // buf
       
   282 
       
   283 	}
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CBrowserFavouritesContainer::ConstructL
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CBrowserFavouritesContainer::ConstructL
       
   290 ( const TRect& aRect, CBrowserFavouritesView& aView )
       
   291 	{
       
   292     iView = &aView;
       
   293 
       
   294 	//CAknNavigationControlContainer* naviPane = iView->ApiProvider().Display().NaviPaneL();
       
   295 
       
   296     CreateWindowL();
       
   297     SetMopParent( iView );
       
   298 
       
   299     ConstructComponentControlsL( aRect, *iView );
       
   300 
       
   301     TAknsItemID tileIID = KAknsIIDSkinBmpListPaneNarrowA;
       
   302     TAknLayoutRect listGenPane;
       
   303     listGenPane.LayoutRect(iAvkonAppUi->ClientRect() , 
       
   304         AknLayout::list_gen_pane( 0 ));
       
   305 
       
   306     TAknLayoutRect column;
       
   307     column.LayoutRect(iAvkonAppUi->ClientRect() , 
       
   308         AknLayout::A_column());
       
   309 
       
   310     iSkinContext = CAknsListBoxBackgroundControlContext::NewL(
       
   311         KAknsIIDSkinBmpMainPaneUsual, 
       
   312         listGenPane.Rect(), //TODOVRa: Should come from LAF!
       
   313         EFalse, tileIID,
       
   314         column.Rect() ); //TODOVRa: Should come from LAF!
       
   315     SetRect( aRect );
       
   316     ActivateL();
       
   317     }
       
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CBrowserFavouritesContainer::MopSupplyObject
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 TTypeUid::Ptr CBrowserFavouritesContainer::MopSupplyObject( TTypeUid aId )
       
   325     {
       
   326     if( aId.iUid == MAknsControlContext::ETypeId  )
       
   327         {
       
   328         return MAknsControlContext::SupplyMopObject( aId, iSkinContext );
       
   329         }
       
   330 
       
   331 	return SupplyMopObject( aId, (MAknEditingStateIndicator*)NULL );
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CBrowserFavouritesContainer::HandleResourceChange
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CBrowserFavouritesContainer::HandleResourceChange( TInt aType )
       
   339     {
       
   340     // goes through all the subcomponents
       
   341     CCoeControl::HandleResourceChange( aType );
       
   342     
       
   343     if (aType == KEikDynamicLayoutVariantSwitch)
       
   344         {
       
   345         SetRect(iView->ClientRect());
       
   346         DrawDeferred();
       
   347         }
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CBrowserFavouritesContainer::FocusChanged
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 void CBrowserFavouritesContainer::FocusChanged( TDrawNow aDrawNow )
       
   355     {
       
   356 	if ( iListbox && iListbox->IsVisible() )
       
   357         {
       
   358         Listbox()->SetFocus( IsFocused(), aDrawNow );
       
   359         }
       
   360     }
       
   361 
       
   362 // End of File