uifw/EikStd/coctlsrc/akntoolbarextensionview.cpp
changeset 0 2f259fa3e83a
child 9 aabf2c525e0f
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Popup toolbar extension
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <barsread.h>
       
    20 #include <AknsFrameBackgroundControlContext.h>
       
    21 #include <AknsDrawUtils.h>
       
    22 #include <aknlayoutscalable_avkon.cdl.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 #include <aknbutton.h>
       
    25 #include <eikedwin.h>
       
    26 #include <akntoolbarextension.h>
       
    27 #include <touchfeedback.h>
       
    28 #include <eikcolib.h>
       
    29 
       
    30 #include "akntoolbaritem.h"
       
    31 #include "akntoolbarextensionview.h"
       
    32 
       
    33 #include "aknresourceprovider.h"
       
    34 
       
    35 const TInt KNoItemSelected = -1; 
       
    36 const TUint32 KToolbarExtensionBgColor = 0x00000000;
       
    37 const TInt KToolBarExtensionBgAlpha = 0x7F;
       
    38 const TInt KToolbarButtonBeforeTimeout = 300; 
       
    39 
       
    40 enum TDirection
       
    41     {
       
    42     EDirectionLeft = 0,  
       
    43     EDirectionRight, 
       
    44     EDirectionUp,
       
    45     EDirectionDown, 
       
    46     ENoDirection
       
    47     }; 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CAknToolbarExtensionView::NewL
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CAknToolbarExtensionView* CAknToolbarExtensionView::NewL( TResourceReader& aReader,
       
    56     CAknToolbarExtension* aExtension )
       
    57     {
       
    58     CAknToolbarExtensionView* self = new ( ELeave ) CAknToolbarExtensionView( aExtension);
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL(); 
       
    61     self->ConstructFromResourceL( aReader );
       
    62     CleanupStack::Pop( self );
       
    63     
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // Destructor
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CAknToolbarExtensionView::~CAknToolbarExtensionView()
       
    72     {
       
    73     SetFocus( EFalse );
       
    74     CEikonEnv::Static()->EikAppUi()->RemoveFromStack( this );
       
    75     if ( iSelectedItem >= 0 && iSelectedItem < iItems.Count() ) 
       
    76         {
       
    77         TRAP_IGNORE( iItems[iSelectedItem]->SetIsSelectedL(EFalse) ); 
       
    78         }
       
    79     iVisibleItems.Reset();
       
    80     iItems.ResetAndDestroy(); 
       
    81     delete iFrameContext; 
       
    82     delete iResourceProvider;
       
    83     }
       
    84     
       
    85 // ---------------------------------------------------------------------------
       
    86 // From class CCoeControl.
       
    87 // Constructs extension view
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CAknToolbarExtensionView::ConstructFromResourceL( TResourceReader& aReader )
       
    91     {
       
    92     TInt numberOfItems = aReader.ReadInt16();
       
    93     TBool noFrame(EFalse); 
       
    94     for ( TInt i = 0; i < numberOfItems; ++i )
       
    95         {
       
    96         CAknToolbarItem* item = ConstructControlLC( aReader ); 
       
    97         if ( item->Control() )
       
    98             {
       
    99             iItems.AppendL( item ); 
       
   100             item->Control()->SetContainerWindowL( *this );
       
   101             item->Control()->SetObserver( iExtension );
       
   102 
       
   103             if ( item->ControlType() == EAknCtButton )
       
   104                 {
       
   105                 CAknButton* button = static_cast<CAknButton*>(item->Control() ); 
       
   106                 TInt flags = button->ButtonFlags(); 
       
   107                 if ( !noFrame && ( !( flags & KAknButtonNoFrame ) ||  
       
   108                     !( flags & KAknButtonPressedDownFrame ) ) ) 
       
   109                     {
       
   110                     // Set flag KAknButtonNoFrame for all buttons except the one
       
   111                     // after an editor
       
   112                     flags |= KAknButtonNoFrame; 
       
   113                     flags |= KAknButtonPressedDownFrame;
       
   114                     button->RegisterResourceProvider( iResourceProvider );
       
   115                     button->SetButtonFlags( flags ); 
       
   116                     }
       
   117                 else if ( noFrame )
       
   118                     {
       
   119                     // Setting frames for the button that comes after an editor
       
   120                     if ( flags & KAknButtonNoFrame )
       
   121                         {
       
   122                         flags &= ~KAknButtonNoFrame;
       
   123                         flags &= ~KAknButtonPressedDownFrame;  
       
   124                         button->SetButtonFlags( flags ); 
       
   125                         }
       
   126                     noFrame = EFalse; 
       
   127                     }
       
   128                 AdjustButtonL( *button ); 
       
   129                 }
       
   130             else 
       
   131                 {
       
   132                 if ( Editor( item->ControlType() ) ) 
       
   133                     {
       
   134                     noFrame = ETrue; 
       
   135                     }
       
   136                 }
       
   137             CleanupStack::Pop( item ); 
       
   138             }
       
   139         else
       
   140             {
       
   141             CleanupStack::PopAndDestroy( item );
       
   142             item = NULL;
       
   143             }
       
   144         }
       
   145         
       
   146     if ( iExtension->ExtensionFlags() & KAknTbExtensionDsaMode )
       
   147         {
       
   148         iFrameContext->SetFrame( KAknsIIDQgnGrafPopupTrans ); 
       
   149         }
       
   150         
       
   151     ActivateL(); 
       
   152     // Activating here the items, because ActivateL uses CountComponentControls
       
   153     // which is currently 0 since iVisibleItems is still empty
       
   154     for ( TInt i = 0; i < iItems.Count(); i++ )
       
   155         {
       
   156         iItems[i]->Control()->ActivateL(); 
       
   157         }
       
   158     SetComponentsToInheritVisibility( ETrue );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From class CCoeControl.
       
   163 // Shows or hides extension view
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CAknToolbarExtensionView::MakeVisible( TBool aVisible )
       
   167     {
       
   168     TBool isVisible = IsVisible(); 
       
   169 
       
   170     if ( aVisible && !isVisible )
       
   171         {
       
   172             // the toolbar extension is shown, this happens only with pointer event? 
       
   173             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   174             if ( feedback )
       
   175                 {
       
   176                 feedback->InstantFeedback( ETouchFeedbackPopUp );
       
   177                 }
       
   178 
       
   179         TRect rect; 
       
   180         TRAP_IGNORE( rect = CalculateSizeL() ); 
       
   181         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   182             0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   183         CEikonEnv::Static()->EikAppUi()->HandleStackChanged();
       
   184         
       
   185         // Calling this here, so that iVisibleItems array has been updated and
       
   186         // all items visible in extension get call makevisible
       
   187         CAknControl::MakeVisible( aVisible );
       
   188         SetRect( rect );     
       
   189         DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNormal );    
       
   190         TBool floating = !IsNonFocusing(); 
       
   191         for ( TInt i = 0; i < iItems.Count(); i++ )
       
   192             {
       
   193             if ( !floating && Editor( iItems[i]->ControlType() ) )
       
   194                 {
       
   195                 TRAP_IGNORE( SelectItemL( i, ETrue ) ); 
       
   196                 break; 
       
   197                 }
       
   198             if ( floating && iItems[i]->ControlType() == EAknCtButton )
       
   199                 {
       
   200                 CAknButton* button = static_cast<CAknButton*>( iItems[i]->Control() ); 
       
   201                 TInt j = 0; 
       
   202                 while( button->State( j ) )
       
   203                     {
       
   204                     //Setting the texts empty
       
   205                     TRAP_IGNORE( button->State( j++ )->SetTextL( KNullDesC ) ); 
       
   206                     }
       
   207                 }
       
   208             }
       
   209 
       
   210         if ( floating && iVisibleItems.Count() )
       
   211             {
       
   212             iSelectedItem = NextFocusable( 1 ); 
       
   213             TRAP_IGNORE( iVisibleItems[iSelectedItem]->SetFocusL( 
       
   214                 ETrue, EFalse, ENoDrawNow, this ) ); 
       
   215             }
       
   216         if ( iPreviousItem >= 0 && IsNonFocusing() )
       
   217             {            
       
   218             CAknToolbarItem* prevItem = iVisibleItems[iPreviousItem];
       
   219             if ( prevItem->Control() )
       
   220                 {
       
   221                 if ( prevItem->ControlType() == EAknCtButton ||
       
   222                         prevItem->ControlType() == EAknCtToolbarExtension )
       
   223                    {
       
   224                    CAknButton* button = static_cast<CAknButton*>( prevItem->Control() );
       
   225                    button->ResetState();
       
   226                    }
       
   227                 }
       
   228             iPreviousItem = KNoItemSelected;
       
   229             }
       
   230         DrawNow(); 
       
   231         }
       
   232     else if ( !aVisible && isVisible )
       
   233         {
       
   234         CEikonEnv::Static()->EikAppUi()->UpdateStackedControlFlags( this, 
       
   235             ~0, ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   236         CEikonEnv::Static()->EikAppUi()->HandleStackChanged();
       
   237         CAknControl::MakeVisible( aVisible );
       
   238         TRAP_IGNORE( SelectItemL( iSelectedItem, EFalse ) ); 
       
   239         DrawableWindow()->SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   240         }
       
   241     else 
       
   242         {
       
   243         CAknControl::MakeVisible( aVisible );
       
   244         }
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // From class OfferKeyEventL.
       
   249 // Consumes key events if floating toolbar extension
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 TKeyResponse CAknToolbarExtensionView::OfferKeyEventL( 
       
   253     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   254     {
       
   255     if ( aKeyEvent.iCode == EKeyYes || !IsVisible() )
       
   256         {
       
   257         return EKeyWasNotConsumed; 
       
   258         }
       
   259     //LSK, RSK, KeyOk
       
   260     else if ( IsNonFocusing() && aType == EEventKey 
       
   261             && ( aKeyEvent.iCode == EKeyDevice0 
       
   262                     || aKeyEvent.iCode == EKeyDevice1 
       
   263                     || aKeyEvent.iCode == EKeyDevice3 ) )
       
   264         {
       
   265         if( IsVisible()&& ( aKeyEvent.iCode == EKeyDevice0 ||
       
   266                             aKeyEvent.iCode == EKeyDevice1 ))
       
   267             {
       
   268             iExtension->SetShown(EFalse);
       
   269             return EKeyWasConsumed; 
       
   270             }
       
   271         return EKeyWasNotConsumed;
       
   272         }
       
   273     // When this is visible and without focus, nothing to do 
       
   274     //
       
   275     // Exception for key filter: Image capture key (not a complete solution:
       
   276     //       the key map may change corrding to the products)
       
   277     else if ( IsNonFocusing()&& aType == EEventKey 
       
   278             &&(!( aKeyEvent.iScanCode == EStdKeyDevice3
       
   279                   || aKeyEvent.iScanCode == EStdKeyEnter )) )
       
   280         {
       
   281         return EKeyWasConsumed;
       
   282         }
       
   283     else if( IsVisible() && aType == EEventKey )
       
   284         {
       
   285         switch ( aKeyEvent.iCode )
       
   286             {
       
   287             case EKeyRightArrow:
       
   288                 MoveHighlightL( EDirectionRight, 0 ); 
       
   289                 break; 
       
   290             case EKeyLeftArrow:
       
   291                 MoveHighlightL( EDirectionLeft, 0 ); 
       
   292                 break; 
       
   293             case EKeyUpArrow:
       
   294                 MoveHighlightL( EDirectionUp, 0 ); 
       
   295                 break; 
       
   296             case EKeyDownArrow:
       
   297                 MoveHighlightL( EDirectionDown, 0 ); 
       
   298                 break; 
       
   299             default: 
       
   300                 break;     
       
   301             }
       
   302         return EKeyWasConsumed;
       
   303         }
       
   304     else
       
   305         {
       
   306         CAknToolbarItem* item = NULL; 
       
   307         if ( iSelectedItem >= 0 && iSelectedItem < iVisibleItems.Count() )
       
   308             {
       
   309             item = iVisibleItems[iSelectedItem]; 
       
   310             }
       
   311         // All key events can be given to buttons, other toolbar items must 
       
   312         // be seleceted to get events
       
   313         if ( item && item->Control() )
       
   314             {
       
   315             if ( ( item->ControlType() == EAknCtButton ) || 
       
   316                ( item->ControlType() == EAknCtToolbarExtension )  || item->IsSelected() )
       
   317                 {
       
   318                 if ( aKeyEvent.iScanCode == EStdKeyDevice0 )
       
   319                     {
       
   320                     TKeyEvent keyEvent = aKeyEvent; 
       
   321                     // Button does not accept key events if the code is EStdKeyDevice0
       
   322                     // so changing the key event to EStdKeyDevice3    
       
   323                     keyEvent.iScanCode = EStdKeyDevice3; 
       
   324                     item->Control()->OfferKeyEventL( keyEvent, aType );
       
   325                     }
       
   326                 else if ( aKeyEvent.iScanCode == EStdKeyDevice1 )
       
   327                     {
       
   328                     MakeVisible( EFalse ); 
       
   329                     // Close extension view and let also extension know about it
       
   330                     // so it can change state
       
   331                     iExtension->ViewClosed(); 
       
   332                     // Toolbar should perhaps be closed too! 
       
   333                     }
       
   334                 else
       
   335                     {
       
   336                     item->Control()->OfferKeyEventL( aKeyEvent, aType );
       
   337                     }
       
   338                 }
       
   339             }
       
   340 
       
   341         return EKeyWasNotConsumed; 
       
   342         }
       
   343         
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CAknToolbarExtensionView::CountComponentControls
       
   348 // Gets the number of controls contained in a compound control.
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TInt CAknToolbarExtensionView::CountComponentControls() const
       
   352     {
       
   353     return iVisibleItems.Count(); 
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CAknToolbarExtensionView::ComponentControl
       
   358 // Gets the specified component of a compound control.
       
   359 // -----------------------------------------------------------------------------
       
   360 //    
       
   361 CCoeControl* CAknToolbarExtensionView::ComponentControl( TInt aIndex ) const
       
   362     {
       
   363     if ( aIndex < 0 || aIndex >= iVisibleItems.Count() )
       
   364         {
       
   365         return NULL; 
       
   366         }
       
   367     return iVisibleItems[aIndex]->Control(); 
       
   368     }
       
   369 
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CAknToolbarExtensionView::HandleResourceChange
       
   373 // Handles resource changes
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CAknToolbarExtensionView::HandleResourceChange( TInt aType )
       
   377     {
       
   378 
       
   379     iResourceProvider->HandleResourceChange( aType );
       
   380 
       
   381     // Hide extension, if non-focusing, and no pen support. Later...
       
   382     
       
   383     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   384         {
       
   385         if ( IsVisible() )
       
   386             {
       
   387             TRect rect; 
       
   388             TRAP_IGNORE( rect = CalculateSizeL() ); 
       
   389             SetRect( rect ); 
       
   390             }
       
   391         }
       
   392 
       
   393     // Not calling base class function here, because only visible controls would 
       
   394     // be returned by ComponentControl, and thus the font would not be updated
       
   395     // for all controls
       
   396     for ( TInt i = 0; i < iItems.Count(); ++i )
       
   397         {
       
   398         iItems[i]->Control()->HandleResourceChange( aType );
       
   399         if ( iItems[i]->ControlType() == EAknCtButton )
       
   400             {
       
   401             CAknButton* button = static_cast<CAknButton*>( iItems[i]->Control() ); 
       
   402 
       
   403             if ( aType == KEikDynamicLayoutVariantSwitch )
       
   404                 {
       
   405                 TBool useOutline = iExtension->ExtensionFlags() & KAknTbExtensionDsaMode;  
       
   406                 const CFont* font = AknLayoutUtils::FontFromId( AknLayoutScalable_Avkon::
       
   407                     cell_tb_ext_pane_t1( useOutline ? 0 : 1 ).LayoutLine().FontId() );
       
   408                 button->SetTextFont( font ); 
       
   409                 }
       
   410             
       
   411             if ( aType == KAknsMessageSkinChange )
       
   412                 {
       
   413                 if ( iExtension->ExtensionFlags() & KAknTbExtensionDsaMode )
       
   414                     {
       
   415                     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL(
       
   416                         *button, EColorControlBackground, KRgbWhite ) );
       
   417                     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( 
       
   418                         *button, EColorButtonText, KRgbBlack ) );
       
   419                     }
       
   420                 }
       
   421             }
       
   422         }
       
   423 
       
   424 
       
   425 
       
   426     // Remember to check here if iSelectedItem still is in iVisibleItems, and if 
       
   427     // not then do something. 
       
   428     if ( ( aType == KAknsMessageSkinChange || 
       
   429         aType == KEikDynamicLayoutVariantSwitch ) && IsVisible() )
       
   430         {
       
   431         DrawDeferred(); 
       
   432         }
       
   433     }
       
   434 
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CAknToolbarExtensionView::HandlePointerEventL
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CAknToolbarExtensionView::HandlePointerEventL( 
       
   441     const TPointerEvent& aPointerEvent )
       
   442     {
       
   443     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   444         {
       
   445         if ( !Rect().Contains( aPointerEvent.iPosition) )
       
   446             {
       
   447             iIsDownOutside = ETrue;
       
   448             }
       
   449         else
       
   450             {
       
   451             iIsDownOutside = EFalse;
       
   452             }
       
   453         }
       
   454     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   455         {
       
   456         if ( !Rect().Contains( aPointerEvent.iPosition) && iIsDownOutside )
       
   457             {
       
   458             // tapped outside view, 
       
   459             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   460             if ( feedback )
       
   461                 {
       
   462                 feedback->InstantFeedback( ETouchFeedbackPopUp );
       
   463                 }
       
   464 
       
   465             MakeVisible( EFalse ); 
       
   466             // Close extension view and let also extension know about it
       
   467             // so it can change state
       
   468             iExtension->ViewClosed(); 
       
   469             iIsDownOutside = EFalse;
       
   470             return; 
       
   471             }
       
   472         }
       
   473 
       
   474     TPointerEvent event( aPointerEvent );
       
   475     TBool override ( EFalse );
       
   476     
       
   477     if ( aPointerEvent.iType == TPointerEvent::EButton1Down && IsNonFocusing() && iPreviousItem >=0 )
       
   478         {
       
   479         CAknToolbarItem* prevItem = iVisibleItems[iPreviousItem];
       
   480         if ( prevItem->Control() &&
       
   481              !prevItem->Control()->Rect().Contains( aPointerEvent.iPosition ) )
       
   482             {
       
   483             if ( prevItem->ControlType() == EAknCtButton ||
       
   484                     prevItem->ControlType() == EAknCtToolbarExtension )
       
   485                {
       
   486                CAknButton* button = static_cast<CAknButton*>( prevItem->Control() );
       
   487                event.iType = TPointerEvent::EButton1Up;
       
   488                button->HandlePointerEventL ( event );
       
   489                }
       
   490             }            
       
   491         }
       
   492     // Cancel previous button
       
   493     if ( iPreviousItem >=0 && ( aPointerEvent.iType == TPointerEvent::EDrag || 
       
   494         aPointerEvent.iType == TPointerEvent::EButtonRepeat ) )
       
   495         {
       
   496         CAknToolbarItem* prevItem = iVisibleItems[iPreviousItem];
       
   497 
       
   498         if ( prevItem->Control() &&
       
   499              !prevItem->Control()->Rect().Contains( aPointerEvent.iPosition ) )
       
   500                 {
       
   501                 if ( prevItem->ControlType() == EAknCtButton ||
       
   502                      prevItem->ControlType() == EAknCtToolbarExtension )
       
   503                     {
       
   504                     CAknButton* button = static_cast<CAknButton*>( prevItem->Control() );
       
   505                     event.iType = TPointerEvent::EButton1Up;
       
   506                     button->HandlePointerEventL ( event );
       
   507                     override = ETrue;
       
   508                     iPreviousItem = KNoItemSelected;
       
   509                     }
       
   510                 }        
       
   511         }
       
   512     
       
   513     CAknToolbarItem* item = NULL;
       
   514     for ( TInt ii = 0; ii < iVisibleItems.Count(); ++ii )
       
   515         {
       
   516         item = iVisibleItems[ii];
       
   517         if ( item->Control() && 
       
   518              item->Control()->Rect().Contains( aPointerEvent.iPosition ) )
       
   519             {
       
   520             if ( item->ControlType() == EAknCtButton || 
       
   521                  item->ControlType() == EAknCtToolbarExtension )
       
   522                 {
       
   523                 CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
       
   524                 if ( ii != iPreviousItem )
       
   525                     {
       
   526                     if ( !button->IsDimmed() && !IsNonFocusing() )
       
   527                         {
       
   528                         MoveHighlightL( ENoDirection, ii ); 
       
   529                         // focus has moved from one button to another due to dragging, 
       
   530                         // give sensitive feedback
       
   531                         if ( iPreviousItem != iSelectedItem )
       
   532                             {
       
   533                             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   534                             if ( feedback && 
       
   535                             ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
   536                               aPointerEvent.iType == TPointerEvent::EButtonRepeat ) )
       
   537                                 {
       
   538                                 feedback->InstantFeedback( ETouchFeedbackSensitiveButton );
       
   539                                 }
       
   540                             }
       
   541                         }
       
   542                     if ( aPointerEvent.iType == TPointerEvent::EDrag || 
       
   543                          aPointerEvent.iType == TPointerEvent::EButtonRepeat )
       
   544                         {
       
   545                         // focus has moved from one button to another due to dragging, 
       
   546                         // give sensitive feedback
       
   547                         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   548                         if ( feedback && 
       
   549                         ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
   550                           aPointerEvent.iType == TPointerEvent::EButtonRepeat ) )
       
   551                             {
       
   552                             feedback->InstantFeedback( ETouchFeedbackSensitiveButton );
       
   553                             }
       
   554                         button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 0 );
       
   555                         event.iType = TPointerEvent::EButton1Down;
       
   556                         button->HandlePointerEventL( event );
       
   557                         override = ETrue;
       
   558                         }
       
   559                     iPreviousItem = ii;
       
   560                     }
       
   561                 
       
   562                 if ( aPointerEvent.iType == TPointerEvent::EButton1Down )                    
       
   563                     {
       
   564                     iDownItem = ii;
       
   565                     button->SetHelpNoteTimeouts( KToolbarButtonBeforeTimeout, 0 );
       
   566                     }
       
   567                 
       
   568                 if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   569                     {
       
   570                     // Up and down events are in different items, give basic
       
   571                     // feedback to the released item.
       
   572                     if ( ii != iDownItem )
       
   573                         {
       
   574                         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   575                         if ( feedback )
       
   576                             {
       
   577                             feedback->InstantFeedback( ETouchFeedbackBasicButton );
       
   578                             }
       
   579                         }
       
   580                 
       
   581                     button->HandlePointerEventL( aPointerEvent );
       
   582                     iPreviousItem = KNoItemSelected;
       
   583                     override = ETrue;
       
   584                     }
       
   585                 }
       
   586             if ( IsNonFocusing() )
       
   587                 {
       
   588                 SelectItemL( ii, ETrue );
       
   589                 }
       
   590             }
       
   591         }
       
   592     if ( !override )        
       
   593         {
       
   594         CAknControl::HandlePointerEventL( aPointerEvent );        
       
   595         }
       
   596     }
       
   597 
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // Returns control corresponding the specified command id. 
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 CCoeControl* CAknToolbarExtensionView::ControlOrNull( TInt aCommandId ) const
       
   604     {
       
   605     for ( TInt i=0; i < iItems.Count(); i++ )
       
   606         {
       
   607         if ( aCommandId == iItems[i]->CommandId() )
       
   608             {
       
   609             return iItems[i]->Control(); 
       
   610             }
       
   611         }
       
   612     return NULL; 
       
   613     }
       
   614 
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CAknToolbarExtension::CommandIdByControl
       
   618 // 
       
   619 // -----------------------------------------------------------------------------
       
   620 // 
       
   621 TInt CAknToolbarExtensionView::CommandIdByControl( CCoeControl* aControl ) const
       
   622     {
       
   623     for ( TInt i=0; i < iItems.Count(); i++ )
       
   624         {
       
   625         if ( aControl == iItems[i]->Control() )
       
   626             {
       
   627             return iItems[i]->CommandId(); 
       
   628             }
       
   629         }
       
   630     return KErrNotFound; 
       
   631     }
       
   632 
       
   633 
       
   634 
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CAknToolbarExtensionView::Editor
       
   638 // Checks if the controltype given is editor
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 TBool CAknToolbarExtensionView::Editor( TInt aControlType )
       
   642     {
       
   643     // This is almost copied from toolbar item, perhaps to CAknToolbarUtils
       
   644     switch ( aControlType )
       
   645         {
       
   646         case EEikCtEdwin:
       
   647         case EEikCtGlobalTextEditor:
       
   648         case EEikCtRichTextEditor:
       
   649         case EAknCtIntegerEdwin:
       
   650         case EEikCtFlPtEd:
       
   651         case EEikCtFxPtEd:
       
   652             return ETrue; 
       
   653         default:
       
   654             return EFalse;
       
   655         }
       
   656     }
       
   657 
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CAknToolbarExtensionView::AddItemL
       
   661 // Adds new extension item
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CAknToolbarExtensionView::AddItemL( CCoeControl* aItem,
       
   665                                          TInt aType,
       
   666                                          TInt aCommandId,
       
   667                                          TInt aFlags,
       
   668                                          TInt aIndex )
       
   669     {
       
   670     if ( aItem && aIndex >= 0 && aIndex <= iItems.Count() )
       
   671         {
       
   672         aItem->SetContainerWindowL( *this );
       
   673         aItem->SetObserver( iExtension );
       
   674         aItem->ActivateL(); 
       
   675         CAknToolbarItem* tbItem = new ( ELeave ) CAknToolbarItem( aItem, aType, 
       
   676             aCommandId, aFlags );
       
   677         CleanupStack::PushL( tbItem );
       
   678         iItems.InsertL( tbItem, aIndex );
       
   679         CleanupStack::Pop( tbItem );
       
   680         if ( aType == EAknCtButton )
       
   681             {
       
   682             CAknButton* button = static_cast<CAknButton*>( aItem ); 
       
   683             AdjustButtonL( *button );
       
   684             }
       
   685         CheckButtonFrames( ETrue, aIndex ); 
       
   686         // Do something here for the selected item when focusing toolbar ready
       
   687         }
       
   688     else
       
   689         {
       
   690         User::Leave( KErrArgument );
       
   691         }
       
   692     }
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // CAknToolbarExtensionView::AdjustButtonL
       
   696 // Adjusts button to what is needed by toolbar extension view. 
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 void CAknToolbarExtensionView::AdjustButtonL( CAknButton& aButton )
       
   700     {
       
   701     aButton.SetTextAndIconAlignment( CAknButton::EIconOverText ); 
       
   702 
       
   703     TBool useOutline = iExtension->ExtensionFlags() & KAknTbExtensionDsaMode;  
       
   704     const CFont* font = AknLayoutUtils::FontFromId( AknLayoutScalable_Avkon::
       
   705         cell_tb_ext_pane_t1( useOutline ? 0 : 1 ).LayoutLine().FontId() );
       
   706 
       
   707     aButton.SetTextFont( font ); 
       
   708     aButton.SetTextColorIds( KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG60 );
       
   709 
       
   710     if ( iExtension->ExtensionFlags() & KAknTbExtensionDsaMode )
       
   711         {
       
   712         AknLayoutUtils::OverrideControlColorL( aButton, 
       
   713             EColorControlBackground, KRgbWhite );
       
   714         AknLayoutUtils::OverrideControlColorL( aButton, 
       
   715             EColorButtonText, KRgbBlack );
       
   716         }
       
   717     }
       
   718 
       
   719 
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CAknToolbarExtensionView::RemoveItemL
       
   723 // Removes an item corresponding to command id
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CAknToolbarExtensionView::RemoveItemL( TInt aCommandId )
       
   727     {
       
   728     TInt itemIndex = ToolbarItemIndexById( EFalse, aCommandId );
       
   729     if ( itemIndex == KErrNotFound )
       
   730         {
       
   731         User::Leave( KErrNotFound ); 
       
   732         }
       
   733     if ( itemIndex >= 0 && itemIndex < iItems.Count() )
       
   734         {
       
   735         // Need to remove item also from iVisibleItems array, so the non-existent
       
   736         // item is not returned by ComponentControl
       
   737         TInt visibleIndex = ToolbarItemIndexById( ETrue, aCommandId ); 
       
   738         if ( visibleIndex >= 0 && visibleIndex < iVisibleItems.Count() )
       
   739             {
       
   740             iVisibleItems.Remove( visibleIndex ); 
       
   741             }
       
   742         delete iItems[itemIndex];
       
   743         iItems.Remove( itemIndex );
       
   744         // Need to check button frames so that only the item next to editor has
       
   745         // frames
       
   746         CheckButtonFrames( EFalse, itemIndex ); 
       
   747         }
       
   748     }
       
   749 
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // CAknToolbarExtensionView::Draw
       
   753 // Draw frames for extension view
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 void CAknToolbarExtensionView::Draw( const TRect& aRect ) const
       
   757     {
       
   758     TRect rect( Rect() );
       
   759     CWindowGc& gc = SystemGc();
       
   760     gc.SetClippingRect( aRect );
       
   761     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   762     if ( iExtension->ExtensionFlags() & KAknTbExtensionDsaMode )
       
   763         {
       
   764         gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   765         gc.SetBrushColor( TRgb( KToolbarExtensionBgColor, KToolBarExtensionBgAlpha ) );
       
   766         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   767         gc.DrawRect( rect );
       
   768         gc.SetDrawMode( CGraphicsContext::EDrawModePEN );
       
   769         TSize penSize( 1, 1 );
       
   770         gc.SetPenSize( penSize );
       
   771         gc.SetPenStyle( CGraphicsContext::EDottedPen );
       
   772         gc.SetPenColor( KRgbWhite );
       
   773         gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   774         gc.DrawRect( rect );
       
   775         }
       
   776     else
       
   777         {
       
   778         AknsDrawUtils::Background( skin, iFrameContext, gc, rect );
       
   779         }
       
   780 
       
   781 
       
   782     // draw toolbar item highlight
       
   783     if ( !IsNonFocusing() && iSelectedItem != KNoItemSelected )
       
   784         {
       
   785         CAknToolbarItem* item = iVisibleItems[iSelectedItem];
       
   786         if ( item && item->HighlightRect().Intersects( aRect ) )
       
   787             {
       
   788             TRect outerRect( item->HighlightRect() );
       
   789             TRect innerRect(outerRect); 
       
   790 
       
   791             TAknWindowLineLayout unit = AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine();
       
   792             innerRect.Shrink( unit.iW/10, unit.iH/10 ); 
       
   793 
       
   794             if ( !AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
       
   795                                             gc, outerRect, innerRect,
       
   796                                             KAknsIIDQsnFrGrid, KAknsIIDDefault ) )
       
   797                 {
       
   798                 gc.SetBrushColor( KRgbRed );
       
   799                 gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   800                 gc.DrawRect( item->HighlightRect() );
       
   801                 }                
       
   802             }
       
   803         }
       
   804 
       
   805 
       
   806     }
       
   807 
       
   808 // ---------------------------------------------------------------------------
       
   809 // Default constructor
       
   810 // ---------------------------------------------------------------------------
       
   811 //
       
   812 CAknToolbarExtensionView::CAknToolbarExtensionView( 
       
   813     CAknToolbarExtension* aExtension): iExtension( aExtension ),
       
   814     iSelectedItem( KNoItemSelected ), iNumberOfColumns( 1 ),
       
   815     iIsDownOutside( EFalse )
       
   816     {
       
   817     }
       
   818 
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CAknToolbarExtensionView::ConstructL
       
   822 // 2nd phase constructor
       
   823 // -----------------------------------------------------------------------------
       
   824 // 
       
   825 void CAknToolbarExtensionView::ConstructL()
       
   826     {
       
   827     CreateWindowL(); 
       
   828     if( CAknEnv::Static()->TransparencyEnabled() )
       
   829         {
       
   830         Window().SetRequiredDisplayMode( EColor16MA ); // Without this, ACT does not work in all cases in HW
       
   831         TInt err = Window().SetTransparencyAlphaChannel();
       
   832 
       
   833         if ( err == KErrNone )
       
   834             {
       
   835             // Set the window initially completely transparent. This needs to be called only once.
       
   836             Window().SetBackgroundColor(~0);
       
   837             if ( iExtension->ExtensionFlags() & KAknTbExtensionTransparent )
       
   838                 {
       
   839                 iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQgnGrafPopupTrans, 
       
   840                     TRect(), TRect(), EFalse );  
       
   841                 }
       
   842             else
       
   843                 {
       
   844                 iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopupSub, 
       
   845                     TRect(), TRect(), EFalse );  
       
   846                 }
       
   847             }
       
   848         else
       
   849             {
       
   850             iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopupSub, 
       
   851                 TRect(), TRect(), EFalse );  
       
   852             
       
   853             }
       
   854         }
       
   855     else
       
   856         {
       
   857         iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopupSub, 
       
   858             TRect(), TRect(), EFalse );  
       
   859         }
       
   860                 
       
   861     SetGloballyCapturing( ETrue );
       
   862     SetPointerCapture( ETrue );
       
   863     // Control stack priority needs to be same as toolbars, otherwise floating
       
   864     // toolbar will receive the key events when extension is open. If lowering 
       
   865     // toolbar's control stack priority, then this can be lowered too. 
       
   866     CEikonEnv::Static()->EikAppUi()->AddToStackL( this, ECoeStackPriorityCba,
       
   867         ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   868     MakeVisible( EFalse ); 
       
   869     SetFocusing( EFalse ); 
       
   870 
       
   871     iResourceProvider = CAknResourceProvider::NewL();
       
   872     iPreviousItem = KNoItemSelected;
       
   873     }
       
   874 
       
   875 // -----------------------------------------------------------------------------
       
   876 // CAknToolbarExtensionView::ConstructControlLC
       
   877 // Constructs one of the toolbar extension items
       
   878 // -----------------------------------------------------------------------------
       
   879 // 
       
   880 CAknToolbarItem* CAknToolbarExtensionView::ConstructControlLC( TResourceReader& aReader )
       
   881     {
       
   882     CAknToolbarItem* item = new(ELeave) CAknToolbarItem;
       
   883     CleanupStack::PushL( item );
       
   884     item->ConstructFromResourceL( aReader );
       
   885     return item;
       
   886     }
       
   887 
       
   888 
       
   889 // -----------------------------------------------------------------------------
       
   890 // CAknToolbarExtensionView::CalculateSizeL
       
   891 // Calculates size and position for toolbar extension
       
   892 // -----------------------------------------------------------------------------
       
   893 // 
       
   894 TRect CAknToolbarExtensionView::CalculateSizeL()
       
   895     {
       
   896     iVisibleItems.Reset();
       
   897     TBool landscape = Layout_Meta_Data::IsLandscapeOrientation(); 
       
   898     
       
   899     
       
   900     TRect extensionRect;
       
   901     TRect windowRect;
       
   902     TRect gridExtRect;
       
   903     TRect cellExtRect;
       
   904 
       
   905     TRect mainPaneRect = static_cast<CEikAppUiFactory*> 
       
   906                         ( iEikonEnv->AppUiFactory() )->ClientRect();
       
   907     TBool floating = !IsNonFocusing(); 
       
   908 
       
   909     if ( floating )
       
   910         {
       
   911         extensionRect = RectFromLayout( mainPaneRect,
       
   912             AknLayoutScalable_Avkon::popup_tb_float_extension_window( 0 ) );
       
   913 
       
   914         windowRect = TRect( TPoint(), extensionRect.Size() );
       
   915 
       
   916         gridExtRect = RectFromLayout( windowRect,
       
   917             AknLayoutScalable_Avkon::grid_tb_float_ext_pane( 0 ) );
       
   918 
       
   919         cellExtRect = RectFromLayout( gridExtRect,
       
   920             AknLayoutScalable_Avkon::cell_tb_float_ext_pane( 0, 0, 0 ) );
       
   921         }   
       
   922     else 
       
   923         {
       
   924         extensionRect = RectFromLayout( mainPaneRect,
       
   925             AknLayoutScalable_Avkon::popup_tb_extension_window( 0 ) );
       
   926 
       
   927         windowRect = TRect( TPoint(), extensionRect.Size() );
       
   928 
       
   929         gridExtRect = RectFromLayout( windowRect,
       
   930             AknLayoutScalable_Avkon::grid_tb_ext_pane( landscape ? 1 : 0 ) );
       
   931 
       
   932         cellExtRect = RectFromLayout( gridExtRect,
       
   933             AknLayoutScalable_Avkon::cell_tb_ext_pane( landscape ? 1 : 0, 0, 0 ) );
       
   934         }
       
   935 
       
   936     TSize buttonSize = cellExtRect.Size(); 
       
   937 
       
   938     iNumberOfColumns = gridExtRect.Width() / buttonSize.iWidth; 
       
   939    
       
   940     // Calculate and set controls positions according to layout rects
       
   941     TInt extensionWidth = CalculateControlPositions( 
       
   942         windowRect, gridExtRect, cellExtRect );
       
   943     
       
   944     //In some cases, extension height is more larger than grid rect. 
       
   945     //And for they are only used to define the margin size, width is more exact than height.
       
   946     TSize viewSize( extensionWidth + ( extensionRect.Width() - gridExtRect.Width() ),
       
   947         ( extensionRect.Width() - gridExtRect.Width() ) + iNumberOfRows * 
       
   948         buttonSize.iHeight ); 
       
   949     
       
   950     TInt variety = GetVariety( iNumberOfRows - 1, landscape );
       
   951 
       
   952      // To get the correct y-coordinate
       
   953     TRect positionRect = RectFromLayout( mainPaneRect, floating ? 
       
   954          AknLayoutScalable_Avkon::popup_tb_float_extension_window( variety ) : 
       
   955          AknLayoutScalable_Avkon::popup_tb_extension_window( variety ) );
       
   956          
       
   957     if( landscape && !floating )
       
   958         {
       
   959 
       
   960         TRect extButtonRect( iExtension->Rect() );
       
   961 
       
   962         // Calculate new y coordinate according to button middle point
       
   963         TInt newY = extButtonRect.iTl.iY + mainPaneRect.iTl.iY;             
       
   964         // Check that rect with new y fits to extension view area
       
   965         if( newY < extensionRect.iTl.iY ) // Top
       
   966             {
       
   967             newY = extensionRect.iTl.iY;
       
   968             }
       
   969         else if( newY + viewSize.iHeight > extensionRect.iBr.iY ) // Bottom
       
   970             {
       
   971             newY = positionRect.iTl.iY;
       
   972             }
       
   973         positionRect.iTl.iY = newY;
       
   974         }
       
   975     //In some case, such as browser application, 
       
   976     //view position is incorrect in portait mode. So, reset the position 
       
   977     //according to the view size and toolbar window position.
       
   978     else if ( !landscape && !floating 
       
   979             && iExtension && iExtension->DrawableWindow() )
       
   980         {        
       
   981         TPoint buttonPos = iExtension->DrawableWindow()->Position();
       
   982         TInt newY = buttonPos.iY - viewSize.iHeight;
       
   983         if ( newY < extensionRect.iTl.iY )
       
   984             {
       
   985             newY = extensionRect.iTl.iY;
       
   986             }
       
   987         positionRect.iTl.iY = newY;
       
   988         }
       
   989         
       
   990     TInt xCoordinate = extensionRect.iTl.iX; 
       
   991     // Get 
       
   992     if ( iNumberOfRows == 1 )
       
   993         {
       
   994         variety = 0; 
       
   995         // Currently checking from number of items, might need to be changed
       
   996         if ( iVisibleItems.Count() == 2 )
       
   997             {
       
   998             variety = landscape ? 5 : 1; 
       
   999             }
       
  1000         else if ( iVisibleItems.Count() == 3 && landscape)
       
  1001             {
       
  1002             variety = 6; 
       
  1003             }
       
  1004         extensionRect = RectFromLayout( mainPaneRect,
       
  1005             AknLayoutScalable_Avkon::popup_tb_extension_window( variety ) );
       
  1006         xCoordinate = extensionRect.iTl.iX; 
       
  1007         }
       
  1008 
       
  1009     TPoint position( xCoordinate, positionRect.iTl.iY ); 
       
  1010 
       
  1011     TRect outerRect( TPoint(), viewSize );
       
  1012     TRect innerRect(outerRect); 
       
  1013 
       
  1014     TAknWindowLineLayout unit = AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine();
       
  1015     innerRect.Shrink( unit.iW/10, unit.iH/10 ); 
       
  1016     iFrameContext->SetFrameRects( outerRect , innerRect );
       
  1017 
       
  1018     return TRect( position, viewSize ); 
       
  1019     }
       
  1020 
       
  1021 // -----------------------------------------------------------------------------
       
  1022 // CAknToolbarExtensionView::CalculateControlPositions
       
  1023 // 
       
  1024 // -----------------------------------------------------------------------------
       
  1025 //
       
  1026 TInt CAknToolbarExtensionView::CalculateControlPositions( TRect& aWindowRect, 
       
  1027                                                           TRect& aGridRect, 
       
  1028                                                           TRect& aCellRect )
       
  1029     {
       
  1030     TInt width( 0 ), extensionWidth( 0 ), row( 0 );
       
  1031     TPoint controlPosition( 0, 0 );
       
  1032     TInt maxNumberOfRows = aGridRect.Height() / aCellRect.Height();
       
  1033     TSize cellSize = aCellRect.Size();
       
  1034     TInt extGridRight = aGridRect.iBr.iX;
       
  1035     TInt extGridLeft = aGridRect.iTl.iX;
       
  1036     TBool floating = !IsNonFocusing();
       
  1037     // iVisibleItems may not be updated, so count hidden items
       
  1038     TInt visibleItems( iItems.Count() - CountHiddenItems() );
       
  1039     
       
  1040     // If extension does not fill the whole grid rect, this takes the missing
       
  1041     // cells width into account when locating items from right to left
       
  1042     if ( AknLayoutUtils::LayoutMirrored() && visibleItems < iNumberOfColumns )
       
  1043         {
       
  1044         TInt missingCells( iNumberOfColumns - visibleItems );
       
  1045         extGridRight = aGridRect.iBr.iX - cellSize.iWidth * missingCells;
       
  1046         }
       
  1047 
       
  1048     // Fetch button icon size
       
  1049     TSize iconSize;
       
  1050     if ( floating )
       
  1051         {
       
  1052         iconSize = RectFromLayout( aCellRect, 
       
  1053             AknLayoutScalable_Avkon::cell_tb_float_ext_pane_g1( 1 ) ).Size(); 
       
  1054         }
       
  1055     else
       
  1056         {
       
  1057         iconSize = RectFromLayout( aCellRect, 
       
  1058         AknLayoutScalable_Avkon::cell_tb_ext_pane_g1( 1 ) ).Size(); 
       
  1059         }
       
  1060     
       
  1061     for ( TInt i = 0; i < iItems.Count(); i++ )
       
  1062         {
       
  1063         if ( iItems[i]->IsHidden() )
       
  1064             {
       
  1065             continue; 
       
  1066             }
       
  1067         // Buttons
       
  1068         if ( iItems[i]->ControlType() == EAknCtButton )
       
  1069             {
       
  1070 
       
  1071             // Layout items from right to left -> calculate position from right
       
  1072             // end of the grid rect
       
  1073             if ( AknLayoutUtils::LayoutMirrored() )
       
  1074                 {
       
  1075                 controlPosition.SetXY( extGridRight - width - cellSize.iWidth,
       
  1076                     aGridRect.iTl.iY + row * cellSize.iHeight ); 
       
  1077                 }
       
  1078             // Left to right
       
  1079             else
       
  1080                 {
       
  1081                 controlPosition.SetXY( extGridLeft + width,
       
  1082                     aGridRect.iTl.iY + row * cellSize.iHeight ); 
       
  1083                 }
       
  1084                 
       
  1085             width += cellSize.iWidth; 
       
  1086             iItems[i]->Control()->SetExtent( controlPosition, cellSize ); 
       
  1087             TRAP_IGNORE( iVisibleItems.AppendL( iItems[i] ) ); 
       
  1088             CAknButton* button = static_cast<CAknButton*>( 
       
  1089                 iItems[i]->Control() ); 
       
  1090             button->SetIconSize( iconSize ); 
       
  1091             if ( floating )
       
  1092                 {
       
  1093                 TRect highlightRect = RectFromLayout( 
       
  1094                     TRect( controlPosition, cellSize ), 
       
  1095                     AknLayoutScalable_Avkon::grid_highlight_pane_cp12( 0 ) ); 
       
  1096                 iItems[i]->SetHighlightRect( highlightRect ); 
       
  1097                 }
       
  1098             }
       
  1099         // Editors take the whole row
       
  1100         else if ( Editor( iItems[i]->ControlType() ) )
       
  1101             {
       
  1102             // Changing to next line
       
  1103             if ( width > 0 )
       
  1104                 {
       
  1105                 width = 0; 
       
  1106                 row++; 
       
  1107                 }
       
  1108             if ( row >= maxNumberOfRows )
       
  1109                 {
       
  1110                 break; 
       
  1111                 }
       
  1112 
       
  1113             TInt position = maxNumberOfRows - row - 1; 
       
  1114             TRAP_IGNORE( ResizeFindPaneL( aWindowRect, 
       
  1115                 Layout_Meta_Data::IsLandscapeOrientation(), position, i ) ); 
       
  1116             width = aGridRect.Width(); 
       
  1117             }
       
  1118         else
       
  1119             {
       
  1120             // Other controls here later..
       
  1121             }
       
  1122 
       
  1123         extensionWidth = Max( extensionWidth , width ); 
       
  1124         
       
  1125         // No more items to this row
       
  1126         if ( width + cellSize.iWidth > aGridRect.Width() )
       
  1127             {
       
  1128             width = 0;
       
  1129             // No more item to extension
       
  1130             if ( row + 1 >= maxNumberOfRows || i + 1 == iItems.Count() )
       
  1131                 {
       
  1132                 break; 
       
  1133                 }
       
  1134                 
       
  1135             // Switch row only if there are visible items left to locate
       
  1136             if ( iVisibleItems.Count() < visibleItems )
       
  1137                 {
       
  1138                 row++;
       
  1139                 }
       
  1140             }
       
  1141 
       
  1142         }
       
  1143     iNumberOfRows = row + 1;
       
  1144     return extensionWidth;
       
  1145     }
       
  1146 
       
  1147 
       
  1148 // -----------------------------------------------------------------------------
       
  1149 // CAknToolbarExtensionView::CountHiddenItems
       
  1150 // Returns hidden items count
       
  1151 // -----------------------------------------------------------------------------
       
  1152 //
       
  1153 TInt CAknToolbarExtensionView::CountHiddenItems()
       
  1154     {
       
  1155     TInt hiddenItems( 0 );
       
  1156     for ( TInt i = 0; i < iItems.Count(); i++ )
       
  1157         {
       
  1158         if ( iItems[i]->IsHidden() )
       
  1159             {
       
  1160             hiddenItems++;
       
  1161             }
       
  1162         }
       
  1163     return hiddenItems;
       
  1164     }
       
  1165 
       
  1166 
       
  1167 // -----------------------------------------------------------------------------
       
  1168 // CAknToolbarExtensionView::SelectItemL
       
  1169 // Selects or unselects items
       
  1170 // -----------------------------------------------------------------------------
       
  1171 //
       
  1172 void CAknToolbarExtensionView::SelectItemL( TInt aIndex, TBool aSelect )
       
  1173     {
       
  1174     if ( aSelect )
       
  1175         {
       
  1176         if ( aIndex != iSelectedItem )
       
  1177             {
       
  1178             if ( iSelectedItem > KNoItemSelected &&
       
  1179                  iSelectedItem < iVisibleItems.Count() )
       
  1180                 {
       
  1181                 iVisibleItems[iSelectedItem]->SetIsSelectedL( EFalse );
       
  1182                 }
       
  1183 
       
  1184             if ( aIndex > KNoItemSelected && aIndex < iVisibleItems.Count() )
       
  1185                 {
       
  1186                 if ( iVisibleItems[aIndex]->SetIsSelectedL( ETrue ) )
       
  1187                     {
       
  1188                     iSelectedItem = aIndex;
       
  1189                     }
       
  1190                 else
       
  1191                     {
       
  1192                     iSelectedItem = KNoItemSelected;
       
  1193                     }
       
  1194                 }
       
  1195             else
       
  1196                 {
       
  1197                 iSelectedItem = KNoItemSelected;
       
  1198                 }
       
  1199             }
       
  1200         }
       
  1201     else
       
  1202         {
       
  1203         if ( aIndex == iSelectedItem )
       
  1204             {
       
  1205             if ( aIndex != KNoItemSelected && aIndex < iVisibleItems.Count() )
       
  1206                 {
       
  1207                 iVisibleItems[aIndex]->SetIsSelectedL( EFalse );
       
  1208                 }
       
  1209             iSelectedItem = KNoItemSelected;
       
  1210             }
       
  1211         }
       
  1212     }
       
  1213 
       
  1214 
       
  1215 
       
  1216 // -----------------------------------------------------------------------------
       
  1217 // CAknToolbarExtensionView::RectFromLayout
       
  1218 // -----------------------------------------------------------------------------
       
  1219 //
       
  1220 TRect CAknToolbarExtensionView::RectFromLayout( const TRect& aParent,
       
  1221         const TAknWindowComponentLayout& aComponentLayout ) const
       
  1222     {
       
  1223     TAknWindowLineLayout lineLayout = aComponentLayout.LayoutLine();
       
  1224     TAknLayoutRect layoutRect;
       
  1225     layoutRect.LayoutRect( aParent, lineLayout );
       
  1226     return layoutRect.Rect();
       
  1227     }
       
  1228 
       
  1229 
       
  1230 // -----------------------------------------------------------------------------
       
  1231 // CAknToolbarExtensionView::ResizeFindPane
       
  1232 // Resizes editor and the button after it. 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 //
       
  1235 void CAknToolbarExtensionView::ResizeFindPaneL( TRect& aWindowRect, TBool aLandscape,
       
  1236     TInt aPosition, TInt& aIndex )
       
  1237     {
       
  1238     TRect editorRect = RectFromLayout( aWindowRect,
       
  1239         AknLayoutScalable_Avkon::tb_ext_find_pane( aLandscape ? 1 : 0 ) );
       
  1240             
       
  1241     editorRect.Move( 0, -editorRect.Height() * ( aPosition ) ); 
       
  1242 
       
  1243     TAknTextLineLayout layoutLine = 
       
  1244         AknLayoutScalable_Avkon::tb_ext_find_pane_t1( 0 ).LayoutLine();
       
  1245     TAknLayoutText layoutText;
       
  1246     layoutText.LayoutText( editorRect, layoutLine );
       
  1247     // Using curretly the skin color id of hwr/vkb input field
       
  1248     TAknsQsnTextColorsIndex colorIndex = EAknsCIQsnTextColorsCG60;    
       
  1249 
       
  1250     CEikEdwin* edwin = static_cast<CEikEdwin*>( iItems[aIndex]->Control() ); 
       
  1251     AknLayoutUtils::LayoutEdwin( edwin, editorRect, layoutLine, colorIndex ); 
       
  1252 
       
  1253     iVisibleItems.AppendL( iItems[aIndex] ); 
       
  1254 
       
  1255     if ( aIndex + 1 >= iItems.Count() || iItems[aIndex +1]->ControlType() != 
       
  1256         EAknCtButton )
       
  1257         {
       
  1258         // If no button after editor, then return
       
  1259         return; 
       
  1260         }
       
  1261     aIndex++; 
       
  1262     // Now calculate the size for the button after editor
       
  1263     TRect findButtonRect = RectFromLayout( editorRect, 
       
  1264         AknLayoutScalable_Avkon::tb_ext_find_button_pane( 0 ) ); 
       
  1265     iItems[aIndex]->Control()->SetRect( findButtonRect ); 
       
  1266     iVisibleItems.AppendL( iItems[aIndex] ); 
       
  1267     }
       
  1268 
       
  1269 
       
  1270 // -----------------------------------------------------------------------------
       
  1271 // CAknToolbarExtensionView::GetVariety
       
  1272 // -----------------------------------------------------------------------------
       
  1273 //
       
  1274 TInt CAknToolbarExtensionView::GetVariety( TInt aRow, TBool aLandscape )
       
  1275     {
       
  1276     TInt variety = 0; 
       
  1277     if ( IsNonFocusing() )
       
  1278         {
       
  1279         TInt index = iExtension->ExtensionPosition(); 
       
  1280         switch ( aRow ) 
       
  1281             {
       
  1282             case 0: 
       
  1283                 if ( index == 0 )
       
  1284                     {
       
  1285                     variety = aLandscape ? 7 : 2; 
       
  1286                     }
       
  1287                 else if ( index == 1 )
       
  1288                     {
       
  1289                     variety = aLandscape ? 6 : 2; 
       
  1290                     }
       
  1291                 else 
       
  1292                     {
       
  1293                     variety = aLandscape ? 5 : 1; 
       
  1294                     }
       
  1295                 break; 
       
  1296             case 1: 
       
  1297                 if ( index == 0 )
       
  1298                     {
       
  1299                     variety = aLandscape ? 0 : 3; 
       
  1300                     }
       
  1301                 else if ( index == 1 )
       
  1302                     {
       
  1303                     variety = aLandscape ? 6 : 3; 
       
  1304                     }
       
  1305                 else 
       
  1306                     {
       
  1307                     variety = aLandscape ? 8 : 3; 
       
  1308                     }
       
  1309                 break; 
       
  1310             case 2: 
       
  1311             default: 
       
  1312                 variety = aLandscape ? 0 : 4; 
       
  1313                 break; 
       
  1314             case 3: 
       
  1315                 variety = 0; 
       
  1316                 break; 
       
  1317             }
       
  1318         }
       
  1319     else 
       
  1320         {
       
  1321         switch ( aRow ) 
       
  1322             {
       
  1323             case 0: 
       
  1324                 variety = 3; 
       
  1325                 break; 
       
  1326             case 1: 
       
  1327                 variety = 2; 
       
  1328                 break; 
       
  1329             case 2: 
       
  1330                 variety = 1; 
       
  1331                 break; 
       
  1332             case 3: 
       
  1333             default: 
       
  1334                 variety = 0; 
       
  1335                 break; 
       
  1336             }        
       
  1337         }
       
  1338     return variety;     
       
  1339     }
       
  1340 
       
  1341 
       
  1342 // -----------------------------------------------------------------------------
       
  1343 // When an item is added, hidden or removed, there is a need to check that
       
  1344 // the buttons have correct frames. 
       
  1345 // -----------------------------------------------------------------------------
       
  1346 //
       
  1347 void CAknToolbarExtensionView::CheckButtonFrames( TBool aAdd, TInt aIndex )
       
  1348     {
       
  1349     // @todo What if adding editors? Then need to check next buttons, does this 
       
  1350     // work then?
       
  1351     
       
  1352     // this is the index from which to remove noframes flag if necessary
       
  1353     TInt index = aIndex; 
       
  1354     if ( aIndex > 0 && Editor( iItems[aIndex - 1]->ControlType() ) )
       
  1355         {
       
  1356         // Add here later code also for hiding/unhiding
       
  1357         if ( iItems[aIndex]->ControlType() == EAknCtButton )     
       
  1358             {
       
  1359             CAknButton* button = static_cast<CAknButton*>( iItems[aIndex]->Control() ); 
       
  1360             TInt flags = button->ButtonFlags(); 
       
  1361             // Add frames for the button because it comes after an editor
       
  1362             if ( flags & KAknButtonNoFrame )
       
  1363                 {
       
  1364                 flags &= ~KAknButtonNoFrame; 
       
  1365                 flags &= ~KAknButtonPressedDownFrame; 
       
  1366                 button->UnregisterResourceProvider();
       
  1367                 button->SetButtonFlags( flags ); 
       
  1368                 }
       
  1369             }
       
  1370         index++; 
       
  1371         }
       
  1372 
       
  1373     if ( aAdd && iItems.Count() > index && 
       
  1374         iItems[index]->ControlType() == EAknCtButton  ) 
       
  1375         {
       
  1376         CAknButton* button = static_cast<CAknButton*>( iItems[index]->Control() ); 
       
  1377         TInt flags = button->ButtonFlags(); 
       
  1378         // Checking that the button that was previously after editor
       
  1379         // does not have frames
       
  1380         if ( !( flags & KAknButtonNoFrame ) || !( flags & KAknButtonPressedDownFrame ) )
       
  1381             {
       
  1382             flags |= KAknButtonNoFrame; 
       
  1383             flags |= KAknButtonPressedDownFrame;
       
  1384             button->RegisterResourceProvider( iResourceProvider );
       
  1385             button->SetButtonFlags( flags ); 
       
  1386             }
       
  1387         }
       
  1388     }
       
  1389 
       
  1390 
       
  1391 // -----------------------------------------------------------------------------
       
  1392 // CAknToolbarExtensionView::ToolbarItemIndexById
       
  1393 // Returns the index of the toolbar item inside of the iItems or iVisibleItems 
       
  1394 // array.
       
  1395 // -----------------------------------------------------------------------------
       
  1396 //
       
  1397 TInt CAknToolbarExtensionView::ToolbarItemIndexById( TBool aVisibleItems, 
       
  1398     const TInt aId ) const 
       
  1399     {
       
  1400     for ( TInt i = 0; i < aVisibleItems ? iVisibleItems.Count() : 
       
  1401         iItems.Count(); i++ )
       
  1402         {
       
  1403         CAknToolbarItem* item = aVisibleItems ? iVisibleItems[i] : iItems[i];
       
  1404         if ( item && item->CommandId() == aId )
       
  1405             {
       
  1406             return i;
       
  1407             }
       
  1408         }
       
  1409     return KErrNotFound;
       
  1410     }
       
  1411 
       
  1412 
       
  1413 // -----------------------------------------------------------------------------
       
  1414 // CAknToolbarExtensionView::MoveHighlightL
       
  1415 // Moves highlight from one item to another. Does nothing if this is fixed 
       
  1416 // toolbar extension's view. 
       
  1417 // -----------------------------------------------------------------------------
       
  1418 //    
       
  1419 void CAknToolbarExtensionView::MoveHighlightL( TInt aDirection, TInt aIndex )
       
  1420     {
       
  1421     if ( IsNonFocusing() || !iVisibleItems.Count() )
       
  1422         {
       
  1423         iSelectedItem = KNoItemSelected;
       
  1424         return; 
       
  1425         }
       
  1426 
       
  1427     TInt oldFocused = iSelectedItem; 
       
  1428     if ( iSelectedItem == KNoItemSelected )
       
  1429         {
       
  1430         iSelectedItem = 0; 
       
  1431         }
       
  1432 
       
  1433     switch ( aDirection )
       
  1434         {
       
  1435         case EDirectionUp: 
       
  1436             {
       
  1437             iSelectedItem = NextFocusable( -iNumberOfColumns ); 
       
  1438             break; 
       
  1439             }
       
  1440 
       
  1441         case EDirectionDown: 
       
  1442             {
       
  1443             iSelectedItem = NextFocusable( iNumberOfColumns ); 
       
  1444             break;             
       
  1445             }
       
  1446         case EDirectionRight: 
       
  1447             {
       
  1448             iSelectedItem = NextFocusable( 1 ); 
       
  1449             break; 
       
  1450             }
       
  1451 
       
  1452         case EDirectionLeft: 
       
  1453             {
       
  1454             iSelectedItem = NextFocusable( -1 ); 
       
  1455             break;             
       
  1456             }
       
  1457         case ENoDirection: 
       
  1458             {
       
  1459             iSelectedItem = aIndex; 
       
  1460             break; 
       
  1461             }
       
  1462         }
       
  1463 
       
  1464     CAknToolbarItem* item = NULL;
       
  1465 
       
  1466     if ( iSelectedItem != KNoItemSelected )  
       
  1467         {
       
  1468         item = iVisibleItems[iSelectedItem];
       
  1469 
       
  1470         // set this item focused
       
  1471         item->SetFocusL( ETrue, EFalse, ENoDrawNow, this );
       
  1472         DrawNow( item->HighlightRect() ); 
       
  1473         }
       
  1474     item = NULL; 
       
  1475 
       
  1476     if ( oldFocused != KNoItemSelected && oldFocused != aIndex )
       
  1477         {
       
  1478         item = iVisibleItems[oldFocused];
       
  1479         if ( item && item->Control() )
       
  1480             {
       
  1481             SelectItemL( oldFocused, EFalse );
       
  1482 
       
  1483             // take the focus away
       
  1484             item->SetFocusL( EFalse, EFalse, EDrawNow, this );
       
  1485             DrawNow( item->HighlightRect() ); 
       
  1486             }
       
  1487         }
       
  1488     }
       
  1489 
       
  1490 
       
  1491 
       
  1492 // -----------------------------------------------------------------------------
       
  1493 // CAknToolbarExtensionView::NextFocusable
       
  1494 // Calculates next focusable item. Used with floating toolbar extension. 
       
  1495 // -----------------------------------------------------------------------------
       
  1496 //
       
  1497 TInt CAknToolbarExtensionView::NextFocusable( TInt aStep )
       
  1498     {
       
  1499     TInt index = iSelectedItem; 
       
  1500     TInt startIndex = iSelectedItem; 
       
  1501 
       
  1502     CAknButton* button = NULL;  
       
  1503     // we will do it till we don't get valid non-dimmed item or till we don't
       
  1504     // make the whole round ( all items are dimmed )
       
  1505     do 
       
  1506         {
       
  1507         button = NULL; 
       
  1508         if ( aStep == 1 && index >= iVisibleItems.Count() - 1 )
       
  1509             {
       
  1510             index = 0;
       
  1511             }
       
  1512         else if ( aStep == -1 && index == 0 )
       
  1513             {
       
  1514             index = iVisibleItems.Count() - 1;
       
  1515             }
       
  1516         else if ( aStep > 1 )
       
  1517             {
       
  1518             if ( index + aStep >= iVisibleItems.Count() )
       
  1519                 {
       
  1520                 index = ( index + 1 ) % aStep; 
       
  1521                 }
       
  1522             else 
       
  1523                 {
       
  1524                 index += aStep; 
       
  1525                 }
       
  1526             }
       
  1527         else if ( aStep < -1 )
       
  1528             {
       
  1529             if ( index + aStep < 0 ) 
       
  1530                 {
       
  1531                 TInt modResult = index - 1;  
       
  1532                 index = iVisibleItems.Count() - 1 ; 
       
  1533                 if ( modResult < 0 )
       
  1534                     {
       
  1535                     modResult = iNumberOfColumns - 1; 
       
  1536                     }
       
  1537                 while ( index % ( +aStep ) != modResult )
       
  1538                     {
       
  1539                     index--; 
       
  1540                     }
       
  1541                 }
       
  1542             else 
       
  1543                 {
       
  1544                 index += aStep; 
       
  1545                 }
       
  1546             }
       
  1547         else             
       
  1548             {
       
  1549             index += aStep; 
       
  1550             }
       
  1551         button = static_cast<CAknButton*>( iVisibleItems[index]->Control() );
       
  1552 
       
  1553         } while ( ( !button || button->IsDimmed() ) && startIndex != index );
       
  1554 
       
  1555     return index; 
       
  1556     }
       
  1557 
       
  1558 
       
  1559 // -----------------------------------------------------------------------------
       
  1560 // Sets item dimmed
       
  1561 // -----------------------------------------------------------------------------
       
  1562 //
       
  1563 void CAknToolbarExtensionView::SetItemDimmed( TInt aCommandId, TBool aDimmed )
       
  1564     {
       
  1565     CCoeControl* control = ControlOrNull( aCommandId );     
       
  1566     if ( control ) 
       
  1567         {
       
  1568         control->SetDimmed( aDimmed ); 
       
  1569         if ( IsVisible() )
       
  1570             {
       
  1571             control->DrawNow(); 
       
  1572             }
       
  1573         }
       
  1574     }
       
  1575 
       
  1576 // -----------------------------------------------------------------------------
       
  1577 // Hides an item
       
  1578 // -----------------------------------------------------------------------------
       
  1579 //
       
  1580 void CAknToolbarExtensionView::HideItemL( TInt aCommandId, TBool aHide )
       
  1581     {
       
  1582     CAknToolbarItem* item = NULL; 
       
  1583     for ( TInt i=0; i < iItems.Count(); i++ )
       
  1584         {
       
  1585         if ( aCommandId == iItems[i]->CommandId() )
       
  1586             {
       
  1587             item = iItems[i]; 
       
  1588             break; 
       
  1589             }
       
  1590         }
       
  1591 
       
  1592     if ( item && item->Control() && item->IsHidden() != aHide ) 
       
  1593         {
       
  1594         item->SetHidden( aHide ); 
       
  1595         }
       
  1596     }
       
  1597 
       
  1598 //end file