uifw/EikStd/coctlsrc/AknToolbar.cpp
changeset 0 2f259fa3e83a
child 6 9f56a4e1b8ab
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Popup toolbar component
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <akntoolbar.h>
       
    21 #include <akntoolbarobserver.h> 
       
    22 #include <aknbutton.h>  // CAknButton
       
    23 #include <akntouchpane.h> // CAknTouchPane
       
    24 #include "akntoolbaritem.h" 
       
    25 #include <akntoolbarextension.h>
       
    26 
       
    27 #include <barsread.h>   // TResourceReader
       
    28 #include <eikfctry.h>   // SEikControlInfo
       
    29 #include <eikappui.h>   // CEikAppUi
       
    30 #include <eikpanic.h>
       
    31 #include <avkon.hrh>
       
    32 #include <eikon.hrh>    // toolbar flags
       
    33 #include <aknappui.h>  
       
    34 #include <systemwarninglevels.hrh> // KRAMGOODTHRESHOLD
       
    35 #include <eikbtgpc.h>   // CEikButtonGroupContainer
       
    36 #include <avkon.rsg>
       
    37 
       
    38 #include <aknViewAppUi.h>
       
    39 #include <aknview.h>
       
    40 #include <AknsDrawUtils.h>
       
    41 #include <AknsControlContext.h>
       
    42 #include <aknlayout.cdl.h>
       
    43 #include <skinlayout.cdl.h>
       
    44 #include <aknlayoutscalable_avkon.cdl.h>
       
    45 #include <AknUtils.h>
       
    46 #include <AknsFrameBackgroundControlContext.h>
       
    47 #include <layoutmetadata.cdl.h>
       
    48 #include <AknPriv.hrh>
       
    49 #include <hal.h>
       
    50 #include <AknsMaskedLayerBackgroundControlContext.h>
       
    51 #include <AknSgcc.h>
       
    52 #include <AknStatuspaneUtils.h>
       
    53 #include <AknsConstants.h>
       
    54 #include <centralrepository.h>
       
    55 #include <AknSkinsInternalCRKeys.h>
       
    56 #include <eikdialg.h>
       
    57 #include <eikapp.h>
       
    58 #include <AknDef.h>
       
    59 
       
    60 #include <AknTasHook.h> // for testability hooks
       
    61 #include <touchfeedback.h>
       
    62 #include <eikcolib.h>
       
    63 
       
    64 #include <gfxtranseffect/gfxtranseffect.h> 
       
    65 #include <akntranseffect.h>
       
    66 #include <akntransitionutils.h>
       
    67 #include "touchtoolbardata.h"
       
    68 
       
    69 // CONSTANTS
       
    70 const TInt KLineArrayGranularity = 5;
       
    71 
       
    72 const TInt KFocusedNone = -1;
       
    73 const TInt KSelectedNone = -2;
       
    74 
       
    75 const TInt KToolbarButtonBeforeTimeout = 300; 
       
    76 const TInt KToolbarButtonInViewTimeout = 5000; 
       
    77 
       
    78 const TInt KFixedtoolbarButtons = 3; // Number of buttons fixed toolbar has to have
       
    79 //const TUint32 KToolbarColorKey = 0x00000000; // ARGB
       
    80 
       
    81 const TUint32 KToolbarBgColor = 0x00000000;
       
    82 const TInt KToolBarBgAlpha = 0x7F;
       
    83 
       
    84 #ifdef RD_SCALABLE_UI_V2
       
    85 const TInt KDisableToolbar = 0xfff1; 
       
    86 const TInt KEnableToolbar = 0xfff2; 
       
    87 #endif
       
    88 
       
    89 // toolbar's internal flags
       
    90 enum TInternalFlags
       
    91     {
       
    92     EInIdle,                // toolbar is shown in idle view
       
    93     ESlidingSupported,      // whether toolbar can be show up with sliding effect if it is needed
       
    94     EWithSliding,           // defines whether toolbar should be shown with sliding effect
       
    95     ENoItemsVisible,        // used to check if no items are visible, this is needed to know if CBA needs to be created again
       
    96     EShown,                 // whether toolbar is shown right now( IsVisible() is not safe enough because can be changed from outside with MakeVisible()
       
    97     EShowingAgain,          // used to check if toolbar is shown again when allready shown, this is needed for not sliding when toolbar is allready shown
       
    98     ESliding,               // set if toolbar is currently sliding
       
    99     EFixedShown,            // tells to fixed toolbar if it needs to be shown when the layout is good
       
   100     ECalledFromFW,          // indicates to SetToolbarVisibility that it was called by the framework
       
   101     EAppOverrideVisibility, // indicates whether fixed toolbar visibility has been overriden by the application
       
   102     EDisabled,              // whether toolbar is disabled or not
       
   103     EDrawBackground,        // whether only toolbar background should be drawn
       
   104     EItemsHidden,            // whether application has called HideItemsAndDrawOnlyBackground
       
   105     EItemsHiddenWithPriority,    // whether application has called HideItemsAndDrawOnlyBackground with priority
       
   106     ESwitchForItemsHidden,   // switch for clearing EItemsHidden when the toolbar is to be shown
       
   107     EDefaultToolbar          //used for hideitemsanddrawonlybackground
       
   108     };
       
   109 
       
   110 // Control stack priority for toolbar to enable view deactivation
       
   111 const TInt KCoeStackToolbarPriority = ECoeStackPriorityCba; 
       
   112 
       
   113 
       
   114 // ============================ MEMBER FUNCTIONS ===============================
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CAknToolbar::NewL
       
   118 // Two-phased constructor.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C CAknToolbar* CAknToolbar::NewL( const TInt aResourceId )
       
   122     {
       
   123     CAknToolbar* self = NewLC( aResourceId );
       
   124     CleanupStack::Pop( self );
       
   125     return self;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CAknToolbar::NewLC
       
   130 // Two-phased constructor.
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C CAknToolbar* CAknToolbar::NewLC( const TInt aResourceId )
       
   134     {
       
   135     CAknToolbar* self = new ( ELeave ) CAknToolbar();
       
   136     CleanupStack::PushL( self );
       
   137     self->ConstructL();
       
   138     self->ConstructFromResourceL( aResourceId );
       
   139     AKNTASHOOK_ADDL( self, "CAknToolbar" );
       
   140     return self;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CAknToolbar::CAknToolbar
       
   145 // C++ default constructor.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 CAknToolbar::CAknToolbar()
       
   149     : iItems( KLineArrayGranularity ),
       
   150       iVisibleItems( KLineArrayGranularity ),
       
   151       iFocusedItem( KFocusedNone ),
       
   152       iSelectedItem( KSelectedNone ),
       
   153       iInitialFocusedItem ( KFocusedNone ),
       
   154       iLastFocusedItem(  KFocusedNone ),
       
   155       iOrientation( EAknOrientationHorizontal ), 
       
   156       iSoftkeyResource( R_AVKON_SOFTKEYS_SELECT_CLOSE__SELECT ),
       
   157       iPreviousItem( KSelectedNone ),
       
   158       iDrawingPriority( ECoeWinPriorityLow )
       
   159     {
       
   160     CEikApplication* application = iAvkonAppUi->Application();
       
   161 
       
   162     if ( application )
       
   163         {
       
   164         TVwsViewId idleView;
       
   165         TInt err = AknDef::GetPhoneIdleViewId( idleView );
       
   166         
       
   167         if ( application->AppDllUid() == idleView.iAppUid )
       
   168             {
       
   169             iInternalFlags.Set( EInIdle );
       
   170             }
       
   171         }
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // Destructor
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C CAknToolbar::~CAknToolbar()
       
   179     {
       
   180     AKNTASHOOK_REMOVE();
       
   181     SetFocus( EFalse );
       
   182     CEikonEnv::Static()->EikAppUi()->RemoveFromStack( this );
       
   183 
       
   184     iVisibleItems.Reset();
       
   185     iItems.ResetAndDestroy();
       
   186             
       
   187     delete iToolbarCba;    
       
   188     delete iFrameContext;
       
   189     delete iBgContext; 
       
   190     if ( iIdle && iIdle->IsActive() )
       
   191         {
       
   192         iIdle->Cancel(); 
       
   193         }
       
   194     delete iIdle; 
       
   195         
       
   196     iToolbarObserver = NULL; // not owned
       
   197 
       
   198     GfxTransEffect::Deregister( this );
       
   199 
       
   200     CTouchToolbarData* d = CTouchToolbarData::GetData( this );
       
   201     if ( d )
       
   202         {
       
   203         CAknTransitionUtils::RemoveObserver( d, 
       
   204             CAknTransitionUtils::EEventControlTransitionFinished );
       
   205         CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
       
   206         delete d;
       
   207         }
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CAknToolbar::ConstructL
       
   212 // Symbian 2nd phase constructor.
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CAknToolbar::ConstructL()
       
   216     {            
       
   217     // create control's window
       
   218     CreateWindowL();
       
   219     SetFocusing( EFalse ); 
       
   220 
       
   221     DrawableWindow()->SetPointerGrab( ETrue );
       
   222     DrawableWindow()->SetShadowDisabled( ETrue );
       
   223     DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   224 
       
   225     CEikonEnv::Static()->EikAppUi()->AddToStackL( this, KCoeStackToolbarPriority,
       
   226         ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   227 
       
   228     SetComponentsToInheritVisibility( ETrue );
       
   229     SetShown( EFalse );
       
   230     iBgIID = KAknsIIDNone;
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CAknToolbar::CountComponentControls
       
   235 // Gets the number of controls contained in a compound control.
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C TInt CAknToolbar::CountComponentControls() const
       
   239     {
       
   240     return iVisibleItems.Count();
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CAknToolbar::ConstructFromResourceL
       
   245 // Constructs controls from a resource file.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CAknToolbar::ConstructFromResourceL( TResourceReader& aReader )
       
   249     {
       
   250     aReader.ReadInt8(); //version, not used currently
       
   251     aReader.ReadInt8();  //lines, not used currently
       
   252     iFlags = aReader.ReadInt32();
       
   253 
       
   254     TBool enableTransparency = CAknEnv::Static()->TransparencyEnabled() && 
       
   255         ( ( !( iFlags & KAknToolbarFixed ) && 
       
   256                 !( iFlags & KAknToolbarFloatingUnTransparent ) ) || 
       
   257         ( iFlags & KAknToolbarTransparent && iFlags & KAknToolbarFixed ) ); 
       
   258 
       
   259 
       
   260     if( enableTransparency ) 
       
   261         {
       
   262         Window().SetRequiredDisplayMode( EColor16MA ); // Without this, ACT does not work in all cases in HW
       
   263         TInt err = Window().SetTransparencyAlphaChannel();
       
   264 
       
   265         if ( err == KErrNone ) // it should all ways be true in NGA
       
   266             {
       
   267             // Set the window initially completely transparent. This needs to be called only once.
       
   268             Window().SetBackgroundColor(~0);
       
   269             }
       
   270         }
       
   271 
       
   272 
       
   273 
       
   274     iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopupSub, 
       
   275             TRect(), TRect(), ( iFlags & KAknToolbarFixed )? ETrue : EFalse );  
       
   276 
       
   277     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
   278         KAknsIIDQsnBgScreen, TRect(), ETrue );
       
   279 
       
   280     SetWithSliding( ETrue ); 
       
   281 
       
   282     TInt softkeyResource = aReader.ReadUint32(); //softkeys
       
   283 
       
   284     if ( softkeyResource > 0 )
       
   285         {
       
   286         iSoftkeyResource = softkeyResource; 
       
   287         }
       
   288 
       
   289     const TInt controlCount = aReader.ReadInt16();
       
   290 
       
   291     for ( TInt ii = 0; ii < controlCount; ii++ )
       
   292         {
       
   293         CAknToolbarItem* item = ConstructControlLC( aReader ); 
       
   294         if ( item )
       
   295             {
       
   296             if ( IsSupportedItemType( item->ControlType() ) )
       
   297                 {
       
   298                 iItems.AppendL( item );
       
   299                 CleanupStack::Pop( item ); 
       
   300                 }
       
   301             else
       
   302                 {
       
   303                 // we don't support this type
       
   304                 CleanupStack::PopAndDestroy( item ); 
       
   305                 }
       
   306             }
       
   307         }
       
   308     aReader.ReadInt32(); // extension link, not used currently
       
   309 
       
   310 
       
   311     SetOrientation( iOrientation ); 
       
   312     
       
   313     // If toolbar is fixed need to set size for toolbar so that it can reduce 
       
   314     // the rects correctly. 
       
   315     if ( iFlags & KAknToolbarFixed )
       
   316         {
       
   317         if ( iFlags & KAknToolbarDefault )
       
   318             {
       
   319             SetDimmed( ETrue ); 
       
   320             }
       
   321         SetFocusing( EFalse ); 
       
   322         SetRect( CalculateSizeAndPosition() ); 
       
   323         }
       
   324 
       
   325     AdjustAllButtons();
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CAknToolbar::ConstructFromResourceL
       
   330 // Constructs controls from a resource file.
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CAknToolbar::ConstructFromResourceL( const TInt aResourceId ) 
       
   334     {    
       
   335     TResourceReader reader;
       
   336     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   337     ConstructFromResourceL( reader );
       
   338     CleanupStack::PopAndDestroy();
       
   339     iToolbarResourceId = aResourceId;
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CAknToolbar::ControlOrNull
       
   344 // Gets a pointer to the specified control.
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 EXPORT_C CCoeControl* CAknToolbar::ControlOrNull( const TInt aControlId ) const
       
   348     {
       
   349     for ( TInt ii = 0; ii < iItems.Count(); ii++ )
       
   350         {
       
   351         CAknToolbarItem* item = iItems[ii];
       
   352         if ( item->CommandId() == aControlId )
       
   353             {
       
   354             return item->Control();
       
   355             }
       
   356         }
       
   357     return NULL;
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CAknToolbar::SetToolbarVisibility
       
   362 // Shows or hides toolbar.
       
   363 // The position of the top left corner should be set in advance.
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 EXPORT_C void CAknToolbar::SetToolbarVisibility( const TBool aVisible )
       
   367     {
       
   368     SetToolbarVisibility( aVisible, ETrue );
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CAknToolbar::SetToolbarVisibility
       
   373 // If flag RD_SCALABLE_UI_V2 is not defined, toolbar is always focusing. 
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C void CAknToolbar::SetToolbarVisibility( const TBool aVisible,
       
   377                                                  const TBool aFocusing )
       
   378     {
       
   379     if ( iInternalFlags.IsSet( EDisabled ) )
       
   380         {
       
   381         return; 
       
   382         }
       
   383 
       
   384     TBool visible = aVisible;
       
   385     
       
   386     if ( iInternalFlags.IsSet( ECalledFromFW ) )
       
   387         {
       
   388         if ( iInternalFlags.IsSet( EAppOverrideVisibility ) )
       
   389             {
       
   390             visible = EFalse;
       
   391             }
       
   392         }
       
   393     else
       
   394         {
       
   395         if ( aVisible )
       
   396             {
       
   397             iInternalFlags.Clear( EAppOverrideVisibility );
       
   398             }
       
   399         else
       
   400             {
       
   401             iInternalFlags.Set( EAppOverrideVisibility );
       
   402             }
       
   403         }        
       
   404       
       
   405     if ( iFlags & KAknToolbarFixed )
       
   406         {
       
   407         if ( visible )
       
   408             {
       
   409             iInternalFlags.Set( EFixedShown );
       
   410             }
       
   411         else
       
   412             {
       
   413             iInternalFlags.Clear( EFixedShown );
       
   414             }
       
   415 
       
   416         if ( visible && ( !AknLayoutUtils::PenEnabled() || 
       
   417             ( !Layout_Meta_Data::IsLandscapeOrientation() && iFlags & KAknToolbarDefault ) ) )
       
   418             {
       
   419             return; 
       
   420             }
       
   421 
       
   422         }
       
   423     if ( iFlags & KAknToolbarAlwaysFocusing )
       
   424         {
       
   425         SetFocusing( ETrue );
       
   426         }
       
   427     else
       
   428         {
       
   429 #ifdef RD_SCALABLE_UI_V2
       
   430         if ( iFlags & KAknToolbarFixed )
       
   431             {
       
   432             SetFocusing( EFalse );             
       
   433             }
       
   434         else
       
   435             {
       
   436             SetFocusing( aFocusing );
       
   437             }
       
   438 #else
       
   439         SetFocusing( ETrue ); 
       
   440 #endif
       
   441         }
       
   442 
       
   443     if ( iInternalFlags.IsSet( EShown ) && visible )
       
   444         {
       
   445         if ( iFlags & KAknToolbarFixed )
       
   446             {
       
   447             return; 
       
   448             }
       
   449         if ( iInternalFlags.IsSet( EShown ) )
       
   450             {
       
   451             //using IsVisible() to avoide setting flag when toolbar is invisible.  
       
   452             if ( IsVisible() )
       
   453                 {
       
   454                 iInternalFlags.Set( EShowingAgain );
       
   455                 }            
       
   456             ShowViaIdle(); 
       
   457             }
       
   458 
       
   459         return;
       
   460         }
       
   461        
       
   462     if ( visible )
       
   463         {
       
   464         if ( !(iFlags & KAknToolbarFixed ) )
       
   465             {
       
   466             ShowViaIdle(); 
       
   467             }
       
   468         else
       
   469             {
       
   470             TRAPD( err, ShowToolbarL() );
       
   471             if ( err != KErrNone )
       
   472                 {
       
   473                 // if we failed then softkeys should be deleted just in case if they 
       
   474                 // were created before leave
       
   475                 delete iToolbarCba;
       
   476                 iToolbarCba = NULL;
       
   477                 
       
   478                 SetFocus( EFalse );
       
   479                 CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   480                     ~0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   481 
       
   482                 }
       
   483     
       
   484             }
       
   485 
       
   486         }
       
   487     else
       
   488         {
       
   489         TRAP_IGNORE( HideToolbarL() );
       
   490         }
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 static CTouchToolbarData* CheckRegistration( CCoeControl* aControl )
       
   497     {
       
   498     TInt key = reinterpret_cast<TInt>( aControl );
       
   499     TBool selectPressed = EFalse;
       
   500     
       
   501     CTouchToolbarData* data = reinterpret_cast<CTouchToolbarData*>( 
       
   502                                         CAknTransitionUtils::GetData( key ) );
       
   503 
       
   504     if ( data && data->SelectPressed() )
       
   505         {
       
   506         selectPressed = ETrue;
       
   507         }
       
   508 
       
   509     // If we're not already registered from the touchpane, register here for
       
   510     // a toolbar transition without the touchpane.
       
   511     if ( !data || !data->BetweenRegisterAndBegin() )
       
   512         {
       
   513         // We need to reset the data here, to make sure that
       
   514         // DemarcationRectSet() is false below.
       
   515         TRect rect;
       
   516         if ( CTouchToolbarData::SetData( aControl, rect, EFalse ) != 
       
   517              KErrNone )
       
   518             {
       
   519             return NULL;
       
   520             }
       
   521             
       
   522         // if already registered, then the toolbar client may have chosen a different
       
   523         // effect for the toolbar
       
   524         if( !GfxTransEffect::IsRegistered( aControl ) )
       
   525             {
       
   526             GfxTransEffect::Register( aControl, KGfxToolbarControlUid, EFalse );
       
   527             }
       
   528         GfxTransEffect::Enable();
       
   529 
       
   530         data = reinterpret_cast<CTouchToolbarData*>( 
       
   531                                         CAknTransitionUtils::GetData( key ) );
       
   532 
       
   533         if ( selectPressed )
       
   534             {
       
   535             data->SetSelectPressed( selectPressed );
       
   536             }    
       
   537         }
       
   538 
       
   539     return data;
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CAknToolbar::ShowToolbarL
       
   544 // Makes toolbar visible and activates it
       
   545 // The position of the top left corner should be set in advance.
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void CAknToolbar::ShowToolbarL()
       
   549     {
       
   550     if ( iFlags & KAknToolbarFixed &&
       
   551          ( !AknLayoutUtils::PenEnabled() ||
       
   552            iFlags & KAknToolbarDefault ) )
       
   553         {
       
   554         if ( IsVisible() )
       
   555             {
       
   556             MakeVisible( EFalse );
       
   557             }
       
   558         return;
       
   559         }
       
   560     iInternalFlags.Clear( EDrawBackground ); 
       
   561     // get specific settings from observer
       
   562     if ( iToolbarObserver )
       
   563         {
       
   564         iToolbarObserver->DynInitToolbarL( iToolbarResourceId, this );
       
   565         }
       
   566 
       
   567     // Check buttons if fixed toolbar
       
   568     if ( iFlags & KAknToolbarFixed && ! ( iFlags & KAknToolbarDefault ) )
       
   569         {
       
   570         CheckFixedToolbarButtonsL();
       
   571         }
       
   572 
       
   573     TRect rect( CalculateSizeAndPosition() );
       
   574 
       
   575     if ( iVisibleItems.Count() > 0  || ( iFlags & KAknToolbarFixed ) ) 
       
   576         {
       
   577         TBool tmpDisplayed = CEikonEnv::Static()->EikAppUi()->IsDisplayingMenuOrDialog();
       
   578         TBool tmpCondition = IsNonFocusing() ||( !IsNonFocusing() && tmpDisplayed ) ;
       
   579         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   580                 tmpCondition ? ECoeStackFlagRefusesFocus : ECoeStackFlagStandard, 
       
   581             ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   582         
       
   583         // This is called so toolbar can get focus if needed
       
   584         CEikonEnv::Static()->EikAppUi()->HandleStackChanged(); 
       
   585             
       
   586         TPoint startPos = rect.iTl;
       
   587         if ( iInternalFlags.IsSet( ESlidingSupported ) && iInternalFlags.IsSet( EWithSliding ) && 
       
   588             iOrientation == EAknOrientationHorizontal )
       
   589             {
       
   590             startPos.iX = -rect.Size().iWidth;
       
   591             }
       
   592         SetExtent( startPos, rect.Size() );
       
   593         UpdateControlPositions(); 
       
   594 
       
   595         TBool redrawStoreEnabled(EFalse);
       
   596         if( !CAknEnv::Static()->TransparencyEnabled() )
       
   597             {
       
   598             redrawStoreEnabled = Window().IsRedrawStoreEnabled();
       
   599             }
       
   600 
       
   601         CTouchToolbarData* data = CheckRegistration( this );      
       
   602         if ( data && !(iFlags & KAknToolbarFixed) && iAvkonAppUi->IsForeground() )
       
   603             {
       
   604             data->SetBetweenRegisterAndBegin( EFalse );
       
   605             
       
   606             CAknTransitionUtils::SetAllParents( this );
       
   607 
       
   608             Window().ClearRedrawStore( );
       
   609 
       
   610             GfxTransEffect::NotifyExternalState( ENotifyGlobalAbort );
       
   611             GfxTransEffect::Begin( this, KGfxControlAppearAction );
       
   612             }
       
   613 
       
   614         SetShown( ETrue );
       
   615 
       
   616         if ( data )
       
   617             {
       
   618             if ( data->DemarcationRectSet() )
       
   619                 {
       
   620                 GfxTransEffect::SetBeginDemarcation( this, data->DemarcationRect() );
       
   621                 }
       
   622             else
       
   623                 {        
       
   624                 GfxTransEffect::SetBeginDemarcation( this, rect );
       
   625                 }
       
   626 
       
   627             if ( CAknTransitionUtils::AddObserver( data, 
       
   628                          CAknTransitionUtils::EEventControlTransitionFinished,
       
   629                          reinterpret_cast<TDesC8*>( this ) ) == KErrNone )
       
   630                 {
       
   631                 GfxTransEffect::End( this );
       
   632                 }
       
   633             else
       
   634                 {
       
   635                 CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
       
   636                 delete data;
       
   637                 GfxTransEffect::Deregister( this );
       
   638                 }
       
   639 
       
   640             if ( !CAknEnv::Static()->TransparencyEnabled() && redrawStoreEnabled )
       
   641                 {
       
   642                 Window().EnableRedrawStore( ETrue );
       
   643                 }
       
   644             }
       
   645 
       
   646         // notify observer, for example touch pane, that toolbar was shown
       
   647         if ( Observer() )
       
   648             {
       
   649             Observer()->HandleControlEventL( this, 
       
   650                 MCoeControlObserver::EEventStateChanged );
       
   651             }
       
   652 
       
   653 
       
   654         // Default toolbar window priority to low to prevent toolbar
       
   655         // to be drawn on top of a full-screen application
       
   656         if ( iFlags & KAknToolbarDefault && !iInternalFlags.IsSet( EItemsHidden ) )
       
   657             {
       
   658             DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityLow );
       
   659             }
       
   660         else
       
   661             {
       
   662             DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNormal );    
       
   663             }
       
   664         
       
   665         if ( iFlags & KAknToolbarFixed )
       
   666             {
       
   667             SetOrdinalPositions();
       
   668             }
       
   669 
       
   670         ActivateL();
       
   671 
       
   672         //Also activating the items that are currently not in iVisibleItems
       
   673         for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
   674             {
       
   675             iItems[ii]->Control()->ActivateL(); 
       
   676             }
       
   677 
       
   678 
       
   679         // softkeys for focused toolbar only
       
   680         if ( !IsNonFocusing() && IsFocused() )
       
   681             {
       
   682             TBool withoutCba( iFlags & KAknToolbarWithoutCba );                    
       
   683             
       
   684             if ( !withoutCba )
       
   685                 {                    
       
   686                 if ( !iToolbarCba )
       
   687                     {
       
   688                     iToolbarCba = 
       
   689                         CEikButtonGroupContainer::NewL( CEikButtonGroupContainer::ECba, 
       
   690                                                         CEikButtonGroupContainer::EHorizontal,
       
   691                                                         this, iSoftkeyResource );
       
   692                     }
       
   693 
       
   694                 if ( iToolbarCba->ButtonGroup() )
       
   695                     {
       
   696                     static_cast<CEikCba*>( iToolbarCba->ButtonGroup() )->
       
   697                         SetSkinBackgroundId( KAknsIIDQsnBgAreaControlPopup );
       
   698                     }
       
   699                 }
       
   700             }
       
   701         else if ( iToolbarCba )
       
   702             {
       
   703             delete iToolbarCba;
       
   704             iToolbarCba = NULL;
       
   705             }
       
   706 
       
   707 
       
   708         if ( iInternalFlags.IsSet( ESlidingSupported ) && iInternalFlags.IsSet( EWithSliding ) )
       
   709             {
       
   710             SlideToolbar( rect.iTl );
       
   711             }
       
   712         else 
       
   713             {
       
   714             if ( !( iFlags & KAknToolbarFixed ) ) 
       
   715                 {
       
   716                 InitFocusedItemL( ETrue );
       
   717                 }
       
   718             DrawNow();
       
   719             }
       
   720         }
       
   721     else
       
   722         {
       
   723         SetShown( EFalse );
       
   724 
       
   725         // notify observer, for example touch pane, that toolbar was closed
       
   726         if ( Observer() )
       
   727             {
       
   728             Observer()->HandleControlEventL( this, 
       
   729                 MCoeControlObserver::EEventStateChanged );
       
   730             }
       
   731         }
       
   732 
       
   733     if ( !IsNonFocusing() )
       
   734         {
       
   735         SetFocus( ETrue );
       
   736         }
       
   737     }
       
   738  
       
   739 // -----------------------------------------------------------------------------
       
   740 // CAknToolbar::HideToolbar
       
   741 // Disactivate toolbar and hides it.
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CAknToolbar::HideToolbarL()
       
   745     {
       
   746     if ( !iInternalFlags.IsSet( EShown ) ) // nothing to hide
       
   747         {
       
   748         if ( iFlags & KAknToolbarDefault && !AknLayoutUtils::PenEnabled()
       
   749               && IsVisible() )
       
   750             {
       
   751             MakeVisible( EFalse );
       
   752             }
       
   753         return;
       
   754         }
       
   755 
       
   756    if ( iIdle && iIdle->IsActive() ) 
       
   757         {
       
   758         iIdle->Cancel();  
       
   759         }       
       
   760         
       
   761     if ( !IsNonFocusing() & IsFocused() )
       
   762         {
       
   763         SetFocus( EFalse );
       
   764         }
       
   765     
       
   766     iLastFocusedItem = iFocusedItem;
       
   767   
       
   768     SelectItemL( iSelectedItem, EFalse );
       
   769     if ( !IsNonFocusing() && iFocusedItem < iVisibleItems.Count() &&
       
   770         iFocusedItem >= 0 )
       
   771         {
       
   772         // Take focus away from control so that it shows tooltip next time
       
   773         iVisibleItems[iFocusedItem]->SetFocusL( EFalse, ETrue, ENoDrawNow, this );
       
   774         }
       
   775 
       
   776     if ( iToolbarCba )
       
   777         {
       
   778         // we don't want toolbar to be focused again after softkeys are deleted
       
   779         // so it shouldn't get focus as the top item
       
   780         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   781             ~0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   782                     
       
   783         delete iToolbarCba;
       
   784         iToolbarCba = NULL;
       
   785             
       
   786         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   787             0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys);
       
   788         
       
   789         }
       
   790 
       
   791     
       
   792     // Drawing toolbar background, when application hides toolbar
       
   793     if ( ( !iInternalFlags.IsSet( ECalledFromFW ) && !iInternalFlags.IsSet( EItemsHidden ) || 
       
   794         iInternalFlags.IsSet( EDrawBackground ) ) && iFlags & KAknToolbarFixed && 
       
   795         !( iFlags & KAknToolbarDsaMode ) && !( iFlags & KAknToolbarNoBackground ) ||
       
   796         iInternalFlags.IsSet( EItemsHidden ) && iFlags & KAknToolbarFixed &&
       
   797         !( iFlags & KAknToolbarDsaMode) && !( iFlags & KAknToolbarNoBackground ) ) 
       
   798         {
       
   799         
       
   800         if ( iInternalFlags.IsSet( EItemsHiddenWithPriority ) )
       
   801             {
       
   802             DrawableWindow()->SetOrdinalPosition( 0, iDrawingPriority );
       
   803             iInternalFlags.Clear( EItemsHiddenWithPriority );
       
   804             }
       
   805         else
       
   806             {
       
   807             DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityLow );            
       
   808             }
       
   809 
       
   810         iInternalFlags.Set( EDrawBackground );
       
   811 
       
   812         for ( TInt i = 0; i < iVisibleItems.Count(); i++ )
       
   813             {
       
   814             iVisibleItems[i]->Control()->MakeVisible( EFalse ); 
       
   815             }
       
   816           
       
   817         TRect rect = Rect(); 
       
   818         Window().Invalidate( rect );
       
   819         ActivateGc(); 
       
   820         Window().BeginRedraw( rect );
       
   821 
       
   822         CWindowGc& gc = SystemGc();
       
   823         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   824 
       
   825         AknsDrawUtils::Background( skin, iBgContext, this, gc, rect, 
       
   826             KAknsDrawParamNoClearUnderImage );
       
   827 
       
   828 
       
   829         Window().EndRedraw();
       
   830         DeactivateGc();
       
   831         iInternalFlags.Clear( EShown ); 
       
   832         }
       
   833     CTouchToolbarData* data = CheckRegistration( this );
       
   834 
       
   835     TBool foreground = iAvkonAppUi->IsForeground();
       
   836     // The window is created asynchronously (in CreateDelayedWindow(), so if 
       
   837     // you click the toolbar button quickly enough, you can get here before
       
   838     // the window has actually been created, and in that case the app would
       
   839     // crash, hence the check.
       
   840     if ( &Window() && data && !data->SelectPressed() && !(iFlags & KAknToolbarFixed)
       
   841         && foreground )
       
   842         {
       
   843         data->SetBetweenRegisterAndBegin( EFalse );
       
   844 
       
   845         GfxTransEffect::NotifyExternalState( ENotifyGlobalAbort );
       
   846         GfxTransEffect::Begin( this, KGfxControlDisappearAction );
       
   847         }
       
   848 
       
   849     if ( !iInternalFlags.IsSet( EDrawBackground ) )
       
   850         {
       
   851         SetShown( EFalse );
       
   852         }
       
   853 
       
   854     if ( &Window() && data && !data->SelectPressed() && !(iFlags & KAknToolbarFixed)
       
   855          && foreground )        
       
   856         {
       
   857         if ( data->DemarcationRectSet() )
       
   858             {
       
   859             GfxTransEffect::SetEndDemarcation( this, data->DemarcationRect() );
       
   860             }
       
   861         else
       
   862             {        
       
   863             GfxTransEffect::SetEndDemarcation( this, Rect() );
       
   864             }
       
   865 
       
   866         if ( CAknTransitionUtils::AddObserver( data, 
       
   867                 CAknTransitionUtils::EEventControlTransitionFinished,
       
   868                 reinterpret_cast<const TDesC8*>( this ) ) == KErrNone )
       
   869             {
       
   870             GfxTransEffect::End( this );
       
   871             }
       
   872         else
       
   873             {
       
   874             CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
       
   875             delete data;
       
   876             GfxTransEffect::Deregister( this );
       
   877             }
       
   878         }
       
   879     else if ( data )
       
   880         {
       
   881         CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
       
   882         delete data;
       
   883         }
       
   884     if ( !iInternalFlags.IsSet( EDrawBackground ) ) 
       
   885         {
       
   886         DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   887         }
       
   888 
       
   889     CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   890         ~0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   891 
       
   892     // notify observer, for example touch pane, that toolbar was closed
       
   893     if ( Observer() )
       
   894         {
       
   895         Observer()->HandleControlEventL( this, 
       
   896             MCoeControlObserver::EEventStateChanged );
       
   897         }
       
   898     }
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // CAknToolbar::SetItemDimmed
       
   902 // Dims (greys out) or undims a toolbar item.
       
   903 // -----------------------------------------------------------------------------
       
   904 //    
       
   905 EXPORT_C void CAknToolbar::SetItemDimmed( const TInt aCommandId, 
       
   906                                           const TBool aDimmed, 
       
   907                                           const TBool aDrawNow ) 
       
   908     {
       
   909     if( IsDimmed() )
       
   910     	return;
       
   911     CAknToolbarItem* item = ToolbarItemById( aCommandId );
       
   912     if ( item && item->Control() ) 
       
   913         {
       
   914         item->Control()->SetDimmed( aDimmed );
       
   915         if ( aDimmed && IsFocused() && item->Control()->IsFocused() )
       
   916             {
       
   917             // move selection to the next non-dimmed item
       
   918             if ( iFocusedItem == iVisibleItems.Count() - 1 )
       
   919                 {
       
   920                 TRAP_IGNORE( MoveHighlightL( 0, aDrawNow ) );
       
   921                 }
       
   922             else 
       
   923                 {
       
   924                 TRAP_IGNORE( MoveHighlightL( ToolbarVisibleIndexById( aCommandId ) + 1, 
       
   925                     aDrawNow ) );
       
   926                 }
       
   927             if ( iFocusedItem == KFocusedNone && item->Control()->IsFocused()  )
       
   928                 {
       
   929                 item->Control()->SetFocus( EFalse );
       
   930                 }
       
   931             }
       
   932         if ( aDrawNow )
       
   933             {
       
   934             item->Control()->DrawDeferred();
       
   935             }
       
   936         }
       
   937     }
       
   938 
       
   939 
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // CAknToolbar::HideItem
       
   943 // Hides or unhides a toolbar item.
       
   944 // -----------------------------------------------------------------------------
       
   945 //    
       
   946 EXPORT_C void CAknToolbar::HideItem( const TInt aCommandId,
       
   947                                      const TBool aHide, 
       
   948                                      const TBool aDrawNow )
       
   949     {
       
   950     CAknToolbarItem* item = ToolbarItemById( aCommandId );
       
   951     
       
   952     if ( !aHide && item && item->ControlType() == EAknCtButton && item->Control() )
       
   953         {
       
   954         CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
   955         button->ResetState();           
       
   956         }
       
   957     
       
   958     if ( item && item->Control() && item->IsHidden() != aHide ) 
       
   959         {
       
   960         item->SetHidden( aHide ); 
       
   961 
       
   962         TInt itemIndex; 
       
   963         TRect rect; 
       
   964         if ( aHide )
       
   965             {
       
   966             itemIndex = ToolbarVisibleIndexByControl( item->Control() ); 
       
   967             TRAP_IGNORE( SelectItemL ( itemIndex, EFalse ) ); 
       
   968             rect = CalculateSizeAndPosition();
       
   969             }
       
   970         else
       
   971             {
       
   972             rect = CalculateSizeAndPosition();
       
   973             itemIndex = ToolbarVisibleIndexByControl( item->Control() ); 
       
   974             }
       
   975         UpdateControlVisibility(); 
       
   976         UpdateControlPositions();
       
   977         
       
   978         if ( itemIndex >=0 && itemIndex <= iFocusedItem && !IsNonFocusing() )
       
   979             {
       
   980             if ( aHide )
       
   981                 {
       
   982                 // Check if the hidden item was the last
       
   983                 if ( iFocusedItem >= iVisibleItems.Count() )
       
   984                     {
       
   985                     iFocusedItem = iVisibleItems.Count() - 1; 
       
   986                     }
       
   987                 else if ( iVisibleItems.Count() > 0 && 
       
   988                           !( itemIndex == 0 && iFocusedItem == 0 ) && 
       
   989                           ( itemIndex != iFocusedItem ) )
       
   990                     {
       
   991                     TRAP_IGNORE( MoveHighlightL( iFocusedItem - 1, EFalse ) );    
       
   992                     }
       
   993                 }
       
   994             else 
       
   995                 {
       
   996                 TRAP_IGNORE( MoveHighlightL( iFocusedItem + 1, EFalse ) );    
       
   997                 }
       
   998             }
       
   999         if ( iInternalFlags.IsSet( EShown ) && aDrawNow )
       
  1000             {
       
  1001             if ( !( iFlags & KAknToolbarFlexiblePosition ) )
       
  1002                 {
       
  1003                 SetPosition( rect.iTl );
       
  1004                 }
       
  1005             SetSize( rect.Size() );
       
  1006             DrawDeferred();
       
  1007             }
       
  1008         }
       
  1009     else 
       
  1010         {
       
  1011         if ( aDrawNow )
       
  1012             {
       
  1013             DrawDeferred();
       
  1014             }
       
  1015         }
       
  1016     }
       
  1017 
       
  1018 
       
  1019 // -----------------------------------------------------------------------------
       
  1020 // CAknToolbar::SetToolbarObserver
       
  1021 // Sets the observer for the toolbar
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 EXPORT_C void CAknToolbar::SetToolbarObserver( MAknToolbarObserver* aObserver ) 
       
  1025     {
       
  1026     iToolbarObserver = aObserver;
       
  1027     }
       
  1028 
       
  1029 // -----------------------------------------------------------------------------
       
  1030 // CAknToolbar::ToolbarObserver
       
  1031 // Returns a pointer to the toolbar observer.
       
  1032 // -----------------------------------------------------------------------------
       
  1033 //
       
  1034 EXPORT_C MAknToolbarObserver* CAknToolbar::ToolbarObserver() 
       
  1035     {
       
  1036     return iToolbarObserver;
       
  1037     }
       
  1038 // -----------------------------------------------------------------------------
       
  1039 // CAknToolbar::HandlePointerEventL
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 EXPORT_C void CAknToolbar::HandlePointerEventL( 
       
  1043         const TPointerEvent& aPointerEvent )
       
  1044     {
       
  1045     if ( !DrawableWindow()->IsNonFading() && ( DrawableWindow()->IsFaded() 
       
  1046          || iInternalFlags.IsSet( EDrawBackground ) ) )
       
  1047         { 
       
  1048         return; 
       
  1049         } 
       
  1050 
       
  1051     TPointerEvent event( aPointerEvent );
       
  1052     TBool override ( EFalse );
       
  1053             
       
  1054     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )            
       
  1055         {
       
  1056         iPreviousItem = KSelectedNone;
       
  1057         }
       
  1058         
       
  1059     // Cancel previous button
       
  1060     if ( iPreviousItem >=0 && ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
  1061         aPointerEvent.iType == TPointerEvent::EButtonRepeat ) )
       
  1062         {
       
  1063         CAknToolbarItem* prevItem = iVisibleItems[iPreviousItem];
       
  1064 
       
  1065         if ( prevItem->Control() 
       
  1066             && ( prevItem->ControlType() == EAknCtButton
       
  1067             || prevItem->ControlType() == EAknCtToolbarExtension ) )
       
  1068             {
       
  1069             CAknButton* button = static_cast<CAknButton*>( prevItem->Control() );
       
  1070             if ( !button->TouchArea().Contains( aPointerEvent.iPosition ) )
       
  1071                 {
       
  1072                 event.iType = TPointerEvent::EButton1Up;
       
  1073                 button->HandlePointerEventL ( event );
       
  1074                 override = ETrue;
       
  1075                 iPreviousItem = KSelectedNone;
       
  1076                 }
       
  1077             }
       
  1078         }
       
  1079     
       
  1080     CAknToolbarItem* item = NULL;
       
  1081     for ( TInt ii = 0; ii < iVisibleItems.Count(); ++ii )
       
  1082         {
       
  1083         item = iVisibleItems[ii];
       
  1084         if ( item->Control() && 
       
  1085              item->Control()->Rect().Contains( aPointerEvent.iPosition ) )
       
  1086             {
       
  1087             if ( item->ControlType() == EAknCtButton || 
       
  1088                  item->ControlType() == EAknCtToolbarExtension )
       
  1089                 {
       
  1090                 CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  1091                 
       
  1092                 if ( button->TouchArea().Contains( aPointerEvent.iPosition ) )
       
  1093                     {
       
  1094                     if ( ii != iPreviousItem )
       
  1095                         {
       
  1096                         if ( !button->IsDimmed() )
       
  1097                             {
       
  1098                             MoveHighlightL( ii, ETrue ); 
       
  1099                             // focus has moved from one button to another due to dragging, 
       
  1100                             // give sensitive feedback
       
  1101                             if ( iPreviousItem != iFocusedItem && 
       
  1102                                 ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
  1103                                 aPointerEvent.iType == TPointerEvent::EButtonRepeat ) )
       
  1104                                 {
       
  1105                                 MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1106                                 if ( feedback )
       
  1107                                     {
       
  1108                                     feedback->InstantFeedback( ETouchFeedbackSensitiveButton );
       
  1109                                     }
       
  1110                                 }
       
  1111                             }
       
  1112 
       
  1113                         if ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
  1114                             aPointerEvent.iType == TPointerEvent::EButtonRepeat ) 
       
  1115                             {
       
  1116                             button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 0 );
       
  1117                             event.iType = TPointerEvent::EButton1Down;
       
  1118                             button->HandlePointerEventL( event );
       
  1119                             override = ETrue;
       
  1120                             }
       
  1121                         iPreviousItem = ii;
       
  1122                         }
       
  1123 
       
  1124                     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )                    
       
  1125                         {
       
  1126                         iDownItem = ii;
       
  1127                         button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 0 );
       
  1128                         }
       
  1129                 
       
  1130                     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
  1131                         {
       
  1132                         // Up and down events are in different items, give basic
       
  1133                         // feedback to the released item.
       
  1134                         if ( ii != iDownItem && !button->IsDimmed() )
       
  1135                             {
       
  1136                             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1137                             if ( feedback )
       
  1138                                 {
       
  1139                                 feedback->InstantFeedback( ETouchFeedbackBasicButton );
       
  1140                                 }
       
  1141                             }
       
  1142                 
       
  1143                         button->HandlePointerEventL( aPointerEvent );
       
  1144                         override = ETrue;
       
  1145                         }
       
  1146                     }
       
  1147                 else
       
  1148                     {
       
  1149                     // Button touchArea did not contain pointerevent
       
  1150                     break;
       
  1151                     }
       
  1152                     
       
  1153                 }
       
  1154             SelectItemL( ii, ETrue );
       
  1155             }
       
  1156         }
       
  1157 
       
  1158     if ( !override )        
       
  1159         {
       
  1160         CAknControl::HandlePointerEventL( aPointerEvent );        
       
  1161         }
       
  1162     }
       
  1163 
       
  1164 // -----------------------------------------------------------------------------
       
  1165 // CAknToolbar::HandleResourceChange
       
  1166 // Handles a change to the control's resources.
       
  1167 // -----------------------------------------------------------------------------
       
  1168 //
       
  1169 EXPORT_C void CAknToolbar::HandleResourceChange( TInt aType ) 
       
  1170     {
       
  1171     // Base class method is not called because only visible components are
       
  1172     // returned by ComponentControl -> all icons wouldn't be updated.
       
  1173     
       
  1174     if ( aType == KAknToolbarSetHiddenAndDrawBackground )
       
  1175         {
       
  1176         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1177             {
       
  1178             aType = KAknToolbarSetHidden;
       
  1179             }
       
  1180         else
       
  1181             {
       
  1182             if ( IsShown() )
       
  1183                 {
       
  1184                 iInternalFlags.Set( ECalledFromFW );
       
  1185                 if ( !( iFlags & KAknToolbarNoBackground ) )
       
  1186                     {
       
  1187                     iInternalFlags.Set( EDrawBackground );                  
       
  1188                     }
       
  1189                 
       
  1190                 SetToolbarVisibility(EFalse, EFalse);
       
  1191                 iInternalFlags.Clear( ECalledFromFW );
       
  1192                 }
       
  1193             else if ( iFlags & KAknToolbarDefault )
       
  1194                 {
       
  1195                 iInternalFlags.Clear( EFixedShown );
       
  1196                 }
       
  1197             return;
       
  1198             }
       
  1199         }
       
  1200         
       
  1201     if ( aType == KAknToolbarSetVisible && iFlags & KAknToolbarDefault 
       
  1202             && !AknLayoutUtils::PenEnabled() )
       
  1203         {
       
  1204         return; 
       
  1205         }
       
  1206     else if ( aType == KAknToolbarSetVisible && !IsShown() )
       
  1207         {
       
  1208         iInternalFlags.Set( ECalledFromFW );
       
  1209         iInternalFlags.Clear( EDrawBackground ); 
       
  1210         SetToolbarVisibility(ETrue, EFalse);
       
  1211         iInternalFlags.Clear( ECalledFromFW );
       
  1212         }
       
  1213     else if ( aType == KAknToolbarSetHidden && IsShown() )
       
  1214         {
       
  1215         iInternalFlags.Set( ECalledFromFW );
       
  1216         iInternalFlags.Clear( EDrawBackground ); 
       
  1217         SetToolbarVisibility(EFalse, EFalse);
       
  1218         iInternalFlags.Clear( ECalledFromFW );
       
  1219         }
       
  1220     else if ( aType == KAknToolbarSetHidden && 
       
  1221               iInternalFlags.IsSet( EFixedShown ) )
       
  1222         {
       
  1223         iInternalFlags.Clear( EFixedShown );
       
  1224         }
       
  1225             
       
  1226     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1227         {
       
  1228         iPreviousItem = KSelectedNone;
       
  1229         for(TInt i = 0; i < iVisibleItems.Count(); i++)
       
  1230             {
       
  1231             CAknToolbarItem* item = iVisibleItems[ i ];
       
  1232             CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  1233             button->ResetState();
       
  1234             }
       
  1235         if ( iFlags & KAknToolbarDefault && !AknLayoutUtils::PenEnabled() && IsVisible() )
       
  1236             {
       
  1237             TRAP_IGNORE( HideToolbarL() ); 
       
  1238             return; 
       
  1239             }
       
  1240         else if ( iFlags & KAknToolbarFixed )
       
  1241             {
       
  1242             if ( Layout_Meta_Data::IsLandscapeOrientation() && AknLayoutUtils::PenEnabled() )
       
  1243                 {
       
  1244                 iOrientation = EAknOrientationVertical; 
       
  1245                 if ( ( iInternalFlags.IsSet( EFixedShown ) 
       
  1246                     || ( iInternalFlags.IsSet( EItemsHidden )
       
  1247                     && iInternalFlags.IsSet( EAppOverrideVisibility ) ) )
       
  1248                     && !iInternalFlags.IsSet( EShown ) )
       
  1249                     {
       
  1250                     // When the window is faded (e.g. while showing
       
  1251                     // some note, ShowViaIdle is too slow
       
  1252                     if ( DrawableWindow()->IsFaded() )
       
  1253                         {
       
  1254                         TRAP_IGNORE( ShowToolbarL() );
       
  1255                         }
       
  1256                     else
       
  1257                         {
       
  1258                         ShowViaIdle();                          
       
  1259                         }
       
  1260                     }
       
  1261                 }
       
  1262             else if ( !( iFlags & KAknToolbarDefault ) && AknLayoutUtils::PenEnabled() )
       
  1263                 {
       
  1264                 iOrientation = EAknOrientationHorizontal; 
       
  1265                 if ( iInternalFlags.IsSet( EFixedShown ) && !iInternalFlags.IsSet( EShown ) )
       
  1266                     {
       
  1267                     // If showing toolbar because HideItemsAndDrawOnlyBackground( EFalse )
       
  1268                     // called, show toolbar immediately (ShowViaIdle is too slow)
       
  1269                     if ( iInternalFlags.IsSet( EItemsHidden ) )
       
  1270                         {
       
  1271                         iInternalFlags.Clear( EItemsHidden );
       
  1272                         TRAP_IGNORE( ShowToolbarL() ); 
       
  1273                         }
       
  1274                     else
       
  1275                         {
       
  1276                         ShowViaIdle();
       
  1277                         }
       
  1278                     }
       
  1279                 }
       
  1280             else if ( ( !AknLayoutUtils::PenEnabled() || iFlags & KAknToolbarDefault ) && iInternalFlags.IsSet( EShown ) )
       
  1281                 {
       
  1282                 TRAP_IGNORE( HideToolbarL() ); 
       
  1283                 return; 
       
  1284                 }
       
  1285             else
       
  1286                 {
       
  1287                 iOrientation = EAknOrientationHorizontal; 
       
  1288                 }
       
  1289                 
       
  1290             // Ordinal positions must be set in both landscape & portrait. In
       
  1291             // portrait that is needed in order to bring dialogs on top of the
       
  1292             // fixed toolbar whereas in landscape that is needed to disable
       
  1293             // toolbar's buttons when there is a dialog on the screen.
       
  1294             if ( iInternalFlags.IsSet( EShown ) )
       
  1295                 {
       
  1296                 SetOrdinalPositions();
       
  1297                 }
       
  1298             }
       
  1299 
       
  1300         //Recalculate size no matter whether toolbar is visible.
       
  1301         {
       
  1302         TRect rect( CalculateSizeAndPosition() );
       
  1303 
       
  1304         if ( !( iFlags & KAknToolbarFlexiblePosition ) )
       
  1305             {
       
  1306             SetPosition( rect.iTl );
       
  1307             }
       
  1308         else 
       
  1309             {
       
  1310             UpdateControlPositions(); 
       
  1311             }
       
  1312 
       
  1313         SetSize( rect.Size() );
       
  1314         }
       
  1315             
       
  1316         if ( iInternalFlags.IsSet( EShown ) )
       
  1317         	{
       
  1318             if ( IsFocused() )
       
  1319                 {
       
  1320                 TRAP_IGNORE( MoveHighlightL( iFocusedItem, EFalse ) );
       
  1321                 }
       
  1322             
       
  1323             }
       
  1324         }
       
  1325         
       
  1326     for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
  1327         {
       
  1328         iItems[ii]->Control()->HandleResourceChange( aType );
       
  1329         }
       
  1330         
       
  1331     if ( iInternalFlags.IsSet( EShown ) && ( aType == KAknsMessageSkinChange || 
       
  1332         aType == KEikDynamicLayoutVariantSwitch ) )
       
  1333         {
       
  1334         if ( aType == KAknsMessageSkinChange )
       
  1335             {
       
  1336             DrawDeferred();    
       
  1337             }
       
  1338         }
       
  1339         
       
  1340     if ( aType == KEikMessageFadeAllWindows )
       
  1341         {
       
  1342         // non-fixed toolbar should not be focusable when its window is faded
       
  1343         if ( !( iFlags & KAknToolbarFixed ) && IsVisible() && !IsNonFocusing() )
       
  1344             {
       
  1345             // Cope with a situation where a focusing toolbar was visible when
       
  1346             // the application lost foreground when e.g. a task swapper was shown.
       
  1347             // In that case TopFocusedControl == NULL since it has not been set
       
  1348             // yet in CCoeAppUi. KEikMessageFadeAllWindows is sent via AknPopupFader
       
  1349             // which is a window server message observer i.e. it gets all ws
       
  1350             // events before any other processing is done.
       
  1351             CAknAppUi* appUi = iAvkonAppUi;
       
  1352 
       
  1353             CCoeControl* topControl = appUi->TopFocusedControl();
       
  1354             
       
  1355             if ( topControl )
       
  1356                 {
       
  1357                 appUi->UpdateStackedControlFlags( this, ~0, 
       
  1358                     ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
  1359 
       
  1360                 appUi->HandleStackChanged();                
       
  1361                 }
       
  1362             }
       
  1363         }
       
  1364     else if ( aType == KEikMessageUnfadeWindows )    
       
  1365         {
       
  1366         if ( !( iFlags & KAknToolbarFixed ) && IsVisible() && !IsNonFocusing() )
       
  1367             {
       
  1368             // window is unfaded, toolbar can be focused again
       
  1369             CAknAppUi* appUi = iAvkonAppUi;
       
  1370             
       
  1371             appUi->UpdateStackedControlFlags( this, ECoeStackFlagStandard, 
       
  1372                 ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
  1373             
       
  1374             appUi->HandleStackChanged();
       
  1375             }
       
  1376         }
       
  1377     }
       
  1378 
       
  1379 
       
  1380 // -----------------------------------------------------------------------------
       
  1381 // CAknToolbar::HandleControlEventL
       
  1382 // Handles an event from an observed toolbar item.
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 EXPORT_C void CAknToolbar::HandleControlEventL( CCoeControl* aControl,
       
  1386                                                 TCoeEvent aEventType )
       
  1387     {
       
  1388     switch ( aEventType )
       
  1389         {
       
  1390         
       
  1391         case MCoeControlObserver::EEventRequestCancel:
       
  1392             {
       
  1393             CAknToolbarItem* item = ToolbarItemByControl( aControl );
       
  1394             if ( item )
       
  1395                 {
       
  1396                 if ( item->ControlType() == EAknCtButton ||
       
  1397                      item->ControlType() == EAknCtToolbarExtension )
       
  1398                     {
       
  1399                     CAknButton* button = static_cast<CAknButton*>( aControl );
       
  1400                     button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout,
       
  1401                         KToolbarButtonInViewTimeout );
       
  1402                     }
       
  1403                 }
       
  1404             break;
       
  1405             }
       
  1406         case MCoeControlObserver::EEventRequestExit:
       
  1407             {
       
  1408             HideToolbarL();
       
  1409             break;
       
  1410             }
       
  1411         case MCoeControlObserver::EEventStateChanged:
       
  1412             {
       
  1413             iEventModifiers &= ~(ELongPress | ELongPressEnded); 
       
  1414 
       
  1415             if ( ( iFlags & KAknToolbarLastUsedItemFocused ) && 
       
  1416                 !IsNonFocusing() && IsFocused() )
       
  1417                 {                
       
  1418                 iInitialFocusedItem = iFocusedItem;
       
  1419                 }
       
  1420             CAknToolbarItem* item = ToolbarItemByControl( aControl );
       
  1421             if ( item )
       
  1422                 {
       
  1423                 if ( item->ControlType() == EAknCtButton || 
       
  1424                      item->ControlType() == EAknCtToolbarExtension)
       
  1425                     {
       
  1426                     CAknButton* button = static_cast<CAknButton*>( aControl ); 
       
  1427                     button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 
       
  1428                         KToolbarButtonInViewTimeout ); 
       
  1429                     }
       
  1430                 
       
  1431                 if ( iToolbarObserver )
       
  1432                     {
       
  1433                     // We don't want to start a transition if the toolbar
       
  1434                     // is closed because select/ok was pressed.
       
  1435                     CTouchToolbarData* d = CTouchToolbarData::GetData( this );
       
  1436                     if ( !d )
       
  1437                         {
       
  1438                         TRect rect;
       
  1439                         if ( CTouchToolbarData::SetData( this, rect, EFalse ) != 
       
  1440                                 KErrNone )
       
  1441                             {
       
  1442                             return;
       
  1443                             }
       
  1444                             
       
  1445                         d = CTouchToolbarData::GetData( this );    
       
  1446                         }
       
  1447                     
       
  1448                     if (NULL != d)
       
  1449                         {
       
  1450                         d->SetSelectPressed( ETrue );
       
  1451                         }
       
  1452                     
       
  1453                     if ( iAvkonAppUi && iAvkonAppUi->IsForeground() )
       
  1454                         {
       
  1455                         iToolbarObserver->OfferToolbarEventL( item->CommandId() );
       
  1456                         }
       
  1457                     d = CTouchToolbarData::GetData( this );
       
  1458                     if ( d )
       
  1459                         {
       
  1460                         d->SetSelectPressed( EFalse );
       
  1461                         }
       
  1462                     }
       
  1463                 }
       
  1464             break;
       
  1465             }
       
  1466         case MCoeControlObserver::EEventRequestFocus:
       
  1467             {
       
  1468             if ( !IsNonFocusing() && !aControl->IsDimmed() )
       
  1469                 {
       
  1470                 CAknToolbarItem* item = ToolbarItemByControl( aControl ); 
       
  1471                 if ( item->ControlType() == EAknCtButton || 
       
  1472                      item->ControlType() == EAknCtToolbarExtension )
       
  1473                     {
       
  1474                     CAknButton* button = static_cast<CAknButton*>(aControl); 
       
  1475                     if ( button->IsDimmed() )
       
  1476                         {
       
  1477                         break; 
       
  1478                         }
       
  1479                     }
       
  1480                 // focus should be moved to this control
       
  1481                 TInt index = ToolbarVisibleIndexByControl( aControl );
       
  1482                 if ( index == KErrNotFound )
       
  1483                     {
       
  1484                     return;
       
  1485                     }
       
  1486                 if ( !IsFocused() )
       
  1487                     {
       
  1488                     iLastFocusedItem = index;
       
  1489                     SetFocus( ETrue, EDrawNow );
       
  1490                     }
       
  1491                 else
       
  1492                     {
       
  1493                     MoveHighlightL( index, ETrue );
       
  1494                     }
       
  1495                 }
       
  1496             break;
       
  1497             }
       
  1498         case CAknButton::ELongPressEvent: 
       
  1499         case CAknButton::ELongPressEndedEvent: 
       
  1500             {
       
  1501             iEventModifiers &= ~( ELongPressEnded | ELongPress); 
       
  1502             iEventModifiers |= ( aEventType == CAknButton::ELongPressEvent ) ? 
       
  1503                 ELongPress : ELongPressEnded;  
       
  1504             CAknToolbarItem* item = ToolbarItemByControl( aControl );
       
  1505 
       
  1506             if ( item && iToolbarObserver && iAvkonAppUi && iAvkonAppUi->IsForeground() )
       
  1507                 {
       
  1508                 iToolbarObserver->OfferToolbarEventL( item->CommandId() );
       
  1509                 }
       
  1510             break; 
       
  1511             }
       
  1512         default:
       
  1513             {
       
  1514             break;
       
  1515             }
       
  1516         }
       
  1517     }
       
  1518 
       
  1519 // -----------------------------------------------------------------------------
       
  1520 // CAknToolbar::PositionChanged
       
  1521 // -----------------------------------------------------------------------------
       
  1522 //
       
  1523 EXPORT_C void CAknToolbar::PositionChanged()
       
  1524     {
       
  1525     if ( iFlags & KAknToolbarFlexiblePosition && !iInternalFlags.IsSet( ESliding ) )
       
  1526         {
       
  1527         SetSize( CalculateSizeAndPosition().Size() );
       
  1528         
       
  1529         if ( IsFocused() )
       
  1530             {
       
  1531             TRAP_IGNORE( MoveHighlightL( iFocusedItem, EFalse ) ); 
       
  1532             }
       
  1533         }
       
  1534 
       
  1535     UpdateControlPositions(); 
       
  1536     }
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 // CAknToolbar::ProcessCommandL
       
  1540 // From MEikCommandObserver.
       
  1541 // Processes user commands.
       
  1542 // -----------------------------------------------------------------------------
       
  1543 //     
       
  1544 EXPORT_C void CAknToolbar::ProcessCommandL( TInt aCommandId )
       
  1545     {
       
  1546     switch ( aCommandId )
       
  1547         {            
       
  1548         case EAknSoftkeySelect:
       
  1549             {
       
  1550             // shouldn't be KFocusedNone either
       
  1551             __ASSERT_ALWAYS( ( iFocusedItem >= 0 && iFocusedItem < iVisibleItems.Count() ), 
       
  1552                 Panic( EEikPanicInvalidIndex )); 
       
  1553                 
       
  1554             if ( iFlags & KAknToolbarLastUsedItemFocused )
       
  1555                 {                
       
  1556                 iInitialFocusedItem = iFocusedItem;            
       
  1557                 }
       
  1558 
       
  1559             CAknToolbarItem* item = iVisibleItems[iFocusedItem];
       
  1560             if ( item && item->Control() )
       
  1561                 {
       
  1562                 if ( !( item->ControlType() == EAknCtButton || 
       
  1563                         item->ControlType() == EAknCtToolbarExtension ) )
       
  1564                     {
       
  1565                     SelectItemL( iFocusedItem, EFalse );
       
  1566                     if ( iToolbarObserver )
       
  1567                         {
       
  1568                         iToolbarObserver->OfferToolbarEventL( item->CommandId() );
       
  1569                         }
       
  1570                     }
       
  1571                 }
       
  1572             break;
       
  1573             }
       
  1574             
       
  1575         case EAknSoftkeyClose:
       
  1576         case EAknSoftkeyDone:
       
  1577             {
       
  1578             HideToolbarL();
       
  1579             break;
       
  1580             }
       
  1581 
       
  1582         default:
       
  1583             {
       
  1584             break;
       
  1585             }
       
  1586         }
       
  1587     }
       
  1588 
       
  1589 // -----------------------------------------------------------------------------
       
  1590 // CAknToolbar::SetDimmed
       
  1591 // Sets toolbar dimmed. Doesn't redraw.
       
  1592 // -----------------------------------------------------------------------------
       
  1593 //    
       
  1594 EXPORT_C void CAknToolbar::SetDimmed( TBool aDimmed ) 
       
  1595     {
       
  1596     for ( TInt ii = 0; ii < iItems.Count(); ii++ )
       
  1597         {
       
  1598         CAknToolbarItem* item = iItems[ii];
       
  1599         if ( item && item->Control() )
       
  1600             {
       
  1601             item->Control()->SetDimmed( aDimmed );
       
  1602             }
       
  1603         }
       
  1604     if ( aDimmed && !IsNonFocusing() )
       
  1605         {
       
  1606         iFocusedItem = KFocusedNone;
       
  1607         if ( !iToolbarCba )
       
  1608             {
       
  1609             return; 
       
  1610             }
       
  1611         iToolbarCba->MakeCommandVisibleByPosition( 
       
  1612             CEikButtonGroupContainer::ELeftSoftkeyPosition, EFalse ); 
       
  1613         iToolbarCba->MakeCommandVisibleByPosition( 
       
  1614             CEikButtonGroupContainer::EMiddleSoftkeyPosition, EFalse ); 
       
  1615         iToolbarCba->DrawDeferred(); 
       
  1616         }
       
  1617     CCoeControl::SetDimmed( aDimmed );
       
  1618     }
       
  1619 
       
  1620 // -----------------------------------------------------------------------------
       
  1621 // CAknToolbar::OfferKeyEventL
       
  1622 // Handles key events.
       
  1623 // -----------------------------------------------------------------------------
       
  1624 //    
       
  1625 EXPORT_C TKeyResponse CAknToolbar::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
  1626                                                    TEventCode aType )
       
  1627     {
       
  1628     if ( aKeyEvent.iCode == EKeyEscape )
       
  1629         {
       
  1630         return EKeyWasNotConsumed; 
       
  1631         }
       
  1632         
       
  1633     if ( IsNonFocusing() || !IsFocused() )
       
  1634         {
       
  1635         if ( iSelectedItem != KSelectedNone )
       
  1636             {
       
  1637             CAknToolbarItem* item = iVisibleItems[iSelectedItem];
       
  1638             if ( item->Control() && !item->RefusesKeys() )
       
  1639                 {
       
  1640                 return item->Control()->OfferKeyEventL( aKeyEvent, aType );
       
  1641                 }
       
  1642             }
       
  1643         return EKeyWasNotConsumed;
       
  1644         }
       
  1645 
       
  1646     if ( ( iFlags & KAknToolbarWithoutCba ) && 
       
  1647         !IsNonFocusing() && IsFocused() )
       
  1648         {
       
  1649         if ( aKeyEvent.iCode == EKeyCBA1 || aKeyEvent.iCode == EKeyCBA2 || 
       
  1650              aKeyEvent.iScanCode == EStdKeyDevice0 )
       
  1651             {
       
  1652             return EKeyWasNotConsumed;                 
       
  1653             }
       
  1654         
       
  1655         CEikMenuPane* menuPane = NULL;
       
  1656         TBool useFactoryMenu = ETrue;
       
  1657         
       
  1658         // if this is a view app then ask menu from the currently active view
       
  1659         TVwsViewId uid;
       
  1660         
       
  1661         if ( iAvkonAppUi->GetActiveViewId( uid ) == KErrNone )
       
  1662             {
       
  1663             if ( uid.iAppUid != uid.iViewUid )
       
  1664                 {
       
  1665                 CEikMenuBar* menuBar = iAvkonViewAppUi->View( uid.iViewUid )->MenuBar();
       
  1666                 
       
  1667                 if ( menuBar )
       
  1668                     {
       
  1669                     menuPane = menuBar->MenuPane();
       
  1670                     useFactoryMenu = EFalse;
       
  1671                     }
       
  1672                 }
       
  1673             }
       
  1674 
       
  1675         // use factory menu if available
       
  1676         if ( useFactoryMenu )
       
  1677             {
       
  1678             CEikMenuBar* menuBar = iEikonEnv->AppUiFactory( *iAvkonAppUi )->MenuBar();
       
  1679             
       
  1680             if ( menuBar )
       
  1681                 {
       
  1682                 menuPane = menuBar->MenuPane();
       
  1683                 }
       
  1684             }
       
  1685         // if menu is displayed then toolbar should not use key events.
       
  1686         if ( menuPane )
       
  1687             {
       
  1688             if ( menuPane->IsVisible() )
       
  1689                 {
       
  1690                 return EKeyWasNotConsumed;
       
  1691                 }
       
  1692             }
       
  1693         }
       
  1694     
       
  1695     TInt count = iItems.Count();
       
  1696     if ( count == 0 || iFocusedItem == KFocusedNone )
       
  1697         {
       
  1698         return EKeyWasNotConsumed;
       
  1699         }
       
  1700     
       
  1701     CAknToolbarItem* item = iVisibleItems[iFocusedItem];
       
  1702     
       
  1703     if ( ( !item || !item->IsSelected() ) && aType == EEventKey )
       
  1704         {
       
  1705         switch ( aKeyEvent.iCode )
       
  1706             {
       
  1707             case EKeyRightArrow:
       
  1708             case EKeyDownArrow:
       
  1709             case EKeyTab:
       
  1710                 if ( ( aKeyEvent.iCode == EKeyDownArrow  &&
       
  1711                     iOrientation != EAknOrientationVertical ) || 
       
  1712                     ( aKeyEvent.iCode == EKeyRightArrow  && 
       
  1713                     iOrientation != EAknOrientationHorizontal ) )
       
  1714                     {
       
  1715                     return EKeyWasNotConsumed;
       
  1716                     }
       
  1717 
       
  1718                 if ( count == 1 )
       
  1719                     {
       
  1720                     return EKeyWasConsumed;
       
  1721                     }
       
  1722                 
       
  1723                 if ( iFocusedItem + 1 < iVisibleItems.Count() )
       
  1724                     {
       
  1725                     MoveHighlightL( iFocusedItem + 1, ETrue );
       
  1726                     }
       
  1727                 else
       
  1728                     {
       
  1729                     MoveHighlightL( 0, ETrue );
       
  1730                     }
       
  1731                 return EKeyWasConsumed;
       
  1732                 
       
  1733             case EKeyLeftArrow:
       
  1734             case EKeyUpArrow:
       
  1735                 if ( ( aKeyEvent.iCode == EKeyUpArrow &&
       
  1736                     iOrientation != EAknOrientationVertical ) || 
       
  1737                     ( aKeyEvent.iCode == EKeyLeftArrow && 
       
  1738                     iOrientation != EAknOrientationHorizontal ) )
       
  1739                     {
       
  1740                     return EKeyWasNotConsumed;
       
  1741                     }
       
  1742                     
       
  1743                 if ( count == 1 )
       
  1744                     {
       
  1745                     return EKeyWasConsumed;
       
  1746                     }
       
  1747                 
       
  1748                 if ( iFocusedItem - 1 >= 0 )
       
  1749                     {
       
  1750                     MoveHighlightL( iFocusedItem - 1, ETrue, EFalse, ETrue );
       
  1751                     }
       
  1752                 else
       
  1753                     {
       
  1754                     MoveHighlightL( iVisibleItems.Count() - 1, ETrue, EFalse, 
       
  1755                                      ETrue );
       
  1756                     }
       
  1757                 return EKeyWasConsumed;
       
  1758                 
       
  1759             default:
       
  1760                 break;
       
  1761             }
       
  1762         }
       
  1763         
       
  1764     // All key events can be given to buttons, other toolbar items must 
       
  1765     // be seleceted to get events
       
  1766     if ( item && item->Control() )
       
  1767         {
       
  1768         if ( ( item->ControlType() == EAknCtButton ) || 
       
  1769            ( item->ControlType() == EAknCtToolbarExtension )  || item->IsSelected() )
       
  1770             {
       
  1771             if ( aKeyEvent.iScanCode == EStdKeyDevice0 )
       
  1772                 {
       
  1773                 TKeyEvent keyEvent = aKeyEvent; 
       
  1774                 // Button does not accept key events if the code is EStdKeyDevice0
       
  1775                 // so changing the key event to EStdKeyDevice3    
       
  1776                 keyEvent.iScanCode = EStdKeyDevice3; 
       
  1777                 item->Control()->OfferKeyEventL( keyEvent, aType );
       
  1778                 }
       
  1779             else
       
  1780                 {
       
  1781                 item->Control()->OfferKeyEventL( aKeyEvent, aType );
       
  1782                 }
       
  1783             }
       
  1784         }
       
  1785 
       
  1786     return EKeyWasConsumed; // To avoid loss of focus
       
  1787     }
       
  1788 
       
  1789 // -----------------------------------------------------------------------------
       
  1790 // CAknToolbar::InputCapabilities
       
  1791 // Gets the control's input capabilities.
       
  1792 // -----------------------------------------------------------------------------
       
  1793 //    
       
  1794 EXPORT_C TCoeInputCapabilities CAknToolbar::InputCapabilities() const 
       
  1795     {
       
  1796     return TCoeInputCapabilities::EAllText;
       
  1797     }
       
  1798 
       
  1799 // -----------------------------------------------------------------------------
       
  1800 // CAknToolbar::MopSupplyObject
       
  1801 // Retrieves an object of the same type as that encapsulated in aId.
       
  1802 // -----------------------------------------------------------------------------
       
  1803 //    
       
  1804 EXPORT_C TTypeUid::Ptr CAknToolbar::MopSupplyObject( TTypeUid aId )
       
  1805     {
       
  1806     if ( aId.iUid == CEikCba::ETypeId )
       
  1807         {
       
  1808         if ( iToolbarCba && iToolbarCba->ButtonGroupType() == 
       
  1809             CEikButtonGroupContainer::ECba )
       
  1810             {
       
  1811             return aId.MakePtr( static_cast<CEikCba*>( iToolbarCba->ButtonGroup() ) );
       
  1812             }    
       
  1813         else
       
  1814             {
       
  1815             return TTypeUid::Null();
       
  1816             }
       
  1817         }
       
  1818     else if ( iToolbarCba && aId.iUid == CEikButtonGroupContainer::ETypeId )
       
  1819         {
       
  1820         return aId.MakePtr( iToolbarCba );
       
  1821         }
       
  1822     return CCoeControl::MopSupplyObject(aId);
       
  1823     }
       
  1824 
       
  1825 // -----------------------------------------------------------------------------
       
  1826 // CAknToolbar::Draw
       
  1827 // From MCoeControlBackground
       
  1828 // Draw the background for a given control.
       
  1829 // The text drawer that shall be used to draw text on the specific background 
       
  1830 // can be fetched through the GetTextDrawer() method. 
       
  1831 // -----------------------------------------------------------------------------
       
  1832 //    
       
  1833 EXPORT_C void CAknToolbar::Draw( CWindowGc& aGc, const CCoeControl& aControl, 
       
  1834                                  const TRect& aRect ) const 
       
  1835     {
       
  1836     if ( !( iFlags & KAknToolbarFixed ) )
       
  1837         {
       
  1838         SetOrdinalPositions();
       
  1839         }
       
  1840 
       
  1841     if ( iFlags & KAknToolbarNoBackground )
       
  1842         {
       
  1843         return;
       
  1844         }
       
  1845 
       
  1846     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1847     
       
  1848     aGc.SetClippingRect( aRect );
       
  1849     
       
  1850     CAknToolbarItem* item = ToolbarItemByControl( &aControl ); 
       
  1851     
       
  1852     if ( iFlags & KAknToolbarFixed )
       
  1853         {
       
  1854         TRAP_IGNORE( DrawFixedBackgroundL( aGc, aControl, aRect) );
       
  1855         return;
       
  1856         }
       
  1857 
       
  1858     if ( item && ( item->ControlType() == EAknCtButton || 
       
  1859         item->ControlType() == EAknCtToolbarExtension ) ) 
       
  1860         {
       
  1861         CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  1862         if ( !( button && ( button->ButtonFlags() & KAknButtonNoFrame ) ) )
       
  1863             {
       
  1864             AknsDrawUtils::Background( skin, iFrameContext, aGc, aRect );
       
  1865             }
       
  1866         }
       
  1867     else
       
  1868         {
       
  1869         AknsDrawUtils::Background( skin, iFrameContext, aGc, aRect );
       
  1870         }
       
  1871 
       
  1872     if ( iFocusedItem == KFocusedNone )
       
  1873         {
       
  1874         return; 
       
  1875         }
       
  1876     if ( !IsNonFocusing() && ( iFlags & KAknToolbarSmall ) && 
       
  1877         &aControl == iVisibleItems[iFocusedItem]->Control() )
       
  1878             {
       
  1879             CAknToolbarItem* item = iVisibleItems[iFocusedItem];
       
  1880             if ( item && item->HighlightRect().Intersects( aRect ) )
       
  1881                 {
       
  1882                 TAknLayoutRect topLeft;
       
  1883                 topLeft.LayoutRect( item->HighlightRect(),
       
  1884                     SkinLayout::Highlight_skin_placing__grid__Line_2() );
       
  1885           
       
  1886                 TAknLayoutRect bottomRight;
       
  1887                 bottomRight.LayoutRect( item->HighlightRect(),
       
  1888                     SkinLayout::Highlight_skin_placing__grid__Line_5() );
       
  1889           
       
  1890                 TRect outerRect( topLeft.Rect().iTl, bottomRight.Rect().iBr );
       
  1891                 TRect innerRect( topLeft.Rect().iBr, bottomRight.Rect().iTl );
       
  1892 
       
  1893                 if ( iFlags & KAknToolbarTransparent )
       
  1894                     {
       
  1895                     outerRect.Move(TPoint(-(topLeft.Rect().iTl.iX),-(topLeft.Rect().iTl.iY))); 
       
  1896                     AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(),
       
  1897                                               aGc, outerRect, innerRect,
       
  1898                                               KAknsIIDQsnFrGrid, KAknsIIDDefault );  // to another skin id ( Alpha )
       
  1899                     }
       
  1900                 else
       
  1901                     {
       
  1902                     if ( !AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
       
  1903                                                 aGc, outerRect, innerRect,
       
  1904                                                 KAknsIIDQsnFrGrid, KAknsIIDDefault ) )
       
  1905                         {
       
  1906                         aGc.SetBrushColor( KRgbRed );
       
  1907                         aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  1908                         aGc.DrawRect( item->HighlightRect() );
       
  1909                         }                
       
  1910                     }
       
  1911                 }
       
  1912             }
       
  1913 
       
  1914     }
       
  1915 
       
  1916 // -----------------------------------------------------------------------------
       
  1917 // CAknToolbar::ComponentControl
       
  1918 // Gets the specified component of a compound control.
       
  1919 // -----------------------------------------------------------------------------
       
  1920 //    
       
  1921 EXPORT_C CCoeControl* CAknToolbar::ComponentControl( TInt aIndex ) const
       
  1922     {
       
  1923     if ( aIndex < iVisibleItems.Count() && aIndex >= 0 )
       
  1924         {
       
  1925         return iVisibleItems[aIndex]->Control();
       
  1926         }
       
  1927     return NULL;
       
  1928     }
       
  1929 
       
  1930 // -----------------------------------------------------------------------------
       
  1931 // CAknToolbar::SizeChanged
       
  1932 // Responds to size changes to sets the size and position of the contents 
       
  1933 // of this control.
       
  1934 // -----------------------------------------------------------------------------
       
  1935 //    
       
  1936 EXPORT_C void CAknToolbar::SizeChanged()
       
  1937     {
       
  1938     // Setup skin
       
  1939     const TRect popupRect( Rect() );
       
  1940     if(  popupRect.IsEmpty() || !iFrameContext )
       
  1941     {
       
  1942         return ;
       
  1943     }
       
  1944     TAknLayoutRect topLeft;
       
  1945     topLeft.LayoutRect( popupRect, SkinLayout::Submenu_skin_placing_Line_2() );
       
  1946     TAknLayoutRect bottomRight;
       
  1947     bottomRight.LayoutRect( popupRect, SkinLayout::Submenu_skin_placing_Line_5() );
       
  1948     TRect outerRect = TRect( topLeft.Rect().iTl, bottomRight.Rect().iBr );
       
  1949     TRect innerRect = TRect( topLeft.Rect().iBr, bottomRight.Rect().iTl );
       
  1950 
       
  1951     if ( ( !( iFlags & KAknToolbarFixed ) && 
       
  1952          !( iFlags & KAknToolbarFloatingUnTransparent ) ) )
       
  1953         {
       
  1954         TRegionFix<4> transparentRegion;
       
  1955         // left side
       
  1956         transparentRegion.AddRect( TRect( outerRect.iTl, TPoint( innerRect.iTl.iX, outerRect.iBr.iY ) ) );
       
  1957         // right side
       
  1958         transparentRegion.AddRect( TRect( TPoint( innerRect.iBr.iX, outerRect.iTl.iY ), outerRect.iBr ) );
       
  1959         // top center
       
  1960         transparentRegion.AddRect( TRect( innerRect.iTl.iX, outerRect.iTl.iY, innerRect.iBr.iX, innerRect.iTl.iY ) );
       
  1961         // bottom center
       
  1962         transparentRegion.AddRect( TRect( innerRect.iTl.iX, innerRect.iBr.iY, innerRect.iBr.iX, outerRect.iBr.iY ) );
       
  1963 
       
  1964         Window().SetTransparentRegion( transparentRegion );
       
  1965         }
       
  1966 
       
  1967     iFrameContext->SetFrameRects( outerRect, innerRect );
       
  1968 
       
  1969     iFrameContext->SetParentPos( Position() ); 
       
  1970 
       
  1971     iBgContext->SetParentPos( iAvkonAppUi->ApplicationRect().iTl );
       
  1972     iBgContext->SetRect( iAvkonAppUi->ApplicationRect() ); 
       
  1973     
       
  1974     //reset button tooltip position
       
  1975     UpdateItemTooltipPosition();
       
  1976     }
       
  1977 
       
  1978 // -----------------------------------------------------------------------------
       
  1979 // CAknToolbar::FocusChanged
       
  1980 // This function is called whenever a control gains or loses focus.
       
  1981 // -----------------------------------------------------------------------------
       
  1982 // 
       
  1983 EXPORT_C void CAknToolbar::FocusChanged( TDrawNow aDrawNow )
       
  1984     {
       
  1985     if ( !iInternalFlags.IsSet( EShown ) || IsNonFocusing() )
       
  1986         {
       
  1987         return; // nothing should be done in this case 
       
  1988         }
       
  1989 
       
  1990     TBool withoutCba( iFlags & KAknToolbarWithoutCba );    
       
  1991     if ( IsFocused() )
       
  1992         {
       
  1993         if ( !withoutCba )
       
  1994             {            
       
  1995             if ( !iToolbarCba )
       
  1996                 {
       
  1997                 TRAP_IGNORE( iToolbarCba = 
       
  1998                     CEikButtonGroupContainer::NewL( CEikButtonGroupContainer::ECba, 
       
  1999                                                     CEikButtonGroupContainer::EHorizontal,
       
  2000                                                     this, iSoftkeyResource ) ); //lint !e665
       
  2001                 }
       
  2002             }
       
  2003         if ( iToolbarCba && iToolbarCba->ButtonGroup() )
       
  2004             {
       
  2005             static_cast<CEikCba*>( iToolbarCba->ButtonGroup() )->SetSkinBackgroundId( 
       
  2006                 KAknsIIDQsnBgAreaControlPopup );
       
  2007             }
       
  2008         
       
  2009         if ( iLastFocusedItem == KFocusedNone ) 
       
  2010             {
       
  2011             TRAP_IGNORE( InitFocusedItemL( aDrawNow ) );
       
  2012             }
       
  2013         else
       
  2014             {
       
  2015             TRAP_IGNORE( MoveHighlightL( iLastFocusedItem, aDrawNow ) );
       
  2016             }
       
  2017         }
       
  2018     else
       
  2019         {
       
  2020         iLastFocusedItem = iFocusedItem;
       
  2021         }
       
  2022     }
       
  2023     
       
  2024 // -----------------------------------------------------------------------------
       
  2025 // CAknToolbar::ExtensionInterface
       
  2026 // For future extensions
       
  2027 // -----------------------------------------------------------------------------
       
  2028 //
       
  2029 EXPORT_C void* CAknToolbar::ExtensionInterface( TUid /*aInterface*/ )
       
  2030     {
       
  2031     return NULL;
       
  2032     }
       
  2033 // -----------------------------------------------------------------------------
       
  2034 // CAknToolbar::Draw
       
  2035 // Draw a control called by window server.
       
  2036 // -----------------------------------------------------------------------------
       
  2037 //    
       
  2038 EXPORT_C void CAknToolbar::Draw( const TRect& aRect ) const
       
  2039     {
       
  2040     if ( !( iFlags & KAknToolbarFixed ) )
       
  2041         {
       
  2042         SetOrdinalPositions();
       
  2043         }
       
  2044 
       
  2045     CWindowGc& gc = SystemGc();
       
  2046     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  2047     // Draw background         
       
  2048     if ( iFlags & KAknToolbarFixed && 
       
  2049          iBgRect.Height() > 0 &&
       
  2050          iBgRect.Width() > 0 )
       
  2051         {
       
  2052         if ( aRect.Intersects( iBgRect ) )
       
  2053             {
       
  2054             TBool idleLayout( AknStatuspaneUtils::IdleLayoutActive() );
       
  2055             TBool wallpaperInUse( EFalse );    
       
  2056 
       
  2057             if ( iInternalFlags.IsSet( EInIdle ) || idleLayout )
       
  2058                 {
       
  2059                 CRepository* repository = 0;
       
  2060                 TRAP_IGNORE( repository = CRepository::NewL(KCRUidPersonalisation) );
       
  2061 				if( repository )	
       
  2062 					{
       
  2063 					repository->Get( KPslnWallpaperType, wallpaperInUse );
       
  2064 					delete repository;
       
  2065 					}
       
  2066                 }
       
  2067             
       
  2068             if ( wallpaperInUse != 0 && Layout_Meta_Data::IsLandscapeOrientation() && iInternalFlags.IsSet( EItemsHidden ) )
       
  2069                 {                
       
  2070                 iBgContext->SetBitmap( KAknsIIDWallpaper );
       
  2071                 }
       
  2072             AknsDrawUtils::Background( skin, iBgContext, this, gc, iBgRect, 
       
  2073             KAknsDrawParamNoClearUnderImage );
       
  2074             }
       
  2075         }
       
  2076 
       
  2077     if ( ( iFlags & KAknToolbarFixed ) ||
       
  2078          ( iFlags & KAknToolbarNoBackground ) )
       
  2079         {
       
  2080         // fixed toolbar doesn't draw anything itself - all drawing is done
       
  2081         // through background drawer implementation
       
  2082         return;
       
  2083         }
       
  2084 
       
  2085     gc.SetClippingRect( aRect );
       
  2086 
       
  2087     if ( iFlags & KAknToolbarFixed )
       
  2088         {
       
  2089         AknsDrawUtils::Background( skin, iFrameContext, this, gc, aRect, KAknsDrawParamNoClearUnderImage );
       
  2090         }
       
  2091     else
       
  2092         {
       
  2093         AknsDrawUtils::Background( skin, iFrameContext, gc, aRect );
       
  2094         }         
       
  2095 
       
  2096     // draw toolbar item highlight if toolbar is not small
       
  2097     if ( !IsNonFocusing() && iFocusedItem != KFocusedNone && !( iFlags & KAknToolbarSmall ) )
       
  2098         {
       
  2099         CAknToolbarItem* item = iVisibleItems[iFocusedItem];
       
  2100         if ( item && item->HighlightRect().Intersects( aRect ) )
       
  2101             {
       
  2102             TAknLayoutRect topLeft;
       
  2103             topLeft.LayoutRect( item->HighlightRect(),
       
  2104                 SkinLayout::Highlight_skin_placing__grid__Line_2() );
       
  2105           
       
  2106             TAknLayoutRect bottomRight;
       
  2107             bottomRight.LayoutRect( item->HighlightRect(),
       
  2108                 SkinLayout::Highlight_skin_placing__grid__Line_5() );
       
  2109           
       
  2110             TRect outerRect( topLeft.Rect().iTl, bottomRight.Rect().iBr );
       
  2111             TRect innerRect( topLeft.Rect().iBr, bottomRight.Rect().iTl );
       
  2112     
       
  2113             if ( !AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
       
  2114                                             gc, outerRect, innerRect,
       
  2115                                             KAknsIIDQsnFrGrid, KAknsIIDDefault ) )
       
  2116                 {
       
  2117                 gc.SetBrushColor( KRgbRed );
       
  2118                 gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  2119                 gc.DrawRect( item->HighlightRect() );
       
  2120                 }                
       
  2121             }
       
  2122         }
       
  2123     }
       
  2124 
       
  2125 // -----------------------------------------------------------------------------
       
  2126 // CAknToolbar::AddItemL
       
  2127 // Adds one new item to the toolbar.
       
  2128 // -----------------------------------------------------------------------------
       
  2129 //
       
  2130 EXPORT_C void CAknToolbar::AddItemL( CCoeControl* aItem, 
       
  2131                                      const TInt aType, 
       
  2132                                      const TInt aCommandId, 
       
  2133                                      const TInt aFlags ) 
       
  2134     {
       
  2135     AddItemL( aItem, aType, aCommandId, aFlags, iItems.Count() );
       
  2136     }
       
  2137 
       
  2138 // -----------------------------------------------------------------------------
       
  2139 // CAknToolbar::AddItemL
       
  2140 // Adds one new item to the toolbar.
       
  2141 // -----------------------------------------------------------------------------
       
  2142 //
       
  2143 EXPORT_C void CAknToolbar::AddItemL( CCoeControl* aItem, 
       
  2144                                      const TInt aType, 
       
  2145                                      const TInt aCommandId, 
       
  2146                                      const TInt aFlags, 
       
  2147                                      const TInt aIndex ) 
       
  2148     {
       
  2149     if ( aItem && IsSupportedItemType( aType ) )
       
  2150         {
       
  2151         aItem->SetContainerWindowL( *this );
       
  2152         aItem->SetBackground( this );
       
  2153         
       
  2154         if ( aType != EAknCtToolbarExtension )
       
  2155             {
       
  2156             aItem->SetObserver( this );
       
  2157             }
       
  2158 
       
  2159         CAknToolbarItem* tbItem = new ( ELeave ) CAknToolbarItem( aItem, aType, 
       
  2160             aCommandId, aFlags );
       
  2161         CleanupStack::PushL( tbItem );
       
  2162         iItems.InsertL( tbItem, aIndex );
       
  2163         CleanupStack::Pop( tbItem );
       
  2164 
       
  2165         TRect rect = CalculateSizeAndPosition();
       
  2166         UpdateControlVisibility();
       
  2167         TInt itemIndex = ToolbarVisibleIndexById( aCommandId ); 
       
  2168 
       
  2169         if ( itemIndex <= iFocusedItem && IsFocused() && itemIndex >= 0 )
       
  2170             {
       
  2171             MoveHighlightL( iFocusedItem + 1, EFalse );   
       
  2172             }
       
  2173         if ( aType == EAknCtButton || aType == EAknCtToolbarExtension  )
       
  2174             {
       
  2175             AdjustButton( *static_cast<CAknButton*>( aItem ) );
       
  2176             }
       
  2177 
       
  2178         if ( iInternalFlags.IsSet( EShown ) )
       
  2179             {
       
  2180             aItem->ActivateL(); 
       
  2181 
       
  2182             if ( !( iFlags & KAknToolbarFlexiblePosition ) )
       
  2183                 {
       
  2184                 SetPosition( rect.iTl );
       
  2185                 }
       
  2186             else 
       
  2187                 {
       
  2188                 UpdateControlPositions(); 
       
  2189                 }
       
  2190             SetSize( rect.Size() );
       
  2191             DrawDeferred();
       
  2192             }
       
  2193         }
       
  2194     else
       
  2195         {
       
  2196         User::Leave( KErrNotSupported );
       
  2197         }
       
  2198     }
       
  2199 
       
  2200 // -----------------------------------------------------------------------------
       
  2201 // CAknToolbar::RemoveItem
       
  2202 // Removes the item according to the specified ID
       
  2203 // -----------------------------------------------------------------------------
       
  2204 //
       
  2205 EXPORT_C void CAknToolbar::RemoveItem( const TInt aCommandId ) 
       
  2206     {
       
  2207     TInt itemIndex = ToolbarItemIndexById( aCommandId );
       
  2208     if ( itemIndex >= 0 && itemIndex < iItems.Count() )
       
  2209         {
       
  2210         TInt visibleIndex = ToolbarVisibleIndexById( aCommandId ); 
       
  2211 
       
  2212         delete iItems[itemIndex];
       
  2213         iItems.Remove( itemIndex );
       
  2214 
       
  2215         TRect rect = CalculateSizeAndPosition();
       
  2216         UpdateControlVisibility();
       
  2217 
       
  2218         if ( visibleIndex >= 0 && visibleIndex < iFocusedItem && IsFocused() )
       
  2219             {
       
  2220             TRAP_IGNORE( MoveHighlightL( iFocusedItem - 1, EFalse ) ); 
       
  2221             }
       
  2222         if ( iInternalFlags.IsSet( EShown ) )
       
  2223             {
       
  2224             if ( !( iFlags & KAknToolbarFlexiblePosition ) )
       
  2225                 {
       
  2226                 SetPosition( rect.iTl );
       
  2227                 }
       
  2228             else 
       
  2229                 {
       
  2230                 UpdateControlPositions(); 
       
  2231                 }
       
  2232             SetSize( rect.Size() );
       
  2233             DrawDeferred();
       
  2234             }
       
  2235         }
       
  2236     }
       
  2237 
       
  2238 // -----------------------------------------------------------------------------
       
  2239 // CAknToolbar::IsSupportedItemType
       
  2240 // Returns ETrue if item is supported. 
       
  2241 // -----------------------------------------------------------------------------
       
  2242 //
       
  2243 EXPORT_C TBool CAknToolbar::IsSupportedItemType( const TInt aType ) const 
       
  2244     {
       
  2245     switch ( aType )
       
  2246         {
       
  2247         case EAknCtButton:
       
  2248         case EAknCtToolbarExtension :
       
  2249             {
       
  2250             return ETrue;
       
  2251             }
       
  2252         default:
       
  2253             {
       
  2254 #ifdef RD_SCALABLE_UI_V2
       
  2255             if ( iFlags & KAknToolbarSmall || iFlags & KAknToolbarFixed  )
       
  2256                 {
       
  2257                 return EFalse; 
       
  2258                 }
       
  2259             else 
       
  2260                 {
       
  2261                 return ETrue;
       
  2262                 }
       
  2263 #else   
       
  2264             return EFalse; 
       
  2265 #endif
       
  2266 
       
  2267             }
       
  2268         }
       
  2269     }
       
  2270    
       
  2271 // -----------------------------------------------------------------------------
       
  2272 // CAknToolbar::SetInitialFocusedItem
       
  2273 // Changes the command ID for the initially focused item when toolbar
       
  2274 //  is shown or gain focus.
       
  2275 // -----------------------------------------------------------------------------
       
  2276 //
       
  2277 EXPORT_C void CAknToolbar::SetInitialFocusedItem( const TInt aCommandId )
       
  2278     {
       
  2279     iInitialFocusedItem = ToolbarVisibleIndexById( aCommandId );
       
  2280     }
       
  2281 
       
  2282 // -----------------------------------------------------------------------------
       
  2283 // CAknToolbar::SetEmphasis
       
  2284 // Called by the framework to handle the emphasising or 
       
  2285 // de-emphasising of a toolbar window when it is needed. 
       
  2286 // -----------------------------------------------------------------------------
       
  2287 //   
       
  2288 EXPORT_C void CAknToolbar::SetEmphasis( const TBool aEmphasis )
       
  2289     {
       
  2290     if ( iInternalFlags.IsSet( EShown ) )
       
  2291         {
       
  2292         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
  2293             aEmphasis ? 0 : ECoeStackFlagRefusesFocus, ECoeStackFlagRefusesFocus );
       
  2294         }
       
  2295     }
       
  2296 
       
  2297 // -----------------------------------------------------------------------------
       
  2298 // CAknToolbar::IsShown
       
  2299 // Returns toolbar visibility at this moment 
       
  2300 // -----------------------------------------------------------------------------
       
  2301 //
       
  2302 EXPORT_C TBool CAknToolbar::IsShown() const
       
  2303     {
       
  2304     return ( iInternalFlags.IsSet( EShown ) || ( iIdle && iIdle->IsActive() ) );
       
  2305     }
       
  2306     
       
  2307 // -----------------------------------------------------------------------------
       
  2308 // CAknToolbar::SetWithSliding
       
  2309 // Specifies whether toolbar should be shown with sliding effect or not.
       
  2310 // By default toolbar is shown with sliding.
       
  2311 // -----------------------------------------------------------------------------
       
  2312 //
       
  2313 EXPORT_C void CAknToolbar::SetWithSliding( const TBool /* aSlide */ )
       
  2314     {
       
  2315     }
       
  2316 
       
  2317 // -----------------------------------------------------------------------------
       
  2318 // CAknToolbar::SetCloseOnCommand
       
  2319 // -----------------------------------------------------------------------------
       
  2320 //    
       
  2321 EXPORT_C void CAknToolbar::SetCloseOnCommand( const TInt aCommandId,
       
  2322                                               const TBool aClose )
       
  2323     {
       
  2324     CAknToolbarItem* item = ToolbarItemById( aCommandId );
       
  2325     if ( item )
       
  2326         {
       
  2327         item->SetCloseOnCommand( aClose );
       
  2328         }
       
  2329     } //lint !e1762 function cannot be made const
       
  2330 
       
  2331 // -----------------------------------------------------------------------------
       
  2332 // CAknToolbar::SetCloseOnAllCommands
       
  2333 // -----------------------------------------------------------------------------
       
  2334 //    
       
  2335 EXPORT_C void CAknToolbar::SetCloseOnAllCommands( const TBool aClose )
       
  2336     {
       
  2337     for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
  2338         {
       
  2339         iItems[ii]->SetCloseOnCommand( aClose );
       
  2340         }
       
  2341     }
       
  2342 
       
  2343 // -----------------------------------------------------------------------------
       
  2344 // CAknToolbar::SetOrientation
       
  2345 // -----------------------------------------------------------------------------
       
  2346 //    
       
  2347 EXPORT_C void CAknToolbar::SetOrientation( const TAknOrientation aOrientation )
       
  2348     {
       
  2349     iOrientation = aOrientation;
       
  2350     if ( iFlags & KAknToolbarFixed )
       
  2351         {
       
  2352         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  2353             {
       
  2354             iOrientation = EAknOrientationVertical; 
       
  2355             }
       
  2356         else
       
  2357             {
       
  2358             iOrientation = EAknOrientationHorizontal; 
       
  2359             }
       
  2360         }
       
  2361     if ( iFlags & KAknToolbarTransparent )
       
  2362         {        
       
  2363         TAknsItemID bgContextId; 
       
  2364         if ( iFlags & KAknToolbarSmall )
       
  2365             {
       
  2366             bgContextId = KAknsIIDQgnGrafPopupTrans;
       
  2367             }
       
  2368         else 
       
  2369             {
       
  2370             bgContextId = ( iOrientation == EAknOrientationHorizontal ? 
       
  2371                 KAknsIIDQgnGrafBgTouchHorizontal : KAknsIIDQgnGrafBgTouchVertical );
       
  2372             }
       
  2373         iFrameContext->SetFrame( bgContextId );
       
  2374         if ( iFlags & KAknToolbarSmall )
       
  2375             {
       
  2376             iFrameContext->SetCenter( KAknsIIDQgnGrafPopupTransCenter ); 
       
  2377             }
       
  2378         } 
       
  2379 
       
  2380     TRect rect = CalculateSizeAndPosition();
       
  2381     // Set focused item again to avoid panic in a case when toolbar has more 
       
  2382     // items in previous orientation and some of the items that do not 
       
  2383     // fit to toolbar in this orientation was focused. 
       
  2384     if ( IsFocused() )
       
  2385         {
       
  2386         TRAP_IGNORE( MoveHighlightL( iFocusedItem, EFalse ) ); 
       
  2387         }
       
  2388 
       
  2389     if ( iInternalFlags.IsSet( EShown ) )
       
  2390         {
       
  2391         if ( !( iFlags & KAknToolbarFlexiblePosition ) )
       
  2392             {
       
  2393             SetPosition( rect.iTl );
       
  2394             }
       
  2395         else 
       
  2396             {
       
  2397             UpdateControlPositions(); 
       
  2398             }
       
  2399         SetSize( rect.Size() );
       
  2400         DrawDeferred();
       
  2401         }
       
  2402     }
       
  2403 
       
  2404 // -----------------------------------------------------------------------------
       
  2405 // CAknToolbar::NotifyBackgroundChange
       
  2406 // -----------------------------------------------------------------------------
       
  2407 //
       
  2408 EXPORT_C void CAknToolbar::UpdateBackground() 
       
  2409     {
       
  2410     return ;
       
  2411     }
       
  2412 
       
  2413 
       
  2414 // -----------------------------------------------------------------------------
       
  2415 // CAknToolbar::ShowToolbarForBackgroundUpdate
       
  2416 // Shows toolbar after it has been hidden with HideToolbarForBackgroundUpdate
       
  2417 // this function is deserted for NGA's removing BitmapDevice
       
  2418 // -----------------------------------------------------------------------------
       
  2419 //
       
  2420 void CAknToolbar::ShowToolbarForBackgroundUpdate()
       
  2421     {
       
  2422 	  return;
       
  2423     }
       
  2424 
       
  2425 // -----------------------------------------------------------------------------
       
  2426 // CAknToolbar::DisableToolbarL
       
  2427 // This disables toolbar so that it cannot be enabled. This is needed especially
       
  2428 // if a dialog is shown on the screen and toolbar should not be enabled by the 
       
  2429 // user from touch pane. 
       
  2430 // -----------------------------------------------------------------------------
       
  2431 //
       
  2432 EXPORT_C void CAknToolbar::DisableToolbarL( TBool aDisable )
       
  2433     {
       
  2434     if ( iInternalFlags.IsSet( EShown ) )
       
  2435         {
       
  2436         User::Leave( KErrToolbarShown ); 
       
  2437         }
       
  2438 
       
  2439     // notify observer (touch pane) that toolbar is disabled 
       
  2440     if ( aDisable )
       
  2441         {
       
  2442         iInternalFlags.Set( EDisabled );
       
  2443         
       
  2444         if ( Observer() )
       
  2445             {
       
  2446             Observer()->HandleControlEventL( this, 
       
  2447                 static_cast<MCoeControlObserver::TCoeEvent>( KDisableToolbar ) );
       
  2448             }
       
  2449         }
       
  2450     else 
       
  2451         {
       
  2452         iInternalFlags.Clear( EDisabled );
       
  2453 
       
  2454         if ( Observer() )
       
  2455             {
       
  2456             Observer()->HandleControlEventL( this, 
       
  2457                 static_cast<MCoeControlObserver::TCoeEvent>( KEnableToolbar ) );
       
  2458             }
       
  2459         }
       
  2460     }
       
  2461 
       
  2462 // -----------------------------------------------------------------------------
       
  2463 // CAknToolbar::IsToolbarDisabled
       
  2464 // Returns ETrue if toolbar is disabled
       
  2465 // -----------------------------------------------------------------------------
       
  2466 //    
       
  2467 EXPORT_C TBool CAknToolbar::IsToolbarDisabled() const
       
  2468     {
       
  2469     return iInternalFlags.IsSet( EDisabled ); 
       
  2470     }
       
  2471 
       
  2472 // -----------------------------------------------------------------------------
       
  2473 // CAknToolbar::SetFocusedItemL
       
  2474 // Sets toolbar item focused if found. 
       
  2475 // -----------------------------------------------------------------------------
       
  2476 //    
       
  2477 EXPORT_C void CAknToolbar::SetFocusedItemL( const TInt aCommandId )
       
  2478     {
       
  2479     TInt visibleIndex = ToolbarVisibleIndexById( aCommandId ); 
       
  2480     if ( visibleIndex == KErrNotFound || IsNonFocusing() )
       
  2481         {
       
  2482         User::Leave( KErrNotFound ); 
       
  2483         }
       
  2484 
       
  2485     if ( visibleIndex == iFocusedItem )
       
  2486         {
       
  2487         return;
       
  2488         }
       
  2489 
       
  2490     // There are only buttons in a focusable toolbar
       
  2491     CAknToolbarItem* item = iVisibleItems[visibleIndex];
       
  2492     CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  2493 
       
  2494     if ( button && button->IsDimmed() )
       
  2495         {
       
  2496         return; 
       
  2497         }
       
  2498 
       
  2499     TInt oldFocused = iFocusedItem; 
       
  2500 
       
  2501     iFocusedItem = visibleIndex; 
       
  2502 
       
  2503     // set this item focused
       
  2504     item->SetFocusL( ETrue, EFalse, ENoDrawNow, this );
       
  2505     DrawNow( item->HighlightRect() );
       
  2506 
       
  2507     if ( oldFocused != KFocusedNone )
       
  2508         {
       
  2509         item = iVisibleItems[oldFocused];
       
  2510         if ( item && item->Control() )
       
  2511             {
       
  2512             SelectItemL( oldFocused, EFalse );
       
  2513 
       
  2514             // take the focus away
       
  2515             item->SetFocusL( EFalse, EFalse, ENoDrawNow, this );
       
  2516             DrawNow( item->HighlightRect() );
       
  2517             }
       
  2518         }
       
  2519     }
       
  2520 
       
  2521 // -----------------------------------------------------------------------------
       
  2522 // CAknToolbar::FocusedItem
       
  2523 // Returns focused toolbar item command id  
       
  2524 // -----------------------------------------------------------------------------
       
  2525 //    
       
  2526 EXPORT_C TInt CAknToolbar::FocusedItem() const
       
  2527     {
       
  2528     if ( iFocusedItem < 0 || iFocusedItem >= iVisibleItems.Count() )
       
  2529         {
       
  2530         return KErrNotFound; 
       
  2531         }
       
  2532     CAknToolbarItem* item = iVisibleItems[iFocusedItem]; 
       
  2533     return item->CommandId(); 
       
  2534     }
       
  2535 
       
  2536 // -----------------------------------------------------------------------------
       
  2537 // CAknToolbar::PrepareForFocusLossL
       
  2538 // Takes focus away from editor/other controls if needed
       
  2539 // -----------------------------------------------------------------------------
       
  2540 //    
       
  2541 void CAknToolbar::PrepareForFocusLossL()
       
  2542     {
       
  2543     if ( iSelectedItem != KSelectedNone )
       
  2544         {
       
  2545         SelectItemL( iSelectedItem, EFalse ); 
       
  2546         }
       
  2547     }
       
  2548 
       
  2549 
       
  2550 // -----------------------------------------------------------------------------
       
  2551 // CAknToolbar::EventModifiers
       
  2552 // Returns event modifiers
       
  2553 // -----------------------------------------------------------------------------
       
  2554 //    
       
  2555 EXPORT_C TInt CAknToolbar::EventModifiers() const
       
  2556     {
       
  2557     return iEventModifiers; 
       
  2558     }
       
  2559 
       
  2560 
       
  2561 // -----------------------------------------------------------------------------
       
  2562 // CAknToolbar::ToolbarFlags
       
  2563 // Returns toolbar flags
       
  2564 // -----------------------------------------------------------------------------
       
  2565 //    
       
  2566 EXPORT_C TInt CAknToolbar::ToolbarFlags() const
       
  2567     {
       
  2568     return iFlags; 
       
  2569     }
       
  2570 
       
  2571 
       
  2572 // -----------------------------------------------------------------------------
       
  2573 // CAknToolbar::FadeBehindPopup
       
  2574 // Fades behind popup
       
  2575 // -----------------------------------------------------------------------------
       
  2576 //    
       
  2577 void CAknToolbar::FadeBehindPopup( TBool aFade )
       
  2578     {
       
  2579     iFader.FadeBehindPopup( this, this, aFade );
       
  2580     }
       
  2581 
       
  2582 
       
  2583 // -----------------------------------------------------------------------------
       
  2584 // CAknToolbar::CountFadedComponents
       
  2585 // Counts faded components
       
  2586 // -----------------------------------------------------------------------------
       
  2587 //    
       
  2588 TInt CAknToolbar::CountFadedComponents()
       
  2589     {
       
  2590     TInt count = 1; //this
       
  2591     if ( iToolbarCba )
       
  2592         {
       
  2593         count++; 
       
  2594         }
       
  2595     if ( ToolbarExtension() && ToolbarExtension()->ExtensionView() )
       
  2596         {
       
  2597         count++; 
       
  2598         }
       
  2599     return count; 
       
  2600     }
       
  2601 
       
  2602 // -----------------------------------------------------------------------------
       
  2603 // CAknToolbar::FadedComponent
       
  2604 // Returns faded components
       
  2605 // -----------------------------------------------------------------------------
       
  2606 //    
       
  2607 CCoeControl* CAknToolbar::FadedComponent(TInt aIndex)
       
  2608     {
       
  2609     switch ( aIndex )
       
  2610         {
       
  2611         case 0: 
       
  2612             return this; 
       
  2613         case 1: 
       
  2614             if ( iToolbarCba )
       
  2615                 {
       
  2616                 return iToolbarCba; 
       
  2617                 }
       
  2618             return ToolbarExtension()->ExtensionView();         
       
  2619         case 2: 
       
  2620             return ToolbarExtension()->ExtensionView(); 
       
  2621         default: 
       
  2622             return NULL; 
       
  2623         }
       
  2624     }
       
  2625 
       
  2626 
       
  2627 // -----------------------------------------------------------------------------
       
  2628 // CAknToolbar::ReduceRect
       
  2629 // Reduces main pane rect
       
  2630 // -----------------------------------------------------------------------------
       
  2631 //    
       
  2632 void CAknToolbar::ReduceRect( TRect& aBoundingRect ) const
       
  2633     {
       
  2634     TBool toolbarNotVisible( !IsShown() && !( iFlags & KAknToolbarDefault ) );
       
  2635     TBool fixedToolbar( iFlags & KAknToolbarFixed );
       
  2636     TBool landscapeOrientation( Layout_Meta_Data::IsLandscapeOrientation() );
       
  2637     TBool touchEnabled( AknLayoutUtils::PenEnabled() );
       
  2638     TBool defaultContent( iFlags & KAknToolbarDefault );
       
  2639 
       
  2640     if ( toolbarNotVisible || 
       
  2641          !fixedToolbar ||
       
  2642          ( defaultContent && !landscapeOrientation ) ||
       
  2643          !touchEnabled ||
       
  2644          ( fixedToolbar && defaultContent ) )
       
  2645         {
       
  2646         return;
       
  2647         }
       
  2648     TRect appRect, toolbarRect; 
       
  2649     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow, 
       
  2650                                        appRect); 
       
  2651     if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2652         {
       
  2653         toolbarRect = RectFromLayout( appRect,
       
  2654             AknLayoutScalable_Avkon::area_side_right_pane( 6 ) );
       
  2655         }
       
  2656     else
       
  2657         {
       
  2658         toolbarRect = RectFromLayout( appRect,
       
  2659             AknLayoutScalable_Avkon::area_side_right_pane( 0 ) );
       
  2660         }
       
  2661 
       
  2662 
       
  2663     if ( toolbarRect.Intersects( aBoundingRect ) )
       
  2664         {
       
  2665         toolbarRect.Intersection( aBoundingRect );
       
  2666 
       
  2667         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  2668             {
       
  2669             aBoundingRect.iBr.iX = toolbarRect.iTl.iX; 
       
  2670             }
       
  2671         else 
       
  2672             {
       
  2673             aBoundingRect.iBr.iY = toolbarRect.iTl.iY; 
       
  2674             }
       
  2675         }
       
  2676     }
       
  2677  
       
  2678 
       
  2679 // -----------------------------------------------------------------------------
       
  2680 // CAknToolbar::SetSoftkeyResourceIdL
       
  2681 // Sets softkey resource id for toolbar
       
  2682 // -----------------------------------------------------------------------------
       
  2683 //    
       
  2684 EXPORT_C void CAknToolbar::SetSoftkeyResourceIdL( TInt aSoftkeyResourceId )
       
  2685     {
       
  2686     iSoftkeyResource = aSoftkeyResourceId; 
       
  2687     if ( iToolbarCba )
       
  2688         {
       
  2689         iToolbarCba->SetCommandSetL( iSoftkeyResource ); 
       
  2690         iToolbarCba->DrawDeferred(); 
       
  2691         }
       
  2692     }
       
  2693 
       
  2694 
       
  2695 // -----------------------------------------------------------------------------
       
  2696 // CAknToolbar::ExtensionEventL
       
  2697 // Extension notifies of its events using this method
       
  2698 // -----------------------------------------------------------------------------
       
  2699 //
       
  2700 void CAknToolbar::ExtensionEventL( TInt aCommandId )
       
  2701     {
       
  2702     if ( iToolbarObserver )
       
  2703         {
       
  2704         iToolbarObserver->OfferToolbarEventL( aCommandId ); 
       
  2705         }
       
  2706     }
       
  2707 
       
  2708 // -----------------------------------------------------------------------------
       
  2709 // CAknToolbar::ConstructControlLC
       
  2710 // Constructs one of the toolbar items
       
  2711 // -----------------------------------------------------------------------------
       
  2712 //    
       
  2713 CAknToolbarItem* CAknToolbar::ConstructControlLC( TResourceReader& aReader )
       
  2714     {
       
  2715     CAknToolbarItem* item = new(ELeave) CAknToolbarItem;
       
  2716     CleanupStack::PushL( item );
       
  2717 
       
  2718     item->ConstructFromResourceL( aReader );
       
  2719     if ( item->Control() )
       
  2720         {
       
  2721         item->Control()->SetContainerWindowL( *this );
       
  2722         item->Control()->SetBackground( this );
       
  2723 
       
  2724         if ( item->ControlType() != EAknCtToolbarExtension )
       
  2725             {
       
  2726             item->Control()->SetObserver( this );
       
  2727             }
       
  2728         }
       
  2729     else
       
  2730         {
       
  2731         CleanupStack::PopAndDestroy( item );
       
  2732         item = NULL;
       
  2733         }
       
  2734     
       
  2735     return item;
       
  2736     }
       
  2737 
       
  2738 // -----------------------------------------------------------------------------
       
  2739 // CAknToolbar::CalculateSizeAndPosition
       
  2740 // Calculates size and position of the toolbar.
       
  2741 // -----------------------------------------------------------------------------
       
  2742 //
       
  2743 TRect CAknToolbar::CalculateSizeAndPosition()
       
  2744     {
       
  2745     iVisibleItems.Reset();
       
  2746     iPreviousItem = KSelectedNone;
       
  2747     if ( iItems.Count() <= 0 )
       
  2748         {
       
  2749         return TRect();
       
  2750         }
       
  2751 
       
  2752     TRect mainPaneRect;
       
  2753     if ( !( iFlags & KAknToolbarFixed ) )
       
  2754         {
       
  2755         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
  2756                                        mainPaneRect );
       
  2757         if ( iAvkonAppUi->TouchPane() )
       
  2758             {
       
  2759             iAvkonAppUi->TouchPane()->ReduceRect( mainPaneRect );
       
  2760             }
       
  2761         }
       
  2762     else
       
  2763         {
       
  2764         TRect appRect; 
       
  2765         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow, 
       
  2766                                            appRect); 
       
  2767         if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2768             {
       
  2769             iOrientation = EAknOrientationHorizontal; 
       
  2770             mainPaneRect = RectFromLayout( appRect,
       
  2771                 AknLayoutScalable_Avkon::area_side_right_pane( 6 ) );
       
  2772             }
       
  2773         else
       
  2774             {
       
  2775             iOrientation = EAknOrientationVertical; 
       
  2776             mainPaneRect = RectFromLayout( appRect,
       
  2777                 AknLayoutScalable_Avkon::area_side_right_pane( 0 ) );
       
  2778             }
       
  2779         }
       
  2780 
       
  2781     TRect toolbarRect;
       
  2782     TRect gridPaneRect;
       
  2783     TRect cellPaneRect;
       
  2784 
       
  2785     TBool smallToolbar = iFlags & KAknToolbarSmall; 
       
  2786 
       
  2787     CalculateRects( mainPaneRect, toolbarRect, gridPaneRect, cellPaneRect ); 
       
  2788 
       
  2789     // The position of the toolbar is by default fixed, but it can be changed
       
  2790     TPoint position;
       
  2791     TBool flexiblePosition = iFlags & KAknToolbarFlexiblePosition;
       
  2792     if ( flexiblePosition )
       
  2793         {
       
  2794         position = Position();
       
  2795         }
       
  2796     else
       
  2797         {
       
  2798         position = toolbarRect.iTl;
       
  2799         }
       
  2800 
       
  2801     TInt minToolbarWidthOrHeight;
       
  2802     // Maximum possible width of the toolbar with the specified position
       
  2803     TInt maxToolbarWidthOrHeight;
       
  2804 
       
  2805     if ( iOrientation == EAknOrientationHorizontal )
       
  2806         {        
       
  2807         // Width of empty toolbar
       
  2808         minToolbarWidthOrHeight = toolbarRect.Width() - gridPaneRect.Width();
       
  2809         // Maximum width for toolbar
       
  2810         maxToolbarWidthOrHeight = mainPaneRect.Width() - 
       
  2811                           ( position.iX - mainPaneRect.iTl.iX );
       
  2812         }
       
  2813     else
       
  2814         {
       
  2815         if ( iFlags & KAknToolbarFixed )
       
  2816             {
       
  2817             minToolbarWidthOrHeight = 0; 
       
  2818             maxToolbarWidthOrHeight = gridPaneRect.Height(); 
       
  2819             }
       
  2820         else    
       
  2821             {
       
  2822              // Height of empty toolbar
       
  2823             minToolbarWidthOrHeight = toolbarRect.Height() - gridPaneRect.Height();        
       
  2824             // Maximum height for toolbar
       
  2825             maxToolbarWidthOrHeight = mainPaneRect.Height() - 
       
  2826                           ( position.iY - mainPaneRect.iTl.iY );        
       
  2827             }
       
  2828         }
       
  2829   
       
  2830     
       
  2831     TInt gridPaneWidth= 0;
       
  2832     TInt gridPaneHeight = 0;
       
  2833     
       
  2834     TInt maxGridPaneWidthOrHeight = maxToolbarWidthOrHeight - minToolbarWidthOrHeight;
       
  2835     
       
  2836 
       
  2837     // Layout the component controls in grid pane. Note: Code does not use the
       
  2838     // actual cells from the layout, because toolbar must be able to contain any
       
  2839     // kind of control. It assumes that the cells are side by side in grid pane
       
  2840     // and that grid pane is filled from left to right. Code takes the height of
       
  2841     // the controls from button pane, but uses the control's own width.
       
  2842     TRect currentCellPaneRect = cellPaneRect;
       
  2843     iBgRect = TRect( TPoint( 0,0 ), toolbarRect.Size() );
       
  2844     if ( iInternalFlags.IsSet( ESwitchForItemsHidden ) 
       
  2845             && iInternalFlags.IsSet( EItemsHidden ))
       
  2846         {
       
  2847         iInternalFlags.Clear( EItemsHidden );
       
  2848         }
       
  2849     for ( TInt ii = 0;
       
  2850           ii < iItems.Count() && 
       
  2851           ( iOrientation == EAknOrientationHorizontal ? 
       
  2852                 currentCellPaneRect.iBr.iX - gridPaneRect.iTl.iX: 
       
  2853                 currentCellPaneRect.iBr.iY - gridPaneRect.iTl.iY ) 
       
  2854                 <= maxGridPaneWidthOrHeight; ++ii )
       
  2855         {
       
  2856         CAknToolbarItem* item = iItems[ii];
       
  2857         if ( item && item->Control() && !item->IsHidden() && !iInternalFlags.IsSet( EItemsHidden ) )
       
  2858             {
       
  2859             switch ( item->ControlType() )
       
  2860                 {
       
  2861                 case EAknCtButton:
       
  2862                 case EAknCtToolbarExtension :
       
  2863 
       
  2864                     {                    
       
  2865                     TRect controlRect;
       
  2866                     
       
  2867                     if ( iFlags & KAknToolbarSmall )
       
  2868                         {
       
  2869                         controlRect = currentCellPaneRect; 
       
  2870                         }
       
  2871                     else if ( iFlags & KAknToolbarFixed )
       
  2872                         {
       
  2873                         controlRect = currentCellPaneRect; 
       
  2874                         TAknLayoutRect centerLayout;
       
  2875                         centerLayout.LayoutRect( currentCellPaneRect,
       
  2876                             AknLayoutScalable_Avkon::cell_sctrl_middle_pane_g2( iOrientation == EAknOrientationHorizontal ).LayoutLine() );
       
  2877                         TRect graphicsRect = centerLayout.Rect();
       
  2878 
       
  2879                         CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  2880                         button->SetIconSize( graphicsRect.Size() ); 
       
  2881 
       
  2882                         TMargins8 margins;
       
  2883                         margins.iTop = currentCellPaneRect.iTl.iY - graphicsRect.iTl.iY;
       
  2884                         margins.iBottom = graphicsRect.iBr.iY - currentCellPaneRect.iBr.iY;
       
  2885                         margins.iLeft = currentCellPaneRect.iTl.iX - graphicsRect.iTl.iX;
       
  2886                         margins.iRight = graphicsRect.iBr.iX - currentCellPaneRect.iBr.iX;
       
  2887                         button->SetMargins( margins ); 
       
  2888                         }
       
  2889                     else    
       
  2890                         {
       
  2891                         controlRect = CalculateControlRect( currentCellPaneRect ); 
       
  2892                         }
       
  2893                     item->Control()->SetRect( controlRect );
       
  2894                     
       
  2895                     if ( iOrientation == EAknOrientationHorizontal )
       
  2896                         {
       
  2897                         iBgRect.iTl.iX += controlRect.Width();
       
  2898                         }
       
  2899                     else
       
  2900                         {
       
  2901                         iBgRect.iTl.iY += controlRect.Height();
       
  2902                         }
       
  2903                     break;
       
  2904                     }
       
  2905                 default:
       
  2906                     {
       
  2907                     CCoeControl* control = item->Control();
       
  2908 
       
  2909                     TRect controlRect  = RectFromLayout( currentCellPaneRect,
       
  2910                        AknLayoutScalable_Avkon::toolbar_button_pane() );
       
  2911     
       
  2912                     if ( iOrientation == EAknOrientationHorizontal )
       
  2913                         {                       
       
  2914                         control->SetExtent( controlRect.iTl,
       
  2915                                             TSize( control->Rect().Width(),
       
  2916                                                    controlRect.Height() ) );
       
  2917 
       
  2918                         currentCellPaneRect.Resize( control->Rect().Width() -
       
  2919                                                     controlRect.Width(), 0);
       
  2920                         }
       
  2921                     else
       
  2922                         {
       
  2923                         control->SetExtent( controlRect.iTl,
       
  2924                                             TSize( controlRect.Width(),
       
  2925                                                    control->Rect().Height() ) );
       
  2926 
       
  2927                         currentCellPaneRect.Resize( 0, control->Rect().Height() -
       
  2928                                                        controlRect.Height() );
       
  2929                         }
       
  2930                     break;
       
  2931                     }
       
  2932                 }
       
  2933             TRect highlightRect; 
       
  2934             if ( smallToolbar )
       
  2935                 {
       
  2936                 highlightRect = currentCellPaneRect; 
       
  2937                 }
       
  2938             else if ( iOrientation == EAknOrientationHorizontal )
       
  2939                 {
       
  2940                 highlightRect = RectFromLayout( currentCellPaneRect,
       
  2941                     AknLayoutScalable_Avkon::grid_highlight_pane_cp2(0) );
       
  2942                 }
       
  2943             else 
       
  2944                 {
       
  2945                 highlightRect = RectFromLayout( currentCellPaneRect, 
       
  2946                     AknLayoutScalable_Avkon::grid_highlight_pane_cp2(3) );
       
  2947                 }
       
  2948     
       
  2949             item->SetHighlightRect( highlightRect );   
       
  2950 
       
  2951 
       
  2952 #ifdef RD_SCALABLE_UI_V2
       
  2953             // Only buttons are shown with focusable toolbar or small toolbar.
       
  2954             if ( ( IsNonFocusing() && !smallToolbar ) || 
       
  2955                 item->ControlType() == EAknCtButton || item->ControlType() == EAknCtToolbarExtension  )
       
  2956 #else
       
  2957             if ( item->ControlType() == EAknCtButton || item->ControlType() == EAknCtToolbarExtension  )
       
  2958 #endif
       
  2959                 {
       
  2960                 if ( iOrientation == EAknOrientationHorizontal && 
       
  2961                     gridPaneWidth + currentCellPaneRect.Width() <= 
       
  2962                     maxGridPaneWidthOrHeight )
       
  2963                     {
       
  2964                     iVisibleItems.Append( item );
       
  2965                     gridPaneWidth += currentCellPaneRect.Width();
       
  2966                     }
       
  2967                     
       
  2968                 else if ( iOrientation == EAknOrientationVertical &&
       
  2969                     gridPaneHeight + currentCellPaneRect.Height() <= 
       
  2970                     maxGridPaneWidthOrHeight )
       
  2971                     {
       
  2972                     iVisibleItems.Append( item );
       
  2973                     gridPaneHeight += currentCellPaneRect.Height();
       
  2974                     gridPaneWidth = item->Control()->Rect().Width();
       
  2975                     }
       
  2976 
       
  2977                 // Set up next cell pane rect
       
  2978                 if ( iOrientation == EAknOrientationVertical )
       
  2979                     {
       
  2980                     currentCellPaneRect.SetRect( TPoint( currentCellPaneRect.iTl.iX,
       
  2981                                                   currentCellPaneRect.iBr.iY ),
       
  2982                                                  cellPaneRect.Size() );
       
  2983                     }
       
  2984                 else
       
  2985                     {
       
  2986                     currentCellPaneRect.SetRect( TPoint( currentCellPaneRect.iBr.iX,
       
  2987                                                   currentCellPaneRect.iTl.iY ),
       
  2988                                                  cellPaneRect.Size() );
       
  2989                     }
       
  2990                 }
       
  2991             else
       
  2992                 {
       
  2993                 if ( item->IsSelected() )
       
  2994                     {
       
  2995                     TRAP_IGNORE( item->SetIsSelectedL( EFalse ) );
       
  2996                     }
       
  2997 
       
  2998                 currentCellPaneRect.SetRect( TPoint( currentCellPaneRect.iTl.iX,
       
  2999                                              currentCellPaneRect.iTl.iY ),
       
  3000                                              cellPaneRect.Size() );
       
  3001                 }
       
  3002             }
       
  3003         }
       
  3004 
       
  3005     if ( TooFewItemsVisible() ) 
       
  3006         {
       
  3007         return TRect( position, TSize(0,0) ); 
       
  3008         }
       
  3009 
       
  3010     
       
  3011     TRect rect;
       
  3012     
       
  3013     if ( iFlags & KAknToolbarFixed )
       
  3014             {
       
  3015             rect = toolbarRect; 
       
  3016             return rect; 
       
  3017             }
       
  3018             
       
  3019     if ( iOrientation == EAknOrientationHorizontal )
       
  3020         {
       
  3021         TInt mid = mainPaneRect.Width() / 2;
       
  3022         if ( !flexiblePosition ) 
       
  3023             {
       
  3024             position.iX = mainPaneRect.iTl.iX + 
       
  3025                 ( mid - ( minToolbarWidthOrHeight + gridPaneWidth ) / 2 ); 
       
  3026             if ( position.iX < toolbarRect.iTl.iX )
       
  3027                 {
       
  3028                 position.iX = toolbarRect.iTl.iX; 
       
  3029                 }
       
  3030             }
       
  3031         rect = TRect( position, TSize( minToolbarWidthOrHeight + gridPaneWidth,
       
  3032                                    toolbarRect.Height() ) );
       
  3033         }    
       
  3034     else 
       
  3035         {
       
  3036         TInt mid = mainPaneRect.Height() / 2;
       
  3037         if ( !flexiblePosition ) 
       
  3038             {
       
  3039             position.iY = mainPaneRect.iTl.iY + 
       
  3040                 ( mid - ( minToolbarWidthOrHeight + gridPaneHeight ) / 2 ); 
       
  3041             if ( position.iY < toolbarRect.iTl.iY )
       
  3042                 {
       
  3043                 position.iY = toolbarRect.iTl.iY; 
       
  3044                 }
       
  3045             }
       
  3046         rect = TRect( position, TSize( toolbarRect.Width(), 
       
  3047                         minToolbarWidthOrHeight + gridPaneHeight ) );
       
  3048         }
       
  3049            
       
  3050     return rect;
       
  3051     }
       
  3052 
       
  3053 
       
  3054 
       
  3055 // -----------------------------------------------------------------------------
       
  3056 // CAknToolbar::CalculateRects
       
  3057 // Calculates rects for toolbar.
       
  3058 // -----------------------------------------------------------------------------
       
  3059 //
       
  3060 void CAknToolbar::CalculateRects( TRect& aMainPaneRect, TRect& aToolbarRect, 
       
  3061     TRect& aGridPaneRect, TRect& aCellPaneRect )
       
  3062     {
       
  3063     TBool smallToolbar = iFlags & KAknToolbarSmall; 
       
  3064 
       
  3065     TInt variety;
       
  3066     
       
  3067     if ( smallToolbar )
       
  3068         {
       
  3069         if ( iOrientation == EAknOrientationHorizontal )
       
  3070             {        
       
  3071             variety = 1;    
       
  3072             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3073                 AknLayoutScalable_Avkon::popup_toolbar_trans_pane( variety ) );
       
  3074 
       
  3075             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
       
  3076                 AknLayoutScalable_Avkon::grid_tb_trans_pane( variety ) );
       
  3077             
       
  3078             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3079                 AknLayoutScalable_Avkon::cell_toolbar_trans_pane( 0, variety ) );
       
  3080             }
       
  3081         else
       
  3082             {        
       
  3083             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3084                 AknLayoutScalable_Avkon::popup_toolbar_trans_pane() );
       
  3085 
       
  3086             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
       
  3087                 AknLayoutScalable_Avkon::grid_tb_trans_pane() );
       
  3088             
       
  3089             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3090                 AknLayoutScalable_Avkon::cell_toolbar_trans_pane( 0 ) );
       
  3091         
       
  3092             }
       
  3093         }
       
  3094     else if ( iFlags & KAknToolbarFixed )
       
  3095         {
       
  3096         if ( iOrientation == EAknOrientationHorizontal )
       
  3097             {        
       
  3098             variety = 4;    
       
  3099             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3100                 AknLayoutScalable_Avkon::grid_sctrl_middle_pane( 1 ) );
       
  3101 
       
  3102             aGridPaneRect = TRect( TPoint(), aToolbarRect.Size() ); 
       
  3103             
       
  3104             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3105                 AknLayoutScalable_Avkon::cell_sctrl_middle_pane( 1, 0, 0 ) );
       
  3106             }
       
  3107         else
       
  3108             {
       
  3109             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3110                 AknLayoutScalable_Avkon::grid_sctrl_middle_pane( 0 ) );
       
  3111 
       
  3112             aGridPaneRect = TRect( TPoint(), aToolbarRect.Size() ); 
       
  3113 
       
  3114 
       
  3115             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3116                 AknLayoutScalable_Avkon::cell_sctrl_middle_pane( 0, 0, 0 ) );
       
  3117             }
       
  3118         }
       
  3119     else    
       
  3120         {
       
  3121         if ( iOrientation == EAknOrientationHorizontal )
       
  3122             {        
       
  3123             variety = 4;    
       
  3124             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3125                 AknLayoutScalable_Avkon::popup_toolbar_window( variety ) );
       
  3126 
       
  3127             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
       
  3128                 AknLayoutScalable_Avkon::grid_toobar_pane() );
       
  3129             
       
  3130             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3131                 AknLayoutScalable_Avkon::cell_toolbar_pane( 0 ) );
       
  3132             }
       
  3133         else
       
  3134             {        
       
  3135             aToolbarRect = RectFromLayout( aMainPaneRect,
       
  3136                 AknLayoutScalable_Avkon::popup_toolbar_window( 6 ) );
       
  3137 
       
  3138             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
       
  3139                 AknLayoutScalable_Avkon::grid_toobar_pane( 6 ) );
       
  3140             
       
  3141             aCellPaneRect = RectFromLayout( aGridPaneRect,     
       
  3142                 AknLayoutScalable_Avkon::cell_toolbar_pane( 0, 1, 0 ) );
       
  3143         
       
  3144             }
       
  3145         }
       
  3146    }
       
  3147 
       
  3148 // -----------------------------------------------------------------------------
       
  3149 // CAknToolbar::CalculateControlRect
       
  3150 // Calculates control rect for toolbar item.
       
  3151 // -----------------------------------------------------------------------------
       
  3152 //
       
  3153 TRect CAknToolbar::CalculateControlRect( TRect& aCurrentCellPaneRect )
       
  3154     {
       
  3155     TRect controlRect;     
       
  3156     if ( iOrientation == EAknOrientationHorizontal )
       
  3157         {
       
  3158         controlRect = RectFromLayout( aCurrentCellPaneRect,
       
  3159             AknLayoutScalable_Avkon::toolbar_button_pane() );                        
       
  3160         }                    
       
  3161     else
       
  3162         {
       
  3163         controlRect = RectFromLayout( aCurrentCellPaneRect,
       
  3164             AknLayoutScalable_Avkon::toolbar_button_pane( 2 ) );                        
       
  3165         }
       
  3166     return controlRect; 
       
  3167     }
       
  3168 
       
  3169 // -----------------------------------------------------------------------------
       
  3170 // CAknToolbar::CheckNumberOfVisibleItems
       
  3171 // Checks number of visible items and deletes or created CBA if needed
       
  3172 // -----------------------------------------------------------------------------
       
  3173 //
       
  3174 TBool CAknToolbar::TooFewItemsVisible()
       
  3175     {
       
  3176     if( !iVisibleItems.Count() )
       
  3177         {
       
  3178         if ( iFlags & KAknToolbarFixed )
       
  3179             {
       
  3180             return EFalse;
       
  3181             }
       
  3182         else
       
  3183             {
       
  3184             //if the number of toolbar items is 0 then toolbar CBA is deleted
       
  3185             if ( iToolbarCba )
       
  3186                 {
       
  3187                 delete iToolbarCba;
       
  3188                 iToolbarCba = NULL;
       
  3189                 }
       
  3190         
       
  3191             DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
  3192 
       
  3193             iInternalFlags.Set( ENoItemsVisible );
       
  3194             return ETrue;     
       
  3195             }
       
  3196         }
       
  3197     else if ( iInternalFlags.IsSet( ENoItemsVisible ) )   
       
  3198         {
       
  3199         iInternalFlags.Clear( ENoItemsVisible );
       
  3200 
       
  3201         TBool withoutCba( iFlags & KAknToolbarWithoutCba );                    
       
  3202 
       
  3203         DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
  3204 
       
  3205         // toolbar CBA is created here because it had been deleted due to 
       
  3206         // too few items in toolbar
       
  3207         if ( !withoutCba && !IsNonFocusing() )
       
  3208             {
       
  3209             TRAP_IGNORE( iToolbarCba = CEikButtonGroupContainer::NewL( 
       
  3210                 CEikButtonGroupContainer::ECba, 
       
  3211                 CEikButtonGroupContainer::EHorizontal,
       
  3212                 this, iSoftkeyResource ) );
       
  3213 
       
  3214             if ( iToolbarCba->ButtonGroup() )
       
  3215                 {
       
  3216                 static_cast<CEikCba*>( iToolbarCba->ButtonGroup() )->
       
  3217                     SetSkinBackgroundId( KAknsIIDQsnBgAreaControlPopup );
       
  3218                 }
       
  3219                 TRAP_IGNORE( InitFocusedItemL( ETrue ) );
       
  3220             
       
  3221             }
       
  3222         }
       
  3223     return EFalse; 
       
  3224     }
       
  3225 
       
  3226 // -----------------------------------------------------------------------------
       
  3227 // CAknToolbar::ToolbarItemByControl
       
  3228 // Returns toolbar item object for the specified control.
       
  3229 // -----------------------------------------------------------------------------
       
  3230 //
       
  3231 CAknToolbarItem* CAknToolbar::ToolbarItemByControl( const CCoeControl* aControl ) const 
       
  3232     {
       
  3233     if ( aControl )
       
  3234         {
       
  3235         for ( TInt ii = 0; ii < iItems.Count(); ii++ ) 
       
  3236             {
       
  3237             CAknToolbarItem* item = iItems[ii];
       
  3238             if ( item && item->Control() && item->Control() == aControl )
       
  3239                 {
       
  3240                 return item;
       
  3241                 }
       
  3242             }
       
  3243         }
       
  3244     return NULL;
       
  3245     }
       
  3246 
       
  3247 // -----------------------------------------------------------------------------
       
  3248 // CAknToolbar::ToolbarItemById
       
  3249 // Returns toolbar item object for the specified command ID
       
  3250 // -----------------------------------------------------------------------------
       
  3251 //
       
  3252 CAknToolbarItem* CAknToolbar::ToolbarItemById( const TInt aId ) const 
       
  3253     {
       
  3254     for ( TInt ii = 0; ii < iItems.Count(); ii++ )
       
  3255         {
       
  3256         CAknToolbarItem* item = iItems[ii];
       
  3257         if ( item && item->CommandId() == aId )
       
  3258             {
       
  3259             return item;
       
  3260             }
       
  3261         }
       
  3262     return NULL;
       
  3263     }
       
  3264 
       
  3265 // -----------------------------------------------------------------------------
       
  3266 // CAknToolbar::ToolbarItemIndexById
       
  3267 // Returns the index of the toolbar item inside of the iItems array.
       
  3268 // -----------------------------------------------------------------------------
       
  3269 //
       
  3270 TInt CAknToolbar::ToolbarItemIndexById( const TInt aId ) const 
       
  3271     {
       
  3272     for ( TInt ii = 0; ii < iItems.Count(); ii++ )
       
  3273         {
       
  3274         CAknToolbarItem* item = iItems[ii];
       
  3275         if ( item && item->CommandId() == aId )
       
  3276             {
       
  3277             return ii;
       
  3278             }
       
  3279         }
       
  3280     return KErrNotFound;
       
  3281     }
       
  3282 
       
  3283 // -----------------------------------------------------------------------------
       
  3284 // CAknToolbar::ToolbarItemIndexByControl
       
  3285 // Returns toolbar item index for the specified control or KErrNotFound.
       
  3286 // -----------------------------------------------------------------------------
       
  3287 //
       
  3288 TInt CAknToolbar::ToolbarItemIndexByControl( const CCoeControl* aControl ) const 
       
  3289     {
       
  3290     if ( aControl )
       
  3291         {
       
  3292         for ( TInt ii = 0; ii < iItems.Count(); ii++ ) 
       
  3293             {
       
  3294             CAknToolbarItem* item = iItems[ii];
       
  3295             if ( item && item->Control() == aControl )
       
  3296                 {
       
  3297                 return ii;
       
  3298                 }
       
  3299             }
       
  3300         }
       
  3301     return KErrNotFound;
       
  3302     }
       
  3303 
       
  3304 // -----------------------------------------------------------------------------
       
  3305 // CAknToolbar::ToolbarVisibleIndexById
       
  3306 // Returns the index of the toolbar item inside of the iVisibleItems array.
       
  3307 // -----------------------------------------------------------------------------
       
  3308 //
       
  3309 TInt CAknToolbar::ToolbarVisibleIndexById( const TInt aId ) const 
       
  3310     {
       
  3311     for ( TInt ii = 0; ii < iVisibleItems.Count(); ii++ )
       
  3312         {
       
  3313         CAknToolbarItem* item = iVisibleItems[ii];
       
  3314         if ( item && item->CommandId() == aId )
       
  3315             {
       
  3316             return ii;
       
  3317             }
       
  3318         }
       
  3319     return KErrNotFound;
       
  3320     }
       
  3321 
       
  3322 
       
  3323 
       
  3324 // -----------------------------------------------------------------------------
       
  3325 // CAknToolbar::ToolbarVisibleIndexByControl
       
  3326 // Returns visible toolbar item index for the specified control or KErrNotFound.
       
  3327 // -----------------------------------------------------------------------------
       
  3328 //
       
  3329 TInt CAknToolbar::ToolbarVisibleIndexByControl( const CCoeControl* aControl ) const 
       
  3330     {
       
  3331     if ( aControl )
       
  3332         {
       
  3333         for ( TInt ii = 0; ii < iVisibleItems.Count(); ii++ ) 
       
  3334             {
       
  3335             CAknToolbarItem* item = iVisibleItems[ii];
       
  3336             if ( item && item->Control() == aControl )
       
  3337                 {
       
  3338                 return ii;
       
  3339                 }
       
  3340             }
       
  3341         }
       
  3342     return KErrNotFound;
       
  3343     }
       
  3344 
       
  3345 // -----------------------------------------------------------------------------
       
  3346 // CAknToolbar::SlideToolbar
       
  3347 // Draws the toolbar with sliding effect.
       
  3348 // -----------------------------------------------------------------------------
       
  3349 //    
       
  3350 void CAknToolbar::SlideToolbar( const TPoint& aEndPos )
       
  3351     {          
       
  3352     // Currently supports sliding only from left to right. 
       
  3353     // If some other cases are needed implementation should be changed then.   
       
  3354 
       
  3355     if ( iOrientation == EAknOrientationVertical )
       
  3356         {
       
  3357         return; 
       
  3358         }
       
  3359     
       
  3360     TPoint start = Position();
       
  3361     iStep = (  aEndPos.iX - start.iX ) / 10;
       
  3362 
       
  3363     iEndPos = aEndPos.iX; 
       
  3364 
       
  3365     SlideWithIdle(); 
       
  3366 
       
  3367     }
       
  3368 
       
  3369 // -----------------------------------------------------------------------------
       
  3370 // CAknToolbar::SetRightCbaText
       
  3371 // Changes CBA if no item is focused.
       
  3372 // -----------------------------------------------------------------------------
       
  3373 //  
       
  3374 void CAknToolbar::SetRightCbaTextL()
       
  3375     {
       
  3376     if ( !iToolbarCba )
       
  3377         {
       
  3378         return;
       
  3379         }
       
  3380     
       
  3381     if ( IsFocused() && iFocusedItem == KFocusedNone )
       
  3382         {
       
  3383         iToolbarCba->MakeCommandVisibleByPosition( 
       
  3384             CEikButtonGroupContainer::ELeftSoftkeyPosition, EFalse ); 
       
  3385         iToolbarCba->MakeCommandVisibleByPosition( 
       
  3386             CEikButtonGroupContainer::EMiddleSoftkeyPosition, EFalse ); 
       
  3387         iToolbarCba->DrawDeferred();
       
  3388         }
       
  3389     }
       
  3390 // -----------------------------------------------------------------------------
       
  3391 // CAknToolbar::GetNextSelectableItemIndex
       
  3392 // Returns next not dimmed and not hidden control index.
       
  3393 // -----------------------------------------------------------------------------
       
  3394 //    
       
  3395 TInt CAknToolbar::GetNextSelectableItemIndex( TInt aStartIndex, TBool aMoveForward )
       
  3396     {
       
  3397     TInt index( aStartIndex );
       
  3398     
       
  3399     if ( IsNonFocusing() )
       
  3400         {
       
  3401         return KFocusedNone; 
       
  3402         }
       
  3403     
       
  3404     __ASSERT_ALWAYS( iVisibleItems.Count(), Panic( EEikPanicInvalidLength ) ); 
       
  3405     
       
  3406     CAknButton* button = NULL;  
       
  3407     // we will do it till we don't get valid non-dimmed item or till we don't
       
  3408     // make the whole round ( all items are dimmed )
       
  3409     do 
       
  3410         {
       
  3411         button = NULL; 
       
  3412         if ( aMoveForward && index >= iVisibleItems.Count() - 1 )
       
  3413             {
       
  3414             index = 0;
       
  3415             }
       
  3416         else if ( !aMoveForward && index == 0 )
       
  3417             {
       
  3418             index = iVisibleItems.Count() - 1;
       
  3419             }
       
  3420         else
       
  3421             {
       
  3422             if ( aMoveForward )
       
  3423                 {
       
  3424                 ++index;
       
  3425                 }
       
  3426             else 
       
  3427                 {
       
  3428                 --index;
       
  3429                 }
       
  3430             }
       
  3431         button = static_cast<CAknButton*>( iVisibleItems[index]->Control() );
       
  3432 
       
  3433         } while ( ( !button || button->IsDimmed() ) && aStartIndex != index );
       
  3434                       
       
  3435     // no non-dimmed items
       
  3436     if ( aStartIndex == index )
       
  3437         {
       
  3438         return KFocusedNone;
       
  3439         }
       
  3440     
       
  3441     return index;
       
  3442     }
       
  3443 
       
  3444 // -----------------------------------------------------------------------------
       
  3445 // CAknToolbar::MoveHighlightL
       
  3446 // Moves highlight from one item to another
       
  3447 // -----------------------------------------------------------------------------
       
  3448 //    
       
  3449 void CAknToolbar::MoveHighlightL( TInt aItemIndex, 
       
  3450                                    const TBool aDrawNow,
       
  3451                                    const TBool aMoveForward,
       
  3452                                    const TBool aPrepareControl )
       
  3453     {
       
  3454     if ( IsNonFocusing() || !iVisibleItems.Count() )
       
  3455         {
       
  3456         // Item cannot get focus, when toolbar is non-focusing
       
  3457         aItemIndex = KFocusedNone;
       
  3458         }
       
  3459     
       
  3460     if ( aItemIndex >= iVisibleItems.Count() )
       
  3461         {
       
  3462         aItemIndex = iVisibleItems.Count() - 1;
       
  3463         }
       
  3464     else if ( aItemIndex < 0 && aItemIndex != KFocusedNone )
       
  3465         {
       
  3466         aItemIndex = 0;
       
  3467         }
       
  3468         
       
  3469     if ( aItemIndex == iFocusedItem )
       
  3470         {
       
  3471         if ( iFocusedItem >= 0 && iFocusedItem < iVisibleItems.Count() )
       
  3472             {
       
  3473             // Set item focused again so that tooltip is shown again. 
       
  3474             iVisibleItems[iFocusedItem]->SetFocusL( ETrue, aPrepareControl,
       
  3475                 aDrawNow ? EDrawNow : ENoDrawNow, this );
       
  3476             }
       
  3477         return;
       
  3478         }
       
  3479     
       
  3480     TInt oldFocused = iFocusedItem;
       
  3481     if ( oldFocused < 0 || oldFocused >= iVisibleItems.Count() )
       
  3482         {
       
  3483         oldFocused = KFocusedNone;
       
  3484         }
       
  3485     iFocusedItem = aItemIndex;
       
  3486     CAknToolbarItem* item = NULL;
       
  3487     CAknButton* button = NULL; 
       
  3488     
       
  3489     if ( iFocusedItem != KFocusedNone )  
       
  3490         {
       
  3491         // There are only buttons in a focusable toolbar
       
  3492         item = iVisibleItems[iFocusedItem];
       
  3493         button = static_cast<CAknButton*>( item->Control() ); 
       
  3494 
       
  3495         if ( button && button->IsDimmed() )
       
  3496             {
       
  3497             // we should skip dimmed controls
       
  3498             TInt index = GetNextSelectableItemIndex( iFocusedItem, 
       
  3499                 aMoveForward );
       
  3500             if ( index == KFocusedNone )
       
  3501                 {
       
  3502                 // all items are dimmed
       
  3503                 iFocusedItem = KFocusedNone;
       
  3504                 SetRightCbaTextL();
       
  3505                 // Draw last hightlighted item again to remove highlight
       
  3506                 if ( oldFocused >= 0 && oldFocused < iVisibleItems.Count() )
       
  3507                     {
       
  3508                     CAknToolbarItem* oldItem = iVisibleItems[oldFocused]; 
       
  3509                     DrawNow( oldItem->HighlightRect() );     
       
  3510                     }
       
  3511                 return;
       
  3512                 }
       
  3513             // there is only one non dimmed item
       
  3514             else if ( index == oldFocused )
       
  3515                 {
       
  3516                 iFocusedItem = oldFocused; 
       
  3517                 return;
       
  3518                 }
       
  3519             else
       
  3520                 {
       
  3521                 iFocusedItem = index;
       
  3522                 }
       
  3523                 
       
  3524             __ASSERT_DEBUG( ( index >= 0 && index < iVisibleItems.Count() ), 
       
  3525                 Panic( EEikPanicInvalidIndex ) );
       
  3526             item = iVisibleItems[index];
       
  3527             }
       
  3528            
       
  3529         // set this item focused
       
  3530         item->SetFocusL( ETrue, aPrepareControl,
       
  3531                          aDrawNow ? EDrawNow : ENoDrawNow, this );
       
  3532         item->Control()->DrawNow( item->HighlightRect() ); 
       
  3533         }
       
  3534     
       
  3535     if ( oldFocused != KFocusedNone )
       
  3536         {
       
  3537         item = iVisibleItems[oldFocused];
       
  3538         if ( item && item->Control() )
       
  3539             {
       
  3540             SelectItemL( oldFocused, EFalse );
       
  3541 
       
  3542             // take the focus away
       
  3543             item->SetFocusL( EFalse, aPrepareControl,
       
  3544                              aDrawNow ? EDrawNow : ENoDrawNow, this );
       
  3545             item->Control()->DrawNow( item->HighlightRect() ); 
       
  3546             }
       
  3547         }
       
  3548     }
       
  3549 
       
  3550 // -----------------------------------------------------------------------------
       
  3551 // CAknToolbar::InitFocusedItemL
       
  3552 // Set the focus to the middle or first item. Size and position should be
       
  3553 // calculated already, to avoid iVisibleItems.Count() to be 0.
       
  3554 // -----------------------------------------------------------------------------
       
  3555 //
       
  3556 void CAknToolbar::InitFocusedItemL( const TBool aDrawNow )
       
  3557     {
       
  3558     __ASSERT_ALWAYS( iVisibleItems.Count(), Panic( EEikPanicInvalidLength ) );
       
  3559     
       
  3560     if ( iInitialFocusedItem >= 0 && 
       
  3561          iInitialFocusedItem < iVisibleItems.Count() )
       
  3562         {
       
  3563         MoveHighlightL( iInitialFocusedItem, aDrawNow );
       
  3564         return;
       
  3565         }
       
  3566     
       
  3567     if ( iFlags & KAknToolbarMiddleItemFocused && iVisibleItems.Count() != 1 )
       
  3568         {
       
  3569         // focus is in the middle
       
  3570         if ( iVisibleItems.Count() % 2 )
       
  3571             {
       
  3572             // if the number of visible items is odd number
       
  3573             MoveHighlightL( iVisibleItems.Count() / 2, aDrawNow );
       
  3574             }
       
  3575         else
       
  3576             {
       
  3577             // if the number of visible items is even number
       
  3578             MoveHighlightL( iVisibleItems.Count() / 2 - 1, aDrawNow );
       
  3579             }
       
  3580         }
       
  3581     else // default behaviour
       
  3582         {
       
  3583         MoveHighlightL( 0, aDrawNow );
       
  3584         }
       
  3585     }
       
  3586 
       
  3587 // -----------------------------------------------------------------------------
       
  3588 // CAknToolbar::SetShown
       
  3589 // Sets the flag on or off.
       
  3590 // -----------------------------------------------------------------------------
       
  3591 //
       
  3592 void CAknToolbar::SetShown( const TBool aShown )
       
  3593     {
       
  3594     if ( aShown )
       
  3595         {
       
  3596         iInternalFlags.Set( EShown );
       
  3597         }
       
  3598     else
       
  3599         {
       
  3600         iInternalFlags.Clear( EShown );
       
  3601         }
       
  3602 
       
  3603     if ( !( iFlags & KAknToolbarWithoutCba ) && !IsNonFocusing() &&
       
  3604         !( iFlags & KAknToolbarSmall ) )
       
  3605         {
       
  3606         FadeBehindPopup( aShown ); 
       
  3607         }
       
  3608     CCoeControl::MakeVisible( aShown );
       
  3609     // Need to call here, because ComponentControl only returns
       
  3610     // visible items
       
  3611     UpdateControlVisibility();
       
  3612     }
       
  3613 
       
  3614 // -----------------------------------------------------------------------------
       
  3615 // CAknToolbar::SelectItemL
       
  3616 // -----------------------------------------------------------------------------
       
  3617 //
       
  3618 void CAknToolbar::SelectItemL( const TInt aIndex, const TBool aSelect )
       
  3619     {
       
  3620     if ( aSelect )
       
  3621         {
       
  3622         if ( aIndex != iSelectedItem )
       
  3623             {
       
  3624             if ( iSelectedItem != KSelectedNone &&
       
  3625                  iSelectedItem < iVisibleItems.Count() )
       
  3626                 {
       
  3627                 iVisibleItems[iSelectedItem]->SetIsSelectedL( EFalse );
       
  3628                 }
       
  3629 
       
  3630             if ( aIndex != KSelectedNone && aIndex < iVisibleItems.Count() )
       
  3631                 {
       
  3632                 if ( iVisibleItems[aIndex]->SetIsSelectedL( ETrue ) )
       
  3633                     {
       
  3634                     iSelectedItem = aIndex;
       
  3635                     }
       
  3636                 else
       
  3637                     {
       
  3638                     iSelectedItem = KSelectedNone;
       
  3639                     }
       
  3640                 }
       
  3641             else
       
  3642                 {
       
  3643                 iSelectedItem = KSelectedNone;
       
  3644                 }
       
  3645             }
       
  3646         }
       
  3647     else
       
  3648         {
       
  3649         if ( aIndex == iSelectedItem )
       
  3650             {
       
  3651             if ( aIndex != KSelectedNone && aIndex < iVisibleItems.Count() )
       
  3652                 {
       
  3653                 iVisibleItems[aIndex]->SetIsSelectedL( EFalse );
       
  3654                 }
       
  3655             iSelectedItem = KSelectedNone;
       
  3656             }
       
  3657         }
       
  3658     }
       
  3659 
       
  3660 // -----------------------------------------------------------------------------
       
  3661 // CAknToolbar::RectFromLayout
       
  3662 // -----------------------------------------------------------------------------
       
  3663 //
       
  3664 TRect CAknToolbar::RectFromLayout( const TRect& aParent,
       
  3665         const TAknWindowComponentLayout& aComponentLayout ) const
       
  3666     {
       
  3667     TAknWindowLineLayout lineLayout = aComponentLayout.LayoutLine();
       
  3668     TAknLayoutRect layoutRect;
       
  3669     layoutRect.LayoutRect( aParent, lineLayout );
       
  3670     return layoutRect.Rect();
       
  3671     }
       
  3672 
       
  3673 // -----------------------------------------------------------------------------
       
  3674 // CAknToolbar::WaitForScreenSwitch. This is called by CIdle when it returns. 
       
  3675 // Toolbar is shown again with new screen capture. 
       
  3676 // this function is deserted for NGA's removing BitmapDevice
       
  3677 // -----------------------------------------------------------------------------
       
  3678 //
       
  3679 TInt CAknToolbar::WaitForScreenSwitch(TAny* /*aThis*/)
       
  3680     {
       
  3681     return KErrNone; 
       
  3682     }
       
  3683 
       
  3684 // -----------------------------------------------------------------------------
       
  3685 // CAknToolbar::HideToolbarForBackgroundUpdate
       
  3686 // This hides toolbar so that it is possible to get a screen capture. 
       
  3687 // -----------------------------------------------------------------------------
       
  3688 //
       
  3689 void CAknToolbar::HideToolbarForBackgroundUpdate()
       
  3690     {
       
  3691 	  return;
       
  3692     }
       
  3693 
       
  3694 // -----------------------------------------------------------------------------
       
  3695 // CAknToolbar::UpdateTooltipPositions
       
  3696 // Updates tooltips positions
       
  3697 // -----------------------------------------------------------------------------
       
  3698 //
       
  3699 void CAknToolbar::UpdateControlPositions()
       
  3700     {
       
  3701     for ( TInt ii = 0; ii < iVisibleItems.Count(); ++ii )
       
  3702         {
       
  3703         iVisibleItems[ii]->RegisterPosition( Position() );
       
  3704         }
       
  3705     }
       
  3706 
       
  3707 // -----------------------------------------------------------------------------
       
  3708 // CAknToolbar::ShowViaIdle
       
  3709 // Shows toolbar via CIdle.
       
  3710 // -----------------------------------------------------------------------------
       
  3711 //
       
  3712 void CAknToolbar::ShowViaIdle()
       
  3713     {
       
  3714     if ( !iIdle )
       
  3715         {
       
  3716         TRAPD( err, iIdle = CIdle::NewL( CActive::EPriorityStandard ) );
       
  3717         
       
  3718         if ( err != KErrNone)
       
  3719             {
       
  3720             return; 
       
  3721             }
       
  3722         }
       
  3723     
       
  3724     if ( iIdle->IsActive() )
       
  3725         {
       
  3726         iIdle->Cancel();
       
  3727         }
       
  3728 
       
  3729     if ( iFlags & KAknToolbarFixed )   
       
  3730         {
       
  3731         iIdle->SetPriority ( CActive::EPriorityStandard );
       
  3732         }
       
  3733     else
       
  3734         {
       
  3735         iIdle->SetPriority( CActive::EPriorityIdle );
       
  3736         }
       
  3737         
       
  3738     iInternalFlags.Set( EShown );
       
  3739     iIdle->Start( TCallBack ( ShowDelayedToolbar, this ) );
       
  3740     }
       
  3741 
       
  3742 // -----------------------------------------------------------------------------
       
  3743 // CAknToolbar::ShowDelayedToolbar
       
  3744 // Callback for delayed window creation.
       
  3745 // -----------------------------------------------------------------------------
       
  3746 //
       
  3747 TInt CAknToolbar::ShowDelayedToolbar( TAny* aThis )
       
  3748     {
       
  3749     CAknToolbar* toolbar = static_cast<CAknToolbar*>(aThis);
       
  3750     if ( !toolbar->iInternalFlags.IsSet( EShowingAgain ) && 
       
  3751          toolbar->iInternalFlags.IsSet( EShown ) )
       
  3752         {
       
  3753         TRAPD(err,toolbar->ShowToolbarL()); 
       
  3754         if ( err != KErrNone )
       
  3755             {
       
  3756             // if we failed then softkeys should be deleted just in case if they 
       
  3757             // were created before leave
       
  3758             delete toolbar->iToolbarCba;
       
  3759             toolbar->iToolbarCba = NULL;
       
  3760                 
       
  3761             toolbar->SetFocus( EFalse );
       
  3762             CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( toolbar, 
       
  3763                 ~0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
  3764 
       
  3765             }
       
  3766         }
       
  3767     else
       
  3768         {
       
  3769         toolbar->DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNormal );
       
  3770         toolbar->iInternalFlags.Clear( EShowingAgain );
       
  3771         }
       
  3772     return KErrNone; 
       
  3773     }
       
  3774 
       
  3775 
       
  3776 // -----------------------------------------------------------------------------
       
  3777 // CAknToolbar::CheckHitAreas
       
  3778 // Registers buttons to check hit areas in the case of fixed toolbar
       
  3779 // -----------------------------------------------------------------------------
       
  3780 //
       
  3781 void CAknToolbar::CheckHitAreas()
       
  3782     {
       
  3783     CAknButton* button = NULL; 
       
  3784 
       
  3785     for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
  3786         {
       
  3787         if ( iItems[ii]->ControlType() == EAknCtButton || 
       
  3788              iItems[ii]->ControlType() == EAknCtToolbarExtension  )
       
  3789             {
       
  3790             button = static_cast<CAknButton*>(iItems[ii]->Control());             
       
  3791             button->CheckHitArea(); 
       
  3792             }
       
  3793        }
       
  3794 
       
  3795     }
       
  3796 
       
  3797 // -----------------------------------------------------------------------------
       
  3798 // CAknToolbar::Toolbar Extension
       
  3799 // Return pointer to toolbar extension if available
       
  3800 // -----------------------------------------------------------------------------
       
  3801 //
       
  3802 EXPORT_C CAknToolbarExtension* CAknToolbar::ToolbarExtension() const 
       
  3803     {
       
  3804     for ( TInt i = 0; i < iItems.Count(); ++i )
       
  3805         {
       
  3806         if ( iItems[i]->ControlType() == EAknCtToolbarExtension )
       
  3807             {
       
  3808             return static_cast<CAknToolbarExtension*>( iItems[i]->Control() ); 
       
  3809             }
       
  3810         }
       
  3811     return NULL;     
       
  3812     }
       
  3813 
       
  3814 // -----------------------------------------------------------------------------
       
  3815 // Calls dyninittoolbarL about extension opening. 
       
  3816 // -----------------------------------------------------------------------------
       
  3817 //
       
  3818 void CAknToolbar::DynInitExtensionL( CCoeControl* aControl )  
       
  3819     {
       
  3820     TInt commandId = ToolbarItemByControl( aControl )->CommandId(); 
       
  3821     if ( iToolbarObserver )
       
  3822         {
       
  3823         iToolbarObserver->DynInitToolbarL( commandId, this );
       
  3824         }
       
  3825     }
       
  3826 
       
  3827 
       
  3828 // -----------------------------------------------------------------------------
       
  3829 // CAknToolbar::CheckFixedToolbarButtonsL
       
  3830 // Counts button components of fixed toolbar and adds button(s) if needed
       
  3831 // -----------------------------------------------------------------------------
       
  3832 //    
       
  3833 void CAknToolbar::CheckFixedToolbarButtonsL()
       
  3834     {
       
  3835     if ( iFlags & KAknToolbarFixed )
       
  3836         {
       
  3837         // Count button components
       
  3838         TInt count ( 0 );
       
  3839         for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
  3840             {
       
  3841             if ( iItems[ii]->ControlType() == EAknCtButton || 
       
  3842                 iItems[ii]->ControlType() == EAknCtToolbarExtension )
       
  3843                 {
       
  3844                 ++count;
       
  3845                 }
       
  3846            }
       
  3847            
       
  3848         // Add missing button components
       
  3849         for ( TInt kk = count; kk < KFixedtoolbarButtons; ++kk )
       
  3850             {
       
  3851             CAknButton* button = CAknButton::NewLC( NULL, NULL, NULL, NULL, 
       
  3852                 KNullDesC, KNullDesC, 0, 0 );
       
  3853             button->SetDimmed( ETrue );
       
  3854             AddItemL( button, EAknCtButton, -1, 0 );
       
  3855             CleanupStack::Pop( button );
       
  3856             AdjustButton( *button );
       
  3857             }
       
  3858         }
       
  3859     }
       
  3860 
       
  3861 // -----------------------------------------------------------------------------
       
  3862 // CAknToolbar::DrawFixedBackgroundL
       
  3863 // Draws background of fixed toolbar
       
  3864 // -----------------------------------------------------------------------------
       
  3865 //    
       
  3866 void CAknToolbar::DrawFixedBackgroundL( CWindowGc& aGc, 
       
  3867                                         const CCoeControl& aControl, 
       
  3868                                         const TRect& aRect ) const
       
  3869     {
       
  3870     // What happens here is:
       
  3871     // 1. Check if we are in the idle state and a wallpaper is in use.
       
  3872     // 2. If wallpaper is not used then just blit a correct piece of the skin
       
  3873     //    background to the screen and return.
       
  3874     // 3. If we're in idle and wallpaper is used then draw wallpaper to a
       
  3875     //    temporary bitmap.
       
  3876     // 4. Skin background with additional mask (either qgn_graf_bg_lsc_bottom_mask_icon 
       
  3877     //    or qgn_graf_bg_prt_bottom_mask_icon) is blitted on top of the wallpaper. 
       
  3878     //    Skin background's original mask is ignored. Note that these additional
       
  3879     //    masks are larger than the actual fixed toolbar so only a portion of them
       
  3880     //    should be used.
       
  3881     //    Blit the generated background bitmap to the screen.
       
  3882     TBool wallpaperInUse = EFalse;
       
  3883     TInt itemsInCleanupStack = 0;
       
  3884     
       
  3885     if ( iInternalFlags.IsSet( EInIdle ) )
       
  3886         {
       
  3887         CRepository* repository = CRepository::NewL( KCRUidPersonalisation );
       
  3888         repository->Get( KPslnWallpaperType, wallpaperInUse );
       
  3889         delete repository;
       
  3890         }
       
  3891 
       
  3892     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  3893     
       
  3894     // background context shared by both wallpaper and skin background
       
  3895     TAknsItemID itemID = iInternalFlags.IsSet( EInIdle ) ? KAknsIIDQsnBgScreenIdle : KAknsIIDQsnBgScreen;
       
  3896     if ( iBgIID !=  KAknsIIDNone )
       
  3897     	{
       
  3898     	itemID = iBgIID;
       
  3899     	}
       
  3900     CAknsBasicBackgroundControlContext* context =
       
  3901         CAknsBasicBackgroundControlContext::NewL(
       
  3902         itemID,
       
  3903         iAvkonAppUi->ApplicationRect(),
       
  3904         EFalse );
       
  3905 
       
  3906     CleanupStack::PushL( context );
       
  3907     ++itemsInCleanupStack;
       
  3908 
       
  3909     const TDisplayMode displayMode(
       
  3910         CCoeEnv::Static()->ScreenDevice()->DisplayMode() );
       
  3911         
       
  3912     TBool useDithering = EFalse;
       
  3913     TPoint skinOrigin( aRect.iTl );
       
  3914 
       
  3915     // check if dithering is to be used
       
  3916     if ( ( displayMode == EColor16MA || displayMode == EColor16MU ) && 
       
  3917          ( iFlags & KAknToolbarDsaMode ) /*&&
       
  3918          !bgBmp->IsCompressedInRAM() */)
       
  3919         {
       
  3920         useDithering = ETrue;
       
  3921         }
       
  3922 
       
  3923     // draw skin background to whatever context was chosen (window or bitmap)
       
  3924     AknsDrawUtils::DrawBackground( skin, 
       
  3925                                    context, 
       
  3926                                    this, 
       
  3927                                    aGc,
       
  3928                                    skinOrigin, 
       
  3929                                    TRect( iPosition + aRect.iTl, aControl.Size() ),
       
  3930                                    KAknsDrawParamDefault );
       
  3931 
       
  3932     if ( wallpaperInUse )
       
  3933         {
       
  3934         // Blit wallpaper to the background bitmap.
       
  3935         context->SetBitmap( KAknsIIDWallpaper );
       
  3936         AknsDrawUtils::DrawBackground( skin,
       
  3937                                        context, 
       
  3938                                        this, 
       
  3939                                        aGc,
       
  3940                                        TPoint( 0, 0 ), 
       
  3941                                        TRect( iPosition + aRect.iTl, aControl.Size() ),
       
  3942                                        KAknsDrawParamDefault );
       
  3943             }
       
  3944     if ( useDithering )
       
  3945         {
       
  3946         aGc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
  3947         aGc.SetBrushColor( TRgb( KToolbarBgColor, KToolBarBgAlpha ) );
       
  3948         aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  3949         aGc.DrawRect( Rect() );
       
  3950         }
       
  3951 
       
  3952     CleanupStack::PopAndDestroy( itemsInCleanupStack );
       
  3953     }
       
  3954 
       
  3955 // -----------------------------------------------------------------------------
       
  3956 // CAknToolbar::SlideWithIdle. This is called by CIdle when it returns. 
       
  3957 // Toolbar is drawn again with different coordinates.  
       
  3958 // -----------------------------------------------------------------------------
       
  3959 //
       
  3960 void CAknToolbar::SlideWithIdle()
       
  3961     {
       
  3962     TPoint start(iPosition); 
       
  3963 
       
  3964     if ( start.iX < iEndPos )
       
  3965         {
       
  3966         start.iX += iStep;
       
  3967         if ( start.iX >= iEndPos )
       
  3968             {
       
  3969             start.iX = iEndPos; // needed if start.iX is greater than iEndPos
       
  3970             TRAP_IGNORE( InitFocusedItemL( ETrue ) );
       
  3971             }
       
  3972         SetPosition( start );
       
  3973         DrawNow(); 
       
  3974 
       
  3975         if ( !iIdle )
       
  3976             {
       
  3977             TRAPD( err, iIdle = CIdle::NewL( CActive::EPriorityIdle ) );
       
  3978             if ( err != KErrNone)
       
  3979                 {
       
  3980                 return; 
       
  3981                 }
       
  3982             }
       
  3983             
       
  3984         if ( iIdle->IsActive() )
       
  3985             {
       
  3986             iIdle->Cancel();
       
  3987             }
       
  3988             
       
  3989         iIdle->Start( TCallBack ( ReadyToSlide, this ) );
       
  3990         }
       
  3991     }
       
  3992 
       
  3993 // -----------------------------------------------------------------------------
       
  3994 // CAknToolbar::ReadyToSlide. This is called by CIdle when it returns. 
       
  3995 // Toolbar is drawn again with different coordinates.  
       
  3996 // -----------------------------------------------------------------------------
       
  3997 //
       
  3998 TInt CAknToolbar::ReadyToSlide( TAny* aThis )
       
  3999     {
       
  4000     CAknToolbar* toolbar = static_cast<CAknToolbar*>(aThis);
       
  4001     toolbar->SlideWithIdle();
       
  4002     return KErrNone; 
       
  4003     }
       
  4004 
       
  4005 // -----------------------------------------------------------------------------
       
  4006 // CAknToolbar::AdjustButton
       
  4007 // Adjusts button's properties depending on the toolbar's features.  
       
  4008 // -----------------------------------------------------------------------------
       
  4009 //
       
  4010 void CAknToolbar::AdjustButton( CAknButton& aButton )
       
  4011     {
       
  4012     // tooltip properties
       
  4013     aButton.SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 
       
  4014         KToolbarButtonInViewTimeout );
       
  4015         
       
  4016     aButton.HideTooltipWhenAppFaded( EFalse ); 
       
  4017     
       
  4018     // toolbar buttons don't have margins
       
  4019     if ( aButton.UsesDefaultMargins() )
       
  4020         {
       
  4021         TMargins8 margins;
       
  4022         margins.SetAllValuesTo( 0 );
       
  4023         aButton.SetMargins( margins );
       
  4024         }
       
  4025         
       
  4026     // remove frame graphics if the current toolbar mode doesn't support them
       
  4027     if ( ( iFlags & KAknToolbarSmall ) ||
       
  4028          ( iFlags & KAknToolbarNoBackground ) )
       
  4029         { 
       
  4030         aButton.SetButtonFlags( aButton.ButtonFlags() | KAknButtonNoFrame ); 
       
  4031         }
       
  4032 
       
  4033     // force frame graphics for fixed toolbar button
       
  4034     if ( iFlags & KAknToolbarFixed )
       
  4035         {
       
  4036         aButton.UseMaskedDraw( ETrue );
       
  4037         aButton.SetFrameAndCenterIds( KAknsIIDQgnFrSctrlButton,
       
  4038                                       KAknsIIDQgnFrSctrlButtonCenter,
       
  4039                                       KAknsIIDQgnFrSctrlButtonPressed,
       
  4040                                       KAknsIIDQgnFrSctrlButtonCenterPressed,
       
  4041                                       KAknsIIDQgnFrSctrlButton,
       
  4042                                       KAknsIIDQgnFrSctrlButtonCenter,
       
  4043                                       KAknsIIDQgnFrSctrlButtonPressed,
       
  4044                                       KAknsIIDQgnFrSctrlButtonCenterPressed,
       
  4045                                       KAknsIIDQgnFrSctrlButton,
       
  4046                                       KAknsIIDQgnFrSctrlButtonCenter );
       
  4047                                       
       
  4048         // Touch area tuning - in fixed toolbar only such events
       
  4049         // that hit to touch rect
       
  4050         aButton.CheckHitArea(); 
       
  4051         }
       
  4052     }
       
  4053 
       
  4054 // -----------------------------------------------------------------------------
       
  4055 // CAknToolbar::AdjustAllButtons
       
  4056 // Adjusts all buttons' properties depending on the toolbar's features.  
       
  4057 // -----------------------------------------------------------------------------
       
  4058 //
       
  4059 void CAknToolbar::AdjustAllButtons()
       
  4060     {
       
  4061     for ( TInt i = 0; i < iItems.Count(); ++i )
       
  4062         {
       
  4063         if ( iItems[i]->ControlType() == EAknCtButton || 
       
  4064              iItems[i]->ControlType() == EAknCtToolbarExtension  )
       
  4065             {
       
  4066             AdjustButton( *static_cast<CAknButton*>(iItems[i]->Control() ) );
       
  4067             }
       
  4068         }
       
  4069     }
       
  4070 
       
  4071 // -----------------------------------------------------------------------------
       
  4072 // CAknToolbar::SetOrdinalPositions
       
  4073 // Adjusts toolbar's and overlying dialog's window positions so that dialog is
       
  4074 // displayed on top of the toolbar.  
       
  4075 // -----------------------------------------------------------------------------
       
  4076 //
       
  4077 void CAknToolbar::SetOrdinalPositions() const
       
  4078     {
       
  4079     TBool isDisplayed = CEikonEnv::Static()->EikAppUi()->IsDisplayingMenuOrDialog(); 
       
  4080     CCoeControl* ctrl = NULL;  
       
  4081     RDrawableWindow* ctrlWindow = NULL;
       
  4082     RDrawableWindow* childWindow = NULL;
       
  4083 
       
  4084     if ( !isDisplayed )
       
  4085         {
       
  4086         CEikMenuBar* menuBar = NULL; 
       
  4087         TVwsViewId viewId;
       
  4088         TInt err = iAvkonViewAppUi->GetActiveViewId( viewId );
       
  4089         if ( err == KErrNone && viewId.iAppUid != viewId.iViewUid )
       
  4090             {
       
  4091             // Application has active view
       
  4092             CAknView* view = iAvkonViewAppUi->View( viewId.iViewUid );
       
  4093             if ( view )
       
  4094                 {
       
  4095                 ctrl = menuBar = view->CAknView::MenuBar();
       
  4096                 }
       
  4097             }
       
  4098         else
       
  4099             {
       
  4100             ctrl = menuBar = iEikonEnv->AppUiFactory()->MenuBar();
       
  4101             }
       
  4102 
       
  4103         if ( menuBar )
       
  4104             {
       
  4105             isDisplayed = menuBar->IsDisplayed();
       
  4106             }
       
  4107         if ( isDisplayed )
       
  4108             {
       
  4109             // if menuBar returns ETrue from IsDisplayed, it means it has a menu 
       
  4110             // pane
       
  4111             ctrlWindow = menuBar->MenuPane()->DrawableWindow();
       
  4112             
       
  4113             if ( menuBar->MenuPane()->CascadeMenuPane() )
       
  4114                 {
       
  4115                 // submenu has a submenu
       
  4116                 if ( menuBar->MenuPane()->CascadeMenuPane()->CascadeMenuPane() )
       
  4117                     {
       
  4118                     ctrlWindow = menuBar->MenuPane()->CascadeMenuPane()->DrawableWindow();
       
  4119                     childWindow =                     
       
  4120                         menuBar->MenuPane()->CascadeMenuPane()->CascadeMenuPane()->DrawableWindow();
       
  4121                     }
       
  4122                 else
       
  4123                     {
       
  4124                     childWindow = 
       
  4125                         menuBar->MenuPane()->CascadeMenuPane()->DrawableWindow();
       
  4126                     }
       
  4127                 }
       
  4128             }
       
  4129         }
       
  4130     else
       
  4131         {
       
  4132         ctrl = CCoeEnv::Static()->AppUi()->TopFocusedControl(); 
       
  4133         
       
  4134         if ( ctrl )
       
  4135             {
       
  4136             CEikDialog* dialog = ctrl->MopGetObject( dialog );
       
  4137             
       
  4138             if ( dialog )
       
  4139                 {
       
  4140                 if ( dialog->DrawableWindow() )
       
  4141                     {
       
  4142                     TInt flag = dialog->DialogFlags();
       
  4143                     
       
  4144                     if( !( flag & EEikDialogFlagFillScreen ) && 
       
  4145                         !( flag & EEikDialogFlagFillAppClientRect ) )
       
  4146                         {
       
  4147                         ctrlWindow = dialog->DrawableWindow();
       
  4148                         }
       
  4149                     }
       
  4150                 }
       
  4151             else
       
  4152                 {
       
  4153                 CEikMenuBar* ctrlMenu = ctrl->MopGetObject( ctrlMenu );
       
  4154             
       
  4155                 if ( ctrlMenu && ctrlMenu->IsDisplayed() )
       
  4156                     {
       
  4157                     ctrlWindow = ctrlMenu->MenuPane()->DrawableWindow();
       
  4158                     ctrl = ctrlMenu;
       
  4159                     if ( ctrlMenu->MenuPane()->CascadeMenuPane() )
       
  4160                         {
       
  4161                         childWindow = ctrlMenu->MenuPane()->CascadeMenuPane()->DrawableWindow();
       
  4162                         }
       
  4163                     }
       
  4164                 }
       
  4165             }
       
  4166         }
       
  4167     // Menupane or dialog most probably has softkeys so we need to push
       
  4168     // the control first and then softkeys so that a possible pointer
       
  4169     // capture still works.
       
  4170     if ( ctrlWindow )
       
  4171         {
       
  4172         CEikCba* cba = ctrl->MopGetObject( cba );
       
  4173         
       
  4174         TBool ctrlFaded = ctrlWindow->IsFaded();
       
  4175         TBool childFaded = EFalse;
       
  4176         TBool cbaFaded = EFalse;
       
  4177 
       
  4178         if ( childWindow ) 
       
  4179             {
       
  4180             childFaded = childWindow->IsFaded();
       
  4181             }
       
  4182         if ( cba && cba->DrawableWindow() ) 
       
  4183             {
       
  4184             cbaFaded = cba->DrawableWindow()->IsFaded();
       
  4185             }
       
  4186 
       
  4187         if ( !ctrlFaded )
       
  4188             {
       
  4189             ctrlWindow->SetOrdinalPosition( 0 );            
       
  4190             }
       
  4191         
       
  4192         // Set possible child in front of parent
       
  4193         if ( childWindow && !childFaded )
       
  4194             {
       
  4195             childWindow->SetOrdinalPosition( 0 );    
       
  4196             }
       
  4197        
       
  4198         if ( cba && cba->DrawableWindow()&& !cbaFaded )
       
  4199             {
       
  4200             cba->DrawableWindow()->SetOrdinalPosition( 0 );
       
  4201             }
       
  4202         }
       
  4203     }
       
  4204 
       
  4205 
       
  4206 // -----------------------------------------------------------------------------
       
  4207 // CAknToolbar::HideItemsAndDrawOnlyBackground
       
  4208 // Hides/Unhides toolbar items temporarily. When called with ETrue toolbar draws
       
  4209 // just background in landscape and is hidden in portrait. Calling with EFalse
       
  4210 // returns the situation to normal. 
       
  4211 // -----------------------------------------------------------------------------
       
  4212 //
       
  4213 EXPORT_C void CAknToolbar::HideItemsAndDrawOnlyBackground( TBool aHide ) 
       
  4214     {
       
  4215     __ASSERT_DEBUG( ( iFlags & KAknToolbarFixed ), User::Invariant() );
       
  4216 
       
  4217     if ( aHide )
       
  4218         {
       
  4219         if ( iFlags & KAknToolbarDefault && !( iInternalFlags.IsSet( EItemsHidden ) ) )
       
  4220             {
       
  4221             iInternalFlags.Set( EDefaultToolbar );
       
  4222             }
       
  4223         iInternalFlags.Set( EItemsHidden ); 
       
  4224         iFlags |= KAknToolbarDefault; 
       
  4225         HandleResourceChange( KEikDynamicLayoutVariantSwitch ); 
       
  4226         UpdateControlVisibility();
       
  4227         }
       
  4228     else
       
  4229         {
       
  4230         if ( !( iInternalFlags.IsSet( EItemsHidden ) ) && CountComponentControls() > 0  )
       
  4231     		{
       
  4232     		return;
       
  4233     		}        
       
  4234         TInt messageType( KEikDynamicLayoutVariantSwitch );
       
  4235         //defualt property should not be given up
       
  4236         if ( !iInternalFlags.IsSet( EDefaultToolbar ) ) 
       
  4237             {
       
  4238             iFlags &= ~KAknToolbarDefault;            
       
  4239             }  
       
  4240         
       
  4241         if ( !Layout_Meta_Data::IsLandscapeOrientation() && iInternalFlags.IsSet( EDefaultToolbar ) )
       
  4242             {
       
  4243             messageType = KAknToolbarSetHiddenAndDrawBackground; 
       
  4244             }
       
  4245         else
       
  4246             {
       
  4247             // Clearing this temporarily, it gets setted again from HandleResourceChange
       
  4248             iInternalFlags.Clear( EShown );            
       
  4249             }
       
  4250         iInternalFlags.Set( ESwitchForItemsHidden );
       
  4251         HandleResourceChange( messageType ); 
       
  4252         // Clear this after HandleResourceChange so that correct method
       
  4253         // for toolbar showing is chosen
       
  4254         if ( iInternalFlags.IsSet( EItemsHidden ) )
       
  4255             {
       
  4256             iInternalFlags.Clear( EItemsHidden );
       
  4257             }
       
  4258         iInternalFlags.Clear( EItemsHiddenWithPriority ); 
       
  4259         UpdateControlVisibility();
       
  4260         iInternalFlags.Clear( ESwitchForItemsHidden );
       
  4261         iInternalFlags.Clear( EDefaultToolbar );
       
  4262         }
       
  4263     }
       
  4264 
       
  4265 // -----------------------------------------------------------------------------
       
  4266 // CAknToolbar::HideItemsAndDrawOnlyBackground
       
  4267 // Hides/Unhides toolbar items temporarily. When called with ETrue toolbar draws
       
  4268 // just background with the window priority defined in aPriority. 
       
  4269 // -----------------------------------------------------------------------------
       
  4270 //
       
  4271 EXPORT_C void CAknToolbar::HideItemsAndDrawOnlyBackground( TBool aHide, TInt aPriority ) 
       
  4272     {
       
  4273     if ( aHide )
       
  4274         {
       
  4275         if ( iInternalFlags.IsSet( EShown ) )
       
  4276             {
       
  4277             iInternalFlags.Set( EItemsHiddenWithPriority ); 
       
  4278             iDrawingPriority = aPriority;
       
  4279             }
       
  4280         else if ( aPriority != DrawableWindow()->OrdinalPriority() )
       
  4281             {
       
  4282             DrawableWindow()->SetOrdinalPosition( 0, aPriority );
       
  4283             }
       
  4284         }
       
  4285     HideItemsAndDrawOnlyBackground( aHide );
       
  4286     }
       
  4287 
       
  4288 // -----------------------------------------------------------------------------
       
  4289 // CAknToolbar::SetSkinBackgroundId
       
  4290 // Define new fixed toolbar background theme ID.
       
  4291 // -----------------------------------------------------------------------------
       
  4292 // 
       
  4293 EXPORT_C void CAknToolbar::SetSkinBackgroundId( const TAknsItemID& aIID )
       
  4294 	{
       
  4295 	iBgIID = aIID;	
       
  4296 	}
       
  4297 
       
  4298 // -----------------------------------------------------------------------------
       
  4299 // CAknToolbar::UpdateControlVisibility
       
  4300 // Other details are commented in header
       
  4301 // -----------------------------------------------------------------------------
       
  4302 //
       
  4303 void CAknToolbar::UpdateControlVisibility()
       
  4304     {
       
  4305     for ( TInt ii = 0; ii < iItems.Count(); ii++ )
       
  4306         {
       
  4307         CAknToolbarItem* item = iItems[ii];
       
  4308         TBool makeVisible = iInternalFlags.IsSet( EShown ) 
       
  4309                          && ( ToolbarVisibleIndexByControl( item->Control() ) >= 0 );
       
  4310         item->Control()->MakeVisible( makeVisible ); 
       
  4311         }
       
  4312     }
       
  4313     
       
  4314 // -----------------------------------------------------------------------------
       
  4315 // CAknToolbar::UpdateItemTooltipPosition()
       
  4316 // Update items tooltip position
       
  4317 // -----------------------------------------------------------------------------
       
  4318 //
       
  4319 void CAknToolbar::UpdateItemTooltipPosition()
       
  4320     {
       
  4321     //reset position of button tooltip
       
  4322     TPoint centerPos = static_cast<CEikAppUiFactory*> 
       
  4323                             ( iEikonEnv->AppUiFactory() )->ClientRect().Center();
       
  4324     CAknButton::TTooltipPosition tooltipPosition;
       
  4325     if ( iOrientation == EAknOrientationHorizontal )
       
  4326         {
       
  4327         if ( Position().iY > centerPos.iY )
       
  4328             {
       
  4329             tooltipPosition = CAknButton::EPositionTop;
       
  4330             }
       
  4331         else
       
  4332             {
       
  4333             tooltipPosition = CAknButton::EPositionBottom;
       
  4334             }
       
  4335         }
       
  4336     else
       
  4337         {        
       
  4338         if ( Position().iX > centerPos.iX )
       
  4339             {
       
  4340             tooltipPosition = CAknButton::EPositionLeft;
       
  4341             }
       
  4342         else
       
  4343             {
       
  4344             tooltipPosition = CAknButton::EPositionRight;
       
  4345             }
       
  4346         } 
       
  4347     for ( TInt ii = 0; ii < iItems.Count(); ++ii )
       
  4348         {
       
  4349         // This assumes that every control in touch pane is button
       
  4350         CAknToolbarItem* item = iItems[ii];
       
  4351         if ( item->ControlType() == EAknCtButton || 
       
  4352                 item->ControlType() == EAknCtToolbarExtension )
       
  4353             {
       
  4354             CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
  4355             button->SetTooltipPosition( tooltipPosition );
       
  4356             }
       
  4357         }
       
  4358    
       
  4359     }
       
  4360 // End of file