uiaccelerator_plat/alf_visual_api/inc/alf/alftextstylemanager.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Text style manager class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_ALFTEXTSTYLEMANAGER_H
       
    21 #define C_ALFTEXTSTYLEMANAGER_H
       
    22 
       
    23 #include <e32base.h>
       
    24 
       
    25 /** 
       
    26  * Preconfigured text styles.
       
    27  * Matching text styles always exist in the text style manager.
       
    28  * It is possible to retrieve the associated text style object through
       
    29  * CAlfTextStyleManager::TextStyle() - interface.
       
    30  */
       
    31 enum TAlfPreconfiguredTextStyle
       
    32     {
       
    33     EAlfTextStyleNormal = 0,
       
    34     EAlfTextStyleNormalItalic,
       
    35     EAlfTextStyleMenuItem,
       
    36     EAlfTextStyleSmall,
       
    37     EAlfTextStyleMenuSmall,
       
    38     EAlfTextStyleMenuTitle,
       
    39     EAlfTextStyleLarge,
       
    40     EAlfTextStyleSoftkey,
       
    41     EAlfTextStyleSupplement,
       
    42     EAlfTextStyleTitle,
       
    43     
       
    44     /** Not a default alf style, will be treated as normal. */
       
    45     EAlfTextStyleNotAHuiStyle = EAlfTextStyleNormal
       
    46     };
       
    47 
       
    48 // Forward declarations.
       
    49 class CAlfTextStyle;
       
    50 class CAlfTextVisual;
       
    51 class CAlfEnv;
       
    52 
       
    53 /**
       
    54  * Text style manager class. This class provides means to create and
       
    55  * query text styles that will be used to render text.
       
    56  * Usage:
       
    57  * 
       
    58  * @code
       
    59  *  //Get Textstyle Manager
       
    60  * CAlfTextStyleManager* styleMgr = &iEnv->TextStyleManager();
       
    61  * 
       
    62  *  // Create a textstyle, by passing fontid and preconfigured textstyle as parent id
       
    63  * TInt newStyleId= styleMgr->CreatePlatformTextStyleL( fontStyleId,
       
    64  * 							 EAlfTextStyleNormal );
       
    65  * CAlfTextStyle* newStyle =  styleMgr->TextStyle( newStyleId );
       
    66  * 
       
    67  * //Copy textstyle
       
    68  * TInt copiedId =  styleMgr->CopyTextStyle( newStyleId );
       
    69  * CAlfTextstyle* copiedStyle =  styleMgr->TextStyle( copiedId );
       
    70  * 
       
    71  * //Delete textstyle
       
    72  * TBool issuccess = styleMgr->DeleteTextStyle( newStyleId );
       
    73  * issuccess = styleMgr->DeleteTextStyle( copiedId );
       
    74  * @endcode
       
    75  * 
       
    76  * @see CAlfTextstyle
       
    77  * @see CAlfEnv::TextstyleManager()
       
    78  * @lib alfclient.lib
       
    79  * @since S60 v3.2
       
    80  */
       
    81 NONSHARABLE_CLASS( CAlfTextStyleManager ): public CBase
       
    82     {
       
    83 public:
       
    84 
       
    85     /* Constructors and destructor. */
       
    86     
       
    87     /**
       
    88      * Constructor.
       
    89      */
       
    90     static CAlfTextStyleManager* NewL(CAlfEnv& aEnv);
       
    91     
       
    92     /**
       
    93      * Constructor.
       
    94      */
       
    95     static CAlfTextStyleManager* NewLC(CAlfEnv& aEnv);
       
    96     
       
    97     /**
       
    98      * Destructor.
       
    99      */    
       
   100     ~CAlfTextStyleManager();
       
   101 
       
   102 public:
       
   103     
       
   104     /**
       
   105      * Creates a new text style object based on the S60 font style id passed into this method. 
       
   106      * Text style font and size are set according to the given S60 id. Ids are defined in
       
   107      * avkon.hrh in TAknLogicalFontId enumeration.
       
   108      * A unique toolkit specific ID is constructed and returned. This text style can be
       
   109      * accessed anytime through the TextStyle - method based on the unique ID. The default 
       
   110      * text style has always ID 0.
       
   111      * Text styles cascade properties from their parent styles. By default all text styles
       
   112      * are descended from EAlfTextStyleNormal text style.
       
   113      * If an invalid parent id is given the created text style will use EAlfTextStyleNormal
       
   114      * as its parent.
       
   115      * @see TextStyle()
       
   116      *
       
   117      * Created text styles must be deleted with DeleteTextStyle.
       
   118      * @see DeleteTextStyle()
       
   119      * 
       
   120      * @param aFontStyleId The S60 font style id based on which the text style object will be created.
       
   121      * @param aParentId Toolkit specific ID of the parent text style. The text styles are cascaded.
       
   122      *      
       
   123      * @return Unique toolkit specific ID for the created text style.
       
   124      */
       
   125     IMPORT_C TInt CreatePlatformTextStyleL(TInt aFontStyleId, TInt aParentId);
       
   126     
       
   127     /**
       
   128      * Creates a new text style object based on the parent text style id passed into this method. 
       
   129      * Text style font and size will be the same as the given parent style has.
       
   130      * A unique toolkit specific ID is constructed and returned. This text style can be
       
   131      * accessed anytime through the TextStyle - method based on the unique ID.
       
   132      * Text styles cascade properties from their parent styles. By default all text styles
       
   133      * are descended from EAlfTextStyleNormal text style.
       
   134      * If an invalid parent id is given the created text style will use EAlfTextStyleNormal
       
   135      * as its parent.
       
   136      * @see TextStyle()
       
   137      *
       
   138      * Created text styles must be deleted with DeleteTextStyle.
       
   139      * @see DeleteTextStyle()
       
   140      * 
       
   141      * @param aParentId Toolkit specific ID of the parent text style. The text styles are cascaded.
       
   142      *                  The parent of the created text style is EAlfTextStyleNormal by default.
       
   143      * @return Unique toolkit specific ID for the created text style.
       
   144      */
       
   145     IMPORT_C TInt CreatePlatformTextStyleL(TInt aParentId = EAlfTextStyleNormal);
       
   146     
       
   147     /**
       
   148      * Returns a text style object based on the text style id passed into this method.
       
   149      * If no matching text style is found from the system the method returns the EAlfTextStyleNormal
       
   150      * text style. There is a collection of preconfigured text styles available. They can
       
   151      * be queried using the id enumerations from TAlfPreconfiguredTextStyle.
       
   152      * @see CreatePlatformTextStyleL()
       
   153      * 
       
   154      * @param aId A text style id identifying the requested text style in the text style manager.
       
   155      * @return A pointer to a requested text style. Various attributes of the text style 
       
   156      * can be changed using the returned pointer.
       
   157      */
       
   158     IMPORT_C CAlfTextStyle* TextStyle(TInt aId);    
       
   159     
       
   160     /**
       
   161      * Creates a new text style object that is identical with the given source text style.
       
   162      *
       
   163      * Created/copied text styles must be deleted with DeleteTextStyle.
       
   164      * @see DeleteTextStyle()
       
   165      *
       
   166      * @param aSourceId A toolkit specific ID of the text style to be cloned.
       
   167      * @return Unique toolkit specific ID for the created text style.
       
   168      */
       
   169     IMPORT_C TInt CopyTextStyleL(TInt aSourceId);
       
   170   
       
   171     /**
       
   172      * Deletes the given text style.
       
   173      *
       
   174      * @param aId Text style ID to delete.
       
   175      *
       
   176      * @return Error code. KErrNone if text style was deleted
       
   177      *                     KErrArgument if there is no style defined with given ID
       
   178      *                     KErrAccessDenied if the ID refers to pre-defined styles.
       
   179      */ 
       
   180     IMPORT_C TInt DeleteTextStyle(TInt aId);
       
   181 
       
   182 public: // internal utils
       
   183     CAlfTextStyle* SwitchTextStyle(TInt aStyle, CAlfTextVisual* aUser);
       
   184     void Unregister(CAlfTextVisual* aVisual);
       
   185     void RefreshVisuals(TInt aStyle);
       
   186     void ReleaseAllVisuals();
       
   187     void RefreshAllVisuals();
       
   188     
       
   189 protected:
       
   190 
       
   191     /* Constructors. */
       
   192     
       
   193     /**
       
   194      * Default constructor.
       
   195      */
       
   196     CAlfTextStyleManager();
       
   197     
       
   198     /**
       
   199      * Second-phase constructor.
       
   200      */
       
   201     void ConstructL(CAlfEnv& aEnv);
       
   202     
       
   203 private:
       
   204 	
       
   205     /**
       
   206      * Constructs a collection of CAlfTextStyle objects to match the ones
       
   207      * in TAlfPreconfiguredTextStyle.
       
   208      * @see TAlfPreconfiguredTextStyle
       
   209      */
       
   210     void ConstructPreconfiguredStylesL();	
       
   211 
       
   212     /**
       
   213      * Find free slot index
       
   214      *
       
   215      * @return free slot index
       
   216      */    
       
   217     TInt FindFreeSlotIndex() const;
       
   218     
       
   219     /**
       
   220      * Create a platform style.
       
   221      *
       
   222      * @see CreatePlatformTextStyleL
       
   223      * @see CopyTextStyleL
       
   224      *
       
   225      * @param aFontStyleId The S60 font style id based on which the text style object will be created.
       
   226      * @param aParentId Toolkit specific ID of the parent text style. The text styles are cascaded.
       
   227      * @param aImplementationId 	Describes the type of text style that is created (platform text style, etc.)
       
   228      * @return Unique toolkit specific ID for the created text style.
       
   229      */
       
   230     TInt DoCreatePlatformTextStyleL(TInt aFontStyleId, TInt aParentId, TInt aImplementationId);
       
   231 
       
   232 private:
       
   233 	
       
   234 	/* Private data. Owned */
       
   235     struct TPrivateData;    
       
   236     TPrivateData* iData;
       
   237     
       
   238     };
       
   239 
       
   240 #endif // C_ALFTEXTSTYLEMANAGER_H