uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiTextVisual.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Definition of CHuiTextVisual. CHuiTextVisual is a visual
       
    15 *                that draws text.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __HUITEXTVISUAL_H__
       
    22 #define __HUITEXTVISUAL_H__
       
    23 
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <AknsItemID.h>
       
    27 #include <uiacceltk/HuiVisual.h>
       
    28 #include <uiacceltk/HuiSkin.h>
       
    29 #include <uiacceltk/HuiGc.h>
       
    30 
       
    31 
       
    32 /* Forward declarations. */
       
    33 class CHuiControl;
       
    34 class CHuiTextMesh;
       
    35 class THuiTextStyle;
       
    36 class CAknPictographInterface;
       
    37 class CHuiPictographAnimator;
       
    38 
       
    39 
       
    40 /**
       
    41  * Text visual shows one or more lines of text.
       
    42  *
       
    43  * @todo  Escape sequences for formatting (font, colors) will be supported.
       
    44  * @todo  Changing text style with escape sequences.
       
    45  */
       
    46 NONSHARABLE_CLASS(CHuiTextVisual) : public CHuiVisual
       
    47     {
       
    48 public:
       
    49 
       
    50     /* Types. */
       
    51     
       
    52     enum TLineWrap
       
    53         {
       
    54         /** Lines must be broken manually with line break characters. 
       
    55             If the visual does not use clipping, long text lines will 
       
    56             go outside the visual. This is the default mode. */
       
    57         ELineWrapManual,
       
    58         
       
    59         /** Lines that do not fit in the visual's content area are truncated 
       
    60             with an ellipsis (...). */
       
    61         ELineWrapTruncate,
       
    62         
       
    63         /** Lines are broken to the visual's content area. */
       
    64         ELineWrapBreak
       
    65         };
       
    66 
       
    67     enum TLineSpacingUnits
       
    68         {
       
    69         /** Line spacing is given in pixels */
       
    70         EPixels,
       
    71         
       
    72         /** Line spacing is given in twips */
       
    73         ETwips
       
    74         };
       
    75 
       
    76 
       
    77     /* Constructors and destructor. */
       
    78 
       
    79     /** @beginAPI */
       
    80 
       
    81     /**
       
    82      * Constructs and appends a new text visual to the owner control.
       
    83      *
       
    84      * @param aOwnerControl  Control that will own the new visual.
       
    85      *
       
    86      * @return  The new visual.
       
    87      */
       
    88     IMPORT_C static CHuiTextVisual* AddNewL(CHuiControl& aOwnerControl,
       
    89                                             CHuiLayout* aParentLayout = 0);
       
    90 
       
    91     /** @endAPI */
       
    92     
       
    93     
       
    94     /**
       
    95      * Constructor.
       
    96      */
       
    97     CHuiTextVisual(MHuiVisualOwner& aOwner);
       
    98 
       
    99     /**
       
   100      * Second-phase constructor.
       
   101      */
       
   102     void ConstructL();
       
   103 
       
   104     /**
       
   105      * Destructor.
       
   106      */
       
   107     virtual ~CHuiTextVisual();
       
   108 
       
   109 
       
   110     /* Methods. */
       
   111 
       
   112     /** @beginAPI */
       
   113     
       
   114     /**
       
   115      * Set the text shown in the visual. The text may contain formatting
       
   116      * codes to change the size, color, and alignment of the text.
       
   117      *
       
   118      * @param aText  Descriptor containing the text.
       
   119      */
       
   120     IMPORT_C void SetTextL(const TDesC& aText);
       
   121 
       
   122     /**
       
   123      * Returns the text of the visual.
       
   124      */
       
   125     IMPORT_C const TDesC& Text() const;
       
   126 
       
   127     /**
       
   128      * Sets the alignment of the text visual.
       
   129      */
       
   130     IMPORT_C void SetAlign(THuiAlignHorizontal aAlignHorizontal,
       
   131                            THuiAlignVertical aAlignVertical);
       
   132 
       
   133 
       
   134     /**
       
   135      * Sets the line spacing for multiline text visual when the text wraps around.
       
   136      *
       
   137      * @param aLineSpacing Line spacing between lines in multiline text visual.
       
   138      * @parem aUnits       Defines the units of the line spacing.
       
   139      *                     @see TLineSpacingUnits. 
       
   140      */
       
   141     IMPORT_C void SetLineSpacing(TInt aLineSpacing, TLineSpacingUnits aUnits = EPixels);
       
   142 
       
   143 
       
   144     /**
       
   145      * Sets the default text style of the text visual. This style describes the size
       
   146      * and color of the rendered text.
       
   147      *
       
   148      * @param aStyle           Text style.
       
   149      * @param aBackgroundType  Text background type. Affects the color of 
       
   150      *                         the text. Defaults to EHuiBackgroundTypeLight
       
   151      *                         (ie, black text will be used).
       
   152      */
       
   153     IMPORT_C void SetStyle(THuiPreconfiguredTextStyle aStyle, 
       
   154                            THuiBackgroundType aBackgroundType = EHuiBackgroundTypeLight);
       
   155 
       
   156     /**
       
   157      * Sets the default text style of the text visual. This style describes the style
       
   158      * the text is rendered with. The text style has to be created with the text style 
       
   159      * manager. If the given text style does not exist, the text style is reverted back
       
   160      * to default text style.
       
   161      * @see CHuiTextStyleManager
       
   162      *
       
   163      * @param aTextStyleId Text style ID provided by the text style manager.
       
   164      */
       
   165     IMPORT_C void SetTextStyle(TInt aTextStyleId);
       
   166     
       
   167     /**
       
   168      * Accesses the text style of the text visual.
       
   169      *
       
   170      * If a value has been set by SetFontId which is not in THuiTextStyle, then
       
   171      * this will return EHuiTextStyleNotAHuiStyle
       
   172      */    
       
   173     IMPORT_C THuiPreconfiguredTextStyle Style() const;
       
   174 
       
   175     /**
       
   176      * Accesses the text style id of the text visual, including non-predefined styles
       
   177      *
       
   178      * @return text style id
       
   179      */    
       
   180     IMPORT_C TInt TextStyle() const;
       
   181 
       
   182     /**
       
   183      * Sets the maximum number of lines displayed by the text visual.
       
   184      * The default is KMaxTInt.
       
   185      */
       
   186     IMPORT_C void SetMaxLineCount(TInt aMaxLineCount);
       
   187     
       
   188     /**
       
   189      * Determines the maximum number of line displayed by the text visual.
       
   190      */
       
   191     IMPORT_C TInt MaxLineCount() const;
       
   192     
       
   193     /**
       
   194      * Determines the visual's line wrapping mode.
       
   195      *
       
   196      * @return  Line wrapping mode.
       
   197      */
       
   198     IMPORT_C TLineWrap Wrapping() const;    
       
   199     
       
   200     /**
       
   201      * Sets the line wrapping mode.
       
   202      *
       
   203      * @param aWrap  Line wrapping mode.
       
   204      */
       
   205     IMPORT_C void SetWrapping(TLineWrap aWrap);
       
   206     
       
   207     /**
       
   208      * Determines the background type of the text visual. This was set with a 
       
   209      * call to SetStyle().
       
   210      */    
       
   211     IMPORT_C THuiBackgroundType BackgroundType() const;
       
   212 
       
   213     inline THuiTimedPoint& Offset()
       
   214         {
       
   215         return iOffset;
       
   216         }
       
   217 
       
   218     inline const THuiTimedPoint& Offset() const
       
   219         {
       
   220         return iOffset;
       
   221         }
       
   222 
       
   223     /**
       
   224      * Determines the size of the text in the visual.
       
   225      * Text must have been updated / or drawn to be able
       
   226      * to use these extents.
       
   227      *
       
   228      * @return Size of the text in pixels, or TSize(0,0) if 
       
   229      * text is undefined or the mesh hasn't been updated.
       
   230      * 
       
   231      * @see UpdateMeshL() 
       
   232      */
       
   233     IMPORT_C TSize TextExtents() const;
       
   234 
       
   235 	/**
       
   236 	 * Prepares text for drawing. Updates the text max line
       
   237 	 * width according to the wrapping parameters, sets the
       
   238 	 * text style and updates the text mesh.
       
   239 	 * 
       
   240 	 * @see UpdateMeshL()
       
   241 	 */
       
   242 	IMPORT_C virtual TBool PrepareDrawL();	
       
   243 
       
   244      /**
       
   245      * Sets the color of the text.
       
   246      *
       
   247      * @param aColor           Text color.
       
   248      */
       
   249     IMPORT_C void SetColor(const TRgb& aColor);
       
   250 
       
   251      /**
       
   252      * Sets the color of the text via skin id.
       
   253      *
       
   254      * @param aID           Skin-id of the color group to use
       
   255      * @param aIndex        Index within the color group
       
   256      */
       
   257      IMPORT_C void SetColor(const TAknsItemID& aID,const TInt aIndex);
       
   258 
       
   259     /**
       
   260      * Get the extents of a block of characters given the visual's
       
   261      * current font style.
       
   262      *
       
   263      * Gets the local pixel extents of a block of text within
       
   264      * this text visual.
       
   265      *
       
   266      * Note that these extents do not take into account line breaks,
       
   267      * so it will only return accurate results on single lines of text.
       
   268      *
       
   269      * @param aStart The starting character of the substring.
       
   270      * @param aEnd The end character of the substring.
       
   271      */
       
   272     IMPORT_C TRect SubstringExtents(TUint aStart, TUint aEnd) const;
       
   273 
       
   274     /**
       
   275      * @deprecated Use CHuiDropShadow
       
   276      *
       
   277      * Enables or disables the text shadow.
       
   278      * The text shadow is a special implementation
       
   279      * of shadow that looks good with text. If this value is
       
   280      * false, then the text will not have a shadow.
       
   281      * This method will also reset iShadow opacity to 0 or 1.
       
   282      * 
       
   283      * @param aDoEnable True enables shadows, false disables.
       
   284      */
       
   285     IMPORT_C void EnableShadow(TBool aDoEnable);    
       
   286     
       
   287     
       
   288     /**
       
   289      * Sets highlighting for a part of Text
       
   290      *
       
   291      * @param aStart Startng index of Highlighted text.
       
   292      * @param aEnd Ending index of Highlighted text.
       
   293      * @param aHighlightColor Background color of highlighted text.
       
   294      * @param aHightlightColor Font color of Highlighted text.
       
   295      */
       
   296     IMPORT_C void SetHighlightRange(TInt aStart, TInt aEnd, TRgb& aHighlightColor, TRgb& aHighlightTextColor);
       
   297  	  
       
   298     
       
   299     /** @endAPI */
       
   300 
       
   301     /**
       
   302      * Draw the text visual.
       
   303      */
       
   304     virtual void DrawSelf(CHuiGc& aGc, const TRect& aDisplayRect) const;
       
   305 
       
   306     /**
       
   307      * Returns true if the text has changed and needs redrawing.
       
   308      */
       
   309     virtual TBool Changed() const;
       
   310 
       
   311     /**
       
   312      * Clear the changed flag of the visual, ie, the text has been redrawn.
       
   313      */
       
   314     virtual void ClearChanged();
       
   315 
       
   316     void NotifySkinChangedL();
       
   317 
       
   318     void GetClassName(TDes& aName) const
       
   319         {
       
   320         aName = _L("CHuiTextVisual");
       
   321         }
       
   322         
       
   323     void ExpandRectWithContent(TRect& aRect) const;
       
   324 
       
   325      /**
       
   326      * Updates the text mesh within this text visual. 
       
   327      * Updates the text font and  the text itself (possibly 
       
   328      * renders the text to a bitmap), if needed, and 
       
   329      * recalculates the text extents.
       
   330      */
       
   331     void UpdateMeshL() const;
       
   332 
       
   333     IMPORT_C void UpdateMeshL(const TDesC8& aBuffer);
       
   334     
       
   335 private: 
       
   336 
       
   337 private:
       
   338 
       
   339     /** Line wrapping mode. */
       
   340     TLineWrap iLineWrapping;
       
   341 
       
   342     /** Horizontal alignment. */
       
   343     THuiAlignHorizontal iAlignHorizontal;
       
   344 
       
   345     /** Vertical alignment. */
       
   346     THuiAlignVertical iAlignVertical;
       
   347 
       
   348     /** The text of drawn in the visual. */
       
   349     HBufC* iText; // Owned
       
   350 
       
   351     /** ETrue if the mesh has been updated. */
       
   352     mutable TBool iMeshUpdated;
       
   353 
       
   354     /** ETrue, if the extents have been updated. */
       
   355     mutable TBool iExtentsUpdated;
       
   356 
       
   357     /** ETrue, if the font and style has been updated. */
       
   358     mutable TBool iFontUpdated;
       
   359 
       
   360     /** Text mesh containing the text in a format suitable for 
       
   361         efficient drawing. */
       
   362     CHuiTextMesh* iTextMesh;
       
   363 
       
   364     /** Default text style. Affects both font and other features of the text */
       
   365     THuiPreconfiguredTextStyle iStyle;
       
   366         
       
   367     /** Text background type. Affects text style. */
       
   368     THuiBackgroundType iBackgroundType;
       
   369 
       
   370     /** Offset to the text position. */
       
   371     THuiTimedPoint iOffset;
       
   372 
       
   373     TRgb iFontColor;
       
   374     TAknsItemID iFontColorId;
       
   375     TInt iFontColorIndex;
       
   376     TBool iFontColorValid;
       
   377 
       
   378     /** Pictograph drawing interface */
       
   379     CAknPictographInterface* iPictographInterface; 
       
   380 
       
   381     /** Pictograph animator */
       
   382     CHuiPictographAnimator* iPictographAnimator;
       
   383     
       
   384     
       
   385     TInt iHighlightStart;
       
   386     TInt iHighlightEnd;
       
   387     TRgb iHighlightColor;
       
   388     TRgb iHighlightTextColor;
       
   389 
       
   390     
       
   391 public:
       
   392 
       
   393     // @deprecated Use CHuiDropShadow
       
   394     THuiTimedValue iShadow;
       
   395 
       
   396     };
       
   397 
       
   398 #endif  // __HUITEXTVISUAL_H__