os/textandloc/textrendering/textformatting/tbox/FRMDRAW.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "FRMTLAY.H"
sl@0
    20
#include "FRMCONST.H"
sl@0
    21
sl@0
    22
/** Default C++ constructor.
sl@0
    23
sl@0
    24
This constructs a fully initialized TDrawTextLayoutContext object. Its view
sl@0
    25
rectangle, iLabelMarginWidth and iGutterMarginWidth and iTextStartX are all
sl@0
    26
initialized to zero, the background colour is initialized to the default system
sl@0
    27
background colour, text and graphics are set to be drawn and clipping is set.
sl@0
    28
The graphics context is initialised to null. */
sl@0
    29
EXPORT_C TDrawTextLayoutContext::TDrawTextLayoutContext():
sl@0
    30
	iLabelMarginWidth(0),
sl@0
    31
	iGutterMarginWidth(0),
sl@0
    32
	iTextStartX(0),
sl@0
    33
	iBackgroundColor(TLogicalRgb::ESystemBackgroundColor),
sl@0
    34
	iGc(NULL),
sl@0
    35
	iPictureGc(NULL),
sl@0
    36
	iOverrideTextColor(TLogicalRgb::ESystemForegroundColor),
sl@0
    37
	iDrawMode(EFDrawText | EFDrawGraphics | EFUseClippingRect)
sl@0
    38
	{
sl@0
    39
	}
sl@0
    40
sl@0
    41
/** Sets the graphics context for drawing text and pictures.
sl@0
    42
@param aGc Pointer to the graphics context for drawing text and pictures.
sl@0
    43
@param aPictureGc This argument is not used - all drawing is done using aGc. */
sl@0
    44
EXPORT_C void TDrawTextLayoutContext::SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc/*=NULL*/)
sl@0
    45
	{
sl@0
    46
	iGc=aGc;
sl@0
    47
	iPictureGc=aPictureGc;
sl@0
    48
	iDrawMode&=EFAllFlags-EFUseGcClear;
sl@0
    49
	iDrawMode&=EFAllFlags-EFUseWindowGc;
sl@0
    50
	};
sl@0
    51
sl@0
    52
EXPORT_C void TDrawTextLayoutContext::SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc/*=NULL*/)
sl@0
    53
	{
sl@0
    54
	iGc=aGc;
sl@0
    55
	iPictureGc=aPictureGc;
sl@0
    56
	iDrawMode|=EFUseGcClear;
sl@0
    57
	iDrawMode&=EFAllFlags-EFUseWindowGc;
sl@0
    58
	};
sl@0
    59
sl@0
    60
EXPORT_C void TDrawTextLayoutContext::SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc/*=NULL*/)
sl@0
    61
	{
sl@0
    62
	iGc=aGc;
sl@0
    63
	iPictureGc=aPictureGc;
sl@0
    64
	iDrawMode|=EFUseGcClear;
sl@0
    65
	iDrawMode|=EFUseWindowGc;
sl@0
    66
	iDrawMode|=EFUseClippingRect;
sl@0
    67
	};
sl@0
    68
sl@0
    69
/** Sets whether the background colour as specified by iBackgroundColor should
sl@0
    70
be drawn.
sl@0
    71
@param aDrawToEveryPixel Specify ETrue to draw the background colour, EFalse to
sl@0
    72
draw no background colour. */
sl@0
    73
EXPORT_C void TDrawTextLayoutContext::SetDrawToEveryPixel(TBool aDrawToEveryPixel)
sl@0
    74
	{
sl@0
    75
	if (aDrawToEveryPixel)
sl@0
    76
		iDrawMode|=EFUseBackgroundColor;
sl@0
    77
	else
sl@0
    78
		iDrawMode&=EFAllFlags-EFUseBackgroundColor;
sl@0
    79
	}
sl@0
    80
sl@0
    81
/** Overrides the existing text colour, so that when redrawn, all text has the
sl@0
    82
colour specified, rather than the colour which is set in the text object. To
sl@0
    83
return the text to its original colour, call this function again with an
sl@0
    84
argument of null.
sl@0
    85
@param aOverrideColor If not NULL, overrides the text colour. */
sl@0
    86
EXPORT_C void TDrawTextLayoutContext::SetTextColorOverride(const TRgb *aOverrideColor)
sl@0
    87
	{
sl@0
    88
	if (aOverrideColor)
sl@0
    89
		{
sl@0
    90
		iDrawMode|=EFUseOverrideTextColor;
sl@0
    91
		iOverrideTextColor=*aOverrideColor;
sl@0
    92
		}
sl@0
    93
	else
sl@0
    94
		iDrawMode&=EFAllFlags-EFUseOverrideTextColor;
sl@0
    95
	}
sl@0
    96
sl@0
    97
/** This function is obsolete. When a text object is drawn, all parts of it are
sl@0
    98
drawn. */
sl@0
    99
EXPORT_C void TDrawTextLayoutContext::SetDrawTextOnly()
sl@0
   100
	{
sl@0
   101
	iDrawMode|=EFDrawText;
sl@0
   102
	iDrawMode&=EFAllFlags-EFDrawGraphics;
sl@0
   103
	}
sl@0
   104
sl@0
   105
/** This function is obsolete. When a text object is drawn, all parts of it are
sl@0
   106
drawn. */
sl@0
   107
EXPORT_C void TDrawTextLayoutContext::SetDrawGraphicsOnly()
sl@0
   108
	{
sl@0
   109
	iDrawMode|=EFDrawGraphics;
sl@0
   110
	iDrawMode&=EFAllFlags-EFDrawText;
sl@0
   111
	}
sl@0
   112
sl@0
   113
/** This function is obsolete. When a text object is drawn, all parts of it are
sl@0
   114
drawn. */
sl@0
   115
EXPORT_C void TDrawTextLayoutContext::SetDrawTextAndGraphics()
sl@0
   116
	{
sl@0
   117
	iDrawMode|=EFDrawGraphics;
sl@0
   118
	iDrawMode|=EFDrawText;
sl@0
   119
	}
sl@0
   120
sl@0
   121
/** Sets whether drawing should be clipped to the intersection of the draw
sl@0
   122
rectangle (the aDrawRect parameter passed to CTextLayout::DrawL() or
sl@0
   123
InvertRangeL()) and the text area.
sl@0
   124
@param aClipping True to clip drawing to the clip rectangle. False to ignore
sl@0
   125
the clip rectangle. */
sl@0
   126
EXPORT_C void TDrawTextLayoutContext::SetClipping(TBool aClipping)
sl@0
   127
	{
sl@0
   128
	if (aClipping)
sl@0
   129
		iDrawMode|=EFUseClippingRect;
sl@0
   130
	else
sl@0
   131
		{
sl@0
   132
		iDrawMode&=EFAllFlags-EFUseClippingRect;
sl@0
   133
		}
sl@0
   134
	}
sl@0
   135
	
sl@0
   136
/** Sets the horizontal extent of a paragraph to be filled with paragraph fill
sl@0
   137
colour.
sl@0
   138
@deprecated 7.0
sl@0
   139
@param aFillTextOnly If true, the region filled with paragraph fill colour is
sl@0
   140
the area within the paragraph only. If false, the left text margin, if present,
sl@0
   141
is also filled. */
sl@0
   142
EXPORT_C void TDrawTextLayoutContext::SetParagraphFillTextOnly(TBool aFillTextOnly)
sl@0
   143
	{
sl@0
   144
	if (aFillTextOnly)
sl@0
   145
		iDrawMode|=EFParagraphFillTextOnly;
sl@0
   146
	else
sl@0
   147
 		iDrawMode&=EFAllFlags-EFParagraphFillTextOnly;
sl@0
   148
	}
sl@0
   149
sl@0
   150
/** If the text colour is overridden, this function gets the text override
sl@0
   151
colour, as set by SetTextColorOverride().
sl@0
   152
@return Text override colour. NULL if no text override colour is in use. */
sl@0
   153
EXPORT_C const TRgb* TDrawTextLayoutContext::TextOverrideColor() const 
sl@0
   154
	{
sl@0
   155
	return (iDrawMode&EFUseOverrideTextColor) ? &iOverrideTextColor : NULL;
sl@0
   156
	}
sl@0
   157
sl@0
   158
/** Gets the graphics context for drawing the text and pictures.
sl@0
   159
@return The graphics context. */
sl@0
   160
EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PrimaryGc() const
sl@0
   161
	{
sl@0
   162
	return iGc;
sl@0
   163
	}
sl@0
   164
sl@0
   165
EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PictureGc() const 
sl@0
   166
	{
sl@0
   167
	return iPictureGc;
sl@0
   168
	}
sl@0
   169
sl@0
   170
/** Tests whether clipping is set to the intersection of the draw rectangle,
sl@0
   171
(the aDrawRect parameter passed to CTextLayout::DrawL() or InvertRangeL()) and
sl@0
   172
the text area.
sl@0
   173
@return True if clipping set to clip rectangle, false if not. */
sl@0
   174
EXPORT_C TBool TDrawTextLayoutContext::UseClippingRect() const 
sl@0
   175
	{
sl@0
   176
	return iDrawMode&EFUseClippingRect;
sl@0
   177
	}
sl@0
   178
sl@0
   179
/** Tests if the graphics context for drawing is either CWindowGc
sl@0
   180
or CBitmapContext.
sl@0
   181
sl@0
   182
@return True if the graphics context is either CWindowGc or CBitmapContext.
sl@0
   183
        False otherwise. */
sl@0
   184
EXPORT_C TBool TDrawTextLayoutContext::UseGcClear() const
sl@0
   185
	{
sl@0
   186
	return iDrawMode&EFUseGcClear;
sl@0
   187
	}
sl@0
   188
sl@0
   189
/** Obsolete function. When a text object is drawn, all parts of it are drawn. */
sl@0
   190
EXPORT_C TBool TDrawTextLayoutContext::DrawText() const
sl@0
   191
	{
sl@0
   192
	return iDrawMode&EFDrawText;
sl@0
   193
	}
sl@0
   194
sl@0
   195
/** Obsolete function. When a text object is drawn, all parts of it are drawn.
sl@0
   196
*/
sl@0
   197
EXPORT_C TBool TDrawTextLayoutContext::DrawGraphics() const
sl@0
   198
	{
sl@0
   199
	return iDrawMode&EFDrawGraphics;
sl@0
   200
	}
sl@0
   201
sl@0
   202
/** Tests whether the background colour is used, as set by
sl@0
   203
SetDrawToEveryPixel().
sl@0
   204
@return True if the background colour is used. False if not. */
sl@0
   205
EXPORT_C TBool TDrawTextLayoutContext::UseBackgroundColor() const
sl@0
   206
	{
sl@0
   207
	return iDrawMode&EFUseBackgroundColor;
sl@0
   208
	}
sl@0
   209
sl@0
   210
/** Tests whether the region filled with paragraph fill colour is the area
sl@0
   211
within the paragraph only, or also the area within the left text margin.
sl@0
   212
@deprecated 7.0
sl@0
   213
@return If true, the region filled with paragraph fill colour is the area
sl@0
   214
within the paragraph only. If false, the left text margin, if present, is also
sl@0
   215
filled. */
sl@0
   216
EXPORT_C TBool TDrawTextLayoutContext::ParagraphFillTextOnly() const
sl@0
   217
	{
sl@0
   218
	return iDrawMode&EFParagraphFillTextOnly;
sl@0
   219
	}
sl@0
   220
sl@0
   221
/** Gets the text area. The text area is the view rectangle minus the label and
sl@0
   222
gutter margins.
sl@0
   223
@return The text area. */
sl@0
   224
EXPORT_C TRect TDrawTextLayoutContext::TextArea() const
sl@0
   225
	{
sl@0
   226
	TRect area(iViewRect);
sl@0
   227
	area.iTl.iX+=iLabelMarginWidth+iGutterMarginWidth;
sl@0
   228
	return area;
sl@0
   229
	}
sl@0
   230
sl@0
   231
/** Gets the display height in pixels. The display height is the same as the
sl@0
   232
view rectangle height.
sl@0
   233
@return The display height. */
sl@0
   234
EXPORT_C TInt TDrawTextLayoutContext::DisplayHeight() const
sl@0
   235
	{
sl@0
   236
	return iViewRect.Height();
sl@0
   237
	}
sl@0
   238
sl@0
   239
/** Gets the (window) coordinates of the top left hand corner of the text area.
sl@0
   240
@return The top left hand corner of the text area. */
sl@0
   241
EXPORT_C TPoint TDrawTextLayoutContext::TopLeftTextArea() const
sl@0
   242
	{
sl@0
   243
	return TextArea().iTl;
sl@0
   244
	}
sl@0
   245
sl@0
   246
/** Gets the area occupied by the label and gutter margins.
sl@0
   247
@return Rectangle representing the label and gutter margins. */
sl@0
   248
EXPORT_C TRect TDrawTextLayoutContext::TotalMargin() const
sl@0
   249
	{
sl@0
   250
	TRect area(iViewRect);
sl@0
   251
	area.iBr.iX=area.iTl.iX+iLabelMarginWidth+iGutterMarginWidth;
sl@0
   252
	return area;
sl@0
   253
	}
sl@0
   254
sl@0
   255
/** Gets the area occupied by the label margin.
sl@0
   256
@return Rectangle representing the label margin. */
sl@0
   257
EXPORT_C TRect TDrawTextLayoutContext::LabelMargin() const
sl@0
   258
	{
sl@0
   259
	TRect margin(iViewRect);
sl@0
   260
	margin.iBr.iX=margin.iTl.iX+iLabelMarginWidth;
sl@0
   261
	return margin;
sl@0
   262
	}
sl@0
   263
sl@0
   264
/** Tests whether a label margin has been set.
sl@0
   265
@return True if a label margin has been set. False if not. */
sl@0
   266
EXPORT_C TBool TDrawTextLayoutContext::IsLabelMargin() const
sl@0
   267
	{
sl@0
   268
	return iGutterMarginWidth > 0;
sl@0
   269
	}
sl@0
   270
sl@0
   271
/** Gets the area occupied by the gutter margin.
sl@0
   272
@return Rectangle representing the gutter margin. */
sl@0
   273
EXPORT_C TRect TDrawTextLayoutContext::GutterMargin() const
sl@0
   274
	{
sl@0
   275
	TRect margin(iViewRect);
sl@0
   276
	margin.iTl.iX+=iLabelMarginWidth;
sl@0
   277
	margin.iBr.iX=margin.iTl.iX+iGutterMarginWidth;
sl@0
   278
	return margin;
sl@0
   279
	}
sl@0
   280
sl@0
   281
/** This function is identical to IsLabelMargin().
sl@0
   282
@return True if a label margin has been set, false if not. */
sl@0
   283
EXPORT_C TBool TDrawTextLayoutContext::IsGutterMargin() const
sl@0
   284
	{
sl@0
   285
	return iGutterMarginWidth > 0; 
sl@0
   286
	}
sl@0
   287
sl@0
   288
/** Gets the window coordinates of the top left hand corner at which text may
sl@0
   289
be drawn. This point has the same vertical coordinate as the top of the text
sl@0
   290
area, but its horizontal coordinate is increased by the left text margin width
sl@0
   291
(iTextStartX). This point is the origin for layout coordinates.
sl@0
   292
sl@0
   293
@return The coordinates of the top left hand point at which text can be drawn.
sl@0
   294
*/
sl@0
   295
EXPORT_C TPoint TDrawTextLayoutContext::TopLeftText() const
sl@0
   296
	{
sl@0
   297
	return TopLeftTextArea()+TPoint(iTextStartX,0);
sl@0
   298
	}
sl@0
   299
sl@0
   300
/** Converts a point in window coordinates to layout coordinates. Window
sl@0
   301
coordinates have their origin at the top left corner of the view window. Layout
sl@0
   302
coordinates have their origin at the top left corner of the area within the
sl@0
   303
view rectangle in which text can appear, (this value is returned by
sl@0
   304
TopLeftText()).
sl@0
   305
@param aWinPos Point in window coordinates. On return, set to layout
sl@0
   306
coordinates. */
sl@0
   307
EXPORT_C void TDrawTextLayoutContext::WindowToText(TPoint& aWinPos) const
sl@0
   308
	{
sl@0
   309
	aWinPos-=TopLeftText();
sl@0
   310
	}
sl@0
   311
sl@0
   312
/** Converts a rectangle in window coordinates to layout coordinates. Window
sl@0
   313
coordinates have their origin at the top left corner of the view window. Layout
sl@0
   314
coordinates have their origin at the top left corner of the area within the
sl@0
   315
view rectangle in which text can appear, (this value is returned by
sl@0
   316
TopLeftText()).
sl@0
   317
@param aRect Rectangle in window coordinates. On return, set to layout
sl@0
   318
coordinates. */
sl@0
   319
EXPORT_C void TDrawTextLayoutContext::WindowToText(TRect& aRect) const
sl@0
   320
	{
sl@0
   321
	aRect.Move(TPoint(0,0)-TopLeftText());
sl@0
   322
	}
sl@0
   323
sl@0
   324
/** Converts a point in layout coordinates to window coordinates.
sl@0
   325
@param aTextAreaPos A point in layout coordinates. On return, set to window
sl@0
   326
coordinates. */
sl@0
   327
EXPORT_C void TDrawTextLayoutContext::TextToWindow(TPoint& aTextAreaPos) const
sl@0
   328
	{
sl@0
   329
	aTextAreaPos+=TopLeftText();
sl@0
   330
	}
sl@0
   331
sl@0
   332
/** Converts a rectangle in layout coordinates to window coordinates.
sl@0
   333
@param aRect Rectangle in layout coordinates. On return, set to window
sl@0
   334
coordinates. */
sl@0
   335
EXPORT_C void TDrawTextLayoutContext::TextToWindow(TRect& aRect) const
sl@0
   336
	{
sl@0
   337
	aRect.Move(TopLeftText());
sl@0
   338
	}
sl@0
   339
sl@0
   340
/** Tests if a CWindowGc is being used. */
sl@0
   341
TBool TDrawTextLayoutContext::UseWindowGc() const
sl@0
   342
	{
sl@0
   343
	return iDrawMode & EFUseWindowGc;
sl@0
   344
	}
sl@0
   345
sl@0
   346
/** Returns the current drawing mode flags. */
sl@0
   347
void TDrawTextLayoutContext::SetDrawMode(TUint aDrawMode)
sl@0
   348
	{
sl@0
   349
	iDrawMode = aDrawMode;
sl@0
   350
	}
sl@0
   351
sl@0
   352
/** Returns the flags that identify the current drawing mode. */
sl@0
   353
TUint TDrawTextLayoutContext::DrawMode() const
sl@0
   354
	{
sl@0
   355
	return iDrawMode;
sl@0
   356
	}