emailuis/uicomponents/src/fsseparatorvisualizer.cpp
changeset 0 8466d47a6819
child 29 6b8f3b30d0ec
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:  A visualizer for data items with separator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //#include <fsconfig.h>
       
    20 
       
    21 #include "emailtrace.h"
       
    22 #include "fsseparatorvisualizer.h"
       
    23 #include "fsseparatordata.h"
       
    24 #include "fstreelist.h"
       
    25 #include "fslayoutmanager.h"
       
    26 // <cmail> SF
       
    27 #include <alf/alfanchorlayout.h>
       
    28 #include <alf/alfcurvepath.h>
       
    29 #include <alf/alflinevisual.h>
       
    30 #include <alf/alfenv.h>
       
    31 #include <alf/alfevent.h>
       
    32 // </cmail>
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35  
       
    36 // ---------------------------------------------------------------------------
       
    37 // Two-phased constructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CFsSeparatorVisualizer* 
       
    41     CFsSeparatorVisualizer::NewL( CAlfControl& aOwnerControl )
       
    42     {
       
    43     FUNC_LOG;
       
    44     CFsSeparatorVisualizer* self = new( ELeave ) CFsSeparatorVisualizer( aOwnerControl );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( );
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // C++ destructor.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CFsSeparatorVisualizer::~CFsSeparatorVisualizer() 
       
    57     {
       
    58     FUNC_LOG;
       
    59 
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // The function sets separator's thickness in pixels.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CFsSeparatorVisualizer::SetSeparatorThickness( const TInt aThickness )
       
    68     {
       
    69     FUNC_LOG;
       
    70     iThickness = aThickness;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // The function returns thikness of the separator line.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 TInt CFsSeparatorVisualizer::SeparatorThickness( ) const
       
    79     {
       
    80     FUNC_LOG;
       
    81     return iThickness;
       
    82     }
       
    83     
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Sets the width of separator line. The separator line is always centered 
       
    87 // horizontaly. The line width is given as the percentage of the whole item's width.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CFsSeparatorVisualizer::SetSeparatorWidth ( TReal32 aWidth )
       
    91     {
       
    92     FUNC_LOG;
       
    93     iWidth = aWidth;
       
    94     
       
    95     if ( iWidth > 1.0 )
       
    96         {
       
    97         iWidth = 1.0;
       
    98         }
       
    99     else if ( iWidth < 0.1 )
       
   100         {
       
   101         iWidth = 0.1;
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Returns the width of the separator line.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 TReal32 CFsSeparatorVisualizer::SetSeparatorWidth ( ) const
       
   111     {
       
   112     FUNC_LOG;
       
   113     return iWidth;
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // From class MFsTreeItemVisualizer.
       
   119 // Returns visualizer's type.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 TFsTreeItemVisualizerType CFsSeparatorVisualizer::Type() const
       
   123     {
       
   124     FUNC_LOG;
       
   125     return EFsSeparatorVisualizer;
       
   126     }
       
   127 
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // From class MFsTreeItemVisualizer.
       
   131 // Sets multiple flags for an item at one time.
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CFsSeparatorVisualizer::SetFlags( TUint32 aFlags )
       
   135     {
       
   136     FUNC_LOG;
       
   137     iFlags = aFlags;
       
   138     iFlags &= ~KFsTreeListItemFocusable;
       
   139     iFlags &= ~KFsTreeListItemManagedLayout;
       
   140     iFlags &= ~KFsTreeListItemExtendable;
       
   141     iFlags &= ~KFsTreeListItemExtended;
       
   142     iFlags &= ~KFsTreeListItemAlwaysExtended;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // From class MFsTreeItemVisualizer.
       
   148 // Returns the size of an item in a normal (not extended) state.
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TSize CFsSeparatorVisualizer::Size() const
       
   152     {
       
   153     FUNC_LOG;
       
   154     return iSize;
       
   155     }
       
   156     
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // From class MFsTreeItemVisualizer.
       
   160 //  Sets the item's visualization state to extended. 
       
   161 //  Separator cannot be extended - the function has no effect.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CFsSeparatorVisualizer::SetExtended( TBool /*aFlag*/ )
       
   165     {
       
   166     FUNC_LOG;
       
   167     iFlags &= ~KFsTreeListItemExtended;
       
   168     }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // From class MFsTreeItemVisualizer.
       
   173 // Returns extended/not extended state of the item visualization.
       
   174 // Separator cannot be extended - the function always returns EFalse.
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 TBool CFsSeparatorVisualizer::IsExtended() const
       
   178     {
       
   179     FUNC_LOG;
       
   180     return EFalse;
       
   181     }
       
   182 
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // From class MFsTreeItemVisualizer.
       
   186 // Sets if an item can be in extended state or not.
       
   187 // Separator is not extendable - the function has no effect.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CFsSeparatorVisualizer::SetExtendable( TBool /*aFlag*/ )
       
   191     {
       
   192     FUNC_LOG;
       
   193     iFlags &= ~KFsTreeListItemExtendable;
       
   194     }
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // From class MFsTreeItemVisualizer.
       
   199 // Returns an information if item can be in extended state.
       
   200 // Separator is not extendable - the function always returns EFalse.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TBool CFsSeparatorVisualizer::IsExtendable( )
       
   204     {
       
   205     FUNC_LOG;
       
   206     return EFalse;
       
   207     }
       
   208 
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // From class MFsTreeItemVisualizer.
       
   212 // This functions sets wether an item should always be in extended state.
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CFsSeparatorVisualizer::SetAlwaysExtended( TBool /*aAlwaysExtended*/ )
       
   216     {
       
   217     FUNC_LOG;
       
   218     iFlags &= ~KFsTreeListItemAlwaysExtended;
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // From class MFsTreeItemVisualizer.
       
   224 // This function returns wether an item is always in extended state.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 TBool CFsSeparatorVisualizer::IsAlwaysExtended( ) const
       
   228     {
       
   229     FUNC_LOG;
       
   230     return EFalse;
       
   231     }
       
   232 
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // From class MFsTreeItemVisualizer.
       
   236 // A call to this function means that the item is requested to draw itself
       
   237 // within specified parent layout.
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CFsSeparatorVisualizer::ShowL( CAlfLayout& aParentLayout,
       
   241                                         const TUint aTimeout )
       
   242     {
       
   243     FUNC_LOG;
       
   244     if (!iLayout)
       
   245         {
       
   246         iParentLayout = &aParentLayout;
       
   247         iLayout = CAlfAnchorLayout::AddNewL(iOwnerControl,iParentLayout);
       
   248         iLayout->EnableBrushesL();
       
   249         iLayout->SetClipping(ETrue);
       
   250         iLayout->SetFlag( EAlfVisualFlagIgnorePointer );
       
   251         
       
   252         CAlfCurvePath* path = CAlfCurvePath::NewLC( iOwnerControl.Env() );
       
   253         path->AppendLineL(TPoint(0, 1), TPoint(100, 1), 1 );
       
   254         iLineVisual = CAlfLineVisual::AddNewL( iOwnerControl, iLayout );
       
   255         iLineVisual->SetPath(path, EAlfHasOwnership);
       
   256         iLineVisual->SetThickness( TAlfTimedValue(static_cast<TReal32>(iThickness), 0) );
       
   257         iLineVisual->SetColor(KRgbBlack);
       
   258         CleanupStack::Pop(path);
       
   259         iLineVisual->SetFlag( EAlfVisualFlagIgnorePointer );
       
   260         }
       
   261     else
       
   262         {
       
   263         //visuals are already created but not attached to the list layout
       
   264         if (!iLayout->Layout()) 
       
   265             {
       
   266             aParentLayout.Append(iLayout, aTimeout);
       
   267             iParentLayout = &aParentLayout;
       
   268             }
       
   269         }
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // From class MFsTreeItemVisualizer.
       
   274 // A call to this function means that the item is requested to update its
       
   275 // visual content.
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CFsSeparatorVisualizer::UpdateL( const MFsTreeItemData& aData,
       
   279                                           TBool /*aFocused*/,
       
   280                                           const TUint aLevel,
       
   281                                           CAlfTexture*& /*aMarkIcon*/,
       
   282                                           CAlfTexture*& /*aMenuIcon*/,
       
   283                                           const TUint /*aTimeout*/,
       
   284                                           TBool /*aUpdateData*/)
       
   285     {
       
   286     FUNC_LOG;
       
   287     if ( iLayout && iLineVisual )
       
   288         {
       
   289         if ( aData.Type() == KFsSeparatorDataType )
       
   290             {
       
   291             const CFsSeparatorData* data = static_cast<const CFsSeparatorData*>(&aData);
       
   292             
       
   293             TSize size;
       
   294             
       
   295             size = Size();
       
   296             size.iWidth = iParentLayout->Size().Target().iX - iParentLayout->HorizontalPadding()*2;
       
   297             //shrink width if we are at some level in the hierarchy
       
   298             TInt indentation(0);
       
   299             indentation = iTextIndentation * ( aLevel - 1 );
       
   300             TRect currentSize = size;
       
   301             if (CFsLayoutManager::IsMirrored())
       
   302                 {
       
   303                 currentSize.iBr = currentSize.iBr - TPoint(indentation, 0);
       
   304                 }
       
   305             else
       
   306                 {
       
   307                 currentSize.iTl = currentSize.iTl + TPoint(indentation, 0);
       
   308                 }
       
   309             
       
   310             CAlfCurvePath* path(NULL);
       
   311             path = iLineVisual->Path();
       
   312             
       
   313             if ( path )
       
   314                 {
       
   315                 path->Reset();
       
   316                 
       
   317                 //draw the line in the middle of item's height
       
   318                 TInt y(0);
       
   319                 y = ( currentSize.Height() - iThickness ) / 2;
       
   320                 
       
   321                 //width
       
   322                 TRect separatorRect = currentSize;
       
   323                 
       
   324                 separatorRect.iTl.iY = y;
       
   325                 separatorRect.iBr.iY = y;
       
   326                 
       
   327                 TInt lineWidth(0), space(0);
       
   328                 lineWidth = currentSize.Width() * iWidth;
       
   329                 space = ( currentSize.Width() - lineWidth ) / 2;
       
   330                 
       
   331                 separatorRect.iTl += TPoint( space, 0 );
       
   332                 separatorRect.iBr -= TPoint( space, 0 );
       
   333                 
       
   334                 path->AppendLineL( separatorRect.iTl, separatorRect.iBr, 1 );
       
   335                 
       
   336                 iLineVisual->SetThickness( TAlfTimedValue(static_cast<TReal32>(iThickness), 0) );
       
   337                 iLineVisual->SetColor( data->SeparatorColor() );                
       
   338                 }
       
   339             }        
       
   340         
       
   341         iLayout->UpdateChildrenLayout( 0 );
       
   342         }
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // From class MFsTreeItemVisualizer.
       
   347 // A call to this function means that the item goes out of the visible items
       
   348 // scope.
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CFsSeparatorVisualizer::Hide( const TInt aTimeout )
       
   352     {
       
   353     FUNC_LOG;
       
   354     if ( iLayout )
       
   355         {
       
   356         iParentLayout->Remove(iLayout, aTimeout);
       
   357         iLayout->RemoveAndDestroyAllD();
       
   358         iLayout = NULL;
       
   359         iParentLayout = NULL;
       
   360         iLineVisual = NULL;
       
   361         }
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 //  From class MFsTreeItemVisualizer.
       
   366 //  Method to marquee the text when it's too long.
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 void CFsSeparatorVisualizer::MarqueeL(const TFsTextMarqueeType /*aMarqueeType*/,
       
   370                                                  const TUint /*aMarqueeSpeed*/,
       
   371                                                  const TInt /*aMarqueeStartDelay*/,
       
   372                                                  const TInt /*aMarqueeCycleStartDelay*/,
       
   373                                                  const TInt /*aMarqueeRepetitions*/)
       
   374     {
       
   375     FUNC_LOG;
       
   376 
       
   377     }
       
   378 
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 //  C++ constructor.
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 CFsSeparatorVisualizer::CFsSeparatorVisualizer( CAlfControl& aOwnerControl )
       
   385     : CFsTreeItemVisualizerBase( aOwnerControl ),
       
   386     iThickness( KDefaultSeparatorThickness ),
       
   387     iWidth( 1.0 )
       
   388     {
       
   389     FUNC_LOG;
       
   390     TUint flags(0);
       
   391     SetFlags( flags );
       
   392     SetSize( TSize( KDefaultWidth, KDefaultHeight ));
       
   393     }
       
   394 
       
   395                                                 
       
   396 // ---------------------------------------------------------------------------
       
   397 //  Second phase constructor.
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 void CFsSeparatorVisualizer::ConstructL( )
       
   401     {
       
   402     FUNC_LOG;
       
   403     CFsTreeItemVisualizerBase::ConstructL();
       
   404     }
       
   405