emailuis/uicomponents/src/fscontrolbutton.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 Button component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // <cmail> SF
       
    21 #include "emailtrace.h"
       
    22 #include <alf/alfevent.h>
       
    23 #include <alf/alfdecklayout.h>
       
    24 // </cmail>
       
    25 // Needed for pointer events.
       
    26 #include <alf/alfdisplay.h>
       
    27 #include <alf/alfroster.h>
       
    28 
       
    29 #include <AknUtils.h>
       
    30 
       
    31 #include "fscontrolbutton.h"
       
    32 #include "fscontrolbuttonmodel.h"
       
    33 #include "fscontrolbuttonvisualiser.h"
       
    34 #include "fscontrolbuttonobserver.h"
       
    35 #include "fsgenericpanic.h"
       
    36 #include "fstriggeredcomponent.h"
       
    37 #include "fstextstylemanager.h"
       
    38 #include "fslayoutmanager.h"
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CFsControlButton::CFsControlButton(
       
    48     MFsControlButtonObserver& aParent,
       
    49     CAlfDeckLayout& aParentLayout ) :
       
    50     iParent( aParent ),
       
    51     iParentLayout( aParentLayout )
       
    52     {
       
    53     FUNC_LOG;
       
    54     }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Second phase constructor.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CFsControlButton::ConstructL(
       
    62     CAlfEnv& aEnv,
       
    63     TInt aId,
       
    64     TFsControlButtonType aType,
       
    65     TRect& aStartPoint,
       
    66     CFsTextStyleManager* aTextStyleManager )
       
    67     {
       
    68     FUNC_LOG;
       
    69     CAlfControl::ConstructL( aEnv );
       
    70 
       
    71     iModel = CFsControlButtonModel::NewL(
       
    72         aId, aType, aStartPoint, iParentLayout );
       
    73 
       
    74     iVisualiser = CFsControlButtonVisualiser::NewL(
       
    75         *this, iParentLayout, aTextStyleManager );
       
    76     iVisualiser->InitializeL( *iModel );
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Two-phased constructor.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CFsControlButton* CFsControlButton::NewL(
       
    85     CAlfEnv& aEnv,
       
    86     MFsControlButtonObserver& aParent,
       
    87     TInt aId,
       
    88     TFsControlButtonType aType,
       
    89     TRect& aStartPoint,
       
    90     CAlfDeckLayout& aParentLayout,
       
    91     CFsTextStyleManager* aTextStyleManager )
       
    92     {
       
    93     FUNC_LOG;
       
    94     CFsControlButton* self =
       
    95         new( ELeave ) CFsControlButton( aParent, aParentLayout );
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL(
       
    98         aEnv, aId, aType, aStartPoint, aTextStyleManager );
       
    99     CleanupStack::Pop( self );
       
   100     return self;
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Destructor.
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CFsControlButton::~CFsControlButton()
       
   109     {
       
   110     FUNC_LOG;
       
   111     delete iModel;
       
   112     delete iVisualiser;
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Sets first line of text in button.
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CFsControlButton::SetTextL(
       
   121     const TDesC& aLabel,
       
   122     TFsButtonContent aContent )
       
   123     {
       
   124     FUNC_LOG;
       
   125     iModel->SetTextL( aLabel, aContent );
       
   126     switch ( aContent )
       
   127         {
       
   128         case EFsButtonFirstLine:
       
   129             iVisualiser->UpdateElementL( ECBElemLabelFirstLine );
       
   130             break;
       
   131         case EFsButtonSecondLine:
       
   132             iVisualiser->UpdateElementL( ECBElemLabelSndLine );
       
   133             break;
       
   134         default:
       
   135             User::Leave( KErrNotSupported );
       
   136             break;
       
   137         }
       
   138     }
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // Sets visualiser for the button.
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CFsControlButton::SetVisualiserL(
       
   146     CFsControlButtonVisualiser* aVisualiser )
       
   147     {
       
   148     FUNC_LOG;
       
   149     __ASSERT_ALWAYS( aVisualiser, User::Leave( KErrArgument ) );
       
   150 
       
   151     CFsControlButtonVisualiser* newVisualiser( aVisualiser );
       
   152     CleanupStack::PushL( newVisualiser );
       
   153 
       
   154     newVisualiser->SetParentControlL( this );
       
   155     newVisualiser->SetParentLayoutL( &iParentLayout );
       
   156     newVisualiser->InitializeL( *iModel );
       
   157 
       
   158     CleanupStack::Pop( newVisualiser );
       
   159 
       
   160     delete iVisualiser;
       
   161     iVisualiser = newVisualiser;
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Retrieves button's visualiser.
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 CFsControlButtonVisualiser* CFsControlButton::Visualiser()
       
   170     {
       
   171     FUNC_LOG;
       
   172     return iVisualiser;
       
   173     }
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // Set the layout position index on controlbar.
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CFsControlButton::SetParentIndex( TInt aLayoutPos )
       
   181     {
       
   182     FUNC_LOG;
       
   183     iModel->SetParentIndex( aLayoutPos );
       
   184     }
       
   185 
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // Retrieves id of the button.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TInt CFsControlButton::Id() const
       
   192     {
       
   193     FUNC_LOG;
       
   194     return iModel->Id();
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Sets icon A or B. Panics if button's type is incorrect.
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CFsControlButton::SetIconL(
       
   203     CAlfTexture& aIcon,
       
   204     TFsControlButtonElem aWhich )
       
   205     {
       
   206     FUNC_LOG;
       
   207     iModel->SetIconL( aIcon, aWhich );
       
   208     iVisualiser->UpdateElementL( aWhich );
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Sets width of the button.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CFsControlButton::SetWidth( TInt aWidth )
       
   217     {
       
   218     FUNC_LOG;
       
   219     iModel->SetAutoSizeMode( MFsControlButtonInterface::EFsManual );
       
   220     iModel->SetWidth( aWidth );
       
   221     iVisualiser->Refresh();
       
   222     }
       
   223 
       
   224 // <cmail> Platform layout changes
       
   225 // ---------------------------------------------------------------------------
       
   226 // Sets size of the button.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CFsControlButton::SetSize( const TSize& aSize )
       
   230     {
       
   231     FUNC_LOG;
       
   232     iModel->SetAutoSizeMode( MFsControlButtonInterface::EFsManual );
       
   233     iModel->SetSize( aSize );
       
   234     iVisualiser->Refresh();
       
   235     }
       
   236 // </cmail> Platform layout changes
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Set auto size mode for button.
       
   240 // Defines how the buttons size is changed.
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CFsControlButton::SetAutoSizeMode( TFsAutoSizeMode aAutoSizeMode )
       
   244     {
       
   245     FUNC_LOG;
       
   246     TBool refresh( aAutoSizeMode != iModel->AutoSizeMode() );
       
   247     iModel->SetAutoSizeMode( aAutoSizeMode );
       
   248     if ( refresh )
       
   249         {
       
   250         iVisualiser->Refresh();
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Sets focus to control button.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CFsControlButton::SetFocus( TBool aState )
       
   260     {
       
   261     FUNC_LOG;
       
   262     iModel->SetFocus( aState );
       
   263     iVisualiser->Refresh();
       
   264     }
       
   265 
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // Refresh the button's position.
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CFsControlButton::RefreshButtonPosition( TSize& aParentSize )
       
   272     {
       
   273     FUNC_LOG;
       
   274     iModel->RefreshButtonPosition( aParentSize );
       
   275     }
       
   276 
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // Checks if button has focus.
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TBool CFsControlButton::IsFocused() const
       
   283     {
       
   284     FUNC_LOG;
       
   285     return iModel->IsFocused();
       
   286     }
       
   287 
       
   288 // <cmail> Platform layout changes
       
   289 // ---------------------------------------------------------------------------
       
   290 // Sets position of the button (top left point).
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CFsControlButton::SetPos( const TPoint& aTlPoint )
       
   294     {
       
   295     FUNC_LOG;
       
   296     iModel->SetPos( aTlPoint );
       
   297     iModel->SetAutoSizeMode( MFsControlButtonInterface::EFsManual );
       
   298 
       
   299     // Refresh buttons position to apply mirroring to it.
       
   300     TSize parent( iParentLayout.Size().Target().AsSize() );
       
   301     iModel->RefreshButtonPosition( parent );
       
   302 
       
   303     iVisualiser->Refresh();
       
   304     }
       
   305 // </cmail> Platform layout changes
       
   306 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // Retrieves position of button.
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 const TAlfTimedPoint CFsControlButton::Pos() const
       
   313     {
       
   314     FUNC_LOG;
       
   315     return iVisualiser->Layout()->Pos();
       
   316     }
       
   317 
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // Retrieves size of button.
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 const TAlfTimedPoint CFsControlButton::Size() const
       
   324     {
       
   325     FUNC_LOG;
       
   326     return iVisualiser->Layout()->Size();
       
   327     }
       
   328 
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // Sets component to button which will be triggered when button
       
   332 // is pressed.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void CFsControlButton::SetTriggeredComponent(
       
   336     MFsTriggeredComponent& aComponent )
       
   337     {
       
   338     FUNC_LOG;
       
   339     iTriggeredComponent = &aComponent;
       
   340     }
       
   341 
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // Clears triggered component. No more events to triggered
       
   345 // component are sent.
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CFsControlButton::ClearTriggeredComponent()
       
   349     {
       
   350     FUNC_LOG;
       
   351     iTriggeredComponent = NULL;
       
   352     }
       
   353 
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // Sets alignment of element.
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CFsControlButton::SetElemAlignL(
       
   360     TFsControlButtonElem aButtonElem,
       
   361     TAlfAlignHorizontal aHAlign,
       
   362     TAlfAlignVertical aVAlign )
       
   363     {
       
   364     FUNC_LOG;
       
   365     iVisualiser->SetElemAlignL( aButtonElem, aHAlign, aVAlign );
       
   366     iVisualiser->Refresh();
       
   367     }
       
   368 
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // Sets dimm state of the button.
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CFsControlButton::SetDimmed( TBool aDimmed )
       
   375     {
       
   376     FUNC_LOG;
       
   377     if ( aDimmed != IsDimmed() )
       
   378         {
       
   379         iModel->SetDimmed( aDimmed );
       
   380         iVisualiser->Refresh();
       
   381 
       
   382         iParent.HandleButtonEvent(
       
   383             MFsControlButtonObserver::EEventButtonDimmStateChanged,
       
   384             iModel->Id() );
       
   385         }
       
   386     }
       
   387 
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // Checks dimm state of the button.
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 TBool CFsControlButton::IsDimmed() const
       
   394     {
       
   395     FUNC_LOG;
       
   396     return iModel->IsDimmed();
       
   397     }
       
   398 
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // Shows (enables) button.
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void CFsControlButton::ShowButtonL()
       
   405     {
       
   406     FUNC_LOG;
       
   407     if ( !iVisualiser->IsVisible() )
       
   408         {
       
   409         iVisualiser->ShowL();
       
   410 
       
   411         iParent.HandleButtonEvent(
       
   412             MFsControlButtonObserver::EEventButtonVisibilityChanged,
       
   413             iModel->Id() );
       
   414         }
       
   415     }
       
   416 
       
   417 
       
   418 // ---------------------------------------------------------------------------
       
   419 // Hides (disables) button.
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 void CFsControlButton::HideButton()
       
   423     {
       
   424     FUNC_LOG;
       
   425     if ( iVisualiser->IsVisible() )
       
   426         {
       
   427         iVisualiser->Hide();
       
   428 
       
   429         iParent.HandleButtonEvent(
       
   430             MFsControlButtonObserver::EEventButtonVisibilityChanged,
       
   431             iModel->Id() );
       
   432         }
       
   433     }
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // Checks if button is visible or hidden.
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 TBool CFsControlButton::IsVisible() const
       
   441     {
       
   442     FUNC_LOG;
       
   443     return iVisualiser->IsVisible();
       
   444     }
       
   445 
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // Sets button's background image.
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void CFsControlButton::SetBackgroundImageL( CAlfImageBrush* aImage )
       
   452     {
       
   453     FUNC_LOG;
       
   454     iVisualiser->SetBackgroundImageL( aImage );
       
   455     }
       
   456 
       
   457 
       
   458 // ---------------------------------------------------------------------------
       
   459 // Sets button's background color.
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CFsControlButton::SetBackgroundColor( const TRgb& aColor )
       
   463     {
       
   464     FUNC_LOG;
       
   465     iModel->SetTextColor( aColor, CFsControlButtonModel::EButtonBackground );
       
   466     iVisualiser->SetBackgroundColor( aColor );
       
   467     }
       
   468 
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // Clears button's background color. Button is transparent.
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 void CFsControlButton::ClearBackgroundColor()
       
   475     {
       
   476     FUNC_LOG;
       
   477     iVisualiser->ClearBackgroundColor();
       
   478     }
       
   479 
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // Clears button's background image.
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 void CFsControlButton::ClearBackgroundImage()
       
   486     {
       
   487     FUNC_LOG;
       
   488     iVisualiser->ClearBackgroundImage();
       
   489     }
       
   490 
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // Retrieves text from control button.
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 TPtrC CFsControlButton::Text( TFsButtonContent aContent ) const
       
   497     {
       
   498     FUNC_LOG;
       
   499     return iModel->Text( aContent );
       
   500     }
       
   501 
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // Set new height for the button text.
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CFsControlButton::SetTextHeight( const TInt aTextHeight )
       
   508     {
       
   509     FUNC_LOG;
       
   510     iVisualiser->SetTextHeight( aTextHeight );
       
   511     }
       
   512 
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // Change the current font.
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CFsControlButton::SetTextFontL( const TFontSpec& aFontSpec )
       
   519     {
       
   520     FUNC_LOG;
       
   521     iVisualiser->SetTextFontL( aFontSpec );
       
   522     }
       
   523 
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // Set button's text color when it's not focused or dimmed.
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CFsControlButton::SetNormalTextColor( const TRgb& aColor )
       
   530     {
       
   531     FUNC_LOG;
       
   532     iModel->SetTextColor( aColor, CFsControlButtonModel::EButtonNormal );
       
   533     iVisualiser->Refresh();
       
   534     }
       
   535 
       
   536 
       
   537 // ---------------------------------------------------------------------------
       
   538 // Set button's text color when it's focused.
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 void CFsControlButton::SetFocusedTextColor( const TRgb& aColor )
       
   542     {
       
   543     FUNC_LOG;
       
   544     iModel->SetTextColor( aColor, CFsControlButtonModel::EButtonFocused );
       
   545     iVisualiser->Refresh();
       
   546     }
       
   547 
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 // Set button's text color when it's dimmed.
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CFsControlButton::SetDimmedTextColor( const TRgb& aColor )
       
   554     {
       
   555     FUNC_LOG;
       
   556     iModel->SetTextColor( aColor, CFsControlButtonModel::EButtonDimmed );
       
   557     iVisualiser->Refresh();
       
   558     }
       
   559 
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // Retrieves control button type.
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 TFsControlButtonType CFsControlButton::ControlButtonType() const
       
   566     {
       
   567     FUNC_LOG;
       
   568     return iModel->Type();
       
   569     }
       
   570 
       
   571     // <cmail> Touch
       
   572 // ---------------------------------------------------------------------------
       
   573 // Returns this as CAlfControl
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 CAlfControl* CFsControlButton::AsAlfControl()
       
   577     {
       
   578     return this;
       
   579     }
       
   580     // </cmail>
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 void CFsControlButton::MakeFocusVisible( TBool aShow )
       
   587     {
       
   588     FUNC_LOG;
       
   589     iVisualiser->MakeFocusVisible( aShow );
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 // From class CHuiControl/CAlfControl.
       
   594 // Called when an input event is being offered to the control.
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 TBool CFsControlButton::OfferEventL( const TAlfEvent& aEvent )
       
   598     {
       
   599     FUNC_LOG;
       
   600     TBool result( EFalse );
       
   601 
       
   602     // no key handling when not shown or dimmed.
       
   603     if ( !IsVisible() || IsDimmed() )
       
   604         {
       
   605         return result;
       
   606         }
       
   607 
       
   608     if ( aEvent.IsKeyEvent() )
       
   609         {
       
   610         switch ( aEvent.Code() )
       
   611             {
       
   612             case EEventKeyDown:
       
   613                 {
       
   614                 if ( aEvent.KeyEvent().iScanCode == EStdKeyDevice3 )
       
   615                     {
       
   616                     iParent.HandleButtonEvent(
       
   617                         MFsControlButtonObserver::EEventButtonPressed,
       
   618                         -1 );
       
   619                     result = ETrue;
       
   620                     }
       
   621                 break;
       
   622                 }
       
   623 
       
   624             case EEventKey:
       
   625                 {
       
   626                 if ( aEvent.KeyEvent().iScanCode == EStdKeyDevice3 )
       
   627                     {
       
   628                     iParent.HandleButtonEvent(
       
   629                         MFsControlButtonObserver::EEventButton,
       
   630                         iModel->Id() );
       
   631                     result = ETrue;
       
   632 
       
   633                     if ( iTriggeredComponent )
       
   634                         {
       
   635                         iTriggeredComponent->OpenComponent();
       
   636                         }
       
   637                     }
       
   638                 break;
       
   639                 }
       
   640 
       
   641             case EEventKeyUp:
       
   642                 {
       
   643                 if ( aEvent.KeyEvent().iScanCode == EStdKeyDevice3 )
       
   644                     {
       
   645                     iParent.HandleButtonEvent(
       
   646                         MFsControlButtonObserver::EEventButtonReleased,
       
   647                         -1 );
       
   648                     result = ETrue;
       
   649                     }
       
   650                 break;
       
   651                 }
       
   652 
       
   653             default:
       
   654                 {
       
   655                 // event not consumed - result still got value EFalse
       
   656                 break;
       
   657                 }
       
   658             }
       
   659         }
       
   660     else if ( aEvent.IsPointerEvent() )
       
   661         {
       
   662         const TPointerEvent& pointerEvent( aEvent.PointerEvent() );
       
   663         switch (pointerEvent.iType)
       
   664             {
       
   665             case TPointerEvent::EButton1Down:
       
   666                 {
       
   667                 if( HitTest( aEvent.PointerEvent().iParentPosition ) )
       
   668                     {
       
   669                     iTouchPressed = ETrue;
       
   670                     GrabPointerEvents( ETrue );
       
   671                     result = iParent.HandleButtonEvent(
       
   672                         MFsControlButtonObserver::EEventButtonTouchPressed,
       
   673                         iModel->Id() );
       
   674                     }
       
   675                 break;
       
   676                 }
       
   677             case TPointerEvent::EButton1Up:
       
   678                 {
       
   679                 if( iTouchPressed )
       
   680                     {
       
   681                     GrabPointerEvents( EFalse );
       
   682 
       
   683                     TInt buttonId( KErrNotFound );
       
   684                     if( HitTest( aEvent.PointerEvent().iParentPosition ) )
       
   685                         {
       
   686                         buttonId = iModel->Id();
       
   687                         }
       
   688                     result = iParent.HandleButtonEvent(
       
   689                         MFsControlButtonObserver::EEventButtonTouchReleased,
       
   690                         buttonId );
       
   691                     iTouchPressed = EFalse;
       
   692                     }
       
   693                 break;
       
   694                 }
       
   695             default:
       
   696                 {
       
   697                 break;
       
   698                 }
       
   699             }
       
   700         }
       
   701     return result;
       
   702     }
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 //
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 void CFsControlButton::GrabPointerEvents( TBool aGrab )
       
   709     {
       
   710     CAlfDisplay* display = Display();
       
   711     if( display )
       
   712         {
       
   713         if ( aGrab )
       
   714             {
       
   715             display->Roster().AddPointerEventObserver(
       
   716                 EAlfPointerEventReportUnhandled, *this );
       
   717             }
       
   718         else
       
   719             {
       
   720             display->Roster().RemovePointerEventObserver(
       
   721                 EAlfPointerEventReportUnhandled, *this );
       
   722             }
       
   723         }
       
   724     }