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