emailuis/uicomponents/inc/fstextstylemanager.h
branchRCL_3
changeset 25 3533d4323edc
parent 0 8466d47a6819
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007-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:  This component converts CRichText style's to HuiTextStyle
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_FSTEXTSTYLEMANAGER_H
       
    20 #define C_FSTEXTSTYLEMANAGER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <txtfrmat.h>
       
    24 
       
    25 class CAlfTextStyleManager;
       
    26 
       
    27 /**
       
    28  *  TFsTextStyleData
       
    29  *   
       
    30  *  This class is meant only for internal use of CFsTextStyleManager. It
       
    31  *  encapsulates the style information for storage.
       
    32  *
       
    33  *  @since S60 v3.2
       
    34  */
       
    35 
       
    36 class TFsTextStyleData
       
    37 {
       
    38 public:
       
    39 	TFsTextStyleData( const TCharFormat& aCharFormat, TInt aTextStyleID );
       
    40 
       
    41     /**
       
    42      * Match
       
    43      *
       
    44      * Method for comparing to instances of TFsTextStyleData
       
    45      * 
       
    46      * @since S60 3.2
       
    47      * @param aFirst The first TFsTextStyleData
       
    48      * @param aSecond The other TFsTextStyleData
       
    49      * @return If match ETrue else EFalse
       
    50      */	
       
    51 	static TBool Match( const TFsTextStyleData& aFirst, 
       
    52 			const TFsTextStyleData& aSecond );
       
    53 			
       
    54 	static TBool MatchId( const TFsTextStyleData& aFirst, 
       
    55 			const TFsTextStyleData& aSecond );
       
    56 
       
    57 public: //Data
       
    58 
       
    59 	/**
       
    60 	 * Stored TCharFormat
       
    61 	 */
       
    62 	const TCharFormat iCharFormat;
       
    63 
       
    64     /**
       
    65      * Stored THuiTextStyle id
       
    66      */
       
    67 	TInt iTextStyleID;
       
    68 };
       
    69 
       
    70 
       
    71 /**
       
    72  *  CFsTextStyleManager
       
    73  *   
       
    74  *  This class is designed to convert CRichText style definitions to
       
    75  *  THuiTextStyles. To avoid overlapping style definitions, all previously
       
    76  *  created styles are stored in a list.
       
    77  *
       
    78  *  Example:
       
    79  *  @code
       
    80  *
       
    81  *  manager = CFsTextStyleManager::NewL( Env().TextStyleManager() );
       
    82  *  rText.GetChars( someText, charFormat, position ); //CRichText
       
    83  *  TInt styleID = manager->GetStyleIDL( charFormat );
       
    84  *  visual = CHuiTextVisual::AddNewL( *iControl, iCurveLayout );
       
    85  *  visual->SetTextStyle( styleID );
       
    86  *  
       
    87  *  @endcode
       
    88  *
       
    89  *  @since S60 v3.2
       
    90  */
       
    91 class CFsTextStyleManager : CBase
       
    92     {
       
    93 public:
       
    94 
       
    95 	/**
       
    96 	 * Two-phased constructor.
       
    97 	 * @param aHuiTextStyleManager Reference to the CHuiTextStyleManager
       
    98 	 */
       
    99      static CFsTextStyleManager* NewL( CAlfTextStyleManager& aAlfTextStyleManager );
       
   100 
       
   101      /**
       
   102       * Destructor.
       
   103       */
       
   104      ~CFsTextStyleManager();
       
   105 
       
   106      /**
       
   107       * GetStyleIDL
       
   108       * 
       
   109       * This is the only public method in CFsTextStyleManager. If there
       
   110       * already a style that matches the given TCharFormat, the ID of this
       
   111       * style is returned. If not, a new style is created.
       
   112       *
       
   113       * @since S60 3.2
       
   114       * @param aCharFormat Style format from CRichText
       
   115       * @return ID for THuiTextStyle
       
   116       */
       
   117      TInt GetStyleIDL( const TCharFormat& aCharFormat );
       
   118      
       
   119      /**
       
   120       * FindId
       
   121       * 
       
   122       * The array of previously created styles is searched for matching
       
   123       * TCharFormat. If not found KErrNotFound is returned.
       
   124       *
       
   125       * @since S60 3.2
       
   126       * @param aCharFormat Style format from CRichText
       
   127       * @return ID for THuiTextStyle or KErrNotFound
       
   128       */
       
   129      TInt GetStyleIDWithOpositeUnderlineL( TInt aId );
       
   130 
       
   131 private:
       
   132 
       
   133 		CFsTextStyleManager( CAlfTextStyleManager& aAlfTextStyleManager );
       
   134 		
       
   135 		// void ConstructL(); This wasn't needed at the time 
       
   136 		
       
   137 	     /**
       
   138 	      * FindId
       
   139 	      * 
       
   140 	      * The array of previously created styles is searched for matching
       
   141 	      * TCharFormat. If not found KErrNotFound is returned.
       
   142 	      *
       
   143 	      * @since S60 3.2
       
   144 	      * @param aCharFormat Style format from CRichText
       
   145 	      * @return ID for THuiTextStyle or KErrNotFound
       
   146 	      */
       
   147         TInt FindId( const TCharFormat& aCharFormat );
       
   148         
       
   149         
       
   150         /**
       
   151 	      * FindPositionOfId
       
   152 	      * 
       
   153 	      * The array of previously created styles is searched for matching
       
   154 	      * ID. If not found KErrNotFound is returned.
       
   155 	      *
       
   156 	      * @since S60 3.2
       
   157 	      * @param ID Style format from CRichText
       
   158 	      * @return position in table for THuiTextStyle or KErrNotFound
       
   159 	      */
       
   160         TInt FindPositionOfId(TInt aId);
       
   161 
       
   162 	     /**
       
   163 	      * CreateNewTextStyleL
       
   164 	      * 
       
   165 	      * Creates a new text style using TCharFormat.
       
   166 	      *
       
   167 	      * @since S60 3.2
       
   168 	      * @param aCharFormat Style format from CRichText
       
   169 	      * @return ID for THuiTextStyle
       
   170 	      */
       
   171         TInt CreateNewTextStyleL( const TCharFormat& aCharFormat );
       
   172 
       
   173 private: // data
       
   174 
       
   175     /**
       
   176      * Reference to the CHuiTextStyleManager
       
   177      */
       
   178     CAlfTextStyleManager& iAlfTextStyleManager;
       
   179 
       
   180     /**
       
   181      * Array of previously created styles
       
   182      */
       
   183     RArray<TFsTextStyleData> iStyles;
       
   184 
       
   185     };
       
   186 
       
   187 #endif // C_FSTEXTSTYLEMANAGER_H