|
1 /* |
|
2 * Copyright (c) 1996-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "FRMTLAY.H" |
|
20 #include "FRMCONST.H" |
|
21 |
|
22 /** Default C++ constructor. |
|
23 |
|
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(): |
|
30 iLabelMarginWidth(0), |
|
31 iGutterMarginWidth(0), |
|
32 iTextStartX(0), |
|
33 iBackgroundColor(TLogicalRgb::ESystemBackgroundColor), |
|
34 iGc(NULL), |
|
35 iPictureGc(NULL), |
|
36 iOverrideTextColor(TLogicalRgb::ESystemForegroundColor), |
|
37 iDrawMode(EFDrawText | EFDrawGraphics | EFUseClippingRect) |
|
38 { |
|
39 } |
|
40 |
|
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*/) |
|
45 { |
|
46 iGc=aGc; |
|
47 iPictureGc=aPictureGc; |
|
48 iDrawMode&=EFAllFlags-EFUseGcClear; |
|
49 iDrawMode&=EFAllFlags-EFUseWindowGc; |
|
50 }; |
|
51 |
|
52 EXPORT_C void TDrawTextLayoutContext::SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc/*=NULL*/) |
|
53 { |
|
54 iGc=aGc; |
|
55 iPictureGc=aPictureGc; |
|
56 iDrawMode|=EFUseGcClear; |
|
57 iDrawMode&=EFAllFlags-EFUseWindowGc; |
|
58 }; |
|
59 |
|
60 EXPORT_C void TDrawTextLayoutContext::SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc/*=NULL*/) |
|
61 { |
|
62 iGc=aGc; |
|
63 iPictureGc=aPictureGc; |
|
64 iDrawMode|=EFUseGcClear; |
|
65 iDrawMode|=EFUseWindowGc; |
|
66 iDrawMode|=EFUseClippingRect; |
|
67 }; |
|
68 |
|
69 /** Sets whether the background colour as specified by iBackgroundColor should |
|
70 be drawn. |
|
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) |
|
74 { |
|
75 if (aDrawToEveryPixel) |
|
76 iDrawMode|=EFUseBackgroundColor; |
|
77 else |
|
78 iDrawMode&=EFAllFlags-EFUseBackgroundColor; |
|
79 } |
|
80 |
|
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 |
|
84 argument of null. |
|
85 @param aOverrideColor If not NULL, overrides the text colour. */ |
|
86 EXPORT_C void TDrawTextLayoutContext::SetTextColorOverride(const TRgb *aOverrideColor) |
|
87 { |
|
88 if (aOverrideColor) |
|
89 { |
|
90 iDrawMode|=EFUseOverrideTextColor; |
|
91 iOverrideTextColor=*aOverrideColor; |
|
92 } |
|
93 else |
|
94 iDrawMode&=EFAllFlags-EFUseOverrideTextColor; |
|
95 } |
|
96 |
|
97 /** This function is obsolete. When a text object is drawn, all parts of it are |
|
98 drawn. */ |
|
99 EXPORT_C void TDrawTextLayoutContext::SetDrawTextOnly() |
|
100 { |
|
101 iDrawMode|=EFDrawText; |
|
102 iDrawMode&=EFAllFlags-EFDrawGraphics; |
|
103 } |
|
104 |
|
105 /** This function is obsolete. When a text object is drawn, all parts of it are |
|
106 drawn. */ |
|
107 EXPORT_C void TDrawTextLayoutContext::SetDrawGraphicsOnly() |
|
108 { |
|
109 iDrawMode|=EFDrawGraphics; |
|
110 iDrawMode&=EFAllFlags-EFDrawText; |
|
111 } |
|
112 |
|
113 /** This function is obsolete. When a text object is drawn, all parts of it are |
|
114 drawn. */ |
|
115 EXPORT_C void TDrawTextLayoutContext::SetDrawTextAndGraphics() |
|
116 { |
|
117 iDrawMode|=EFDrawGraphics; |
|
118 iDrawMode|=EFDrawText; |
|
119 } |
|
120 |
|
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) |
|
127 { |
|
128 if (aClipping) |
|
129 iDrawMode|=EFUseClippingRect; |
|
130 else |
|
131 { |
|
132 iDrawMode&=EFAllFlags-EFUseClippingRect; |
|
133 } |
|
134 } |
|
135 |
|
136 /** Sets the horizontal extent of a paragraph to be filled with paragraph fill |
|
137 colour. |
|
138 @deprecated 7.0 |
|
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, |
|
141 is also filled. */ |
|
142 EXPORT_C void TDrawTextLayoutContext::SetParagraphFillTextOnly(TBool aFillTextOnly) |
|
143 { |
|
144 if (aFillTextOnly) |
|
145 iDrawMode|=EFParagraphFillTextOnly; |
|
146 else |
|
147 iDrawMode&=EFAllFlags-EFParagraphFillTextOnly; |
|
148 } |
|
149 |
|
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 |
|
154 { |
|
155 return (iDrawMode&EFUseOverrideTextColor) ? &iOverrideTextColor : NULL; |
|
156 } |
|
157 |
|
158 /** Gets the graphics context for drawing the text and pictures. |
|
159 @return The graphics context. */ |
|
160 EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PrimaryGc() const |
|
161 { |
|
162 return iGc; |
|
163 } |
|
164 |
|
165 EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PictureGc() const |
|
166 { |
|
167 return iPictureGc; |
|
168 } |
|
169 |
|
170 /** Tests whether clipping is set to the intersection of the draw rectangle, |
|
171 (the aDrawRect parameter passed to CTextLayout::DrawL() or InvertRangeL()) and |
|
172 the text area. |
|
173 @return True if clipping set to clip rectangle, false if not. */ |
|
174 EXPORT_C TBool TDrawTextLayoutContext::UseClippingRect() const |
|
175 { |
|
176 return iDrawMode&EFUseClippingRect; |
|
177 } |
|
178 |
|
179 /** Tests if the graphics context for drawing is either CWindowGc |
|
180 or CBitmapContext. |
|
181 |
|
182 @return True if the graphics context is either CWindowGc or CBitmapContext. |
|
183 False otherwise. */ |
|
184 EXPORT_C TBool TDrawTextLayoutContext::UseGcClear() const |
|
185 { |
|
186 return iDrawMode&EFUseGcClear; |
|
187 } |
|
188 |
|
189 /** Obsolete function. When a text object is drawn, all parts of it are drawn. */ |
|
190 EXPORT_C TBool TDrawTextLayoutContext::DrawText() const |
|
191 { |
|
192 return iDrawMode&EFDrawText; |
|
193 } |
|
194 |
|
195 /** Obsolete function. When a text object is drawn, all parts of it are drawn. |
|
196 */ |
|
197 EXPORT_C TBool TDrawTextLayoutContext::DrawGraphics() const |
|
198 { |
|
199 return iDrawMode&EFDrawGraphics; |
|
200 } |
|
201 |
|
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 |
|
206 { |
|
207 return iDrawMode&EFUseBackgroundColor; |
|
208 } |
|
209 |
|
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. |
|
212 @deprecated 7.0 |
|
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 |
|
215 filled. */ |
|
216 EXPORT_C TBool TDrawTextLayoutContext::ParagraphFillTextOnly() const |
|
217 { |
|
218 return iDrawMode&EFParagraphFillTextOnly; |
|
219 } |
|
220 |
|
221 /** Gets the text area. The text area is the view rectangle minus the label and |
|
222 gutter margins. |
|
223 @return The text area. */ |
|
224 EXPORT_C TRect TDrawTextLayoutContext::TextArea() const |
|
225 { |
|
226 TRect area(iViewRect); |
|
227 area.iTl.iX+=iLabelMarginWidth+iGutterMarginWidth; |
|
228 return area; |
|
229 } |
|
230 |
|
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 |
|
235 { |
|
236 return iViewRect.Height(); |
|
237 } |
|
238 |
|
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 |
|
242 { |
|
243 return TextArea().iTl; |
|
244 } |
|
245 |
|
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 |
|
249 { |
|
250 TRect area(iViewRect); |
|
251 area.iBr.iX=area.iTl.iX+iLabelMarginWidth+iGutterMarginWidth; |
|
252 return area; |
|
253 } |
|
254 |
|
255 /** Gets the area occupied by the label margin. |
|
256 @return Rectangle representing the label margin. */ |
|
257 EXPORT_C TRect TDrawTextLayoutContext::LabelMargin() const |
|
258 { |
|
259 TRect margin(iViewRect); |
|
260 margin.iBr.iX=margin.iTl.iX+iLabelMarginWidth; |
|
261 return margin; |
|
262 } |
|
263 |
|
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 |
|
267 { |
|
268 return iGutterMarginWidth > 0; |
|
269 } |
|
270 |
|
271 /** Gets the area occupied by the gutter margin. |
|
272 @return Rectangle representing the gutter margin. */ |
|
273 EXPORT_C TRect TDrawTextLayoutContext::GutterMargin() const |
|
274 { |
|
275 TRect margin(iViewRect); |
|
276 margin.iTl.iX+=iLabelMarginWidth; |
|
277 margin.iBr.iX=margin.iTl.iX+iGutterMarginWidth; |
|
278 return margin; |
|
279 } |
|
280 |
|
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 |
|
284 { |
|
285 return iGutterMarginWidth > 0; |
|
286 } |
|
287 |
|
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. |
|
292 |
|
293 @return The coordinates of the top left hand point at which text can be drawn. |
|
294 */ |
|
295 EXPORT_C TPoint TDrawTextLayoutContext::TopLeftText() const |
|
296 { |
|
297 return TopLeftTextArea()+TPoint(iTextStartX,0); |
|
298 } |
|
299 |
|
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 |
|
304 TopLeftText()). |
|
305 @param aWinPos Point in window coordinates. On return, set to layout |
|
306 coordinates. */ |
|
307 EXPORT_C void TDrawTextLayoutContext::WindowToText(TPoint& aWinPos) const |
|
308 { |
|
309 aWinPos-=TopLeftText(); |
|
310 } |
|
311 |
|
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 |
|
316 TopLeftText()). |
|
317 @param aRect Rectangle in window coordinates. On return, set to layout |
|
318 coordinates. */ |
|
319 EXPORT_C void TDrawTextLayoutContext::WindowToText(TRect& aRect) const |
|
320 { |
|
321 aRect.Move(TPoint(0,0)-TopLeftText()); |
|
322 } |
|
323 |
|
324 /** Converts a point in layout coordinates to window coordinates. |
|
325 @param aTextAreaPos A point in layout coordinates. On return, set to window |
|
326 coordinates. */ |
|
327 EXPORT_C void TDrawTextLayoutContext::TextToWindow(TPoint& aTextAreaPos) const |
|
328 { |
|
329 aTextAreaPos+=TopLeftText(); |
|
330 } |
|
331 |
|
332 /** Converts a rectangle in layout coordinates to window coordinates. |
|
333 @param aRect Rectangle in layout coordinates. On return, set to window |
|
334 coordinates. */ |
|
335 EXPORT_C void TDrawTextLayoutContext::TextToWindow(TRect& aRect) const |
|
336 { |
|
337 aRect.Move(TopLeftText()); |
|
338 } |
|
339 |
|
340 /** Tests if a CWindowGc is being used. */ |
|
341 TBool TDrawTextLayoutContext::UseWindowGc() const |
|
342 { |
|
343 return iDrawMode & EFUseWindowGc; |
|
344 } |
|
345 |
|
346 /** Returns the current drawing mode flags. */ |
|
347 void TDrawTextLayoutContext::SetDrawMode(TUint aDrawMode) |
|
348 { |
|
349 iDrawMode = aDrawMode; |
|
350 } |
|
351 |
|
352 /** Returns the flags that identify the current drawing mode. */ |
|
353 TUint TDrawTextLayoutContext::DrawMode() const |
|
354 { |
|
355 return iDrawMode; |
|
356 } |