emailuis/uicomponents/src/fscontrolbar.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  Main class for Control Bar component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail> SF
       
    20 #include "emailtrace.h"
       
    21 #include <alf/alfevent.h>
       
    22 #include <alf/alfdecklayout.h>
       
    23 //</cmail>
       
    24 #include <AknsConstants.h>
       
    25 #include <AknUtils.h>
       
    26 
       
    27 #include "fscontrolbar.h"
       
    28 #include "fscontrolbarmodel.h"
       
    29 #include "fscontrolbarvisualiser.h"
       
    30 #include "fscontrolbutton.h"
       
    31 #include "fsgenericpanic.h"
       
    32 #include "fscontrolbuttonconst.h"
       
    33 #include "fstextstylemanager.h"
       
    34 #include "fscontrolbuttonmodel.h"
       
    35 #include "fslayoutmanager.h"
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 // <cmail> Touch
       
    45 CFsControlBar::CFsControlBar() :
       
    46     iSelectedButton( KNoButtonFocused ), iTouchEnabled(ETrue)
       
    47 // </cmail>
       
    48     {
       
    49     FUNC_LOG;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Second phase constructor.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CFsControlBar::ConstructL( CAlfEnv& aEnv )
       
    58     {
       
    59     FUNC_LOG;
       
    60     CAlfControl::ConstructL( aEnv );
       
    61 
       
    62     iTextStyleManager =
       
    63         CFsTextStyleManager::NewL( this->Env().TextStyleManager() );
       
    64 
       
    65     // create model for controlBar
       
    66     iModel = CFsControlBarModel::NewL();
       
    67 
       
    68     // create visualiser for controlBar
       
    69     iVisualiser = CFsControlBarVisualiser::NewL( *this, *iModel );
       
    70 
       
    71     // Start listening TAlfActionCommand messages.
       
    72     Env().AddActionObserverL( this );
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Two-phased constructor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C CFsControlBar* CFsControlBar::NewL( CAlfEnv& aEnv )
       
    81     {
       
    82     FUNC_LOG;
       
    83     CFsControlBar* self = CFsControlBar::NewLC( aEnv );
       
    84     CleanupStack::Pop( self );
       
    85     return self;
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Two-phased constructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C CFsControlBar* CFsControlBar::NewLC( CAlfEnv& aEnv )
       
    94     {
       
    95     FUNC_LOG;
       
    96     CFsControlBar* self = new (ELeave) CFsControlBar();
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL( aEnv );
       
    99     return self;
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Destructor.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CFsControlBar::~CFsControlBar()
       
   108     {
       
   109     FUNC_LOG;
       
   110     Env().RemoveActionObserver( this );
       
   111     delete iModel;
       
   112     delete iVisualiser;
       
   113     iObservers.Reset();
       
   114     delete iTextStyleManager;
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Adds new button to model. Panics if button with specified id already
       
   120 // exists in model.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CFsControlBar::AddButtonL(
       
   124     TInt aId,
       
   125     TFsControlButtonType aType )
       
   126     {
       
   127     FUNC_LOG;
       
   128     if ( iModel->ExistsButtonWithId( aId ) )
       
   129         {
       
   130         FsGenericPanic( EFsControlBarButtonWithSpecifiedIdAlreadyExists );
       
   131         User::Leave( KErrAlreadyExists );
       
   132         }
       
   133 
       
   134     if ( aId == ECBFirstFocusableButton )
       
   135         {
       
   136         FsGenericPanic( EFsControlButtonIdRestricted );
       
   137         User::Leave( KErrArgument );
       
   138         }
       
   139 
       
   140     TRect targetRect( GetLayoutRect( iModel->Count() + 1 ) );
       
   141     CFsControlButton* button(
       
   142         CFsControlButton::NewL( Env(), *this, aId, aType, targetRect,
       
   143             *(iVisualiser->Layout() ), iTextStyleManager ) );
       
   144     button->SetParentIndex( iModel->Count() + 1 );
       
   145 
       
   146     iModel->AddButtonL( *button );
       
   147     }
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Adds new button to model.
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TInt CFsControlBar::AddButtonL( TFsControlButtonType aType )
       
   155     {
       
   156     FUNC_LOG;
       
   157     TInt newId( iModel->GenerateButtonId() );
       
   158 
       
   159     AddButtonL( newId, aType );
       
   160 
       
   161     return newId;
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Removes button with specified id from model. Function RemoveButtonById
       
   167 // panics if button with specified id doesn't exist in model.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C TInt CFsControlBar::RemoveButtonL( TInt aId )
       
   171     {
       
   172     FUNC_LOG;
       
   173     // if button is focused -> change focus to next
       
   174     if ( iModel->ButtonById( aId )->IsFocused() )
       
   175         {
       
   176         CFsControlButton* button( iModel->NextButton( aId ) );
       
   177 
       
   178         if ( !button )
       
   179             {
       
   180             button = iModel->PrevButton( aId );
       
   181             }
       
   182 
       
   183         ChangeFocusL( button );
       
   184         }
       
   185 
       
   186     TInt retVal( iModel->RemoveButtonById( aId ) );
       
   187     iVisualiser->RefreshL();
       
   188 
       
   189     return retVal;
       
   190     }
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Retrieves button with specified id from control bar. Panics if button
       
   195 // with specified id doesn't exist in model.
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C MFsControlButtonInterface* CFsControlBar::ButtonById( TInt aId )
       
   199     {
       
   200     FUNC_LOG;
       
   201     return iModel->ButtonById( aId );
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // Sets focus to first button.
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 EXPORT_C void CFsControlBar::SetFocusL( TBool aFocused )
       
   210     {
       
   211     FUNC_LOG;
       
   212     if ( aFocused )
       
   213         {
       
   214         // Gain focus.
       
   215         CFsControlButton* button(
       
   216             iModel->ButtonById( ECBFirstFocusableButton ) );
       
   217         if ( button )
       
   218             {
       
   219             SetFocusByIdL( button->Id() );
       
   220             }
       
   221         }
       
   222     else
       
   223         {
       
   224         // Lose focus.
       
   225         if ( iModel->IsFocused() )
       
   226             {
       
   227             LooseFocus( MFsControlBarObserver::EEventFocusLost );
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // Sets focus to specified button.
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CFsControlBar::SetFocusByIdL( TInt aButtonId )
       
   238     {
       
   239     FUNC_LOG;
       
   240     TBool focusedAlready( iModel->IsFocused() );
       
   241 
       
   242     if ( focusedAlready && iSelectedButton == aButtonId  )
       
   243         {
       
   244         // Button already has the focus.
       
   245         return;
       
   246         }
       
   247 
       
   248     CFsControlButton* button( iModel->ButtonById( aButtonId ) );
       
   249 
       
   250     if ( !button )
       
   251         {
       
   252         User::Leave( KErrNotFound );
       
   253         }
       
   254 
       
   255     // cannot set focus to button that is dimmed or not visible
       
   256     if ( button->IsDimmed() || !button->IsVisible() )
       
   257         {
       
   258         User::Leave( KErrNotSupported );
       
   259         }
       
   260 
       
   261     // bar already focused -> clear focus on button.
       
   262     if ( focusedAlready )
       
   263         {
       
   264         // clear focus on previous selected button
       
   265         iModel->ButtonById( iSelectedButton )->SetFocus( EFalse );
       
   266         }
       
   267 
       
   268     button->SetFocus();
       
   269     iSelectedButton = aButtonId;
       
   270 
       
   271     if ( !focusedAlready )
       
   272         {
       
   273         // set state for bar
       
   274         iModel->SetFocus();
       
   275         // send event that bar is focused
       
   276         NotifyObservers(
       
   277             MFsControlBarObserver::EEventFocusGained, aButtonId );
       
   278         }
       
   279 
       
   280     iVisualiser->RefreshL();
       
   281 
       
   282     // send event that selection changed
       
   283     NotifyObservers( MFsControlBarObserver::EEventSelectionChanged );
       
   284     }
       
   285 
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // Gets focused button or NULL if not focused.
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 EXPORT_C MFsControlButtonInterface* CFsControlBar::GetFocusedButton() const
       
   292     {
       
   293     FUNC_LOG;
       
   294     MFsControlButtonInterface* focusedButton( NULL );
       
   295 
       
   296     if( iModel->IsFocused() )
       
   297         {
       
   298         focusedButton = iModel->ButtonById( iSelectedButton );
       
   299         }
       
   300 
       
   301     return focusedButton;
       
   302     }
       
   303 
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // Sets height of the bar in pixels.
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 EXPORT_C void CFsControlBar::SetHeightL( TInt aHeight )
       
   310     {
       
   311     FUNC_LOG;
       
   312     iModel->SetHeight( aHeight );
       
   313     iVisualiser->UpdateSizeL();
       
   314     }
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // Retrieves height of the bar in pixels.
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 EXPORT_C TInt CFsControlBar::Height() const
       
   322     {
       
   323     FUNC_LOG;
       
   324     return iModel->Size().iHeight;
       
   325     }
       
   326 
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // Sets width of the bar in pixels.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 EXPORT_C void CFsControlBar::SetWidthL( TInt aWidth )
       
   333     {
       
   334     FUNC_LOG;
       
   335     iModel->SetWidth( aWidth );
       
   336     iVisualiser->UpdateSizeL();
       
   337     }
       
   338 
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // Retrieves width of the bar in pixels.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C TInt CFsControlBar::Width() const
       
   345     {
       
   346     FUNC_LOG;
       
   347     return iModel->Size().iWidth;
       
   348     }
       
   349 
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // Sets controlbar's background color.
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 EXPORT_C void CFsControlBar::SetBackgroundColor( const TRgb& aColor )
       
   356     {
       
   357     FUNC_LOG;
       
   358     iVisualiser->SetBackgroundColor( aColor );
       
   359     }
       
   360 
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 // Clears bar's background color. Bar is transparent.
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 EXPORT_C void CFsControlBar::ClearBackgroundColor()
       
   367     {
       
   368     FUNC_LOG;
       
   369     iVisualiser->ClearBackgroundColor();
       
   370     }
       
   371 
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // Sets bar's background image.
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C void CFsControlBar::SetBackgroundImageL( CAlfTexture& aImage )
       
   378     {
       
   379     FUNC_LOG;
       
   380     iVisualiser->SetBackgroundImageL( aImage );
       
   381     }
       
   382 
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // Clears bar's background image.
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 EXPORT_C void CFsControlBar::ClearBackgroundImage()
       
   389     {
       
   390     FUNC_LOG;
       
   391     iVisualiser->ClearBackgroundImage();
       
   392     }
       
   393 
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // Adds additional observer for the bar events.
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 EXPORT_C void CFsControlBar::AddObserverL( MFsControlBarObserver& aObserver )
       
   400     {
       
   401     FUNC_LOG;
       
   402     // add only if not already added.
       
   403     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
   404         {
       
   405         iObservers.AppendL( &aObserver );
       
   406         }
       
   407     }
       
   408 
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // Removes specified observer from the bar events.
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 EXPORT_C void CFsControlBar::RemoveObserver(
       
   415     MFsControlBarObserver& aObserver )
       
   416     {
       
   417     FUNC_LOG;
       
   418     TInt index( iObservers.Find( &aObserver ) );
       
   419 
       
   420     if ( index != KErrNotFound )
       
   421         {
       
   422         iObservers.Remove( index );
       
   423         }
       
   424     }
       
   425 
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // Sets transition time for selector.
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 EXPORT_C void CFsControlBar::SetSelectorTransitionTimeL(
       
   432     TInt aTransitionTime )
       
   433     {
       
   434     FUNC_LOG;
       
   435     iVisualiser->SetSelectorTransitionTimeL( aTransitionTime );
       
   436     }
       
   437 
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // Sets selector's image and opacity.
       
   441 // Ownership of the brush is gained.
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C void CFsControlBar::SetSelectorImageL(
       
   445     CAlfBrush* aSelectorBrush,
       
   446     TReal32 aOpacity )
       
   447     {
       
   448     FUNC_LOG;
       
   449     iVisualiser->SetSelectorImageL( aSelectorBrush, aOpacity );
       
   450     }
       
   451 
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // Retrieves amount of space in pixels from specified point to the end of the
       
   455 // screen.
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 EXPORT_C CAlfVisual* CFsControlBar::Visual()
       
   459     {
       
   460     FUNC_LOG;
       
   461     return iVisualiser->Layout();
       
   462     }
       
   463 
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // Resolve the area reserved for requested layout slot.
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 TRect CFsControlBar::GetLayoutRect( TInt aIndex )
       
   470     {
       
   471     FUNC_LOG;
       
   472     CFsLayoutManager::TFsLayoutMetrics layoutItem;
       
   473     switch( aIndex )
       
   474         {
       
   475         case 1:
       
   476             layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarPaneG1;
       
   477             break;
       
   478         case 2:
       
   479             layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPane;
       
   480             break;
       
   481         case 3:
       
   482             layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarButtonPaneCp01;
       
   483             break;
       
   484         case 4:
       
   485             layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarPaneG2;
       
   486             break;
       
   487         default:
       
   488             layoutItem = CFsLayoutManager::EFsLmMainSpFsCtrlbarPane;
       
   489             break;
       
   490         }
       
   491 
       
   492     TRect targetRect;
       
   493     TRect parentRect;
       
   494 
       
   495     AknLayoutUtils::LayoutMetricsRect(
       
   496         AknLayoutUtils::EScreen, parentRect );
       
   497     CFsLayoutManager::LayoutMetricsRect( parentRect,
       
   498         CFsLayoutManager::EFsLmApplicationWindow, targetRect );
       
   499     parentRect = targetRect;
       
   500     CFsLayoutManager::LayoutMetricsRect( parentRect,
       
   501         CFsLayoutManager::EFsLmMainPane, targetRect );
       
   502     parentRect = targetRect;
       
   503     CFsLayoutManager::LayoutMetricsRect( parentRect,
       
   504         CFsLayoutManager::EFsLmMainSpFsCtrlbarPane, targetRect );
       
   505     parentRect = TRect( TPoint( 0, 0 ), targetRect.Size() );
       
   506     if ( CFsLayoutManager::EFsLmMainSpFsCtrlbarPane != layoutItem )
       
   507         {
       
   508         CFsLayoutManager::LayoutMetricsRect(
       
   509             parentRect, layoutItem, targetRect );
       
   510         }
       
   511 
       
   512     return targetRect;
       
   513     }
       
   514 
       
   515 // <cmail> Touch
       
   516 // ---------------------------------------------------------------------------
       
   517 // Called to disable/enable touch events
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 EXPORT_C void CFsControlBar::EnableTouch(TBool aEnabled)
       
   521     {
       
   522     iTouchWasEnabled = EFalse;
       
   523     iTouchEnabled = aEnabled;
       
   524     }
       
   525 // </cmail>
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 EXPORT_C void CFsControlBar::MakeSelectorVisible(
       
   532         TBool aShow, TBool aFromTouch )
       
   533     {
       
   534     FUNC_LOG;
       
   535     iVisualiser->MakeSelectorVisible( aShow, aFromTouch );
       
   536     }
       
   537 
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // From MAlfActionObserver.
       
   541 // Called by the scheduler when an action command is executed.
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CFsControlBar::HandleActionL( const TAlfActionCommand& aActionCommand )
       
   545     {
       
   546     FUNC_LOG;
       
   547     if ( KFsMessageLayoutChange == aActionCommand.Id() )
       
   548         {
       
   549         iModel->UpdateButtonsPositions();
       
   550         iVisualiser->RefreshL( ETrue );
       
   551         }
       
   552     }
       
   553 
       
   554 
       
   555 // ---------------------------------------------------------------------------
       
   556 // From class CHuiControl/CAlfControl.
       
   557 // Notifies the control that one of the visuals it ows has been laid out.
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 void CFsControlBar::VisualLayoutUpdated( CAlfVisual& aVisual )
       
   561     {
       
   562     FUNC_LOG;
       
   563     TBool screenSizeChanged( EFalse );
       
   564     TInt displayAreaWidth( DisplayArea().Width() );
       
   565 
       
   566     // We don't want more layout updates. Flag is set if the layout needs to
       
   567     // be updated.
       
   568     aVisual.ClearFlags( EAlfVisualFlagLayoutUpdateNotification );
       
   569 
       
   570     if ( displayAreaWidth != iLastScreenWidth )
       
   571         {
       
   572         iLastScreenWidth = displayAreaWidth;
       
   573         screenSizeChanged = ETrue;
       
   574         }
       
   575 
       
   576     if ( iVisualiser )
       
   577         {
       
   578         TRAP_IGNORE( iVisualiser->RefreshL( screenSizeChanged ) );
       
   579         }
       
   580     }
       
   581 
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // From class CHuiControl/CAlfControl.
       
   585 // Called when an input event is being offered to the control.
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 TBool CFsControlBar::OfferEventL( const TAlfEvent& aEvent )
       
   589     {
       
   590     FUNC_LOG;
       
   591     TBool eventHandled( EFalse );
       
   592 
       
   593     // Bar not focused -> no key handling
       
   594     if ( !iModel->IsFocused() )
       
   595         {
       
   596         return eventHandled;
       
   597         }
       
   598 
       
   599     if ( aEvent.IsKeyEvent() )
       
   600         {
       
   601         CFsControlButton* button( NULL );
       
   602 
       
   603         button = iModel->ButtonById( iSelectedButton );
       
   604 
       
   605         if ( button && button->OfferEventL( aEvent ) )
       
   606             {
       
   607             eventHandled = ETrue;
       
   608             }
       
   609         else
       
   610             {
       
   611             if ( EEventKey == aEvent.Code() )
       
   612                 {
       
   613                 switch ( aEvent.KeyEvent().iScanCode )
       
   614                     {
       
   615                     case EStdKeyLeftArrow:
       
   616                         {
       
   617                         button = iModel->PrevButton( iSelectedButton );
       
   618                         ChangeFocusL( button );
       
   619                         eventHandled = ETrue;
       
   620                         break;
       
   621                         }
       
   622 
       
   623                     case EStdKeyRightArrow:
       
   624                         {
       
   625                         button = iModel->NextButton( iSelectedButton );
       
   626                         ChangeFocusL( button );
       
   627                         eventHandled = ETrue;
       
   628                         break;
       
   629                         }
       
   630 
       
   631                     case EStdKeyDownArrow:
       
   632                         {
       
   633                         LooseFocus(
       
   634                             MFsControlBarObserver::EEventFocusLostAtBottom );
       
   635                         eventHandled = ETrue;
       
   636                         break;
       
   637                         }
       
   638 
       
   639                     default:
       
   640                         {
       
   641                         eventHandled = EFalse;
       
   642                         break;
       
   643                         }
       
   644                     }
       
   645                 }
       
   646             }
       
   647         }
       
   648     else if( aEvent.IsPointerEvent() )
       
   649         {
       
   650         const TInt buttonCount( iModel->Count() );
       
   651         TInt buttonIndex( 0 );
       
   652         for( ; buttonIndex < buttonCount && !eventHandled; ++buttonIndex )
       
   653             {
       
   654             eventHandled = iModel->ButtonByIndex(
       
   655                 buttonIndex )->OfferEventL( aEvent );
       
   656             }
       
   657         }
       
   658 
       
   659 
       
   660     return eventHandled;
       
   661     }
       
   662 
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // From class MFsControlButtonObserver.
       
   666 // Handles events from control buttons.
       
   667 // ---------------------------------------------------------------------------
       
   668 //
       
   669 TBool CFsControlBar::HandleButtonEvent(
       
   670     TFsControlButtonEvent aEvent,
       
   671     TInt aButtonId )
       
   672     {
       
   673     FUNC_LOG;
       
   674     TBool eventHandled( ETrue );
       
   675     switch ( aEvent )
       
   676         {
       
   677         // <cmail> Touch
       
   678         case EEventButtonTouchPressed:
       
   679             {
       
   680             MakeSelectorVisible( ETrue, ETrue );
       
   681             if (iTouchEnabled)
       
   682                 {
       
   683                 iTouchWasEnabled = ETrue;
       
   684                 CFsControlButton* button( iModel->ButtonById( aButtonId ) );
       
   685                 if( button && !button->IsFocused())
       
   686                     {
       
   687                     TRAP_IGNORE( ChangeFocusL( button ) );
       
   688                     MakeSelectorVisible( ETrue, ETrue );
       
   689                     NotifyObservers( MFsControlBarObserver::EEventTouchFocused, aButtonId );
       
   690                     }
       
   691                 }
       
   692             else
       
   693                 {
       
   694                 eventHandled = iTouchWasEnabled = EFalse;
       
   695                 }
       
   696             break;
       
   697             }
       
   698         // </cmail>
       
   699 
       
   700         case EEventButtonPressed:
       
   701             {
       
   702             NotifyObservers(
       
   703                 MFsControlBarObserver::EEventButtonPressed, aButtonId );
       
   704             break;
       
   705             }
       
   706 
       
   707         case EEventButton:
       
   708             {
       
   709             NotifyObservers( MFsControlBarObserver::EEventButton, aButtonId );
       
   710             break;
       
   711             }
       
   712 
       
   713         // <cmail> Touch
       
   714         case EEventButtonTouchReleased:
       
   715             {
       
   716             if (iTouchEnabled && iTouchWasEnabled)
       
   717                 {
       
   718                 if( aButtonId > KErrNotFound )
       
   719                     {
       
   720                     NotifyObservers(
       
   721                         MFsControlBarObserver::EEventButtonTouched, aButtonId );
       
   722                     }
       
   723                 else
       
   724                     {
       
   725                     MakeSelectorVisible( EFalse );
       
   726                     }
       
   727                 }
       
   728             else
       
   729                 {
       
   730                 // Mark event not handled, because list might be waiting for this up event
       
   731                 eventHandled = EFalse;
       
   732                 }
       
   733             break;
       
   734             }
       
   735         // </cmail>
       
   736 
       
   737         case EEventButtonReleased:
       
   738             {
       
   739             NotifyObservers(
       
   740                 MFsControlBarObserver::EEventButtonReleased, aButtonId );
       
   741             break;
       
   742             }
       
   743 
       
   744         case EEventButtonVisibilityChanged:
       
   745             {
       
   746             CFsControlButton* button( iModel->ButtonById( aButtonId ) );
       
   747 
       
   748             if ( button->IsVisible() )
       
   749                 {
       
   750                 // Need to update visual order when a button changes it's
       
   751                 // state from hidden to visible.
       
   752                 iVisualiser->ReorderVisuals();
       
   753                 }
       
   754 
       
   755             TRAP_IGNORE( iVisualiser->RefreshL() );
       
   756             }
       
   757             // Intended flow through.
       
   758         case EEventButtonDimmStateChanged:
       
   759             {
       
   760             // The focus is not needed to be changed if the selected button's
       
   761             // dimm state isn't changed.
       
   762             if ( aButtonId != iSelectedButton )
       
   763                 {
       
   764                 break;
       
   765                 }
       
   766 
       
   767             CFsControlButton* button( iModel->ButtonById( aButtonId ) );
       
   768 
       
   769             if ( iModel->IsFocused()
       
   770                 && ( button->IsDimmed() || !button->IsVisible() ) )
       
   771                 {
       
   772                 const TBool mirrored( CFsLayoutManager::IsMirrored() );
       
   773                 button = mirrored
       
   774                     ? iModel->PrevButton( aButtonId )
       
   775                     : iModel->NextButton( aButtonId );
       
   776 
       
   777                 if ( !button )
       
   778                     {
       
   779                     button = mirrored
       
   780                         ? iModel->NextButton( aButtonId )
       
   781                         : iModel->PrevButton( aButtonId );
       
   782                     }
       
   783 
       
   784                 TRAP_IGNORE( ChangeFocusL( button ) );
       
   785                 }
       
   786             break;
       
   787             }
       
   788 
       
   789         default:
       
   790             {
       
   791             FsGenericPanic( EFsControlBarUnknownEvent );
       
   792             break;
       
   793             }
       
   794         }
       
   795     return eventHandled;
       
   796     }
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 // Sends event to observers.
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 void CFsControlBar::NotifyObservers(
       
   804     MFsControlBarObserver::TFsControlBarEvent aEvent,
       
   805     TInt aButtonId )
       
   806     {
       
   807     FUNC_LOG;
       
   808     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   809         {
       
   810         iObservers[i]->HandleControlBarEvent( aEvent, aButtonId );
       
   811         }
       
   812     }
       
   813 
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // Changes focus to another button or looses focus from control bar.
       
   817 // ---------------------------------------------------------------------------
       
   818 //
       
   819 void CFsControlBar::ChangeFocusL( CFsControlButton* aButton )
       
   820     {
       
   821     FUNC_LOG;
       
   822     if ( aButton )
       
   823         {
       
   824         // set focus to specified button
       
   825         SetFocusByIdL( aButton->Id() );
       
   826         }
       
   827     else
       
   828         {
       
   829         // loose focus from bar
       
   830         LooseFocus( MFsControlBarObserver::EEventFocusLostAtSide );
       
   831         }
       
   832     }
       
   833 
       
   834 
       
   835 // ---------------------------------------------------------------------------
       
   836 // Sets needed variables when bar loses focus.
       
   837 // ---------------------------------------------------------------------------
       
   838 //
       
   839 void CFsControlBar::LooseFocus(
       
   840     MFsControlBarObserver::TFsControlBarEvent aLooseFocusEvent )
       
   841     {
       
   842     FUNC_LOG;
       
   843     if ( aLooseFocusEvent == MFsControlBarObserver::EEventFocusLostAtBottom
       
   844          || aLooseFocusEvent == MFsControlBarObserver::EEventFocusLostAtSide
       
   845          || aLooseFocusEvent == MFsControlBarObserver::EEventFocusLost )
       
   846         {
       
   847         CFsControlButton* button( iModel->ButtonById( iSelectedButton ) );
       
   848 
       
   849         if ( button )
       
   850             {
       
   851             button->SetFocus( EFalse );
       
   852             iSelectedButton = KNoButtonFocused;
       
   853             iModel->SetFocus( EFalse );
       
   854             iVisualiser->HideSelector();
       
   855 
       
   856             NotifyObservers( aLooseFocusEvent );
       
   857             }
       
   858         }
       
   859     }
       
   860