emailuis/uicomponents/src/fscontrolbarvisualiser.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 Bar component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail> SF
       
    20 #include "emailtrace.h"
       
    21 #include <alf/alfdecklayout.h>
       
    22 #include <alf/alfgradientbrush.h>
       
    23 #include <alf/alfimagevisual.h>
       
    24 #include <alf/alfborderbrush.h>
       
    25 #include <alf/alfframebrush.h>
       
    26 #include <alf/alfimagebrush.h>
       
    27 #include <alf/alfbrusharray.h>
       
    28 //</cmail>
       
    29 #include <AknUtils.h>
       
    30 
       
    31 #include "fslayoutmanager.h"
       
    32 #include "fscontrolbarvisualiser.h"
       
    33 #include "fscontrolbar.h"
       
    34 #include "fscontrolbarmodel.h"
       
    35 #include "fscontrolbutton.h"
       
    36 #include "fscontrolbuttonvisualiser.h"
       
    37 #include "fscontrolbuttonmodel.h"
       
    38 #include "fsgenericpanic.h"
       
    39 
       
    40 #define DEFAULT_SELECTOR KAknsIIDQsnFrList
       
    41 
       
    42 const TReal KFsSelectorOpacity = 1;
       
    43 const TInt KFsSelectorPaddingTop = 0;
       
    44 const TInt KFsSelectorPaddingBottom = 0;
       
    45 const TInt KFsSelectorPaddingLeft = 0;
       
    46 const TInt KFsSelectorPaddingRight = 0;
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Constructor.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CFsControlBarVisualiser::CFsControlBarVisualiser(
       
    56     CFsControlBar& aParentControl,
       
    57     CFsControlBarModel& aModel ) :
       
    58     iModel( aModel ),
       
    59     iParent( aParentControl ),
       
    60     iLastSelectedButton( -1 )
       
    61     {
       
    62     FUNC_LOG;
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Second phase constructor.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CFsControlBarVisualiser::ConstructL()
       
    71     {
       
    72     FUNC_LOG;
       
    73     // creating layout and visual controls
       
    74     iBarLayout = CAlfDeckLayout::AddNewL( iParent );
       
    75     iBarLayout->EnableBrushesL();
       
    76     iBarLayout->SetFlags( EAlfVisualFlagLayoutUpdateNotification |
       
    77             EAlfVisualFlagManualPosition |
       
    78             EAlfVisualFlagManualSize );
       
    79     iBarLayout->SetSize( iModel.Size() );
       
    80     iBarLayout->SetClipping( ETrue );
       
    81 
       
    82     // controlbar background color
       
    83     CAlfEnv& env( iParent.Env() );
       
    84     iBgColor = CAlfGradientBrush::NewL( env );
       
    85     iBgColor->SetColor( iModel.BarBgColor() );
       
    86     iBarLayout->Brushes()->AppendL( iBgColor, EAlfDoesNotHaveOwnership );
       
    87 
       
    88     // Background image
       
    89     iBgLayout = CAlfLayout::AddNewL( iParent, iBarLayout );
       
    90     iBgLayout->EnableBrushesL();
       
    91 
       
    92     TRect parentRect( TPoint( 0, 0 ), iBarLayout->Size().Target() );
       
    93     TRect layoutRect( 0, 0, 0, 0 );
       
    94 
       
    95     // Adjust the background image size and position.
       
    96     CFsLayoutManager::LayoutMetricsRect( parentRect,
       
    97         CFsLayoutManager::EFsLmBgSpFsCtrlbarPane, layoutRect,
       
    98         0 );
       
    99     iBgLayout->SetSize( layoutRect.Size() );
       
   100     iBgLayout->SetPos( layoutRect.iTl );
       
   101 
       
   102     // Use image from skin.
       
   103     iDefaultBgBrush = CAlfFrameBrush::NewL( env, KAknsIIDQsnFrStatusFlat );
       
   104     TSize size(
       
   105         iBarLayout->Size().Target().iX, iBarLayout->Size().Target().iY );
       
   106     layoutRect = size;
       
   107 
       
   108     //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps
       
   109 
       
   110     /*
       
   111     REMOVED: Not needed
       
   112 
       
   113     TRect childRect( layoutRect );
       
   114     // LAF values needed
       
   115     childRect.Shrink( 4, 4 );
       
   116     iDefaultBgBrush->SetFrameRectsL( childRect, layoutRect );
       
   117     */
       
   118     //</CMAIL>
       
   119 
       
   120     iBgLayout->Brushes()->AppendL(
       
   121         iDefaultBgBrush, EAlfDoesNotHaveOwnership );
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // Two-phased constructor.
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CFsControlBarVisualiser* CFsControlBarVisualiser::NewL(
       
   130     CFsControlBar& aParentControl,
       
   131     CFsControlBarModel& aModel )
       
   132     {
       
   133     FUNC_LOG;
       
   134     CFsControlBarVisualiser* self =
       
   135         new (ELeave) CFsControlBarVisualiser( aParentControl, aModel );
       
   136     CleanupStack::PushL( self );
       
   137     self->ConstructL();
       
   138     CleanupStack::Pop( self );
       
   139     return self;
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Destructor.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 CFsControlBarVisualiser::~CFsControlBarVisualiser()
       
   148     {
       
   149     FUNC_LOG;
       
   150     ClearBackgroundImage();
       
   151     delete iBgColor;
       
   152     delete iSelectorBrush;
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Redraws control.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CFsControlBarVisualiser::RefreshL( TBool aScreenSizeChanged )
       
   161     {
       
   162     FUNC_LOG;
       
   163     TInt focusedButton( -1 );
       
   164     CFsControlButton* button = NULL;
       
   165 
       
   166     if ( aScreenSizeChanged )
       
   167         {
       
   168         iBarLayout->SetSize( iModel.Size() );
       
   169         }
       
   170 
       
   171     for( TInt i( 0 ); iModel.Count() > i; i++ )
       
   172         {
       
   173         button = iModel.ButtonByIndex( i );
       
   174 
       
   175         // draw only visible buttons
       
   176         if ( button->IsVisible() )
       
   177             {
       
   178             if ( button->IsFocused() )
       
   179                 {
       
   180                 focusedButton = i;
       
   181                 }
       
   182 
       
   183             // size of bar changed -> update buttons
       
   184             button->Visualiser()->Refresh();
       
   185             }
       
   186         }
       
   187 
       
   188     if( -1 != focusedButton )
       
   189         {
       
   190         DrawSelectorL( focusedButton, aScreenSizeChanged );
       
   191         }
       
   192     else
       
   193         {
       
   194         HideSelector();
       
   195         }
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // Sets background color for controlbar.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CFsControlBarVisualiser::SetBackgroundColor( const TRgb& aColor )
       
   204     {
       
   205     FUNC_LOG;
       
   206     // set color
       
   207     iBgColor->SetColor( aColor );
       
   208     iBgColor->SetOpacity( 1 );
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Clears controlbar's background color. Controlbar becomes transparent.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C void CFsControlBarVisualiser::ClearBackgroundColor()
       
   217     {
       
   218     FUNC_LOG;
       
   219     iBgColor->SetOpacity( 0 );
       
   220     }
       
   221 
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Sets background image for controlbar.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CFsControlBarVisualiser::SetBackgroundImageL( CAlfTexture& aImage )
       
   228     {
       
   229     FUNC_LOG;
       
   230     if ( iDefaultBgBrush )
       
   231         {
       
   232         ClearBackgroundImage();
       
   233         }
       
   234 
       
   235     if ( !iBgImage )
       
   236         {
       
   237         CAlfEnv& env( iParent.Env() );
       
   238         iBgImage = CAlfImageBrush::NewL( env, TAlfImage( aImage ) );
       
   239         iBgLayout->Brushes()->AppendL( iBgImage, EAlfDoesNotHaveOwnership );
       
   240         }
       
   241     else
       
   242         {
       
   243         iBgImage->SetImage( TAlfImage( aImage ) );
       
   244         }
       
   245     }
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // Clears background image for controlbar.
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CFsControlBarVisualiser::ClearBackgroundImage()
       
   253     {
       
   254     FUNC_LOG;
       
   255     if ( iDefaultBgBrush )
       
   256         {
       
   257         for ( TInt i( iBarLayout->Brushes()->Count() - 1 ); 0 <= i; i-- )
       
   258             {
       
   259             if ( &iBgLayout->Brushes()->At( i ) == iDefaultBgBrush )
       
   260                 {
       
   261                 iBgLayout->Brushes()->Remove( i );
       
   262                 delete iDefaultBgBrush;
       
   263                 iDefaultBgBrush = NULL;
       
   264                 break;
       
   265                 }
       
   266             }
       
   267         }
       
   268     if ( iBgImage )
       
   269         {
       
   270         for ( TInt i( iBarLayout->Brushes()->Count() - 1 ); 0 <= i; i-- )
       
   271             {
       
   272             if ( &iBgLayout->Brushes()->At( i ) == iBgImage )
       
   273                 {
       
   274                 iBgLayout->Brushes()->Remove( i );
       
   275                 delete iBgImage;
       
   276                 iBgImage = NULL;
       
   277                 break;
       
   278                 }
       
   279             }
       
   280         }
       
   281     }
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // Update the size of the controlbar layout.
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CFsControlBarVisualiser::UpdateSizeL()
       
   289     {
       
   290     FUNC_LOG;
       
   291     iBarLayout->SetSize( iModel.Size() );
       
   292     RefreshL();
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // Retrieves controlbar's layout.
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 CAlfDeckLayout* CFsControlBarVisualiser::Layout()
       
   301     {
       
   302     FUNC_LOG;
       
   303     return iBarLayout;
       
   304     }
       
   305 
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // Sets transition time for selector.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 void CFsControlBarVisualiser::SetSelectorTransitionTimeL(
       
   312     TInt aTransitionTime )
       
   313     {
       
   314     FUNC_LOG;
       
   315     iModel.SetSelectorTransitionTime( aTransitionTime );
       
   316     RefreshL();
       
   317     }
       
   318 
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // Change the selector image.
       
   322 // Ownership of the brush is gained.
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CFsControlBarVisualiser::SetSelectorImageL(
       
   326     CAlfBrush* aSelectorBrush,
       
   327     TReal32 aOpacity )
       
   328     {
       
   329     FUNC_LOG;
       
   330     // Update the selector if it is visible.
       
   331     if ( iSelector )
       
   332         {
       
   333         if ( iSelector->Brushes()->Count() )
       
   334             {
       
   335             iSelector->Brushes()->Remove( iSelector->Brushes()->Count() - 1 );
       
   336             }
       
   337 
       
   338         iSelector->Brushes()->AppendL(
       
   339             aSelectorBrush, EAlfDoesNotHaveOwnership );
       
   340         iSelector->SetOpacity( aOpacity );
       
   341         }
       
   342 
       
   343     // Release the old selector brush.
       
   344     delete iSelectorBrush;
       
   345     iSelectorBrush = aSelectorBrush;
       
   346     iSelectorOpacity = aOpacity;
       
   347     }
       
   348 
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // Reorder the visuals. Button visual are build from two separate visual,
       
   352 // background and content. Those are arranged so that the background visual
       
   353 // are set at back and contents are to front. Selector visual is placed
       
   354 // between them.
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 void CFsControlBarVisualiser::ReorderVisuals()
       
   358     {
       
   359     FUNC_LOG;
       
   360     if ( iSelector )
       
   361         {
       
   362         TInt visualOrder( KErrNotFound );
       
   363         if ( KErrNotFound == visualOrder )
       
   364             {
       
   365             visualOrder = iBarLayout->FindVisual( iBgLayout );
       
   366             }
       
   367 
       
   368         // Reorder the buttons.
       
   369         visualOrder++;
       
   370         for ( TInt i( 0 ); iModel.Count() > i; i++ )
       
   371             {
       
   372             // Reorder visual so that the button background visuals get to
       
   373             // bottom and their contents get to the front. Selector will be
       
   374             // places between them.
       
   375             CFsControlButtonVisualiser* button( NULL );
       
   376             button = iModel.ButtonByIndex( i )->Visualiser();
       
   377             if ( button->IsVisible() )
       
   378                 {
       
   379                 iBarLayout->MoveVisualToFront( *button->ContentLayout() );
       
   380                 iBarLayout->Reorder( *button->Layout(), visualOrder );
       
   381                 visualOrder++;
       
   382                 }
       
   383             }
       
   384 
       
   385         // Move the selector after every button's background visual.
       
   386         iBarLayout->Reorder( *iSelector, visualOrder );
       
   387         }
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // Hides\shows selector rectangle over selected button.
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CFsControlBarVisualiser::MakeSelectorVisible(
       
   395         TBool aShow, TBool aFromTouch )
       
   396     {
       
   397     FUNC_LOG;
       
   398 
       
   399     TReal32 opacity( 0 );
       
   400     if( aShow )
       
   401         {
       
   402         opacity = 1;
       
   403         }
       
   404     if( iSelector )
       
   405         {
       
   406         iTouchPressed = aFromTouch;
       
   407         CFsControlButton* button = NULL;
       
   408         const TInt buttonCount( iModel.Count() );
       
   409         for( TInt buttonIndex( 0 ); buttonIndex < buttonCount; ++buttonIndex )
       
   410             {
       
   411             button = iModel.ButtonByIndex( buttonIndex );
       
   412             if( button->IsFocused() )
       
   413                 {
       
   414                 button->MakeFocusVisible( aShow );
       
   415                 break;
       
   416                 }
       
   417             }
       
   418         iSelector->SetOpacity( opacity );
       
   419         }
       
   420     iSelectorOpacity = opacity;
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // Draws selector rectangle over selected button.
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CFsControlBarVisualiser::DrawSelectorL(
       
   428     const TInt aSelectedButtonIndex,
       
   429     TBool aFastDraw )
       
   430     {
       
   431     FUNC_LOG;
       
   432     CFsControlButtonVisualiser* vis( NULL );
       
   433 
       
   434     // set selector's delay
       
   435     TInt transitionTime( aFastDraw ? 0 : iModel.SelectorTransitionTime() );
       
   436     TBool setDefaultBrushBorders( EFalse );
       
   437 
       
   438     if ( !iSelector )
       
   439         {
       
   440         // Flags used because otherwise it would generate a callback here
       
   441         // before the image visual is fully created.
       
   442         iBarLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
   443         iSelector = iParent.AppendVisualL( EAlfVisualTypeVisual, iBarLayout );
       
   444 
       
   445         ReorderVisuals();
       
   446 
       
   447         iBarLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
   448         iSelector->SetFlag( EAlfVisualFlagManualPosition );
       
   449         iSelector->SetFlag( EAlfVisualFlagManualSize );
       
   450 
       
   451         iSelector->EnableBrushesL();
       
   452 
       
   453         if ( !iSelectorBrush )
       
   454             {
       
   455             // Use the default selector brush.
       
   456             CAlfFrameBrush* brush(
       
   457                 CAlfFrameBrush::NewL( iParent.Env(), KAknsIIDQsnFrList ) );
       
   458             // Ownership of the brush is transfered.
       
   459             SetSelectorImageL( brush, KFsSelectorOpacity );
       
   460             // Brush rects are set later.
       
   461             setDefaultBrushBorders = ETrue;
       
   462             }
       
   463         else
       
   464             {
       
   465             // Use the custom selector brush.
       
   466             iSelector->Brushes()->AppendL(
       
   467                 iSelectorBrush, EAlfDoesNotHaveOwnership );
       
   468             iSelector->SetOpacity( iSelectorOpacity );
       
   469             }
       
   470 
       
   471         // When making the selector visible then do it without any delays.
       
   472         transitionTime = 0;
       
   473         }
       
   474 
       
   475     // retieve button's visualiser
       
   476     vis = iModel.ButtonByIndex( aSelectedButtonIndex )->Visualiser();
       
   477 
       
   478     // retieve button's pos and size
       
   479     TPoint point( vis->Pos().iX.Target(), vis->Pos().iY.Target() );
       
   480     TSize size( vis->Size().iX.Target(), vis->Size().iY.Target() );
       
   481     point.operator-=(
       
   482         TPoint( KFsSelectorPaddingLeft, KFsSelectorPaddingTop ) );
       
   483     size += TSize( KFsSelectorPaddingLeft + KFsSelectorPaddingRight,
       
   484         KFsSelectorPaddingTop + KFsSelectorPaddingBottom );
       
   485 
       
   486     if( iTouchPressed )
       
   487         {
       
   488         transitionTime = 0;
       
   489         iTouchPressed = EFalse;
       
   490         }
       
   491 
       
   492     iLastSelectedButton = aSelectedButtonIndex;
       
   493     // set new pos and size of selector
       
   494     iSelector->SetPos( TAlfRealPoint( point ), transitionTime );
       
   495     iSelector->SetSize( TAlfRealSize( size ), transitionTime );
       
   496 
       
   497     // Setting the selector skin to fit the selector visual size.
       
   498     if ( setDefaultBrushBorders )
       
   499         {
       
   500         CAlfBrush& brush(
       
   501             iSelector->Brushes()->At( iSelector->Brushes()->Count() - 1 ) );
       
   502 
       
   503         //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps
       
   504 
       
   505         /*
       
   506 
       
   507         CAlfFrameBrush* defaultSelectorBrush(
       
   508             static_cast<CAlfFrameBrush*>( &brush ) );
       
   509         TRect layoutRect( size );
       
   510 
       
   511 
       
   512         REMOVED: Not needed
       
   513 
       
   514         TRect childRect( layoutRect );
       
   515         // LAF values needed
       
   516         childRect.Shrink( 1, 1 );
       
   517         defaultSelectorBrush->SetFrameRectsL( childRect, layoutRect );
       
   518         */
       
   519         //</CMAIL>
       
   520 
       
   521         }
       
   522     }
       
   523 
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // Hides selector rectangle.
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CFsControlBarVisualiser::HideSelector()
       
   530     {
       
   531     FUNC_LOG;
       
   532     iLastSelectedButton = -1;
       
   533     if ( iSelector )
       
   534         {
       
   535         // Flags used because otherwise it would generate a callback here
       
   536         // before the visual is fully destroyed.
       
   537         iBarLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
   538         iSelector->RemoveAndDestroyAllD();
       
   539         iSelector = NULL;
       
   540         iBarLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
   541         iBarLayout->UpdateChildrenLayout();
       
   542         }
       
   543     }
       
   544