epoc32/include/mw/coetextdrawer.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __COETEXTDRAWER_H__
    17 #define __COETEXTDRAWER_H__
    18 
    19 #include <gulutil.h>	 
    20 #include <gulalign.h>	 
    21 #include <biditext.h>
    22 #include <coemop.h>
    23 
    24 //
    25 // TEXT DRAWER CODE
    26 //
    27 
    28 // forward declarations
    29 class CCoeTextDrawerBase;
    30 class TCoeTextTypeAdaptor;
    31 
    32 /**
    33 This class serves as a smart-pointer handle to a CCoeTextDrawerBase-derived object, used for drawing
    34 user interface text. Through the use of the CCoeControl's TextDrawer() and GetTextDrawer() methods, a
    35 container control can control the text style and color used by its child controls. For example, a button
    36 class can override its GetTextDrawer() method to set the text color used by its text label child control 
    37 depending on the buttons state (e.g. unpressed, pressed, or dimmed).
    38 
    39 The XCoeTextDrawer object manages the life of the heap allocated CCoeTextDrawerBase (deleting it or 
    40 resetting it depending on whether the object is reusable or not).
    41 
    42 XCoeTextDrawer objects shall be allocated on the stack in the control's Draw() method and initialized 
    43 with a heap allocated CCoeTextDrawerBase object fetched from the control's skin, or from its parent or 
    44 background through the CCoeControl::TextDrawer() method. 
    45 
    46 Never create a CCoeTextDrawer-derived object inside your CCoeControl::Draw() method, as this is not 
    47 guaranteed to work in low-memory situations. Non-reusable text drawers must only be created in your
    48 control's GetTextDrawer() method, as this provides error handling in case the text drawer could not be 
    49 created.
    50 
    51 Hence, typical use from inside a CCoeControl's Draw() method:
    52 <code>
    53 XCoeTextDrawer textDrawer(TextDrawer());
    54 textDrawer.SetAlignment(EHLeftVCenter);
    55 textDrawer.SetMargins(iTextMargins);
    56 textDrawer.DrawText(SystemGc(), *iText, iTextRect, ScreenFont(TCoeFont::NormalFont()));
    57 </code>
    58 
    59 @publishedAll
    60 @released
    61 */
    62 class XCoeTextDrawer
    63 	{
    64 public:
    65 	IMPORT_C XCoeTextDrawer(CCoeTextDrawerBase& aTextDrawer);
    66 	IMPORT_C ~XCoeTextDrawer();
    67 	
    68 	IMPORT_C void operator=(CCoeTextDrawerBase& aTextDrawer);
    69 
    70 	IMPORT_C void DrawText(CGraphicsContext& aGc, const TBidiText& aText, const TRect& aTextRect, const CFont& aFont) const;
    71 	IMPORT_C void DrawDisplayOrderedText(CGraphicsContext& aGc, const TDesC& aText, const TRect& aTextRect, const CFont& aFont) const;
    72 	
    73 	IMPORT_C void DrawTextVertical(CGraphicsContext& aGc, const TBidiText& aText, const TRect& aTextRect, const CFont& aFont, TBool aUp = ETrue) const;
    74 	IMPORT_C void DrawDisplayOrderedTextVertical(CGraphicsContext& aGc, const TDesC& aText, const TRect& aTextRect, const CFont& aFont, TBool aUp = ETrue) const;
    75 	
    76 	IMPORT_C TRect ClipRect() const;
    77 	IMPORT_C void SetClipRect(const TRect& aClipRect);
    78 
    79 	inline TRgb TextColor() const;
    80 	inline void SetTextColor(TRgb aColor);
    81 	
    82 	inline TGulAlignment Alignment() const;
    83 	inline void SetAlignment(const TGulAlignment& aAlignment);
    84 	
    85 	inline TMargins8 Margins() const;
    86 	inline void SetMargins(const TMargins8& aMargins);
    87 	
    88 	inline TInt LineGapInPixels() const;
    89 	inline void SetLineGapInPixels(TInt aLineGapInPixels);	
    90 public: 
    91 	IMPORT_C CCoeTextDrawerBase *operator ->();		// deprecated	
    92 private:
    93 	XCoeTextDrawer(const XCoeTextDrawer& aTextDrawer);  
    94 private:	
    95 	CCoeTextDrawerBase* iTextDrawer;
    96 	TRect iClipRect;
    97 	};
    98 
    99 
   100 // forward declaration
   101 class CCoeTextDrawerBaseExt;
   102 
   103 /**
   104 This is the base class for all text drawers implementing different text effects (for example 
   105 shadow or glowing/outlined text). The object can be created and deleted each time it's used, 
   106 or Reset() and reused if it IsReusable(). The latter is recommended.
   107 
   108 Note that the pure virtual DrawText() method is private. This ensures that the object is used 
   109 through the XCoeTextDrawer class (which manages its life). 
   110 
   111 Note also that the accessor and set methods should be used via the owning XCoeTextDrawer object,
   112 and that the MObjectProvider mechanism can be used to identify the actual text drawer implementation.
   113 
   114 @publishedAll
   115 @released
   116 */
   117 class CCoeTextDrawerBase : public CBase, public MObjectProvider
   118 	{
   119 	friend class XCoeTextDrawer;   
   120 public:
   121 	IMPORT_C ~CCoeTextDrawerBase();
   122 	IMPORT_C virtual void Reset();
   123 
   124 	/**
   125 	This method returns the main color used by the CCoeTextDrawer to draw text.
   126 	@return The color used to draw text.
   127 	*/
   128 	virtual TRgb TextColor() const = 0;
   129 	/**
   130 	This method sets the main color to use to draw text.
   131 	@param aColor The color to use to draw text.
   132 	*/
   133 	virtual void SetTextColor(TRgb aColor) = 0;
   134  
   135 	IMPORT_C TGulAlignment Alignment() const;
   136 	IMPORT_C void SetAlignment(const TGulAlignment& aAlignment);
   137 	
   138 	IMPORT_C TMargins8 Margins() const;
   139 	IMPORT_C void SetMargins(const TMargins8& aMargins);
   140 	
   141 	IMPORT_C TInt LineGapInPixels() const;
   142 	IMPORT_C void SetLineGapInPixels(TInt aLineGapInPixels);
   143 public:	// public methods only for use by the owner/creator of the CCoeTextDrawerBase-derived object
   144  	IMPORT_C TBool IsReusable() const;
   145 	IMPORT_C void SetReusable(TBool aIsReusable);
   146 	
   147 	IMPORT_C void SetAppLanguage(TLanguage aAppLang);
   148 protected:
   149  	IMPORT_C CCoeTextDrawerBase();
   150 	IMPORT_C TInt Construct();
   151 	IMPORT_C TGulHAlignment ActualHorizontalAlignment(const TCoeTextTypeAdaptor& aText) const;
   152 private:  
   153 	/**
   154 	Any actual text drawer must implement this method to draw the text passed as argument.
   155 	The implementation must draw the text inside the text rectangle, cropped to the clipping
   156 	rectangle, and with the given margins and alignment taken into account.
   157 	
   158 	Note that the actual horizontal alignment shall depend on the script directionality. 
   159 	Calling	ActualHorizontalAlignment() will return the horizontal alignment where left and 
   160 	right has been swapped for right-to-left scripts.
   161 	*/
   162 	virtual void DrawText(CGraphicsContext& aGc, const TCoeTextTypeAdaptor& aText, const CFont& aFont, 
   163 							const TRect& aTextRect, const TRect& aClipRect) const = 0;
   164 public:
   165 	IMPORT_C virtual TMargins8 EffectMargins();
   166 private:
   167 	/**
   168 	Draws the text vertically inside the text rectangle, cropped to the clipping
   169 	rectangle, and with the given margins and alignment taken into account.
   170 	If aUp is ETrue, text is rotated 90 degrees anti-clockwise; EFalse, text is rotated 90 degrees clockwise.
   171 	
   172 	Note that the actual horizontal alignment shall depend on the script directionality. 
   173 	Calling	ActualHorizontalAlignment() will return the horizontal alignment where left and 
   174 	right has been swapped for right-to-left scripts.
   175 	Also note that the margines are relative to the orientation of the text.
   176 	*/
   177 	IMPORT_C virtual void DrawTextVertical(CGraphicsContext& aGc, const TCoeTextTypeAdaptor& aText, const CFont& aFont, 
   178 							const TRect& aTextRect, const TRect& aClipRect, TBool aUp) const;
   179 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved3();
   180 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved4();
   181 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved5();
   182 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved6();
   183 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved7();
   184 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved8();
   185 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved9();
   186 	IMPORT_C virtual void CCoeTextDrawerBase_Reserved10();
   187  private:
   188 	TBool iIsReusable;	 
   189 	TGulAlignment iAlignment;
   190 	TMargins8 iMargins;
   191 	TInt iLineGap;
   192 	CCoeTextDrawerBaseExt* iExtension;
   193 	};
   194 
   195 
   196 /**
   197 This class allows the XCoeTextDrawer to draw text that is in the form of a TBidiText 
   198 object as well as pre-reordered new-line separated plain text descriptors. (The descriptor 
   199 text is especially useful when using the XCoeTextDrawer together with the FORM component). 
   200 
   201 This removes the need to implement two versions of the DrawText() method.
   202 
   203 @publishedAll
   204 @released
   205 */
   206 class TCoeTextTypeAdaptor
   207 	{
   208 public:
   209 	IMPORT_C TCoeTextTypeAdaptor(const TDesC& aText);		// text lines separated with '\n'
   210 	IMPORT_C TCoeTextTypeAdaptor(const TBidiText& aText);	// TBidiText object
   211 	IMPORT_C TInt NumberOfLines() const;
   212 	IMPORT_C TPtrC LineOfText(TInt aLineNumber, TInt& aWidthInPixels, const CFont& aFont) const;	
   213 	IMPORT_C TBool HasRightToLeftDirectionality() const;
   214 private:
   215 	enum TTextType
   216 		{
   217 		ENewlineSeparated,
   218 		EBidiText
   219 		};
   220 	const TAny* iText;
   221 	TTextType iTextType;
   222 	};
   223 
   224 
   225 /**	
   226 This is a basic text drawer without any text effects. The default text drawer that can be 
   227 used if no other (device specific) text drawers has been added to the system. 
   228 
   229 @publishedAll
   230 @released
   231 */
   232 class CCoePlainTextDrawer : public CCoeTextDrawerBase
   233 	{
   234 public:
   235 	DECLARE_TYPE_ID(0x1020831A)
   236 public:
   237 	IMPORT_C static CCoePlainTextDrawer* New(TRgb aTextColor);
   238 	
   239 	IMPORT_C TRgb TextColor() const;
   240 	IMPORT_C void SetTextColor(TRgb aTextColor);
   241 protected: // from MObjectProvider
   242 	IMPORT_C virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
   243 private:  
   244 	void DrawText(CGraphicsContext& aGc, const TCoeTextTypeAdaptor& aText, const CFont& aFont, 
   245 					const TRect& aTextRect, const TRect& aClipRect) const;
   246 	void Reset();	
   247 	CCoePlainTextDrawer(TRgb aTextColor);
   248 	TInt Construct();	//lint !e1511 Suppress member hides non-virtual member
   249 private:	
   250 	TRgb iTextColor;
   251 	};
   252 	
   253 
   254 
   255 // Inlines		
   256 
   257 /**
   258 This method returns the main color used by by DrawText() and DrawDisplayOrderedText().
   259 @return The color used to draw text.
   260 */
   261 TRgb XCoeTextDrawer::TextColor() const
   262 	{ return iTextDrawer->TextColor(); }
   263 	
   264 /**
   265 This method sets the main color to use by DrawText() and DrawDisplayOrderedText() to draw text.
   266 @param aColor The color to use to draw text.
   267 */
   268 void XCoeTextDrawer::SetTextColor(TRgb aColor)
   269 	{ iTextDrawer->SetTextColor(aColor); }
   270 
   271 /**
   272 Returns the text alignment that will be used by DrawText() and DrawDisplayOrderedText().
   273 Note that left and right alignment will be swapped for right-to-left scripts, unless
   274 the alignment has been set to be absolute (see TGulAlignment).
   275 
   276 @return TGulAlignment value of iAlignment data member
   277 */
   278 TGulAlignment XCoeTextDrawer::Alignment() const
   279 	{ return iTextDrawer->Alignment(); }
   280 
   281 /**
   282 Set the text alignment that will be used by DrawText() and DrawDisplayOrderedText().
   283 Note that left and right alignment will be swapped for right-to-left scripts, unless
   284 the alignment has been set to be absolute (see TGulAlignment).
   285 
   286 @param aAlignment TGulAlignment value.  
   287 */		
   288 void XCoeTextDrawer::SetAlignment(const TGulAlignment& aAlignment)
   289 	{ iTextDrawer->SetAlignment(aAlignment); }
   290 
   291 /**
   292 Returns the text margins that will be used by DrawText() and DrawDisplayOrderedText().
   293 Note that text effects may intrude on the margin.
   294 
   295 @return The margins between the text rect and the actual text, in pixels.
   296 */	
   297 TMargins8 XCoeTextDrawer::Margins() const
   298 	{ return iTextDrawer->Margins(); }
   299 
   300 /**
   301 Set the text margins that will be used by DrawText() and DrawDisplayOrderedText().
   302 Note that text effects may intrude on the margin, and that margins are always relative to the text orientation. 
   303 
   304 @param aMargins The margins between the text rect and the actual text, in pixels.
   305 */		
   306 void XCoeTextDrawer::SetMargins(const TMargins8& aMargins)
   307 	{ iTextDrawer->SetMargins(aMargins); }
   308 	
   309 /**
   310 Returns the gap (in pixels) between lines of text. Default gap is 1 (one) pixel.
   311 @return The gap between lines of text, in pixels.
   312 */	
   313 TInt XCoeTextDrawer::LineGapInPixels() const
   314 	{ return iTextDrawer->LineGapInPixels(); }
   315 	
   316 /**
   317 Set the gap (in pixels) between lines of text. Default gap is 1 (one) pixel.
   318 @param aLineGapInPixels The gap between lines of text, in pixels.
   319 */			
   320 void XCoeTextDrawer::SetLineGapInPixels(TInt aLineGapInPixels)
   321 	{ iTextDrawer->SetLineGapInPixels(aLineGapInPixels); }
   322 
   323 		
   324 #endif	// __COETEXTDRAWER_H__