emailuis/uicomponents/src/fscontrolbuttonvisualiser.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:  Visualiser class for Control Button component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail> SF
       
    20 #include "emailtrace.h"
       
    21 #include <alf/alfcontrol.h>
       
    22 #include <alf/alfdecklayout.h>
       
    23 #include <alf/alfimagevisual.h>
       
    24 #include <alf/alfgridlayout.h>
       
    25 #include <alf/alfenv.h>
       
    26 #include <alf/alftextstylemanager.h>
       
    27 #include <alf/alftextvisual.h>
       
    28 #include <alf/alfanchorlayout.h>
       
    29 #include <alf/alfgradientbrush.h>
       
    30 #include <alf/alfframebrush.h>
       
    31 #include <alf/alfimagebrush.h>
       
    32 #include <alf/alfbrusharray.h>
       
    33 #include <alf/alftextstyle.h>
       
    34 //</cmail>
       
    35 #include <AknsConstants.h>
       
    36 #include <AknUtils.h>
       
    37 #include <touchlogicalfeedback.h>
       
    38 
       
    39 #include "fscontrolbuttonvisualiser.h"
       
    40 #include "fscontrolbuttonmodel.h"
       
    41 #include "fsgenericpanic.h"
       
    42 #include "fstextstylemanager.h"
       
    43 #include "fslayoutmanager.h"
       
    44 #include "fscontrolbar.h"
       
    45 
       
    46 const TInt KFsDefaultFontStyle = EAlfTextStyleNormal;
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Constructor.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CFsControlButtonVisualiser::CFsControlButtonVisualiser(
       
    56     CAlfControl& aParent,
       
    57     CAlfDeckLayout& aParentLayout,
       
    58     CFsTextStyleManager* aTextStyleManager ) :
       
    59     iParent( &aParent ),
       
    60     iParentLayout( &aParentLayout ),
       
    61     iUpdateIconsAlign( EFalse ),
       
    62     iFirstDraw( ETrue ),
       
    63     iVisible( EFalse ),
       
    64     iTextStyleManager( aTextStyleManager )
       
    65     {
       
    66     FUNC_LOG;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Constructor.
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CFsControlButtonVisualiser::CFsControlButtonVisualiser() :
       
    75     iUpdateIconsAlign( EFalse ),
       
    76     iFirstDraw( ETrue ),
       
    77     iVisible( EFalse ),
       
    78     iTextStyleManager( NULL )
       
    79     {
       
    80     FUNC_LOG;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Second phase constructor.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C void CFsControlButtonVisualiser::ConstructL()
       
    89     {
       
    90     FUNC_LOG;
       
    91     if ( iParent )
       
    92         {
       
    93         // Visual for background content
       
    94         iButtonLayout = CAlfLayout::AddNewL( *iParent );
       
    95         iButtonLayout->SetTactileFeedbackL( ETouchEventStylusDown, ETouchFeedbackBasic );
       
    96         iButtonLayout->EnableBrushesL();
       
    97 
       
    98         iButtonContentLayout = CAlfLayout::AddNewL( *iParent );
       
    99 
       
   100         // Request callback after image is loaded to refresh it's size and
       
   101         // position.
       
   102         iParent->Env().TextureManager().AddLoadObserverL( this );
       
   103         }
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Two-phased constructor.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CFsControlButtonVisualiser* CFsControlButtonVisualiser::NewL(
       
   112     CAlfControl& aParent,
       
   113     CAlfDeckLayout& aParentLayout,
       
   114     CFsTextStyleManager* aTextStyleManager )
       
   115     {
       
   116     FUNC_LOG;
       
   117     CFsControlButtonVisualiser* self =
       
   118         new(ELeave)CFsControlButtonVisualiser(
       
   119             aParent, aParentLayout, aTextStyleManager );
       
   120 
       
   121     CleanupStack::PushL( self );
       
   122     self->ConstructL();
       
   123     CleanupStack::Pop( self );
       
   124     return self;
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Destructor.
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C CFsControlButtonVisualiser::~CFsControlButtonVisualiser()
       
   133     {
       
   134     FUNC_LOG;
       
   135     ClearBackgroundImage();
       
   136 
       
   137     // removing from parent
       
   138     if ( iButtonLayout )
       
   139         {
       
   140         // If clase is only needed by debug version only.
       
   141         if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) )
       
   142             {
       
   143             iParentLayout->Remove( iButtonLayout );
       
   144             }
       
   145         iParent->Remove( iButtonLayout );
       
   146         iParent->Env().TextureManager().RemoveLoadObserver( this );
       
   147         delete iButtonLayout;
       
   148         }
       
   149 
       
   150     delete iBgColorBrush;
       
   151     delete iTextFontSpec;
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // From class CFsControlButtonVisualiserBase.
       
   157 // Initializes visualiser with model.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C void CFsControlButtonVisualiser::InitializeL(
       
   161     CFsControlButtonModel& aButtonModel )
       
   162     {
       
   163     FUNC_LOG;
       
   164     iButtonModel = &aButtonModel;
       
   165 
       
   166     // Add background color brush. This cannot be done in ConstructL as the
       
   167     // button model isn't set before.
       
   168     if ( !iBgColorBrush )
       
   169         {
       
   170         iBgColorBrush = CAlfGradientBrush::NewL( iParent->Env() );
       
   171         SetBackgroundColor( iButtonModel->TextColor(
       
   172             CFsControlButtonModel::EButtonBackground ) );
       
   173         iButtonLayout->Brushes()->AppendL(
       
   174             iBgColorBrush, EAlfDoesNotHaveOwnership );
       
   175         }
       
   176 
       
   177     // create needed visuals
       
   178     CreateButtonVisualsL();
       
   179 
       
   180     UpdateBarLayout();
       
   181     }
       
   182 
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // From class CFsControlButtonVisualiserBase.
       
   186 // Refreshes button's content.
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C void CFsControlButtonVisualiser::Refresh()
       
   190     {
       
   191     FUNC_LOG;
       
   192     // draw only if enabled and ready for drawing
       
   193     if ( !IsVisible() )
       
   194         {
       
   195         return;
       
   196         }
       
   197 
       
   198     TBool buttonSizeChanged( iButtonModel->ButtonSizeChanged() );
       
   199 
       
   200     if ( buttonSizeChanged ||
       
   201         iButtonModel->AutoSizeMode()
       
   202             == MFsControlButtonInterface::EFsFitToContent ||
       
   203         iButtonModel->AutoSizeMode()
       
   204             == MFsControlButtonInterface::EFsFitToParent )
       
   205         {
       
   206         TSize buttonSize( iButtonModel->Size() );
       
   207         UpdateButtonSize();
       
   208         buttonSizeChanged |= buttonSize != iButtonModel->Size();
       
   209         }
       
   210 
       
   211     if ( buttonSizeChanged )
       
   212         {
       
   213         UpdateBarLayout();
       
   214         return;
       
   215         }
       
   216 
       
   217     if ( iButtonModel->ButtonPosChanged() )
       
   218         {
       
   219         UpdateButtonPos();
       
   220         if ( !buttonSizeChanged )
       
   221             {
       
   222             UpdateBarLayout();
       
   223             return;
       
   224             }
       
   225         }
       
   226 
       
   227     // recalculate icons alignement if needed
       
   228     if ( iUpdateIconsAlign || iFirstDraw )
       
   229         {
       
   230         if ( iButtonModel->ContainsElement( ECBElemIconA ) )
       
   231             {
       
   232             SetImageAlign( iIconA, iAIconHAlign, iAIconVAlign );
       
   233             }
       
   234 
       
   235         if ( iButtonModel->ContainsElement( ECBElemIconB ) )
       
   236             {
       
   237             SetImageAlign( iIconB, iBIconHAlign, iBIconVAlign );
       
   238             }
       
   239 
       
   240         iUpdateIconsAlign = EFalse;
       
   241         iFirstDraw = EFalse;
       
   242         }
       
   243 
       
   244     // if dimmed
       
   245     if ( iButtonModel->IsDimmed() )
       
   246         {
       
   247         PrepareDrawDimmed();
       
   248         }
       
   249     // if focused
       
   250     else if( iButtonModel->IsFocused() && iDrawFocus )
       
   251         {
       
   252         PrepareDrawFocused();
       
   253         }
       
   254     // normal - no focus, enabled
       
   255     else
       
   256         {
       
   257         PrepareDrawNormal();
       
   258         }
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // From class CFsControlButtonVisualiserBase.
       
   263 // Refreshes button's content, sets topleft point of button in specified
       
   264 // place.
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CFsControlButtonVisualiser::Refresh( TPoint aStartAt )
       
   268     {
       
   269     FUNC_LOG;
       
   270     if ( iButtonModel->AutoPosition() )
       
   271         {
       
   272         TAlfRealPoint pos( aStartAt );
       
   273         if ( CFsLayoutManager::IsMirrored() )
       
   274             {
       
   275             TInt width( iParentLayout->Size().Target().iX );
       
   276             pos.iX = width - aStartAt.iX - iButtonLayout->Size().Target().iX;
       
   277             }
       
   278 
       
   279         // Set new position for background visual and it's content.
       
   280         iButtonLayout->SetFlag( EAlfVisualFlagManualPosition );
       
   281         iButtonContentLayout->SetFlag( EAlfVisualFlagManualPosition );
       
   282         iButtonLayout->SetPos( pos );
       
   283         iButtonContentLayout->SetPos( pos );
       
   284         }
       
   285 
       
   286     Refresh();
       
   287     }
       
   288 
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // From class CFsControlButtonVisualiserBase.
       
   292 // Retrieves end X coordinate of the button.
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 TInt CFsControlButtonVisualiser::GetBottomRight() const
       
   296     {
       
   297     FUNC_LOG;
       
   298     return
       
   299         iButtonModel->TopLeftPoint().iX + iButtonLayout->Size().iX.Target();
       
   300     }
       
   301 
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // From class CFsControlButtonVisualiserBase.
       
   305 // Retrieves position of the button.
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 const TAlfTimedPoint CFsControlButtonVisualiser::Pos() const
       
   309     {
       
   310     FUNC_LOG;
       
   311     return iButtonLayout->Pos();
       
   312     }
       
   313 
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // From class CFsControlButtonVisualiserBase.
       
   317 // Retrieves size of the button.
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 const TAlfTimedPoint CFsControlButtonVisualiser::Size() const
       
   321     {
       
   322     FUNC_LOG;
       
   323     return iButtonLayout->Size();
       
   324     }
       
   325 
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // From class CFsControlButtonVisualiserBase.
       
   329 // Sets background image of the button.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 EXPORT_C void CFsControlButtonVisualiser::SetBackgroundImageL(
       
   333     CAlfImageBrush* aImage )
       
   334     {
       
   335     FUNC_LOG;
       
   336     // Release the old background image.
       
   337     ClearBackgroundImage();
       
   338 
       
   339     // As the ownership of the new brush is gained the pointer can't be lost.
       
   340     CleanupStack::PushL( aImage );
       
   341     iButtonLayout->Brushes()->AppendL( aImage, EAlfDoesNotHaveOwnership );
       
   342     CleanupStack::Pop( aImage );
       
   343 
       
   344     iBgBrush = aImage;
       
   345     }
       
   346 
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // Sets background color for button.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 EXPORT_C void CFsControlButtonVisualiser::SetBackgroundColor(
       
   353     const TRgb& aColor )
       
   354     {
       
   355     FUNC_LOG;
       
   356     iBgColorBrush->SetColor( aColor );
       
   357     iBgColorBrush->SetOpacity( 1 );
       
   358     }
       
   359 
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // Clears button's background color. Button is transparent.
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 EXPORT_C void CFsControlButtonVisualiser::ClearBackgroundColor()
       
   366     {
       
   367     FUNC_LOG;
       
   368     iBgColorBrush->SetOpacity( 0 );
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // From class CFsControlButtonVisualiserBase.
       
   374 // Clears background image of the button.
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C void CFsControlButtonVisualiser::ClearBackgroundImage()
       
   378     {
       
   379     FUNC_LOG;
       
   380     if ( iBgBrush )
       
   381         {
       
   382         for ( TInt i( iButtonLayout->Brushes()->Count() - 1 ); 0 <= i; i-- )
       
   383             {
       
   384             if ( &iButtonLayout->Brushes()->At( i ) == iBgBrush )
       
   385                 {
       
   386                 iButtonLayout->Brushes()->Remove( i );
       
   387                 break;
       
   388                 }
       
   389             }
       
   390         delete iBgBrush;
       
   391         iBgBrush = NULL;
       
   392         }
       
   393     }
       
   394 
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // From class CFsControlButtonVisualiserBase.
       
   398 // Sets alignement of element of the button.
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 EXPORT_C void CFsControlButtonVisualiser::SetElemAlignL(
       
   402     TFsControlButtonElem aButtonElem,
       
   403     TAlfAlignHorizontal aHAlign,
       
   404     TAlfAlignVertical aVAlign )
       
   405     {
       
   406     FUNC_LOG;
       
   407     TFsControlButtonType buttonType( iButtonModel->Type() );
       
   408 
       
   409     // check if button contains this element.
       
   410     if ( !iButtonModel->ContainsElement( aButtonElem ) )
       
   411         {
       
   412         FsGenericPanic( EFsControlButtonIncorrectButtonElement );
       
   413         User::Leave( KErrNotSupported );
       
   414         }
       
   415 
       
   416     switch ( aButtonElem )
       
   417         {
       
   418         case ECBElemIconA:
       
   419             {
       
   420             iAIconHAlign = aHAlign;
       
   421             iAIconVAlign = aVAlign;
       
   422             SetImageAlign( iIconA, aHAlign, aVAlign );
       
   423             break;
       
   424             }
       
   425 
       
   426         case ECBElemIconB:
       
   427             {
       
   428             iBIconHAlign = aHAlign;
       
   429             iBIconVAlign = aVAlign;
       
   430             SetImageAlign( iIconB, aHAlign, aVAlign );
       
   431             break;
       
   432             }
       
   433 
       
   434         case ECBElemLabelFirstLine:
       
   435             {
       
   436             SetTextAlign( iLabelFirstLine, aHAlign, aVAlign );
       
   437             break;
       
   438             }
       
   439 
       
   440         case ECBElemLabelSndLine:
       
   441             {
       
   442             SetTextAlign( iLabelSecondLine, aHAlign, aVAlign );
       
   443             break;
       
   444             }
       
   445 
       
   446         default:
       
   447             {
       
   448             // no other elements available
       
   449             FsGenericPanic( EFsControlButtonIncorrectButtonElement );
       
   450             break;
       
   451             }
       
   452         }
       
   453     }
       
   454 
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // Update elemets after texture loading is completed.
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 EXPORT_C void CFsControlButtonVisualiser::TextureLoadingCompleted(
       
   461     CAlfTexture& aTexture,
       
   462     TInt /*aTextureId*/,
       
   463     TInt aErrorCode )
       
   464     {
       
   465     FUNC_LOG;
       
   466     if ( aErrorCode )
       
   467         {
       
   468         return;
       
   469         }
       
   470 
       
   471     // <cmail> Safety check added. Check why it is needed here.
       
   472     if ( iIconA &&
       
   473             iIconA->Image().HasTexture() &&
       
   474             &iIconA->Image().Texture() == &aTexture )
       
   475         {
       
   476         TRAP_IGNORE( UpdateElementL( ECBElemIconA ) );
       
   477         }
       
   478     if ( iIconB &&
       
   479             iIconB->Image().HasTexture() &&
       
   480             &iIconB->Image().Texture() == &aTexture )
       
   481         {
       
   482         TRAP_IGNORE( UpdateElementL( ECBElemIconB ) );
       
   483         }
       
   484     // </cmail>
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 //
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CFsControlButtonVisualiser::MakeFocusVisible( TBool aShow )
       
   492     {
       
   493     FUNC_LOG;
       
   494     if( aShow )
       
   495         {
       
   496         iDrawFocus = ETrue;
       
   497         PrepareDrawFocused();
       
   498         }
       
   499     else
       
   500         {
       
   501         iDrawFocus = EFalse;
       
   502         PrepareDrawNormal();
       
   503         }
       
   504     }
       
   505 
       
   506 // ---------------------------------------------------------------------------
       
   507 // Updates element content from the model.
       
   508 // ---------------------------------------------------------------------------
       
   509 //
       
   510 EXPORT_C void CFsControlButtonVisualiser::UpdateElementL(
       
   511     TFsControlButtonElem aButtonElem )
       
   512     {
       
   513     FUNC_LOG;
       
   514     // check if button contains this element.
       
   515     if ( !iButtonModel->ContainsElement( aButtonElem ) )
       
   516         {
       
   517         FsGenericPanic( EFsControlButtonIncorrectButtonElement );
       
   518         User::Leave( KErrNotSupported );
       
   519         }
       
   520 
       
   521     switch ( aButtonElem )
       
   522         {
       
   523         case ECBElemIconA:
       
   524             {
       
   525             iIconA->SetImage(
       
   526                 TAlfImage( *iButtonModel->Icon( ECBElemIconA ) ) );
       
   527             // <cmail> Platform layout change
       
   528             //iIconA->SetSize( iIconA->Image().Texture().Size() );
       
   529             // </cmail> Platform layout change
       
   530             break;
       
   531             }
       
   532 
       
   533         case ECBElemIconB:
       
   534             {
       
   535             iIconB->SetImage(
       
   536                 TAlfImage( *iButtonModel->Icon( ECBElemIconB ) ) );
       
   537             // <cmail> Platform layout change
       
   538             //iIconB->SetSize( iIconB->Image().Texture().Size() );
       
   539             // </cmail> Platform layout change
       
   540             break;
       
   541             }
       
   542 
       
   543         case ECBElemLabelFirstLine:
       
   544             {
       
   545             TRAP_IGNORE( iLabelFirstLine->SetTextL( iButtonModel->Text(
       
   546                 MFsControlButtonInterface::EFsButtonFirstLine ) ) );
       
   547             break;
       
   548             }
       
   549 
       
   550         case ECBElemLabelSndLine:
       
   551             {
       
   552             TRAP_IGNORE( iLabelSecondLine->SetTextL( iButtonModel->Text(
       
   553                 MFsControlButtonInterface::EFsButtonSecondLine ) ) );
       
   554             break;
       
   555             }
       
   556 
       
   557         default:
       
   558             {
       
   559             // no other elements available
       
   560             FsGenericPanic( EFsControlButtonIncorrectButtonElement );
       
   561             break;
       
   562             }
       
   563         }
       
   564 
       
   565     UpdateButtonSize();
       
   566     UpdateBarLayout();
       
   567     }
       
   568 
       
   569 
       
   570 // ---------------------------------------------------------------------------
       
   571 // Retrieves width of the button.
       
   572 // ---------------------------------------------------------------------------
       
   573 //
       
   574 TInt CFsControlButtonVisualiser::Width() const
       
   575     {
       
   576     FUNC_LOG;
       
   577     return iButtonModel->Size().iWidth;
       
   578     }
       
   579 
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // Updates size of button.
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 EXPORT_C void CFsControlButtonVisualiser::UpdateButtonSize()
       
   586     {
       
   587     FUNC_LOG;
       
   588     TBool textClipping( ETrue );
       
   589     CAlfTextVisual::TLineWrap textWrapping(
       
   590         CAlfTextVisual::ELineWrapTruncate );
       
   591 
       
   592     const TPoint oldSize( iButtonContentLayout->Size().Target() );
       
   593 
       
   594     iButtonLayout->SetFlag( EAlfVisualFlagManualSize );
       
   595     iButtonContentLayout->SetFlag( EAlfVisualFlagManualSize );
       
   596 
       
   597     switch( iButtonModel->AutoSizeMode() )
       
   598         {
       
   599         case MFsControlButtonInterface::EFsLayout:
       
   600             {
       
   601             if ( iButtonModel->IsLayoutSize() )
       
   602                 {
       
   603                 iButtonModel->SetSize( iButtonModel->GetLayoutSize() );
       
   604                 }
       
   605             break;
       
   606             }
       
   607 
       
   608         case MFsControlButtonInterface::EFsFitToContent:
       
   609             {
       
   610             iButtonModel->SetWidth( CalculateButtonSize() );
       
   611             textWrapping = CAlfTextVisual::ELineWrapManual;
       
   612             textClipping = EFalse;
       
   613             break;
       
   614             }
       
   615 
       
   616         case MFsControlButtonInterface::EFsFitToParent:
       
   617             {
       
   618             iButtonModel->SetWidth( iParentLayout->Size().Target().iX );
       
   619             break;
       
   620             }
       
   621 
       
   622         case MFsControlButtonInterface::EFsManual:
       
   623         default:
       
   624             {
       
   625             break;
       
   626             }
       
   627         }
       
   628 
       
   629     // New size for the button background.
       
   630     iButtonLayout->SetSize( iButtonModel->Size() );
       
   631     // Same size for the content
       
   632     iButtonContentLayout->SetSize( iButtonModel->Size() );
       
   633 
       
   634     if ( iLabelFirstLine )
       
   635         {
       
   636         iLabelFirstLine->SetWrapping( textWrapping );
       
   637         iLabelFirstLine->SetClipping( textClipping );
       
   638         }
       
   639 
       
   640     if ( iLabelSecondLine )
       
   641         {
       
   642         iLabelSecondLine->SetWrapping( textWrapping );
       
   643         iLabelSecondLine->SetClipping( textClipping );
       
   644         }
       
   645 
       
   646     iButtonLayout->UpdateChildrenLayout();
       
   647 
       
   648     TRAP_IGNORE( UpdateElementsSizeL( iButtonModel->Type() ) );
       
   649 
       
   650     // update text styles if needed (at least one text line)
       
   651     const TPoint newSize( iButtonContentLayout->Size().Target() );
       
   652     if ( newSize != oldSize )
       
   653         {
       
   654         iUpdateIconsAlign = ETrue;
       
   655         if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
   656             {
       
   657             UpdateTextStyles();
       
   658             }
       
   659         UpdateBarLayout();
       
   660         }
       
   661     }
       
   662 
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // Retrieves the background layout of the button.
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 CAlfLayout* CFsControlButtonVisualiser::Layout()
       
   669     {
       
   670     FUNC_LOG;
       
   671     return iButtonLayout;
       
   672     }
       
   673 
       
   674 
       
   675 // ---------------------------------------------------------------------------
       
   676 // Retrieves the content layout of the button.
       
   677 // ---------------------------------------------------------------------------
       
   678 //
       
   679 CAlfLayout* CFsControlButtonVisualiser::ContentLayout()
       
   680     {
       
   681     FUNC_LOG;
       
   682     return iButtonContentLayout;
       
   683     }
       
   684 
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // Enables (makes visible) button.
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 EXPORT_C void CFsControlButtonVisualiser::ShowL()
       
   691     {
       
   692     FUNC_LOG;
       
   693     UpdateButtonSize();
       
   694     UpdateButtonPos();
       
   695 
       
   696     if ( KErrNotFound == iParentLayout->FindVisual( iButtonLayout ) )
       
   697         {
       
   698         User::LeaveIfError( iParentLayout->Append( iButtonLayout ) );
       
   699         }
       
   700     if ( KErrNotFound == iParentLayout->FindVisual( iButtonContentLayout ) )
       
   701         {
       
   702         TInt error( iParentLayout->Append( iButtonContentLayout ) );
       
   703         if ( error )
       
   704             {
       
   705             if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) )
       
   706                 {
       
   707                 iParentLayout->Remove( iButtonLayout );
       
   708                 }
       
   709             User::Leave( error );
       
   710             }
       
   711         }
       
   712     iVisible = ETrue;
       
   713     }
       
   714 
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // Disables (hides) button.
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 EXPORT_C void CFsControlButtonVisualiser::Hide()
       
   721     {
       
   722     FUNC_LOG;
       
   723     if ( !iVisible && iButtonModel->IsFocused() )
       
   724         {
       
   725         FsGenericPanic( EFsControlButtonCannotDisableFocusedControl );
       
   726         }
       
   727 
       
   728     TBool refresh( EFalse );
       
   729 
       
   730     if ( KErrNotFound != iParentLayout->FindVisual( iButtonLayout ) )
       
   731         {
       
   732         iParentLayout->Remove( iButtonLayout );
       
   733         refresh = ETrue;
       
   734         }
       
   735 
       
   736     if ( KErrNotFound != iParentLayout->FindVisual( iButtonContentLayout ) )
       
   737         {
       
   738         iParentLayout->Remove( iButtonContentLayout );
       
   739         refresh = ETrue;
       
   740         }
       
   741 
       
   742     iVisible = EFalse;
       
   743     if ( refresh )
       
   744         {
       
   745         UpdateBarLayout();
       
   746         }
       
   747     }
       
   748 
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // Checks if button is visible or hidden.
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 TBool CFsControlButtonVisualiser::IsVisible() const
       
   755     {
       
   756     FUNC_LOG;
       
   757     return iVisible;
       
   758     }
       
   759 
       
   760 
       
   761 // ---------------------------------------------------------------------------
       
   762 // Changes color of text when button focused.
       
   763 // ---------------------------------------------------------------------------
       
   764 //
       
   765 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawFocused()
       
   766     {
       
   767     FUNC_LOG;
       
   768     if ( iLabelFirstLine )
       
   769         {
       
   770         TCharFormat charFormat;
       
   771         TInt styleId( KFsDefaultFontStyle );
       
   772 
       
   773         if ( iTextStyleManager )
       
   774             {
       
   775             ResolveCharFormat( charFormat, iLabelFirstLine );
       
   776             charFormat.iFontPresentation.iUnderline = EUnderlineOff;
       
   777             // Use modified style if possible, otherwise use the default
       
   778             // style.
       
   779             TRAPD( leaveErr,
       
   780                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   781             if ( KErrNone == leaveErr )
       
   782                 {
       
   783                 iLabelFirstLine->SetTextStyle( styleId );
       
   784                 }
       
   785             }
       
   786         iLabelFirstLine->SetColor( iButtonModel->TextColor(
       
   787             CFsControlButtonModel::EButtonFocused ) );
       
   788         }
       
   789 
       
   790     if ( iLabelSecondLine )
       
   791         {
       
   792         TCharFormat charFormat;
       
   793         TInt styleId( KFsDefaultFontStyle );
       
   794 
       
   795         if ( iTextStyleManager )
       
   796             {
       
   797             ResolveCharFormat( charFormat, iLabelSecondLine );
       
   798             charFormat.iFontPresentation.iUnderline = EUnderlineOff;
       
   799             TRAPD( leaveErr,
       
   800                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   801             // Use modified style if possible, otherwise use the default
       
   802             // style.
       
   803             if ( KErrNone == leaveErr )
       
   804                 {
       
   805                 iLabelSecondLine->SetTextStyle( styleId );
       
   806                 }
       
   807             }
       
   808         iLabelSecondLine->SetColor( iButtonModel->TextColor(
       
   809             CFsControlButtonModel::EButtonFocused ) );
       
   810         }
       
   811     }
       
   812 
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // Changes color of text when button's state is normal.
       
   816 // ---------------------------------------------------------------------------
       
   817 //
       
   818 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawNormal()
       
   819     {
       
   820     FUNC_LOG;
       
   821     TCharFormat charFormat;
       
   822 
       
   823     if ( iLabelFirstLine )
       
   824         {
       
   825         TCharFormat charFormat;
       
   826         TInt styleId( KFsDefaultFontStyle );
       
   827 
       
   828         if ( iTextStyleManager )
       
   829             {
       
   830             ResolveCharFormat( charFormat, iLabelFirstLine );
       
   831             charFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
   832             TRAPD( leaveErr,
       
   833                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   834             // Use modified style if possible, otherwise use the default
       
   835             // style.
       
   836             if ( KErrNone == leaveErr )
       
   837                 {
       
   838                 iLabelFirstLine->SetTextStyle( styleId );
       
   839                 }
       
   840             }
       
   841         iLabelFirstLine->SetColor( iButtonModel->TextColor(
       
   842             CFsControlButtonModel::EButtonNormal ) );
       
   843         }
       
   844 
       
   845     if ( iLabelSecondLine )
       
   846         {
       
   847         TCharFormat charFormat;
       
   848         TInt styleId( KFsDefaultFontStyle );
       
   849 
       
   850         if ( iTextStyleManager )
       
   851             {
       
   852             ResolveCharFormat( charFormat, iLabelSecondLine );
       
   853             charFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
   854             TRAPD( leaveErr,
       
   855                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   856             // Use modified style if possible, otherwise use the default
       
   857             // style.
       
   858             if ( KErrNone == leaveErr )
       
   859                 {
       
   860                 iLabelSecondLine->SetTextStyle( styleId );
       
   861                 }
       
   862             }
       
   863         iLabelSecondLine->SetColor( iButtonModel->TextColor(
       
   864             CFsControlButtonModel::EButtonNormal ) );
       
   865         }
       
   866 
       
   867     if ( iIconA )
       
   868         {
       
   869         iIconA->SetColorMode( CAlfImageVisual::EColorModulate );
       
   870         }
       
   871 
       
   872     if ( iIconB )
       
   873         {
       
   874         iIconB->SetColorMode( CAlfImageVisual::EColorModulate );
       
   875         }
       
   876     }
       
   877 
       
   878 
       
   879 // ---------------------------------------------------------------------------
       
   880 // Changes color of text when button's state is dimmed.
       
   881 // ---------------------------------------------------------------------------
       
   882 //
       
   883 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawDimmed()
       
   884     {
       
   885     FUNC_LOG;
       
   886     TCharFormat charFormat;
       
   887 
       
   888     if ( iLabelFirstLine )
       
   889         {
       
   890         TCharFormat charFormat;
       
   891         TInt styleId( KFsDefaultFontStyle );
       
   892 
       
   893         if ( iTextStyleManager )
       
   894             {
       
   895             ResolveCharFormat( charFormat, iLabelFirstLine );
       
   896             charFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
   897             TRAPD( leaveErr,
       
   898                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   899             // Use modified style if possible, otherwise use the default
       
   900             // style.
       
   901             if ( KErrNone == leaveErr )
       
   902                 {
       
   903                 iLabelFirstLine->SetTextStyle( styleId );
       
   904                 }
       
   905             }
       
   906         iLabelFirstLine->SetColor( iButtonModel->TextColor(
       
   907             CFsControlButtonModel::EButtonDimmed ) );
       
   908         }
       
   909 
       
   910     if ( iLabelSecondLine )
       
   911         {
       
   912         TCharFormat charFormat;
       
   913         TInt styleId( KFsDefaultFontStyle );
       
   914 
       
   915         if ( iTextStyleManager )
       
   916             {
       
   917             ResolveCharFormat( charFormat, iLabelSecondLine );
       
   918             charFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
   919             TRAPD( leaveErr,
       
   920                 styleId = iTextStyleManager->GetStyleIDL( charFormat ) );
       
   921             // Use modified style if possible, otherwise use the default
       
   922             // style.
       
   923             if ( KErrNone == leaveErr )
       
   924                 {
       
   925                 iLabelSecondLine->SetTextStyle( styleId );
       
   926                 }
       
   927             }
       
   928         iLabelSecondLine->SetColor( iButtonModel->TextColor(
       
   929             CFsControlButtonModel::EButtonDimmed ) );
       
   930         }
       
   931 
       
   932     if ( iIconA )
       
   933         {
       
   934         iIconA->SetColorMode( CAlfImageVisual::EColorDimmed );
       
   935         }
       
   936 
       
   937     if ( iIconB )
       
   938         {
       
   939         iIconB->SetColorMode( CAlfImageVisual::EColorDimmed );
       
   940         }
       
   941     }
       
   942 
       
   943 
       
   944 // ---------------------------------------------------------------------------
       
   945 // Creates needed number of rows for layout for specified button type.
       
   946 // ---------------------------------------------------------------------------
       
   947 //
       
   948 EXPORT_C void CFsControlButtonVisualiser::CreateButtonVisualsL()
       
   949     {
       
   950     FUNC_LOG;
       
   951     // create icon A visuals
       
   952     if ( iButtonModel->ContainsElement( ECBElemIconA ) )
       
   953         {
       
   954         iIconAContainer =
       
   955             CAlfLayout::AddNewL( *iParent, iButtonContentLayout );
       
   956         iIconA = CAlfImageVisual::AddNewL( *iParent, iIconAContainer );
       
   957         // <cmail> Platform layout change
       
   958         //iIconA->SetScaleMode( CAlfImageVisual::EScaleNormal );
       
   959         iIconA->SetScaleMode( CAlfImageVisual::EScaleFit );
       
   960         // </cmail> Platform layout change
       
   961         iIconAContainer->SetClipping( ETrue );
       
   962         }
       
   963 
       
   964     // create visual for first line of text
       
   965     if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
   966         {
       
   967         iLabelFirstLine =
       
   968             CAlfTextVisual::AddNewL( *iParent, iButtonContentLayout );
       
   969         iLabelFirstLine->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter );
       
   970         iLabelFirstLine->SetPadding(
       
   971             TPoint( iButtonModel->LabelHPadding( iButtonModel->Type() ),
       
   972                 iButtonModel->LabelVPadding( iButtonModel->Type() ) ) );
       
   973         }
       
   974 
       
   975     // create visual for second line of text
       
   976     if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) )
       
   977         {
       
   978         iLabelSecondLine =
       
   979             CAlfTextVisual::AddNewL( *iParent, iButtonContentLayout );
       
   980         iLabelSecondLine->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter );
       
   981         iLabelSecondLine->SetPadding(
       
   982             TPoint( iButtonModel->LabelHPadding( iButtonModel->Type() ),
       
   983                 iButtonModel->LabelVPadding( iButtonModel->Type() ) ) );
       
   984         }
       
   985 
       
   986     // create icon B visuals
       
   987     if ( iButtonModel->ContainsElement( ECBElemIconB ) )
       
   988         {
       
   989         iIconBContainer =
       
   990             CAlfLayout::AddNewL( *iParent, iButtonContentLayout );
       
   991         iIconB = CAlfImageVisual::AddNewL( *iParent, iIconBContainer );
       
   992         iIconB->SetScaleMode( CAlfImageVisual::EScaleNormal );
       
   993         iIconBContainer->SetClipping( ETrue );
       
   994         }
       
   995 
       
   996     // update text styles if needed (at least one text line)
       
   997     if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
   998         {
       
   999         UpdateTextStyles();
       
  1000         }
       
  1001     }
       
  1002 
       
  1003 
       
  1004 // ---------------------------------------------------------------------------
       
  1005 // Calculates button size according to content.
       
  1006 // ---------------------------------------------------------------------------
       
  1007 //
       
  1008 EXPORT_C TInt CFsControlButtonVisualiser::CalculateButtonSize()
       
  1009     {
       
  1010     FUNC_LOG;
       
  1011     if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
  1012         {
       
  1013         // to get correct value from ExpandRectWithContent method
       
  1014         iLabelFirstLine->SetClipping( EFalse );
       
  1015 
       
  1016         iLabelFirstLine->SetWrapping( CAlfTextVisual::ELineWrapManual );
       
  1017 
       
  1018         // Update the text visual to get correct rect size.
       
  1019         TSize size( iLabelFirstLine->TextExtents() );
       
  1020         TAlfRealRect padding( iLabelFirstLine->PaddingInPixels() );
       
  1021         TRect textRect( 0, 0,
       
  1022             padding.iTl.iX + padding.iBr.iX + size.iWidth,
       
  1023             padding.iTl.iY + padding.iBr.iY + size.iHeight );
       
  1024 
       
  1025         if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) )
       
  1026             {
       
  1027             // to get correct value from ExpandRectWithContent method
       
  1028             iLabelSecondLine->SetClipping( EFalse );
       
  1029 
       
  1030             iLabelSecondLine->SetWrapping( CAlfTextVisual::ELineWrapManual );
       
  1031 
       
  1032             // Update the text visual to get correct rect size.
       
  1033             TSize size2( iLabelFirstLine->TextExtents() );
       
  1034             TAlfRealRect padding( iLabelSecondLine->PaddingInPixels() );
       
  1035 
       
  1036             TRect secondLineRect( 0, 0,
       
  1037                 padding.iTl.iX + padding.iBr.iX + size2.iWidth,
       
  1038                 padding.iTl.iY + padding.iBr.iY + size2.iHeight );
       
  1039 
       
  1040             if ( secondLineRect.Width() > textRect.Width() )
       
  1041                 {
       
  1042                 //text size
       
  1043                 textRect = secondLineRect;
       
  1044                 }
       
  1045             }
       
  1046 
       
  1047         // Calculate the difference compared to layout defined object.
       
  1048         TBool supportedType( ETrue );
       
  1049         TRect parentRect = CFsControlBar::GetLayoutRect( 2 );
       
  1050         CFsLayoutManager::TFsText text;
       
  1051         switch ( iButtonModel->Type() )
       
  1052             {
       
  1053             case ECBTypeOneLineLabelIconB:
       
  1054                 CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1055                     CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 1 );
       
  1056                 break;
       
  1057             case ECBTypeOneLineLabelOnly:
       
  1058                 CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1059                     CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 0 );
       
  1060                 break;
       
  1061             case ECBTypeOneLineLabelIconA:
       
  1062                 CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1063                     CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 2 );
       
  1064                 break;
       
  1065             case ECBTypeOneLineLabelTwoIcons:
       
  1066                 CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1067                     CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 3 );
       
  1068                 break;
       
  1069             //case ECBTypeIconOnly: // no text item
       
  1070             case ECBTypeTwoLinesLabelOnly:
       
  1071             case ECBTypeTwoLinesLabelIconA:
       
  1072             case ECBTypeTwoLinesLabelIconB:
       
  1073             case ECBTypeTwoLinesLabelTwoIcons:
       
  1074             default:
       
  1075                 supportedType = EFalse;
       
  1076                 break;
       
  1077             }
       
  1078 
       
  1079         if ( supportedType )
       
  1080             {
       
  1081             const TInt newWidth(
       
  1082                 parentRect.Width() + textRect.Width() - text.iTextRect.Width()
       
  1083                 );
       
  1084             iParentLayout->SetFlags( EAlfVisualFlagLayoutUpdateNotification );
       
  1085             return newWidth;
       
  1086             }
       
  1087         }
       
  1088 
       
  1089     if ( iButtonModel->ContainsElement( ECBElemIconA ) )
       
  1090         {
       
  1091         return iIconAContainer->Size().Target().iX;
       
  1092         }
       
  1093 
       
  1094     if ( iButtonModel->ContainsElement( ECBElemIconB ) )
       
  1095         {
       
  1096         return iIconBContainer->Size().Target().iX;
       
  1097         }
       
  1098 
       
  1099     return iButtonContentLayout->Size().Target().iX;;
       
  1100     }
       
  1101 
       
  1102 
       
  1103 // ---------------------------------------------------------------------------
       
  1104 // Updates position of button.
       
  1105 // ---------------------------------------------------------------------------
       
  1106 //
       
  1107 void CFsControlButtonVisualiser::UpdateButtonPos()
       
  1108     {
       
  1109     FUNC_LOG;
       
  1110     iButtonLayout->SetFlag( EAlfVisualFlagManualPosition );
       
  1111     iButtonContentLayout->SetFlag( EAlfVisualFlagManualPosition );
       
  1112 
       
  1113     // Set position for button background and for the content.
       
  1114     iButtonLayout->SetPos( iButtonModel->TopLeftPoint() );
       
  1115     iButtonContentLayout->SetPos( iButtonModel->TopLeftPoint() );
       
  1116     }
       
  1117 
       
  1118 
       
  1119 // ---------------------------------------------------------------------------
       
  1120 // Updates size of columns in grid layouter for button's elements.
       
  1121 // ---------------------------------------------------------------------------
       
  1122 //
       
  1123 EXPORT_C void CFsControlButtonVisualiser::UpdateElementsSizeL(
       
  1124     TFsControlButtonType aButtonType )
       
  1125     {
       
  1126     FUNC_LOG;
       
  1127     TRect parentRect( TPoint( 0, 0 ), iButtonModel->Size() );
       
  1128     TRect layoutRect( 0, 0, 0, 0 );
       
  1129     TRect iconA;
       
  1130     TRect iconB;
       
  1131     TRect text1;
       
  1132     TRect text2;
       
  1133     CFsLayoutManager::TFsText text;
       
  1134     switch ( aButtonType )
       
  1135         {
       
  1136         case ECBTypeIconOnly:
       
  1137             iconA = iButtonModel->GetLayoutSize( parentRect );
       
  1138             // Need to move the rect as icon doesn't have a separate button
       
  1139             // parent. It's position is related to controlbar's rect.
       
  1140             iconA.Move( -iconA.iTl.iX, -iconA.iTl.iY );
       
  1141             break;
       
  1142         case ECBTypeOneLineLabelOnly:
       
  1143             CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1144                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 0 );
       
  1145             text1 = text.iTextRect;
       
  1146             break;
       
  1147         case ECBTypeOneLineLabelIconA:
       
  1148             CFsLayoutManager::LayoutMetricsRect( parentRect,
       
  1149                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG2,
       
  1150                 iconA, 0 );
       
  1151             CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1152                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 2 );
       
  1153             text1 = text.iTextRect;
       
  1154             break;
       
  1155         case ECBTypeOneLineLabelIconB:
       
  1156             CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1157                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 1 );
       
  1158             text1 = text.iTextRect;
       
  1159             CFsLayoutManager::LayoutMetricsRect( parentRect,
       
  1160                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG1,
       
  1161                 iconB, 0 );
       
  1162             break;
       
  1163         case ECBTypeOneLineLabelTwoIcons:
       
  1164             CFsLayoutManager::LayoutMetricsRect( parentRect,
       
  1165                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG2,
       
  1166                 iconA, 1 );
       
  1167             CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1168                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 3 );
       
  1169             text1 = text.iTextRect;
       
  1170             CFsLayoutManager::LayoutMetricsRect( parentRect,
       
  1171                 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG1,
       
  1172                 iconB, 1 );
       
  1173             break;
       
  1174 
       
  1175         //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps
       
  1176 
       
  1177         /*
       
  1178         REMOVED, Not needed anymore.
       
  1179 
       
  1180         case ECBTypeTwoLinesLabelOnly:
       
  1181             text1 = TRect(0,0,60,20);
       
  1182             text2 = TRect(0,0,60,20);
       
  1183             break;
       
  1184         case ECBTypeTwoLinesLabelIconA:
       
  1185             iconA = TRect(0,0,16,16);
       
  1186             text1 = TRect(0,0,60,20);
       
  1187             text2 = TRect(0,0,60,20);
       
  1188             break;
       
  1189         case ECBTypeTwoLinesLabelIconB:
       
  1190             text1 = TRect(0,0,60,20);
       
  1191             text2 = TRect(0,0,60,20);
       
  1192             iconB = TRect(0,0,16,16);
       
  1193             break;
       
  1194         case ECBTypeTwoLinesLabelTwoIcons:
       
  1195             iconA = TRect(0,0,16,16);
       
  1196             text1 = TRect(0,0,60,20);
       
  1197             text2 = TRect(0,0,60,20);
       
  1198             iconB = TRect(0,0,16,16);
       
  1199             break;
       
  1200         */
       
  1201         //<CMAIL>
       
  1202 
       
  1203         default:
       
  1204             break;
       
  1205         }
       
  1206 
       
  1207     // <cmail> Platform layout changes
       
  1208     if ( iButtonModel->ContainsElement( ECBElemIconA ) )
       
  1209         {
       
  1210         const TSize& size( iconA.Size() );
       
  1211         iIconAContainer->SetSize( size );
       
  1212         iIconAContainer->SetPos( iconA.iTl );
       
  1213         iIconA->SetSize( TAlfRealSize( size ) );
       
  1214         }
       
  1215     if ( iButtonModel->ContainsElement( ECBElemIconB ) )
       
  1216         {
       
  1217         const TSize& size( iconB.Size() );
       
  1218         iIconBContainer->SetSize( iconB.Size() );
       
  1219         iIconBContainer->SetPos( iconB.iTl );
       
  1220         iIconB->SetSize( TAlfRealSize( size ) );
       
  1221         }
       
  1222     if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
  1223         {
       
  1224         iLabelFirstLine->SetSize( text1.Size() );
       
  1225         iLabelFirstLine->SetPos( text1.iTl );
       
  1226         }
       
  1227     if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) )
       
  1228         {
       
  1229         iLabelSecondLine->SetSize( text2.Size() );
       
  1230         iLabelSecondLine->SetPos( text2.iTl );
       
  1231         }
       
  1232     // </cmail> Platform layout changes
       
  1233     }
       
  1234 
       
  1235 
       
  1236 // ---------------------------------------------------------------------------
       
  1237 // Sets text styles for specified button type.
       
  1238 // ---------------------------------------------------------------------------
       
  1239 //
       
  1240 EXPORT_C void CFsControlButtonVisualiser::UpdateTextStyles()
       
  1241     {
       
  1242     FUNC_LOG;
       
  1243     TInt style( KFsDefaultFontStyle );
       
  1244     TBool sizeChanged( EFalse );
       
  1245 
       
  1246     TCharFormat charFormat;
       
  1247     ResolveCharFormat( charFormat, iLabelFirstLine );
       
  1248 
       
  1249     if ( !iTextHeightSet )
       
  1250         {
       
  1251         TRect parentRect(
       
  1252             TPoint( 0, 0 ), iButtonContentLayout->Size().Target() );
       
  1253         CFsLayoutManager::TFsText text;
       
  1254         CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1255             CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, 1 );
       
  1256 
       
  1257         charFormat.iFontSpec = text.iFont->FontSpecInTwips();
       
  1258         }
       
  1259     else
       
  1260         {
       
  1261         CWsScreenDevice* screenDev( CCoeEnv::Static()->ScreenDevice() );
       
  1262 
       
  1263         // Modify the height of the font.
       
  1264         TInt twips( screenDev->VerticalPixelsToTwips( iTextHeight ) );
       
  1265         if ( 0 < iTextHeight && twips != charFormat.iFontSpec.iHeight )
       
  1266             {
       
  1267             charFormat.iFontSpec.iHeight = twips;
       
  1268             sizeChanged = ETrue;
       
  1269             }
       
  1270         }
       
  1271 
       
  1272     if ( iTextStyleManager )
       
  1273         {
       
  1274         // Use default style in case of a leave.
       
  1275         TRAP_IGNORE( style = iTextStyleManager->GetStyleIDL( charFormat ) );
       
  1276         }
       
  1277 
       
  1278     if ( iLabelFirstLine )
       
  1279         {
       
  1280         iLabelFirstLine->SetTextStyle( style );
       
  1281         }
       
  1282 
       
  1283     if ( iLabelSecondLine )
       
  1284         {
       
  1285         iLabelSecondLine->SetTextStyle( style );
       
  1286         }
       
  1287 
       
  1288     if ( sizeChanged )
       
  1289         {
       
  1290         UpdateButtonSize();
       
  1291         }
       
  1292     }
       
  1293 
       
  1294 
       
  1295 // ---------------------------------------------------------------------------
       
  1296 // Sets alignement of specified image of the button.
       
  1297 // ---------------------------------------------------------------------------
       
  1298 //
       
  1299 EXPORT_C void CFsControlButtonVisualiser::SetImageAlign(
       
  1300     CAlfImageVisual* aImage,
       
  1301     TAlfAlignHorizontal aHAlign,
       
  1302     TAlfAlignVertical aVAlign )
       
  1303     {
       
  1304     FUNC_LOG;
       
  1305     TInt iconWidth( aImage->Size().Target().iX );
       
  1306     TInt iconHeight( aImage->Size().Target().iY );
       
  1307 
       
  1308     TAlfTimedPoint startPoint( 0, 0 );
       
  1309     TInt layoutWidth;
       
  1310     TInt layoutHeight;
       
  1311 
       
  1312     if ( aImage == iIconB )
       
  1313         {
       
  1314         layoutWidth = iIconBContainer->Size().Target().iX;
       
  1315         layoutHeight = iIconBContainer->Size().Target().iY;
       
  1316         }
       
  1317     else if ( aImage == iIconA )
       
  1318         {
       
  1319         layoutWidth = iIconAContainer->Size().Target().iX;
       
  1320         layoutHeight = iIconAContainer->Size().Target().iY;
       
  1321         }
       
  1322     else
       
  1323         {
       
  1324         return;
       
  1325         }
       
  1326 
       
  1327     switch ( aHAlign )
       
  1328         {
       
  1329         case EAlfAlignHLeft:
       
  1330             {
       
  1331             startPoint.iX = 0;
       
  1332             break;
       
  1333             }
       
  1334 
       
  1335         case EAlfAlignHCenter:
       
  1336             {
       
  1337             startPoint.iX = layoutWidth / 2 - iconWidth / 2;
       
  1338             break;
       
  1339             }
       
  1340 
       
  1341         case EAlfAlignHRight:
       
  1342             {
       
  1343             startPoint.iX = layoutWidth - iconWidth;
       
  1344             break;
       
  1345             }
       
  1346 
       
  1347         default:
       
  1348             {
       
  1349             FsGenericPanic( EFsControlButtonEnumValueNotSupported );
       
  1350             break;
       
  1351             }
       
  1352         }
       
  1353 
       
  1354     switch ( aVAlign )
       
  1355         {
       
  1356         case EAlfAlignVTop:
       
  1357             {
       
  1358             startPoint.iY = 0;
       
  1359             break;
       
  1360             }
       
  1361 
       
  1362         case EAlfAlignVCenter:
       
  1363             {
       
  1364             startPoint.iY = layoutHeight / 2 - iconHeight / 2;
       
  1365             break;
       
  1366             }
       
  1367 
       
  1368         case EAlfAlignVBottom:
       
  1369             {
       
  1370             startPoint.iY = layoutHeight - iconHeight;
       
  1371             break;
       
  1372             }
       
  1373 
       
  1374         default:
       
  1375             {
       
  1376             FsGenericPanic( EFsControlButtonEnumValueNotSupported );
       
  1377             break;
       
  1378             }
       
  1379         }
       
  1380 
       
  1381     aImage->SetPos( startPoint );
       
  1382     }
       
  1383 
       
  1384 
       
  1385 // ---------------------------------------------------------------------------
       
  1386 // Sets alignment of specified text of the button.
       
  1387 // ---------------------------------------------------------------------------
       
  1388 //
       
  1389 EXPORT_C void CFsControlButtonVisualiser::SetTextAlign(
       
  1390     CAlfTextVisual* aText,
       
  1391     TAlfAlignHorizontal aHAlign,
       
  1392     TAlfAlignVertical aVAlign )
       
  1393     {
       
  1394     FUNC_LOG;
       
  1395     aText->SetAlign( aHAlign, aVAlign );
       
  1396     }
       
  1397 
       
  1398 
       
  1399 // ---------------------------------------------------------------------------
       
  1400 // Set new height for the button text.
       
  1401 // ---------------------------------------------------------------------------
       
  1402 //
       
  1403 EXPORT_C void CFsControlButtonVisualiser::SetTextHeight(
       
  1404     const TInt aTextHeight )
       
  1405     {
       
  1406     FUNC_LOG;
       
  1407     iTextHeight = aTextHeight;
       
  1408     // Use default text height if the value is zero or negative.
       
  1409     iTextHeightSet = ( 0 < iTextHeight );
       
  1410 
       
  1411     // Update text styles if needed (at least one text line)
       
  1412     if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
  1413         {
       
  1414         UpdateTextStyles();
       
  1415         UpdateButtonSize();
       
  1416         }
       
  1417     }
       
  1418 
       
  1419 
       
  1420 // ---------------------------------------------------------------------------
       
  1421 // Change the current font.
       
  1422 // ---------------------------------------------------------------------------
       
  1423 //
       
  1424 EXPORT_C void CFsControlButtonVisualiser::SetTextFontL(
       
  1425     const TFontSpec& aFontSpec )
       
  1426     {
       
  1427     FUNC_LOG;
       
  1428     if ( !iButtonModel->ContainsElement( ECBElemLabelFirstLine ) )
       
  1429         {
       
  1430         User::Leave( KErrNotSupported );
       
  1431         }
       
  1432 
       
  1433     if ( !iTextFontSpec )
       
  1434         {
       
  1435         iTextFontSpec = new( ELeave )TFontSpec();
       
  1436         }
       
  1437 
       
  1438     *iTextFontSpec = aFontSpec;
       
  1439 
       
  1440     // Update text styles.
       
  1441     Refresh();
       
  1442     }
       
  1443 
       
  1444 
       
  1445 // ---------------------------------------------------------------------------
       
  1446 // Sets parent layout.
       
  1447 // ---------------------------------------------------------------------------
       
  1448 //
       
  1449 void CFsControlButtonVisualiser::SetParentLayoutL(
       
  1450     CAlfDeckLayout* aParentLayout )
       
  1451     {
       
  1452     FUNC_LOG;
       
  1453     iParentLayout = aParentLayout;
       
  1454 
       
  1455     if ( iButtonLayout
       
  1456         && KErrNotFound == iParentLayout->FindVisual( iButtonLayout ) )
       
  1457         {
       
  1458         User::LeaveIfError( iParentLayout->Append( iButtonLayout ) );
       
  1459         }
       
  1460     if ( iButtonContentLayout
       
  1461         && KErrNotFound == iParentLayout->FindVisual( iButtonContentLayout ) )
       
  1462         {
       
  1463         User::LeaveIfError( iParentLayout->Append( iButtonContentLayout ) );
       
  1464         }
       
  1465     }
       
  1466 
       
  1467 
       
  1468 // ---------------------------------------------------------------------------
       
  1469 // Sets parent control.
       
  1470 // ---------------------------------------------------------------------------
       
  1471 //
       
  1472 void CFsControlButtonVisualiser::SetParentControlL(
       
  1473     CAlfControl* aParentControl )
       
  1474     {
       
  1475     FUNC_LOG;
       
  1476     // There could be an existing observer available on previously used
       
  1477     // visualiser.
       
  1478     if ( iParent )
       
  1479         {
       
  1480         iParent->Env().TextureManager().RemoveLoadObserver( this );
       
  1481         }
       
  1482 
       
  1483     iParent = aParentControl;
       
  1484     ConstructL();
       
  1485     }
       
  1486 
       
  1487 
       
  1488 // ---------------------------------------------------------------------------
       
  1489 // Set text style manager object.
       
  1490 // ---------------------------------------------------------------------------
       
  1491 //
       
  1492 void CFsControlButtonVisualiser::SetTextStyleManager(
       
  1493     CFsTextStyleManager* aTextStyleManager )
       
  1494     {
       
  1495     FUNC_LOG;
       
  1496     iTextStyleManager = aTextStyleManager;
       
  1497     }
       
  1498 
       
  1499 
       
  1500 // ---------------------------------------------------------------------------
       
  1501 // Updates bar layout.
       
  1502 // ---------------------------------------------------------------------------
       
  1503 //
       
  1504 void CFsControlButtonVisualiser::UpdateBarLayout()
       
  1505     {
       
  1506     FUNC_LOG;
       
  1507     if ( iParentLayout )
       
  1508         {
       
  1509         // This flag is cleared when the layout is updated.
       
  1510         iParentLayout->SetFlags( EAlfVisualFlagLayoutUpdateNotification );
       
  1511         iParentLayout->UpdateChildrenLayout();
       
  1512         }
       
  1513     }
       
  1514 
       
  1515 
       
  1516 // ---------------------------------------------------------------------------
       
  1517 // Resolve the character format from current text visual.
       
  1518 // ---------------------------------------------------------------------------
       
  1519 //
       
  1520 void CFsControlButtonVisualiser::ResolveCharFormat(
       
  1521     TCharFormat& aCharFormat,
       
  1522     CAlfTextVisual* aTextVisual )
       
  1523     {
       
  1524     FUNC_LOG;
       
  1525     // Get the current text style by text style id.
       
  1526     CAlfTextStyle* textStyle(
       
  1527         aTextVisual->Env().TextStyleManager().TextStyle(
       
  1528             aTextVisual->Style() ) );
       
  1529 
       
  1530     // Copy the used format.
       
  1531 
       
  1532     if ( iTextFontSpec )
       
  1533         {
       
  1534         aCharFormat.iFontSpec = *iTextFontSpec;
       
  1535         }
       
  1536     else
       
  1537         {
       
  1538         TRect parentRect(
       
  1539             TPoint( 0, 0 ), iButtonContentLayout->Size().Target() );
       
  1540         CFsLayoutManager::TFsText text;
       
  1541 
       
  1542         // Specify button's type to get related font.
       
  1543         TInt variety( 0 );
       
  1544         switch ( iButtonModel->Type() )
       
  1545             {
       
  1546             case ECBTypeOneLineLabelOnly:
       
  1547                 variety = 0;
       
  1548                 break;
       
  1549             case ECBTypeOneLineLabelIconB:
       
  1550                 variety = 1;
       
  1551                 break;
       
  1552             case ECBTypeOneLineLabelIconA:
       
  1553                 variety = 2;
       
  1554                 break;
       
  1555             case ECBTypeOneLineLabelTwoIcons:
       
  1556                 variety = 3;
       
  1557                 break;
       
  1558             default:
       
  1559                 break;
       
  1560             }
       
  1561         CFsLayoutManager::LayoutMetricsText( parentRect,
       
  1562             CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneT1, text, variety );
       
  1563 
       
  1564         aCharFormat.iFontSpec = text.iFont->FontSpecInTwips();
       
  1565         //alf migration - Might need iFontStyle to be set.
       
  1566         }
       
  1567     aCharFormat.iFontPresentation.iStrikethrough =
       
  1568         textStyle->IsStrikeThrough() ? EStrikethroughOn : EStrikethroughOff;
       
  1569     aCharFormat.iFontPresentation.iUnderline =
       
  1570         textStyle->IsUnderline() ? EUnderlineOn : EUnderlineOff;
       
  1571     }