emailuis/uicomponents/inc/fstreenodevisualizerbase.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 17 Dec 2009 08:39:21 +0200
changeset 0 8466d47a6819
child 20 efd4f1afd43e
permissions -rw-r--r--
Revision: 200949 Kit: 200951

/*
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Base class of item visualizer.
*
*/



#ifndef FSTREENODEVISUALIZERBASE_H_
#define FSTREENODEVISUALIZERBASE_H_


#include <e32base.h>
//<cmail> removed __FS_ALFRED_SUPPORT flag
//#include <fsconfig.h>
//</cmail> removed __FS_ALFRED_SUPPORT flag
#include <gdi.h>
// <cmail> SF
#include <alf/alfeventhandler.h>
// </cmail>
#include "fstreenodevisualizer.h"

class CAlfLayout;
class CAlfTexture;
class CAlfBrush;
class CAlfTexture;
class CAlfAnchorLayout;
class CAlfControl;
class CFsAlfTextStyleManager;
class CAlfTextVisual;

/**
 * CFsTreeNodeVisualizerBase is a base class implementing methods common for
 * all tree node visualizers.
 *
 * Thic class is a concrete implementation for the MFsTreeItemVisualizer 
 * interface.
 * 
 * @code
 *
 * @endcode
 *
 * @lib 
 */
NONSHARABLE_CLASS(CFsTreeNodeVisualizerBase) : public CBase,
                                               public MFsTreeNodeVisualizer,
                                               public MAlfEventHandler
    {
    
public:

    virtual ~CFsTreeNodeVisualizerBase();
    
    
public: //from MFsTreeItemVisualizer

    /**
     * Returns the type of the item's visualizer.
     */
    virtual TFsTreeItemVisualizerType Type() const;
    
    /**
     * Sets horizontal alignment of the displayed plain text.
     * 
     * For AH layout EHuiAlignHLeft is internally converted to EHuiAlignHRight
     * and EHuiAlignHRight is converted to EHuiAlignHLeft.
     * 
     * EAlfAlignHLocale (default setting) - alignment set according to text directionality
     * 
     * @param aAlign Horizontal text alignment type.
     */
    virtual void SetTextAlign( const TAlfAlignHorizontal aAlign );
        
    /**
     * The function sets item's text color for the focused state.
     *
     * @param aColor New color to be set.
     */
    virtual void SetFocusedStateTextColor( TRgb& aColor );
    
    /**
     * The function returns item's text color for the focused state.
     */
    virtual TRgb FocusedStateTextColor() const;
    
    /**
     * The function sets item's text color for the normal (unfocused) state.
     *
     * @param aColor New color to be set.
     */
    virtual void SetNormalStateTextColor( TRgb& aColor );
    
    /**
     * The function returns item's text color for the normal (unfocused) state
     */
    virtual TRgb NormalStateTextColor() const;
        
    /**
     * The function sets the style of item's text.
     * 
     * @param aTextStyleId Text style ID provided by the text style manager.
     */
    virtual void SetTextStyleId ( const TInt aTextStyleId );
    
    /**
     * The function returns the style of item's text.
     * 
     * @return Text style ID provided by the text style manager.
     */
    virtual TInt TextStyleId () const;
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets multiple flags for an item at one time.
     * 
     * @param aFlags Flags for item visualizer.
     */
    virtual void SetFlags( TUint32 aFlags );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns flags of the item visualizer.
     * 
     * @return Item visualizer's flags value.
     */
    virtual TUint32 Flags();
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets visualized item's state to marked/unmarked.
     * 
     * @param aFlag ETrue to visualize item as marked.
     */
    virtual void SetMarked( TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns mark/unmark state of the item's visualization.
     * 
     * @return ETrue if item is visualized as marked.
     */
    virtual TBool IsMarked() const;
     
    /**
     * From MFsTreeItemVisualizer.
     * Sets visualized item's state to dimmed/not dimmed.
     * 
     * @param aFlag ETrue to visualize item as dimmed.
     */
    virtual void SetDimmed( TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns dimmed/not dimmed state of the item's visualization.
     * 
     * @return ETrue if item is visualized as dimmed.
     */
    virtual TBool IsDimmed() const;
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets the size of the item visualization when item is not in expanded 
     * state. 
     * 
     * @param aSize Size in pixels of the an when it is not expanded.
     */
    virtual void SetSize( const TSize aSize );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns the size of an item in a normal (not extended) state.
     * 
     * @return Size in pixels of an item when it is not extended.
     */
    virtual TSize Size() const;     
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets the item's visualization state to expanded. This state is used to
     * preview more data of an item.
     * 
     * @param aFlag ETrue to visualize item as expanded.
     */
    virtual void SetExtended( const TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns expanded/not expanded state of the item visualization.
     * 
     * @return ETrue if item is visualized as expanded.
     */
    virtual TBool IsExtended() const;    
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets if an item can be in expanded state or not.
     * 
     * @param aFlag ETrue if item can be in expanded state.
     */
    virtual void SetExtendable( TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns an information if item can be in expanded state.
     * 
     * @return ETrue if item can be in expanded state.
     */
    virtual TBool IsExtendable( );
    
    /**
     * From MFsTreeItemVisualizer
     * Returns an information if item can be focused.
     * 
     * @return ETrue if item can be focused.
     */
    virtual TBool IsFocusable( ) const;
    
    /**
     * From MFsTreeItemVisualizer
     * Used to set/unset item's ability to receive focus.
     * 
     * @param aFlag ETrue if item can be focused.
     */
    virtual void SetFocusable( const TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets the size of the item visualization area when item is in expanded 
     * state. 
     * 
     * @param aSize Size in pixels of the item when it is expanded.
     */
    virtual void SetExtendedSize( const TSize aSize );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns the size of an item in expanded state.
     * 
     * @return Size in pixels of the item when it is in expanded state.
     */
    virtual TSize ExtendedSize() const;
        
    /**
     * From MFsTreeItemVisualizer.
     * Sets visualized item's state to hidden/visible.
     * 
     * @param ETrue if item should be visualized as hidden.
     */
    virtual void SetHidden( TBool aFlag );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns an information if the item is hidden or not.
     * 
     * @return ETrue if item is hiddden, EFalse if item is visible.
     */
    virtual TBool IsHidden() ;
    
    /**
     * From MFsTreeItemVisualizer.
     * Enables or disables text shadow.
     * 
     * @param aShadowOn Pass ETrue if shadow should be enabled 
     * EFalse otherwise.
     */
    virtual void EnableTextShadow( const TBool aShadowOn = ETrue );
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets text indentation.
     *
     * @param aIndentation Indentation in pixels.
     */
    virtual void SetIndentation( const TInt aIndentation = 0 );
    
    /**
     * From MFsTreeItemVisualizer.
     * Sets item background color.
     * 
     * @param aColor New background color.
     */
    virtual void SetBackgroundColor( const TRgb aColor );
    
    /**
     * From MFsTreeItemVisualizer.
     * Returns background color if it's set.
     * 
     * @param aColor Out parameter. Contains background color.
     * 
     * @return ETrue if background color is set, EFalse otherwise.
     */
    virtual TBool GetBackgroundColor( TRgb& aColor );
        
    /**
     * From MFsTreeItemVisualizer.
     * Sets item background texture.
     * 
     * @param aTexture New background texture.
     */
    virtual void SetBackgroundTexture( const CAlfTexture& aTexture );

    // <cmail>
    /**
     * From MFsTreeItemVisualizer.
     * Sets item background brush. Ownership not transfered.
     * 
     * @param aBrush New background brush.
     */
    virtual void SetBackgroundBrush( CAlfBrush* aBrush );

    /**
     * From MFsTreeItemVisualizer.
     * Returns item background brush.
     * 
     * @param aBrush Out parameter. Contains pointer to a background brush.
     *
     * @return ETrue if background brush is set, EFalse otherwise.
     */
    virtual TBool GetBackgroundBrush( CAlfBrush*& aBrush );
    // </cmail>

    /**
     * From MFsTreeItemVisualizer.
     * Returns background texture if it's set.
     * 
     * @param aTexture Out parameter. Contains pointer to a texture.
     * 
     * @return ETrue if background texture is set, EFalse otherwise.
     */
    virtual TBool GetBackgroundTexture( const CAlfTexture*& aTexture );
    
    /**
     * From MFsTreeItemVisualizer.
     * Clears item background.
     */
    virtual void ClearBackground( );
    
    /**
     * Sets menu for item
     * @param aMenu CTreeList object containing menu items
     */
    virtual void SetMenu( CFsTreeList* aMenu );
     
    /**
     * Returns CFsTreeList object contaning menu items
     * @return Menu for item.
     */
    virtual CFsTreeList* Menu() const;
    
    /**
     * This functions sets wether an item should always be in extended state.
     * 
     * @param ETrue if item should always be in extended state.
     */
    virtual void SetAlwaysExtended( TBool aAlwaysExtended );
    
    /**
     * This function returns wether an item is always in extended state.
     * 
     * @return ETrue if item is always in extended state.
     */
    virtual TBool IsAlwaysExtended( ) const;
    
    /**
     * Sets the text style manager for the item visualizer.
     * 
     * @param aManager Reference to the text style manager.
     */
    virtual void SetTextStyleManager( CFsAlfTextStyleManager& aManager );
    
    /**
     * Sets the text stroke weight for the item visualizer.
     * 
     * @param aIsBold ETrue if the text shoul be bold.
     */
    virtual void SetTextBold( const TBool aIsBold );
    
    /**
     * Gets the text stroke weight for the item visualizer.
     * 
     * @return ETrue if the text is be bold.
     */
    virtual TBool IsTextBold( ) const;
    
    
    /**
     * Method to set text font height in twips.
     * 
     * @param aHeightInTwips Text font height to be set.
     */
    virtual void SetFontHeight(const TInt aHeightInTwips);
    
    /**
     * Gets height of a text font in twips.
     * 
     * @return Height of the font in twips
     */
    virtual TInt FontHeight() const;
    
    /**
     * Method to set text font height in pixels.
     * 
     * @param aHeightInPixels Text font height to be set.
     */
    virtual void SetFontHeightInPixels(const TInt aHeightInPixels);
    
    /**
     * Gets height of a text font in pixels.
     * 
     * @return Height of the font in pixels.
     */
    virtual TInt FontHeightInPixels() const;
    
    /**
     * 
     */
    virtual CAlfLayout& Layout() const;

    /**
     * 
     */
    virtual void ShowL( CAlfLayout& aParentLayout,
            const TUint aTimeout = 0 );
    
    /**
     * 
     */
    virtual void UpdateL( const MFsTreeItemData& aData,
            TBool aFocused,
            const TUint aLevel,
            CAlfTexture*& aMarkIcon,
            CAlfTexture*& aMenuIcon,
            const TUint aTimeout = 0,
            TBool aUpdateData = ETrue);

    /**
     * 
     */
    virtual void Hide( const TInt aTimeout = 0 );
    
    /**
     * This method marquees the text in tree item if it is too long.
     * 
     * @param aMarqueeType Type of marquee.
     * @param aMarqueeSpeed Speed of marquee in pixels per second.
     * @param aMarqueeStartDelay Marquee's start delay in miliseconds.
     * @param aMarqueeCycleStartDelay Marquee cycle's start delay.
     * @param aMarqueeRepetitions Number of marquee's cycles.
     */
    virtual void MarqueeL(const TFsTextMarqueeType aMarqueeType,
                          const TUint aMarqueeSpeed,
                          const TInt aMarqueeStartDelay,
                          const TInt aMarqueeCycleStartDelay,
                          const TInt aMarqueeRepetitions);
    
    /**
     * 
     */
    virtual TBool OfferEventL(const TAlfEvent& aEvent);
    	        
public: //from base class MFsTreeNodeVisualizer

    /**
     * From MFsTreeNodeVisualizer.
     * Sets visualized node's state to rolled/unrolled.
     * 
     * @param aFlag ETrue to visualize node as rolled (collapsed).
     */
    virtual void SetExpanded( TBool aFlag, const MFsTreeItemData* aData = 0 );
    
    /**
     * From MFsTreeNodeVisualizer.
     * Returns rolled/unrolled state of the node's visualization.
     * 
     * @return ETrue if node is visualized as rolled (collapsed).
     */
    virtual TBool IsExpanded() const;
    
    
protected:
    
    /**
     * C++ constructor
     */
    CFsTreeNodeVisualizerBase(CAlfControl& aOwnerControl);
    
    /**
     * Second phase constructor
     *
     */
    void ConstructL( );
    
    
protected:

    /**
     * Function gets text color for a focused item. The color is taken from 
     * the skin if skin support is on, if not then a default value is used.
     * 
     * @return aTextColor Text's color.
     */
    virtual TRgb FocusedStateTextSkinColor( );
    
    /**
     * Function gets text color for a non focused item. The color is taken 
     * from the skin if skin support is on, if not then a default value is 
     * used.
     * 
     * @return aTextColor Text's color.
     */
    virtual TRgb NormalStateTextSkinColor( );
        
    /**
     * Returns horizontal alignment of the displayed text in respect to
     * current layout.
     * 
     * For AH layout EAlfAlignHLeft is internally converted to EAlfAlignHRight
     * and EAlfAlignHRight is converted to EAlfAlignHLeft.
     * 
     * @param aAlign Horizontal text alignment type.
         */
    virtual TAlfAlignHorizontal CurrentTextAlignmentL( TAlfAlignHorizontal aAlignment,
                                                       TDesC* aText,
                                                       CAlfTextVisual* aVisual);
    /**
     * Returns text style id used in the node.
     */
    virtual TInt ModifiedStyleIdL( ) const;
    
public:
    /*
     * Layouting hints for the visualizers. Hints are binary flags so they can be mixed.
     */
    enum TLayoutHint
        {
        ENormalLayout = 0,
        // Use folder layout for item visualizers
        EFolderLayout = (1<<0),
        // Item visualizers are in popup
        EPopupLayout = (1<<1)
        };    
    
    
public:
    
    // Set layout hint(s). Given hints are ORed so previously set flags will remain.
    virtual void SetLayoutHints( const TUint aHints );
    
    /**
     * Check if given layout hint is set.
     */    
    virtual TBool IsLayoutHintSet( const TLayoutHint aHint ) const;    
    
protected:

    enum TFsNodeBackgroundState
        {
        EFsNodeBackgroundNone,
        EFsNodeBackgroundColor,
        EFsNodeBackgroundTexture,
    // <cmail> this feature is waiting for title divider bg graphics
        EFsNodeBackgroundBrush       
    // </cmail>
        };
    
protected:

    /*
     * A parent control for the tree visualizer.
     */
    CAlfControl& iOwnerControl;
    
    /*
     * Parent layout of the item layout, typically list layout.
     * Not own.
     */
    CAlfLayout* iParentLayout;
    
    /**
     * Main layout for the plain text item.
     * Own.
     */
    CAlfAnchorLayout* iLayout;
    
    /*
     * Visualizer's state flag.
     */
    TUint32 iFlags;
    
    /*
     * Horizontal text alignment in visual.
     */
    TAlfAlignHorizontal iTextAlign;
    
    /*
     * Item's size.
     */
    TSize iSize;
    
    /*
     * Item's extended size.
     */
    TSize iExtendedSize;
    
    /**
     * CFsTreeList containing menu for item
     */
    CFsTreeList* iMenu;
     
    /**
     * Text indetation in pixels.
     */
    TInt iTextIndentation;
    
    /**
     * Custom color set for a text in normal state. 
     * ETrue custom color set, EFalse use color from the skin. 
     */
    TBool iIsCustomTextNormalColor;
    
    /**
     * Text's color in normal (unfocused) state.
     */
    TRgb iNormalTextColor;
    
    /**
     * Custom color set for a text in focused state. 
     * ETrue custom color set, EFalse use color from the skin.
     */    
    TBool iIsCustomTextFocusedColor;
    
    /**
     * Text's color in focused state.
     */
    TRgb iFocusedTextColor;
    
    /**
     * Text's style. The id comes from CHuiTextStyleManager.
     */
    TInt iTextStyleId;
    
    /**
     * ETrue if custom text style is used. EFalse text style taken from layout manager.
     */
    TBool iIsCustomTextStyle;
    
    /**
     * Item's text style manager.
     */
    CFsAlfTextStyleManager* iTextStyleManager;
    
    /**
     * Font height
     */
    TInt iFontHeight;
    
    /**
     * State of the background: clear, color, texture.
     */
    TFsNodeBackgroundState iBackgroundState;
    
    /*
     * Background color.
     */
    TRgb iBackgroundColor;
    
    /**
     * Background texture.
     * Not own.
     */
    const CAlfTexture* iBackgroundTexture;

    /**
     * Background brush.
     * Not own.
     */
    CAlfBrush* iBackgroundBrush;
    
    /*
     * Layout hints.
     */
    TUint iLayoutHints;
    };


#endif /*FSTREENODEVISUALIZERBASE_H_*/