First public contribution.
2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 /** Default C++ constructor.
24 This constructs a fully initialized TDrawTextLayoutContext object. Its view
25 rectangle, iLabelMarginWidth and iGutterMarginWidth and iTextStartX are all
26 initialized to zero, the background colour is initialized to the default system
27 background colour, text and graphics are set to be drawn and clipping is set.
28 The graphics context is initialised to null. */
29 EXPORT_C TDrawTextLayoutContext::TDrawTextLayoutContext():
31 iGutterMarginWidth(0),
33 iBackgroundColor(TLogicalRgb::ESystemBackgroundColor),
36 iOverrideTextColor(TLogicalRgb::ESystemForegroundColor),
37 iDrawMode(EFDrawText | EFDrawGraphics | EFUseClippingRect)
41 /** Sets the graphics context for drawing text and pictures.
42 @param aGc Pointer to the graphics context for drawing text and pictures.
43 @param aPictureGc This argument is not used - all drawing is done using aGc. */
44 EXPORT_C void TDrawTextLayoutContext::SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc/*=NULL*/)
47 iPictureGc=aPictureGc;
48 iDrawMode&=EFAllFlags-EFUseGcClear;
49 iDrawMode&=EFAllFlags-EFUseWindowGc;
52 EXPORT_C void TDrawTextLayoutContext::SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc/*=NULL*/)
55 iPictureGc=aPictureGc;
56 iDrawMode|=EFUseGcClear;
57 iDrawMode&=EFAllFlags-EFUseWindowGc;
60 EXPORT_C void TDrawTextLayoutContext::SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc/*=NULL*/)
63 iPictureGc=aPictureGc;
64 iDrawMode|=EFUseGcClear;
65 iDrawMode|=EFUseWindowGc;
66 iDrawMode|=EFUseClippingRect;
69 /** Sets whether the background colour as specified by iBackgroundColor should
71 @param aDrawToEveryPixel Specify ETrue to draw the background colour, EFalse to
72 draw no background colour. */
73 EXPORT_C void TDrawTextLayoutContext::SetDrawToEveryPixel(TBool aDrawToEveryPixel)
75 if (aDrawToEveryPixel)
76 iDrawMode|=EFUseBackgroundColor;
78 iDrawMode&=EFAllFlags-EFUseBackgroundColor;
81 /** Overrides the existing text colour, so that when redrawn, all text has the
82 colour specified, rather than the colour which is set in the text object. To
83 return the text to its original colour, call this function again with an
85 @param aOverrideColor If not NULL, overrides the text colour. */
86 EXPORT_C void TDrawTextLayoutContext::SetTextColorOverride(const TRgb *aOverrideColor)
90 iDrawMode|=EFUseOverrideTextColor;
91 iOverrideTextColor=*aOverrideColor;
94 iDrawMode&=EFAllFlags-EFUseOverrideTextColor;
97 /** This function is obsolete. When a text object is drawn, all parts of it are
99 EXPORT_C void TDrawTextLayoutContext::SetDrawTextOnly()
101 iDrawMode|=EFDrawText;
102 iDrawMode&=EFAllFlags-EFDrawGraphics;
105 /** This function is obsolete. When a text object is drawn, all parts of it are
107 EXPORT_C void TDrawTextLayoutContext::SetDrawGraphicsOnly()
109 iDrawMode|=EFDrawGraphics;
110 iDrawMode&=EFAllFlags-EFDrawText;
113 /** This function is obsolete. When a text object is drawn, all parts of it are
115 EXPORT_C void TDrawTextLayoutContext::SetDrawTextAndGraphics()
117 iDrawMode|=EFDrawGraphics;
118 iDrawMode|=EFDrawText;
121 /** Sets whether drawing should be clipped to the intersection of the draw
122 rectangle (the aDrawRect parameter passed to CTextLayout::DrawL() or
123 InvertRangeL()) and the text area.
124 @param aClipping True to clip drawing to the clip rectangle. False to ignore
125 the clip rectangle. */
126 EXPORT_C void TDrawTextLayoutContext::SetClipping(TBool aClipping)
129 iDrawMode|=EFUseClippingRect;
132 iDrawMode&=EFAllFlags-EFUseClippingRect;
136 /** Sets the horizontal extent of a paragraph to be filled with paragraph fill
139 @param aFillTextOnly If true, the region filled with paragraph fill colour is
140 the area within the paragraph only. If false, the left text margin, if present,
142 EXPORT_C void TDrawTextLayoutContext::SetParagraphFillTextOnly(TBool aFillTextOnly)
145 iDrawMode|=EFParagraphFillTextOnly;
147 iDrawMode&=EFAllFlags-EFParagraphFillTextOnly;
150 /** If the text colour is overridden, this function gets the text override
151 colour, as set by SetTextColorOverride().
152 @return Text override colour. NULL if no text override colour is in use. */
153 EXPORT_C const TRgb* TDrawTextLayoutContext::TextOverrideColor() const
155 return (iDrawMode&EFUseOverrideTextColor) ? &iOverrideTextColor : NULL;
158 /** Gets the graphics context for drawing the text and pictures.
159 @return The graphics context. */
160 EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PrimaryGc() const
165 EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PictureGc() const
170 /** Tests whether clipping is set to the intersection of the draw rectangle,
171 (the aDrawRect parameter passed to CTextLayout::DrawL() or InvertRangeL()) and
173 @return True if clipping set to clip rectangle, false if not. */
174 EXPORT_C TBool TDrawTextLayoutContext::UseClippingRect() const
176 return iDrawMode&EFUseClippingRect;
179 /** Tests if the graphics context for drawing is either CWindowGc
182 @return True if the graphics context is either CWindowGc or CBitmapContext.
184 EXPORT_C TBool TDrawTextLayoutContext::UseGcClear() const
186 return iDrawMode&EFUseGcClear;
189 /** Obsolete function. When a text object is drawn, all parts of it are drawn. */
190 EXPORT_C TBool TDrawTextLayoutContext::DrawText() const
192 return iDrawMode&EFDrawText;
195 /** Obsolete function. When a text object is drawn, all parts of it are drawn.
197 EXPORT_C TBool TDrawTextLayoutContext::DrawGraphics() const
199 return iDrawMode&EFDrawGraphics;
202 /** Tests whether the background colour is used, as set by
203 SetDrawToEveryPixel().
204 @return True if the background colour is used. False if not. */
205 EXPORT_C TBool TDrawTextLayoutContext::UseBackgroundColor() const
207 return iDrawMode&EFUseBackgroundColor;
210 /** Tests whether the region filled with paragraph fill colour is the area
211 within the paragraph only, or also the area within the left text margin.
213 @return If true, the region filled with paragraph fill colour is the area
214 within the paragraph only. If false, the left text margin, if present, is also
216 EXPORT_C TBool TDrawTextLayoutContext::ParagraphFillTextOnly() const
218 return iDrawMode&EFParagraphFillTextOnly;
221 /** Gets the text area. The text area is the view rectangle minus the label and
223 @return The text area. */
224 EXPORT_C TRect TDrawTextLayoutContext::TextArea() const
226 TRect area(iViewRect);
227 area.iTl.iX+=iLabelMarginWidth+iGutterMarginWidth;
231 /** Gets the display height in pixels. The display height is the same as the
232 view rectangle height.
233 @return The display height. */
234 EXPORT_C TInt TDrawTextLayoutContext::DisplayHeight() const
236 return iViewRect.Height();
239 /** Gets the (window) coordinates of the top left hand corner of the text area.
240 @return The top left hand corner of the text area. */
241 EXPORT_C TPoint TDrawTextLayoutContext::TopLeftTextArea() const
243 return TextArea().iTl;
246 /** Gets the area occupied by the label and gutter margins.
247 @return Rectangle representing the label and gutter margins. */
248 EXPORT_C TRect TDrawTextLayoutContext::TotalMargin() const
250 TRect area(iViewRect);
251 area.iBr.iX=area.iTl.iX+iLabelMarginWidth+iGutterMarginWidth;
255 /** Gets the area occupied by the label margin.
256 @return Rectangle representing the label margin. */
257 EXPORT_C TRect TDrawTextLayoutContext::LabelMargin() const
259 TRect margin(iViewRect);
260 margin.iBr.iX=margin.iTl.iX+iLabelMarginWidth;
264 /** Tests whether a label margin has been set.
265 @return True if a label margin has been set. False if not. */
266 EXPORT_C TBool TDrawTextLayoutContext::IsLabelMargin() const
268 return iGutterMarginWidth > 0;
271 /** Gets the area occupied by the gutter margin.
272 @return Rectangle representing the gutter margin. */
273 EXPORT_C TRect TDrawTextLayoutContext::GutterMargin() const
275 TRect margin(iViewRect);
276 margin.iTl.iX+=iLabelMarginWidth;
277 margin.iBr.iX=margin.iTl.iX+iGutterMarginWidth;
281 /** This function is identical to IsLabelMargin().
282 @return True if a label margin has been set, false if not. */
283 EXPORT_C TBool TDrawTextLayoutContext::IsGutterMargin() const
285 return iGutterMarginWidth > 0;
288 /** Gets the window coordinates of the top left hand corner at which text may
289 be drawn. This point has the same vertical coordinate as the top of the text
290 area, but its horizontal coordinate is increased by the left text margin width
291 (iTextStartX). This point is the origin for layout coordinates.
293 @return The coordinates of the top left hand point at which text can be drawn.
295 EXPORT_C TPoint TDrawTextLayoutContext::TopLeftText() const
297 return TopLeftTextArea()+TPoint(iTextStartX,0);
300 /** Converts a point in window coordinates to layout coordinates. Window
301 coordinates have their origin at the top left corner of the view window. Layout
302 coordinates have their origin at the top left corner of the area within the
303 view rectangle in which text can appear, (this value is returned by
305 @param aWinPos Point in window coordinates. On return, set to layout
307 EXPORT_C void TDrawTextLayoutContext::WindowToText(TPoint& aWinPos) const
309 aWinPos-=TopLeftText();
312 /** Converts a rectangle in window coordinates to layout coordinates. Window
313 coordinates have their origin at the top left corner of the view window. Layout
314 coordinates have their origin at the top left corner of the area within the
315 view rectangle in which text can appear, (this value is returned by
317 @param aRect Rectangle in window coordinates. On return, set to layout
319 EXPORT_C void TDrawTextLayoutContext::WindowToText(TRect& aRect) const
321 aRect.Move(TPoint(0,0)-TopLeftText());
324 /** Converts a point in layout coordinates to window coordinates.
325 @param aTextAreaPos A point in layout coordinates. On return, set to window
327 EXPORT_C void TDrawTextLayoutContext::TextToWindow(TPoint& aTextAreaPos) const
329 aTextAreaPos+=TopLeftText();
332 /** Converts a rectangle in layout coordinates to window coordinates.
333 @param aRect Rectangle in layout coordinates. On return, set to window
335 EXPORT_C void TDrawTextLayoutContext::TextToWindow(TRect& aRect) const
337 aRect.Move(TopLeftText());
340 /** Tests if a CWindowGc is being used. */
341 TBool TDrawTextLayoutContext::UseWindowGc() const
343 return iDrawMode & EFUseWindowGc;
346 /** Returns the current drawing mode flags. */
347 void TDrawTextLayoutContext::SetDrawMode(TUint aDrawMode)
349 iDrawMode = aDrawMode;
352 /** Returns the flags that identify the current drawing mode. */
353 TUint TDrawTextLayoutContext::DrawMode() const