1 frmtlay.h |
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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __FRMTLAY_H__ |
|
17 #define __FRMTLAY_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <gdi.h> |
|
22 #include <txtfrmat.h> |
|
23 #include <txtetext.h> |
|
24 #include <frmlaydt.h> |
|
25 #include <frmparam.h> |
|
26 #include <frmvis.h> |
|
27 #include <tagma.h> |
|
28 |
|
29 class CWindowGc; |
|
30 class MLayDoc; |
|
31 class TLayDocTextSource; |
|
32 class TCursorPosition; |
|
33 |
|
34 |
|
35 /** |
|
36 This interface class defines an interface for clients of Form to provided |
|
37 implementations of customisation interfaces relating to the source text |
|
38 document as requried by the internals of Form and Tagma. Its use by |
|
39 Form clients is optional. |
|
40 Derived objects of this interface are registered with the CTextLayout |
|
41 API and are called from the TLayDocTextSource class at present. |
|
42 @publishedPartner |
|
43 @released |
|
44 @see MTmInlineTextSource |
|
45 */ |
|
46 class MFormCustomInterfaceProvider |
|
47 { |
|
48 public: |
|
49 /** |
|
50 Form uses this method to request an interface implmentation for the |
|
51 specified interface Uid. See class description for interfaces covered |
|
52 by this API. |
|
53 @param aInterfaceId |
|
54 The unique identifier for the interface wanted by Form. |
|
55 @return |
|
56 Ptr to interface instance or 0 if not supported by client |
|
57 */ |
|
58 virtual TAny* GetExtendedInterface(const TUid& aInterfaceId) = 0; |
|
59 }; |
|
60 |
|
61 |
|
62 /** Parameter used to control which part of a line (top, baseline or bottom) |
|
63 should be scrolled to a certain vertical position in a view rectangle. Used |
|
64 as a parameter in functions like CTextView::HandleGlobalChangeL() and |
|
65 CTextLayout::SetViewL(). The selected part of the line is called the hotspot. |
|
66 @publishedAll |
|
67 @released |
|
68 */ |
|
69 class TViewYPosQualifier |
|
70 { |
|
71 friend class CTextLayout; |
|
72 friend class CTextView; |
|
73 public: |
|
74 /** Which part of a line (top, baseline or bottom) should appear at a |
|
75 vertical pixel position. */ |
|
76 enum TPartOfLine |
|
77 { |
|
78 /** The top pixel is placed at the specified vertical point. */ |
|
79 EFViewTopOfLine = 1, |
|
80 /** The baseline is placed at the specified vertical point. */ |
|
81 EFViewBaseLine = 0, |
|
82 /** The bottom pixel is placed at the specified vertical point. */ |
|
83 EFViewBottomOfLine = 2 |
|
84 }; |
|
85 |
|
86 /** Whether the top line in the view should be fully visible. */ |
|
87 enum TFullyVisible |
|
88 { |
|
89 /** Force a partially visible top line to be fully visible. */ |
|
90 EFViewForceLineFullyVisible = ETrue, |
|
91 /** Do not force a partially visible top line to be fully visible. */ |
|
92 EFViewDontForceLineFullyVisible = EFalse |
|
93 }; |
|
94 public: |
|
95 inline TViewYPosQualifier(); |
|
96 IMPORT_C void SetHotSpot(TPartOfLine aHotSpot); |
|
97 IMPORT_C void SetFillScreen(TBool aFillScreen = ETrue); |
|
98 IMPORT_C void SetMakeLineFullyVisible(TFullyVisible aMakeLineFullyVisible = EFViewForceLineFullyVisible); |
|
99 private: |
|
100 TPartOfLine iHotSpot; |
|
101 TBool iFillScreen; |
|
102 TFullyVisible iFullyVisible; |
|
103 }; |
|
104 |
|
105 /** |
|
106 A structure used to return the results of a reformatting operation. |
|
107 @see CTextLayout::HandleBlockChangeL() |
|
108 @publishedAll |
|
109 @released |
|
110 */ |
|
111 class TViewRectChanges |
|
112 |
|
113 { |
|
114 public: |
|
115 inline TViewRectChanges(); |
|
116 |
|
117 public: |
|
118 /** The vertical coordinate of the top of the first line of reformatted |
|
119 text. */ |
|
120 TInt iFormattedFrom; |
|
121 /** The vertical coordinate of the bottom of the last line of reformatted |
|
122 text. */ |
|
123 TInt iFormattedTo; |
|
124 /** The number of pixels by which text above the reformatted or edited |
|
125 block has scrolled (positive values mean the text moved down). */ |
|
126 TInt iScrollAtTop; |
|
127 /** The number of pixels by which text below the reformatted or edited |
|
128 block has scrolled (positive values mean the text moved down). */ |
|
129 TInt iScrollAtBottom; |
|
130 }; |
|
131 |
|
132 /** |
|
133 The cursor or cursor selection within a document. |
|
134 |
|
135 If the cursor and anchor position differ, the selection covers the text from |
|
136 the lower to the higher position, not including the character after the higher |
|
137 position. If the selection is changed (by shift plus arrow keys in many UIs) |
|
138 the cursor position changes and the anchor remains the same. |
|
139 @publishedAll |
|
140 @released |
|
141 */ |
|
142 class TCursorSelection |
|
143 |
|
144 { |
|
145 public: |
|
146 inline TCursorSelection(); |
|
147 inline TCursorSelection(TInt aCursorPos,TInt aAnchorPos); |
|
148 inline void SetSelection(TInt aCursorPos,TInt aAnchorPos); |
|
149 inline TInt LowerPos() const; |
|
150 inline TInt HigherPos() const; |
|
151 inline TInt Length() const; |
|
152 public: |
|
153 /** The cursor position. */ |
|
154 TInt iCursorPos; |
|
155 /** The anchor position. */ |
|
156 TInt iAnchorPos; |
|
157 }; |
|
158 |
|
159 /** |
|
160 Parameters used by functions that draw text. |
|
161 |
|
162 An object of this class is passed to CTextLayout::DrawL() and to |
|
163 InvertRangeL(). The draw context includes the view rectangle, the graphics |
|
164 context, the background colour and the margin widths. |
|
165 |
|
166 You only need to use this class directly when you are using a CTextLayout |
|
167 object which is not owned by a CTextView object. |
|
168 @publishedAll |
|
169 @released |
|
170 */ |
|
171 class TDrawTextLayoutContext |
|
172 |
|
173 { |
|
174 private: |
|
175 enum TDrawMode |
|
176 { |
|
177 EFDrawText=0x001, |
|
178 EFDrawGraphics=0x002, |
|
179 EFUseClippingRect=0x004, |
|
180 EFUseWindowGc=0x008, |
|
181 EFUseGcClear=0x020, |
|
182 EFUseBackgroundColor=0x040, |
|
183 EFUseOverrideTextColor=0x080, |
|
184 EFParagraphFillTextOnly=0x100, |
|
185 EFAllFlags=0xfff |
|
186 }; |
|
187 public: |
|
188 IMPORT_C TDrawTextLayoutContext(); |
|
189 |
|
190 IMPORT_C void SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc=NULL); |
|
191 IMPORT_C void SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc=NULL); |
|
192 IMPORT_C void SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc=NULL); |
|
193 IMPORT_C void SetDrawToEveryPixel(TBool aDrawToEveryPixel); |
|
194 IMPORT_C void SetTextColorOverride(const TRgb *aOverrideColor); |
|
195 IMPORT_C void SetDrawTextOnly(); |
|
196 IMPORT_C void SetDrawGraphicsOnly(); |
|
197 IMPORT_C void SetDrawTextAndGraphics(); |
|
198 IMPORT_C void SetClipping(TBool aClipping); |
|
199 // deprecated 7.0 |
|
200 IMPORT_C void SetParagraphFillTextOnly(TBool aFillTextOnly); |
|
201 |
|
202 //Enquiry functions |
|
203 IMPORT_C const TRgb* TextOverrideColor() const; |
|
204 IMPORT_C CGraphicsContext* PrimaryGc() const; |
|
205 IMPORT_C CGraphicsContext* PictureGc() const; |
|
206 IMPORT_C TBool UseClippingRect() const; |
|
207 IMPORT_C TBool UseGcClear() const; |
|
208 IMPORT_C TBool DrawText() const; |
|
209 IMPORT_C TBool DrawGraphics() const; |
|
210 IMPORT_C TBool UseBackgroundColor() const; |
|
211 // deprecated 7.0 |
|
212 IMPORT_C TBool ParagraphFillTextOnly() const; |
|
213 |
|
214 //Physical dimensions |
|
215 IMPORT_C TRect TextArea() const; |
|
216 IMPORT_C TInt DisplayHeight() const; |
|
217 IMPORT_C TPoint TopLeftTextArea() const; |
|
218 IMPORT_C TRect TotalMargin() const; |
|
219 IMPORT_C TRect LabelMargin() const; |
|
220 IMPORT_C TBool IsLabelMargin() const; |
|
221 IMPORT_C TRect GutterMargin() const; |
|
222 IMPORT_C TBool IsGutterMargin() const; |
|
223 IMPORT_C TPoint TopLeftText() const; |
|
224 IMPORT_C void WindowToText(TPoint& aWinPos) const; |
|
225 IMPORT_C void WindowToText(TRect& aRect) const; |
|
226 IMPORT_C void TextToWindow(TPoint& aTextAreaPos) const; |
|
227 IMPORT_C void TextToWindow(TRect& aRect) const; |
|
228 |
|
229 TBool UseWindowGc() const; |
|
230 void SetDrawMode(TUint aDrawMode); |
|
231 TUint DrawMode() const; |
|
232 |
|
233 public: |
|
234 /** The view rectangle (specified in window coordinates). This is used to |
|
235 set the area in which text can be drawn. Text can only be drawn within the |
|
236 intersection between the text area and the aDrawRect parameter passed to |
|
237 CTextLayout::DrawL() or InvertRangeL(). */ |
|
238 TRect iViewRect; |
|
239 /** The label margin width. By default zero. Must have the same value as |
|
240 the label margin width as set in the text layout object. */ |
|
241 TInt iLabelMarginWidth; |
|
242 /** The gutter margin width (also known as the line cursor margin width). |
|
243 By default zero. */ |
|
244 TInt iGutterMarginWidth; |
|
245 /** The horizontal offset between window coordinates and text layout |
|
246 coordinates. */ |
|
247 TInt iTextStartX; |
|
248 /** The background colour for the view rectangle. The background colour is |
|
249 used to fill the parts of the view rectangle in which text cannot appear, |
|
250 for example, below the last line of the document and in the label, line |
|
251 cursor and left text margins. */ |
|
252 TLogicalRgb iBackgroundColor; |
|
253 private: |
|
254 CGraphicsContext* iGc; |
|
255 CGraphicsContext* iPictureGc; |
|
256 TLogicalRgb iOverrideTextColor; |
|
257 TUint iDrawMode; |
|
258 }; |
|
259 |
|
260 /** |
|
261 An abstract class which specifies the protocol for customising the way text |
|
262 and its background are drawn. |
|
263 |
|
264 Common uses for this are to implement custom highlighting or to draw a |
|
265 background bitmap. You must create an object of a class derived from this class |
|
266 and call CTextLayout::SetCustomDraw(), passing a pointer to the object. All of |
|
267 these functions have default implementations. Your class can override any of the |
|
268 virtual functions listed below. |
|
269 @publishedAll |
|
270 @released |
|
271 */ |
|
272 class MFormCustomDraw |
|
273 |
|
274 { |
|
275 public: |
|
276 |
|
277 class TParam |
|
278 /** |
|
279 Parameters used by several custom draw functions |
|
280 @publishedAll |
|
281 @released |
|
282 */ |
|
283 { |
|
284 public: |
|
285 TParam(CGraphicsContext& aGc,MGraphicsDeviceMap& aMap,const TPoint& aTextLayoutTopLeft,const TRect& aDrawRect): |
|
286 iGc(aGc), iMap(aMap), iTextLayoutTopLeft(aTextLayoutTopLeft), iDrawRect(aDrawRect) { } |
|
287 |
|
288 CGraphicsContext& iGc; |
|
289 MGraphicsDeviceMap& iMap; |
|
290 const TPoint& iTextLayoutTopLeft; |
|
291 const TRect& iDrawRect; |
|
292 }; |
|
293 |
|
294 class TLineInfo |
|
295 /** |
|
296 Contains the line metrics. |
|
297 @publishedAll |
|
298 @released |
|
299 */ |
|
300 { |
|
301 public: |
|
302 TLineInfo(const TRect& aOuterRect,const TRect& aInnerRect,TInt aBaseline): |
|
303 iOuterRect(aOuterRect), iInnerRect(aInnerRect), iBaseline(aBaseline) { } |
|
304 |
|
305 const TRect& iOuterRect; |
|
306 const TRect& iInnerRect; |
|
307 TInt iBaseline; |
|
308 }; |
|
309 |
|
310 IMPORT_C virtual void DrawBackground(const TParam& aParam,const TRgb& aBackground,TRect& aDrawn) const; |
|
311 IMPORT_C virtual void DrawLineGraphics(const TParam& aParam,const TLineInfo& aLineInfo) const; |
|
312 IMPORT_C virtual void DrawText(const TParam& aParam,const TLineInfo& aLineInfo,const TCharFormat& aFormat, |
|
313 const TDesC& aText,const TPoint& aTextOrigin,TInt aExtraPixels) const; |
|
314 IMPORT_C virtual TRgb SystemColor(TUint aColorIndex,TRgb aDefaultColor) const; |
|
315 |
|
316 IMPORT_C virtual void MFormCustomDraw_Reserved_1(); |
|
317 IMPORT_C virtual void MFormCustomDraw_Reserved_2(); |
|
318 }; |
|
319 |
|
320 |
|
321 /** |
|
322 An interface class that can be derived from to implement custom line breaking. |
|
323 |
|
324 Custom line breaking allows the Text Views line wrapping algorithm to break |
|
325 lines in any way. For instance, it may be used to avoid the jagged white space |
|
326 at the right edge of text windows caused by normal line wrapping on a small |
|
327 screen. |
|
328 |
|
329 All of these functions have a default implementation. To change the default |
|
330 behaviour, a pointer to an object that overrides any or all of the functions |
|
331 in the interface needs to be passed to the function CTextLayout::SetCustomWrap(). |
|
332 @since 6.2 |
|
333 |
|
334 @see CTextLayout::SetCustomWrap() |
|
335 @publishedAll |
|
336 @released |
|
337 */ |
|
338 class MFormCustomWrap |
|
339 |
|
340 { |
|
341 public: |
|
342 IMPORT_C virtual TUint LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const; |
|
343 IMPORT_C virtual TBool LineBreakPossible(TUint aPrevClass,TUint aNextClass,TBool aHaveSpaces) const; |
|
344 IMPORT_C virtual TBool GetLineBreakInContext(const TDesC& aText,TInt aMinBreakPos,TInt aMaxBreakPos, |
|
345 TBool aForwards,TInt& aBreakPos) const; |
|
346 IMPORT_C virtual TBool IsHangingCharacter(TUint aChar) const; |
|
347 private: |
|
348 IMPORT_C virtual void MFormCustomWrap_Reserved_1(); |
|
349 IMPORT_C virtual void MFormCustomWrap_Reserved_2(); |
|
350 }; |
|
351 |
|
352 |
|
353 /** |
|
354 Mixin class used to customize visible appearance of invisible characters |
|
355 such as a paragraph mark or a tab. |
|
356 |
|
357 @see CTextView::SetCustomInvisibleCharacterRemapper() |
|
358 @publishedAll |
|
359 @released |
|
360 */ |
|
361 class MFormCustomInvisibleCharacterRemapper |
|
362 { |
|
363 public: |
|
364 IMPORT_C static TUint DefaultMapping(TUint aChar, const TNonPrintingCharVisibility aNonPrintingCharVisibility, const TLayDocTextSource& aLayDoc); |
|
365 |
|
366 /** |
|
367 Allows custom remapping of invisible characters. |
|
368 |
|
369 Called by TLayDocTextSource::Map() if it has been created and registered |
|
370 with TLayDocTextSource using CTextLayout::SetInvisibleCharacterRemapper(). |
|
371 |
|
372 Unless there is a specific reason for doing otherwise it is recommended |
|
373 that where this function has not remapped a given character it should |
|
374 pass it to DefaultMapping() to let it try. |
|
375 |
|
376 @param aChar |
|
377 Invisible character to be remapped |
|
378 @param aDesiredVisibilities |
|
379 Current state of flags showing visibility of invisible characters |
|
380 @param aLayDoc |
|
381 Const ref to the calling CLayDocTextSource |
|
382 @return |
|
383 The replacement character if remapping has taken place, else return original character |
|
384 */ |
|
385 virtual TUint Remap(TUint aChar, const TNonPrintingCharVisibility aNonPrintingCharVisibility, const TLayDocTextSource& aLayDoc) = 0; |
|
386 }; |
|
387 |
|
388 |
|
389 /** |
|
390 @internalTechnology |
|
391 Internal to Symbian |
|
392 */ |
|
393 NONSHARABLE_CLASS(TLayDocTextSource) : public MTmSource, public MFormLabelApi, public MTmTextDrawExt |
|
394 { |
|
395 public: |
|
396 |
|
397 enum |
|
398 { |
|
399 EDefaultFontHeightIncreaseFactor = 7, |
|
400 EDefaultMinimumLineDescent = 3 |
|
401 }; |
|
402 |
|
403 TLayDocTextSource(); |
|
404 |
|
405 // overrides for MTmSource pure virtual functions |
|
406 MGraphicsDeviceMap& FormatDevice() const; |
|
407 MGraphicsDeviceMap& InterpretDevice() const; |
|
408 TInt DocumentLength() const; |
|
409 void GetText(TInt aPos,TPtrC& aText,TTmCharFormat& aFormat) const; |
|
410 void GetParagraphFormatL(TInt aPos,RTmParFormat& aFormat) const; |
|
411 TInt ParagraphStart(TInt aPos) const; |
|
412 |
|
413 // overrides for other MTmSource virtual functions |
|
414 TRgb SystemColor(TUint aColorIndex,TRgb aDefaultColor) const; |
|
415 CPicture* PictureL(TInt aPos) const; |
|
416 TInt GetPictureSizeInTwipsL(TInt aPos,TSize& aSize) const; |
|
417 TBool LabelModeSelect(TLabelType aType, TInt aPos); |
|
418 void LabelModeCancel(); |
|
419 void LabelMetrics(TLabelType aType, TSize& aLabelSize, TInt& aMarginSize) const; |
|
420 TUint Map(TUint aChar) const; |
|
421 void SetLineHeight(const TLineHeightParam& aParam,TInt& aAscent,TInt& aDescent) const; |
|
422 TBool PageBreakInRange(TInt aStartPos,TInt aEndPos) const; |
|
423 void DrawBackground(CGraphicsContext& aGc,const TPoint& aTextLayoutTopLeft,const TRect& aRect, |
|
424 const TLogicalRgb& aBackground,TRect& aRectDrawn) const; |
|
425 void DrawLineGraphics(CGraphicsContext& aGc,const TPoint& aTextLayoutTopLeft,const TRect& aRect, |
|
426 const TTmLineInfo& aLineInfo) const; |
|
427 void DrawText(CGraphicsContext& aGc,const TPoint& aTextLayoutTopLeft,const TRect& aRect, |
|
428 const TTmLineInfo& aLineInfo,const TTmCharFormat& aFormat, |
|
429 const TDesC& aText,const TPoint& aTextOrigin,TInt aExtraPixels) const; |
|
430 virtual void DrawPicture(CGraphicsContext& aGc, |
|
431 const TPoint& aTextLayoutTopLeft, const TRect& aRect, |
|
432 MGraphicsDeviceMap& aDevice, const CPicture& aPicture) const; |
|
433 |
|
434 // overrides for the MTmSource virtual functions which implements the MFormCustomWrap |
|
435 // if iCustomWrap is set. |
|
436 TBool LineBreakPossible(TUint aPrevClass,TUint aNextClass,TBool aHaveSpaces) const; |
|
437 TUint LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const; |
|
438 TBool GetLineBreakInContext(const TDesC& aText,TInt aMinBreakPos,TInt aMaxBreakPos, |
|
439 TBool aForwards,TInt& aBreakPos) const; |
|
440 TBool IsHangingCharacter(TUint aChar) const; |
|
441 |
|
442 // other functions |
|
443 TBool CanMap() const; |
|
444 |
|
445 TAny* GetExtendedInterface(const TUid& aInterfaceId); |
|
446 |
|
447 //MTmTextDrawExt implementations |
|
448 virtual void DrawLine(CGraphicsContext& aGc, const TPoint& aPt1, const TPoint& aPt2) const; |
|
449 virtual void DrawText(CGraphicsContext& aGc, const TDesC& aText, const TPoint& aPt) const; |
|
450 virtual void DrawRect(CGraphicsContext& aGc, const TRect& aRc) const; |
|
451 |
|
452 //Set/reset opaque flag of aGc graphics context |
|
453 void SetOpaque(CGraphicsContext& aGc) const; |
|
454 void ResetOpaque(CGraphicsContext& aGc) const; |
|
455 |
|
456 // flags |
|
457 enum |
|
458 { |
|
459 EWrap = 1, |
|
460 ETruncateWithEllipsis = 2, |
|
461 EUseLabelsDevice = 4 |
|
462 }; |
|
463 |
|
464 MLayDoc* iLayDoc; |
|
465 TUint iFlags; // wrap, truncate, etc. |
|
466 TInt iWidth; // wrapping width |
|
467 TChar iEllipsis; // ellipsis character (or none if 0xFFFF) used if truncating |
|
468 TInt iLabelsWidth; |
|
469 TInt iLabelsGutter; |
|
470 CLayoutData::TFormatMode iFormatMode; |
|
471 MGraphicsDeviceMap* iImageDevice; // device map used for drawing text |
|
472 MGraphicsDeviceMap* iLabelsDevice; // device map used for labels |
|
473 MGraphicsDeviceMap* iFormatDevice; // device map used for formatting |
|
474 TInt iFontHeightIncreaseFactor; // percentage automatically added to font heights |
|
475 TInt iMinimumLineDescent; // minimum line descent in pixels |
|
476 TNonPrintingCharVisibility iNonPrintingCharVisibility; |
|
477 const MFormParam* iFormParam; // if non-null, points to the object that supplies system colours |
|
478 const MFormCustomDraw* iCustomDraw; // if non-null, points to custom drawing routines |
|
479 const MFormCustomWrap* iCustomWrap; // if non-null, points to custom wrapping routines |
|
480 /** Optional object able to provide a concrete customisation object for use |
|
481 internally by Form. */ |
|
482 MFormCustomInterfaceProvider* iInterfaceProvider; |
|
483 TBool iDrawOpaque; // Opaque drawing active if the flag is ETrue |
|
484 TInt iExcessHeightRequired; // delta required to position the baseline so there is enough |
|
485 // space for the highset glyph in pixels. |
|
486 MFormCustomInvisibleCharacterRemapper* iInvisibleCharacterRemapper; // Used to customize the remapping of |
|
487 // invisible characters to visible characters |
|
488 }; |
|
489 |
|
490 /** |
|
491 Text layout. |
|
492 |
|
493 CTextLayout is the lowest-level text formatting class in the Text Views API. It |
|
494 obtains text and formatting attributes via the MLayDoc interface class and |
|
495 formats the text to a certain width. |
|
496 |
|
497 It has functions for drawing the text and performing hit-detection that is, |
|
498 converting x-y coordinates to document positions, and vice versa. It defines |
|
499 many public functions that are not generally useful, but are called by the |
|
500 higher-level CTextView class, or exist only for the convenience of closely |
|
501 associated classes like the printing and pagination systems. These are |
|
502 identified in the documentation by the text "not generally useful". |
|
503 |
|
504 When using the CTextLayout class, you must be aware of what functions have |
|
505 previously been called. For example: |
|
506 |
|
507 1) Formatting and scrolling functions must not be called if a CTextView object |
|
508 owns the CTextLayout object, because the CTextView object may be reformatting |
|
509 the CTextLayout object asynchronously by means of an active object, or may hold |
|
510 some state information about the CTextLayout object that would be invalidated |
|
511 by reformatting. These functions are identified in the documentation by the |
|
512 text "Do not use if a CTextView object owns this CTextLayout object.". |
|
513 |
|
514 2) Functions that raise out of memory exceptions can leave the object in an |
|
515 inconsistent state; these functions can be identified as usual by their |
|
516 trailing L. When this occurs, it is necessary to discard the formatting |
|
517 information by calling DiscardFormat(). |
|
518 |
|
519 3) Some functions change formatting parameters like the wrap width or band |
|
520 height, but do not reformat to reflect the change. These functions are |
|
521 identified in the documentation by the text "Reformat needed". |
|
522 @publishedAll |
|
523 @released |
|
524 */ |
|
525 class CTextLayout: public CBase |
|
526 |
|
527 { |
|
528 friend class CTestTextLayout; |
|
529 public: |
|
530 |
|
531 /**Flags used by CTextLayout::SetViewL(). Whether to reformat and redraw.*/ |
|
532 enum TDiscard |
|
533 { |
|
534 /** Discard all formatting; redraw. */ |
|
535 EFViewDiscardAllFormat = TRUE, |
|
536 /** Do not discard all formatting; redraw. */ |
|
537 EFViewDontDiscardFormat = FALSE |
|
538 }; |
|
539 |
|
540 /** Indicates whether blank space should scroll. |
|
541 Used by several CTextView and CTextLayout scrolling functions. */ |
|
542 enum TAllowDisallow |
|
543 { |
|
544 /** Allow blank space to scroll. */ |
|
545 EFAllowScrollingBlankSpace = TRUE, |
|
546 /** Disallow blank space from scrolling. */ |
|
547 EFDisallowScrollingBlankSpace = FALSE |
|
548 }; |
|
549 |
|
550 enum // flags for HandleCharEditL |
|
551 { |
|
552 /** Insert a character, (not a paragraph delimiter). */ |
|
553 EFCharacterInsert, |
|
554 /** Insert a paragraph delimiter. */ |
|
555 EFParagraphDelimiter, |
|
556 /** Delete single character to the left. */ |
|
557 EFLeftDelete, |
|
558 /** Delete single character to the right. */ |
|
559 EFRightDelete |
|
560 }; |
|
561 |
|
562 enum |
|
563 { |
|
564 /** A value greater than any possible display height indicates that the |
|
565 entire visible area, at least, was scrolled, and so there is no point |
|
566 in blitting text; a full redraw is needed. |
|
567 */ |
|
568 EFScrollRedrawWholeScreen = CLayoutData::EFLargeNumber, |
|
569 /** The maximum line width when wrapping is unset. */ |
|
570 EFMaximumLineWidth = CLayoutData::EFBodyWidthForNoWrapping, |
|
571 }; |
|
572 |
|
573 enum |
|
574 { |
|
575 /** Wrapping off; overrides the paragraph format. */ |
|
576 EFAllParagraphsNotWrapped = TRUE, |
|
577 /** Wrapping on, unless CParaFormat::iWrap is false. */ |
|
578 EFParagraphsWrappedByDefault = FALSE |
|
579 }; |
|
580 |
|
581 /** Amount to format. Used by CTextLayout::SetAmountToFormat(). */ |
|
582 enum TAmountFormatted |
|
583 { |
|
584 /** Format the whole document. */ |
|
585 EFFormatAllText = FALSE, |
|
586 /** Format the visible band only. */ |
|
587 EFFormatBand = TRUE, |
|
588 }; |
|
589 |
|
590 enum TScrollFlags |
|
591 { |
|
592 EFScrollOnlyToTopsOfLines = 1 |
|
593 }; |
|
594 |
|
595 /** Formatting information. */ |
|
596 enum TCurrentFormat |
|
597 { |
|
598 /** Returned by some CTextLayout enquiry functions to indicate that no |
|
599 formatting has taken place so that the requested value cannot be |
|
600 calculated. */ |
|
601 EFNoCurrentFormat = -1, |
|
602 /** Returned by CTextLayout::ParagraphHeight() when the paragraph is not formatted. */ |
|
603 EFNotInCurrentFormat = 0 |
|
604 }; |
|
605 public: |
|
606 class TRangeChange |
|
607 /** |
|
608 Specifies the range of characters involved when setting or clearing a |
|
609 text selection. |
|
610 |
|
611 This class is used in the CTextLayout::Highlight() function. The following |
|
612 code demonstrates how it should be used to clear an existing highlight and |
|
613 set a new one: |
|
614 |
|
615 @code |
|
616 CTextLayout::TRangeChange oldHighlight(anchorPos, old_cursorPos, |
|
617 CTextLayout::TRangeChange::EClear); // existing highlight |
|
618 CTextLayout::TRangeChange newHighlight(anchorPos, new_cursorPos, |
|
619 CTextLayout::TRangeChange::ESet); // new one |
|
620 newHighlight.OptimizeWith(oldHighlight); // doesn't matter which range is |
|
621 the parameter and which is the calling object |
|
622 layout.Highlight(oldHighlight,drawRect,context); // doesn't matter in which |
|
623 order this and following line occur |
|
624 layout.Highlight(newHighlight,drawRect,context); |
|
625 @endcode |
|
626 |
|
627 @see CTextLayout::Highlight() |
|
628 @publishedAll |
|
629 @released |
|
630 */ |
|
631 { |
|
632 public: |
|
633 /** Enumerates the possible change types. */ |
|
634 enum TChangeType |
|
635 { |
|
636 /** The object is being used to set a range. */ |
|
637 ESet, |
|
638 /** The object is being used to clear a range. */ |
|
639 EClear |
|
640 }; |
|
641 IMPORT_C TRangeChange(TInt aStart, TInt aEnd, TChangeType aChange); |
|
642 IMPORT_C TRangeChange(); |
|
643 IMPORT_C void Set(TInt aStart, TInt aEnd, TChangeType aChange); |
|
644 IMPORT_C TChangeType Get(TInt& aStart, TInt& aEnd) const; |
|
645 IMPORT_C void OptimizeWith(TRangeChange& aBuddy); |
|
646 IMPORT_C TBool NonNull() const; |
|
647 IMPORT_C TBool Clip(TInt aMin, TInt aMax); |
|
648 |
|
649 TBool IsJoinedTo(const TRangeChange aRange); |
|
650 void Join(const TRangeChange aRange); |
|
651 |
|
652 private: |
|
653 TInt iA; |
|
654 TInt iB; |
|
655 }; |
|
656 |
|
657 public: |
|
658 |
|
659 class TTagmaForwarder: public MTmTextLayoutForwarder |
|
660 /** |
|
661 A standard inquiry interface for the text formatting engine, built on |
|
662 top of a CTextView object. |
|
663 |
|
664 To use it, construct a TTagmaForwarder object, then call InitL(), which |
|
665 finishes background formatting, then call the MTmTextLayoutForwarder |
|
666 functions. |
|
667 @internalComponent |
|
668 */ |
|
669 { |
|
670 public: |
|
671 inline TTagmaForwarder(const CTextLayout& aLayout); |
|
672 |
|
673 private: |
|
674 // from MTmTextLayoutForwarder |
|
675 inline const CTmTextLayout& TextLayout() const; |
|
676 inline void GetOrigin(TPoint& aPoint) const; |
|
677 |
|
678 const CTextLayout& iLayout; |
|
679 }; |
|
680 |
|
681 /** |
|
682 Accesses text supplied by MTmSource. |
|
683 @internalComponent |
|
684 */ |
|
685 class TUtf32SourceCache |
|
686 { |
|
687 public: |
|
688 TUtf32SourceCache(const MTmSource& aSource); |
|
689 TUtf32SourceCache(const CTextLayout& aLayout); |
|
690 TText GetUtf16(TInt aIndex); |
|
691 TChar GetUtf32(TInt aIndex); |
|
692 private: |
|
693 const MTmSource* iSource; |
|
694 TPtrC16 iCurrentView; |
|
695 TInt iCurrentViewIndex; |
|
696 }; |
|
697 friend class TUtf32SourceCache; |
|
698 |
|
699 IMPORT_C static CTextLayout *NewL(MLayDoc *aDoc,TInt aWrapWidth); |
|
700 IMPORT_C ~CTextLayout(); |
|
701 IMPORT_C void DiscardFormat(); |
|
702 IMPORT_C void SetLayDoc(MLayDoc *aDoc); |
|
703 IMPORT_C void SetWrapWidth(TInt aWrapWidth); |
|
704 IMPORT_C void SetBandHeight(TInt aHeight); |
|
705 IMPORT_C TInt BandHeight() const; |
|
706 IMPORT_C void SetImageDeviceMap(MGraphicsDeviceMap *aGd); |
|
707 IMPORT_C void SetLabelsDeviceMap(MGraphicsDeviceMap *aDeviceMap); |
|
708 IMPORT_C void SetAmountToFormat(TAmountFormatted aAmountOfFormat = EFFormatBand); |
|
709 IMPORT_C TBool IsFormattingBand() const; |
|
710 IMPORT_C void SetFormatMode(CLayoutData::TFormatMode aFormatMode,TInt aWrapWidth,MGraphicsDeviceMap* aFormatDevice); |
|
711 IMPORT_C void ForceNoWrapping(TBool aNoWrapping = EFAllParagraphsNotWrapped); |
|
712 IMPORT_C TBool IsWrapping() const; |
|
713 IMPORT_C void SetTruncating(TBool aOn); |
|
714 IMPORT_C TBool Truncating() const; |
|
715 IMPORT_C void SetTruncatingEllipsis(TChar aEllipsis); |
|
716 IMPORT_C TChar TruncatingEllipsis() const; |
|
717 IMPORT_C void SetLabelsMarginWidth(TInt aWidth); |
|
718 IMPORT_C void SetNonPrintingCharsVisibility(TNonPrintingCharVisibility aVisibility); |
|
719 IMPORT_C TNonPrintingCharVisibility NonPrintingCharsVisibility() const; |
|
720 IMPORT_C TBool IsBackgroundFormatting() const; |
|
721 IMPORT_C void NotifyTerminateBackgroundFormatting(); |
|
722 // deprecated 7.0 |
|
723 IMPORT_C void SetExcludePartialLines(TBool aExcludePartialLines = TRUE); |
|
724 // deprecated 7.0 |
|
725 IMPORT_C TBool ExcludingPartialLines() const; |
|
726 IMPORT_C void SetFontHeightIncreaseFactor(TInt aPercentage); |
|
727 IMPORT_C TInt FontHeightIncreaseFactor() const; |
|
728 IMPORT_C void SetMinimumLineDescent(TInt aPixels); |
|
729 IMPORT_C TInt MinimumLineDescent() const; |
|
730 IMPORT_C TInt DocumentLength() const; |
|
731 IMPORT_C TInt ToParagraphStart(TInt& aDocPos) const; |
|
732 IMPORT_C TInt PixelsAboveBand() const; |
|
733 IMPORT_C TInt YBottomLastFormattedLine() const; |
|
734 IMPORT_C TInt FormattedHeightInPixels() const; |
|
735 IMPORT_C TInt PosRangeInBand(TInt& aDocPos) const; |
|
736 IMPORT_C TBool PosInBand(const TTmDocPos& aDocPos,TTmLineInfo* aLineInfo = NULL) const; |
|
737 IMPORT_C TBool PosInBand(TTmDocPos aDocPos,TPoint& aXyPos) const; |
|
738 IMPORT_C TBool PosInBand(TInt aDocPos,TPoint& aXyPos) const; |
|
739 IMPORT_C TBool PosIsFormatted(TInt aDocPos) const; |
|
740 IMPORT_C TInt FirstCharOnLine(TInt aLineNo) const; |
|
741 IMPORT_C TInt FormattedLength() const; |
|
742 IMPORT_C TInt FirstFormattedPos() const; |
|
743 IMPORT_C TInt NumFormattedLines() const; |
|
744 IMPORT_C TInt FirstLineInBand() const; |
|
745 IMPORT_C TInt GetLineRect(TInt aYPos,TRect& aLine) const; |
|
746 IMPORT_C TInt ParagraphHeight(TInt aDocPos) const; |
|
747 IMPORT_C TRect ParagraphRectL(TInt aDocPos) const; |
|
748 IMPORT_C TBool CalculateHorizontalExtremesL(TInt& aLeftX,TInt& aRightX,TBool aOnlyVisibleLines, |
|
749 TBool aIgnoreWrapCharacters = FALSE) const; |
|
750 IMPORT_C void GetCharacterHeightAndAscentL(TInt aDocPos,TInt& aHeight,TInt& aAscent) const; |
|
751 IMPORT_C void GetFontHeightAndAscentL(const TFontSpec& aFontSpec,TInt& aHeight,TInt& aAscent) const; |
|
752 IMPORT_C TInt XyPosToDocPosL(TPoint &aPos, TUint aFlags = 0) const; |
|
753 IMPORT_C TBool DocPosToXyPosL(TInt aDocPos, TPoint& aPos, TUint aFlags = 0) const; |
|
754 IMPORT_C TBool FindXyPos(const TPoint& aXyPos,TTmPosInfo2& aPosInfo,TTmLineInfo* aLineInfo = NULL) const; |
|
755 IMPORT_C TBool FindDocPos(const TTmDocPosSpec& aDocPos,TTmPosInfo2& aPosInfo,TTmLineInfo* aLineInfo = NULL) const; |
|
756 IMPORT_C TRect GetLineRectL(TInt aDocPos1,TInt aDocPos2) const; |
|
757 IMPORT_C TBool PictureRectangleL(TInt aDocPos,TRect& aPictureRect,TBool* aCanScaleOrCrop = NULL) const; |
|
758 IMPORT_C TBool PictureRectangleL(const TPoint& aXyPos,TRect& aPictureRect,TBool* aCanScaleOrCrop = NULL) const; |
|
759 IMPORT_C TInt FirstDocPosFullyInBand() const; |
|
760 IMPORT_C void GetMinimumSizeL(TInt aWrapWidth,TSize& aSize); |
|
761 IMPORT_C void GetMinimumSizeL(TInt aWrapWidth,TBool aAllowLegalLineBreaksOnly,TSize& aSize); |
|
762 IMPORT_C TInt MajorVersion() const; |
|
763 IMPORT_C TInt SetViewL(const TTmDocPos& aDocPos,TInt& aYPos,TViewYPosQualifier aYPosQualifier, |
|
764 TDiscard aDiscardFormat = EFViewDontDiscardFormat); |
|
765 IMPORT_C TInt SetViewL(TInt aDocPos,TInt& aYPos,TViewYPosQualifier aYPosQualifier, |
|
766 TDiscard aDiscardFormat = EFViewDontDiscardFormat); |
|
767 IMPORT_C void FormatBandL(); |
|
768 IMPORT_C void FormatCharRangeL(TInt aStartDocPos,TInt aEndDocPos); |
|
769 void FormatCharRangeL(TInt aStartDocPos,TInt aEndDocPos,TInt aPixelOffset); |
|
770 IMPORT_C TBool FormatNextLineL(TInt& aBotPixel); |
|
771 IMPORT_C TBool FormatLineL(CParaFormat* aParaFormat,TInt& aDocPos,TInt& aHeight,TBool& aPageBreak); |
|
772 IMPORT_C TInt ScrollParagraphsL(TInt& aNumParas,TAllowDisallow aScrollBlankSpace); |
|
773 IMPORT_C TInt ScrollLinesL(TInt& aNumLines,TAllowDisallow aScrollBlankSpace = EFDisallowScrollingBlankSpace); |
|
774 IMPORT_C TInt ChangeBandTopL(TInt& aPixels,TAllowDisallow aScrollBlankSpace = EFDisallowScrollingBlankSpace); |
|
775 IMPORT_C void PageUpL(TInt& aYCursorPos,TInt& aPixelsScrolled); |
|
776 IMPORT_C void PageDownL(TInt& aYCursorPos,TInt& aPixelsScrolled); |
|
777 IMPORT_C TBool HandleCharEditL(TUint aType,TInt& aCursorPos,TInt& aGood,TInt& aFormattedUpTo, |
|
778 TInt& aFormattedFrom,TInt& aScroll,TBool aFormatChanged); |
|
779 IMPORT_C void HandleBlockChangeL(TCursorSelection aSelection,TInt aOldCharsChanged,TViewRectChanges& aViewChanges, |
|
780 TBool aFormatChanged); |
|
781 IMPORT_C void HandleAdditionalCharactersAtEndL(TInt& aFirstPixel,TInt& aLastPixel); |
|
782 // deprecated 6.1 |
|
783 IMPORT_C void ReformatVerticalSpaceL(); |
|
784 IMPORT_C void AdjustVerticalAlignment(CParaFormat::TAlignment aVerticalAlignment); |
|
785 IMPORT_C static void DrawBorders(const MGraphicsDeviceMap* aGd,CGraphicsContext& aGc,const TRect& aRect, |
|
786 const TParaBorderArray& aBorder,const TRgb* aBackground = NULL, |
|
787 TRegion* aClipRegion = NULL,const TRect* aDrawRect = NULL); |
|
788 IMPORT_C void DrawL(const TRect& aDrawRect,const TDrawTextLayoutContext* aDrawTextLayoutContext, |
|
789 const TCursorSelection* aHighlight = NULL); |
|
790 IMPORT_C TBool GetNextVisualCursorPos(const TTmDocPosSpec& aDocPos, |
|
791 TTmPosInfo2& aPosInfo, TBool aToLeft) const; |
|
792 // deprecated 7.0 |
|
793 IMPORT_C void InvertRangeL(const TCursorSelection& aHighlight,const TRect& aDrawRect, |
|
794 const TDrawTextLayoutContext* aDrawTextLayoutContext); |
|
795 IMPORT_C void Highlight(const TRangeChange& aHighlight,const TRect& aDrawRect, |
|
796 const TDrawTextLayoutContext* aDrawTextLayoutContext); |
|
797 IMPORT_C void SetCustomDraw(const MFormCustomDraw* aCustomDraw); |
|
798 IMPORT_C const MFormCustomDraw* CustomDraw() const; |
|
799 IMPORT_C void SetCustomWrap(const MFormCustomWrap* aCustomWrap); |
|
800 IMPORT_C const MFormCustomWrap* CustomWrap() const; |
|
801 IMPORT_C void ExtendFormattingToCoverYL(TInt aYPos); |
|
802 IMPORT_C void ExtendFormattingToCoverPosL(TInt aDocPos); |
|
803 |
|
804 IMPORT_C TInt GetLineNumber(TInt aDocPos); |
|
805 IMPORT_C void SetHighlightExtensions(TInt aLeftExtension, TInt aRightExtension, TInt aTopExtension, TInt aBottomExtension); |
|
806 void SetExcessHeightRequired(TInt aExcessHeightRequired); |
|
807 IMPORT_C void SetInterfaceProvider( MFormCustomInterfaceProvider* aProvider ); |
|
808 inline const CTmTextLayout& TagmaTextLayout() const; |
|
809 inline void GetOrigin(TPoint& aPoint) const; |
|
810 |
|
811 |
|
812 inline void RestrictScrollToTopsOfLines(TBool aRestrict); |
|
813 |
|
814 |
|
815 // Non-exported public functions |
|
816 void DrawBackground(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect, |
|
817 const TLogicalRgb& aBackground) const; |
|
818 TBool CalculateHorizontalExtremes(TInt& aLeftX,TInt& aRightX,TBool aOnlyVisibleLines) const; |
|
819 TBool GetCursor(const TTmDocPos& aDocPos,TTmCursorPlacement aPlacement, |
|
820 TRect& aLineRect,TPoint& aOrigin,TInt& aWidth,TInt& aAscent,TInt& aDescent) const; |
|
821 void GetParagraphRect(const TTmDocPos& aDocPos,TRect& aRect) const; |
|
822 TInt ScrollDocPosIntoViewL(const TTmDocPos& aDocPos); |
|
823 TInt PictureRectangleAndPosL(const TPoint& aXyPos, TRect& aPictureRect, |
|
824 TBool* aCanScaleOrCrop = 0) const; |
|
825 void HighlightUsingExtensions(const CTextLayout::TRangeChange& aChangeHighlight,const TRangeChange& aFullHighlight, |
|
826 const TRect& aDrawRect, const TDrawTextLayoutContext* aDrawTextLayoutContext); |
|
827 inline const TTmHighlightExtensions& HighlightExtensions() const; |
|
828 void GetHighlightRemnants(const TRect& aRect, const TDrawTextLayoutContext& aDrawTextLayoutContext, TRect* aRemainderRects) const; |
|
829 TInt WrapWidth() const; |
|
830 |
|
831 void SetOpaqueLC(); |
|
832 |
|
833 IMPORT_C void SetCustomInvisibleCharacterRemapper(MFormCustomInvisibleCharacterRemapper* aInvisibleCharacterRemapper); |
|
834 IMPORT_C MFormCustomInvisibleCharacterRemapper* GetCustomInvisibleCharacterRemapper(); |
|
835 void SetTextViewCursorPos(TCursorPosition* aPos); // Put in for INC092568 |
|
836 |
|
837 void SetWindow(RWindow* aWnd); |
|
838 void SetReadyToRedraw(); |
|
839 void BeginRedraw(const TRect& aRect); |
|
840 void EndRedraw(); |
|
841 void SetExternalDraw(const TRect& aRect); |
|
842 void ResetExternalDraw(); |
|
843 TBool BeginRedrawCalled() const; |
|
844 IMPORT_C void MakeVisible(TBool aVisible); |
|
845 |
|
846 #ifdef _DEBUG |
|
847 TBool __DbgIsFormattingUpToDate() const; |
|
848 #endif |
|
849 |
|
850 enum TPanicNumber |
|
851 { |
|
852 EUnimplemented, |
|
853 ENoMemory, |
|
854 EDrawingBorderError, |
|
855 EFormatDeviceNotSet, |
|
856 EImageDeviceNotSet, |
|
857 EPixelNotInFormattedLine, |
|
858 EInvalidDocPos, |
|
859 ENoCharRangeToFormat, |
|
860 ECharacterNotFormatted, |
|
861 EPrintPreviewModeError, |
|
862 EBadCharacterEditType, |
|
863 EInvalidLineNumber, |
|
864 EPosNotFormatted, |
|
865 EMustFormatAllText, |
|
866 EPageScrollError, |
|
867 EInvalidRedraw |
|
868 }; |
|
869 static void Panic(TPanicNumber aNumber); |
|
870 |
|
871 private: |
|
872 IMPORT_C CTextLayout(); |
|
873 IMPORT_C void ConstructL(MLayDoc *aDoc,TInt aWrapWidth); |
|
874 void InitFormatParam(TTmFormatParamBase& aParam); |
|
875 TInt ScrollL(TInt aDy,TAllowDisallow aScrollBlankSpace); |
|
876 void FormatBandL(TInt aStartDocPos,TInt aEndDocPos); |
|
877 void PruneFormatL(TBool aFromStart); |
|
878 TInt VisibleHeightInPixels() const; |
|
879 TInt BandHeightInPixels() const; |
|
880 TInt SuggestCursorPos(TInt aCurrentCursorPos) const; |
|
881 TInt SetBandTop(); |
|
882 TBool AddFormattingAtEndL(TTmFormatParamBase& aFormatParam, TInt& aHeightIncrease, TInt& aParagraphsIncrease); |
|
883 |
|
884 static void ResetOpaque(void* aThis); |
|
885 |
|
886 |
|
887 CTmTextLayout iText; // the TAGMA object that contains the text layout |
|
888 TInt iExcessHeightRequired; // The delta required to position the baseline so there is enough |
|
889 // space for the highset glyph in pixels |
|
890 RWindow *iWnd; // the window to be used to draw |
|
891 TBool iBeginRedrawCount; |
|
892 TRect iRedrawRect; |
|
893 TCursorPosition* iTextViewCursorPos; // From and owned by owning CTextView if it exists, |
|
894 // Null otherwise. Put in for INC092568 |
|
895 TBool iIsWndInExternalRedraw; // If ETrue, then iWnd->EndRedraw() will not be called |
|
896 // from within CTextLayout::EndRedraw() as the window redraw |
|
897 // has been initiated externally and will be ended externally as well |
|
898 TBool iReadyToRedraw; // If EFalse, disables CTextLayout::BeginRedraw() and |
|
899 // CTextLayout::EndRedraw() |
|
900 TInt iDummy[5]; // This dummy variable has been inserted to replace the original size of |
|
901 // a variable that had to be moved to avaid a BC break because it had |
|
902 // increased in size. Feel free to reuse this space - just reduce the size |
|
903 // of this variable by the size of any variable you insert in front of it. |
|
904 // Currently it occupies 5 words. |
|
905 TInt iBandTop; // effectively, scroll position: subtract this from CTmTextLayout y position |
|
906 // to give CTextLayout y position |
|
907 TInt iVisibleHeight;// in pixels if iFormatMode is EFScreenMode or EFWysiwygMode, otherwise twips |
|
908 TInt iBandHeight; // in pixels if iFormatMode is EFScreenMode or EFWysiwygMode, otherwise twips |
|
909 |
|
910 TInt iScrollFlags; // from CTextLayout::TScrollFlags |
|
911 TInt iUnformattedStart; // document position of the start of any unformatted text; |
|
912 // if < KMaxTInt, background formatting can be used |
|
913 // (by calling FormatNextLine) to format the remainder |
|
914 TBool iParInvalid; // if true and background formatting is happening, the remainder of the paragraph |
|
915 // containing iUnformattedStart is invalid and must be reformatted; |
|
916 // otherwise, formatting stops when line ends match |
|
917 TTmHighlightExtensions iHighlightExtensions; |
|
918 TLayDocTextSource iSource; // the source of the text |
|
919 // before adding any new member variables to the end of this class, please |
|
920 // consider whether you can insert them before the iDummy member variable |
|
921 // further up, which currently represents wasted space. |
|
922 }; |
|
923 |
|
924 /** |
|
925 Cursor position. |
|
926 |
|
927 The TMovementType enum defined in this class is used to indicate the direction |
|
928 of a scroll or cursor movement. The remainder of this class does not form part |
|
929 of the API. |
|
930 @publishedAll |
|
931 @released |
|
932 */ |
|
933 class TCursorPosition |
|
934 |
|
935 { |
|
936 public: |
|
937 |
|
938 |
|
939 /** Direction of cursor movement. */ |
|
940 enum TMovementType |
|
941 { |
|
942 /** No cursor movement */ |
|
943 EFNoMovement, |
|
944 /** Single character cursor movement to the left */ |
|
945 EFLeft, |
|
946 /** Single character cursor movement to the right */ |
|
947 EFRight, |
|
948 /** Line up cursor movement */ |
|
949 EFLineUp, |
|
950 /** Line down cursor movement */ |
|
951 EFLineDown, |
|
952 /** Page up cursor movement */ |
|
953 EFPageUp, |
|
954 /** Page down cursor movement */ |
|
955 EFPageDown, |
|
956 /** Cursor movement to line start */ |
|
957 EFLineBeg, |
|
958 /** Cursor movement to line end */ |
|
959 EFLineEnd |
|
960 }; |
|
961 |
|
962 /** Selection of the left end or right end of a run of text. */ |
|
963 enum TVisualEnd |
|
964 { |
|
965 /** Leftmost end. */ |
|
966 EVisualLeft, |
|
967 /** Rightmost end. */ |
|
968 EVisualRight |
|
969 }; |
|
970 |
|
971 enum TPosHint |
|
972 { |
|
973 EPosHintUndefined = 0, |
|
974 /** Left to right typing expected. */ |
|
975 EInsertStrongL2R = 1, |
|
976 /** Right to left typing expected. */ |
|
977 EInsertStrongR2L = 2, |
|
978 |
|
979 // Maybe several more. |
|
980 //... |
|
981 EPosHintLast |
|
982 }; |
|
983 |
|
984 inline TCursorPosition(); |
|
985 inline void SetLayout(CTextLayout *aLayout); |
|
986 inline void UpdateLatentX(TInt aX); |
|
987 inline void SetToPreviousHighlight(); |
|
988 inline void SetToCurrentHighlight(); |
|
989 inline void CancelHighlight(); |
|
990 inline void SetDocPos(const TTmDocPos& aDocPos); |
|
991 void UpdateLatentPosition(); |
|
992 TInt SetSelectionL(const TCursorSelection& aSelection); |
|
993 void SetPendingSelection(const TCursorSelection& aSelection); |
|
994 void GetOldSelection(TCursorSelection& aSelection) const; |
|
995 void GetSelection(TCursorSelection& aSelection) const; |
|
996 TInt SetDocPosL(TBool aDragSelectOn,const TTmDocPos& aDocPos); |
|
997 TInt SetXyPosL(TBool aDragSelectOn,TPoint aPos,TBool aAllowPictureFrame); |
|
998 TInt MoveL(TBool aDragSelectOn,TMovementType& aMovement,TBool aAllowPictureFrame); |
|
999 const TTmDocPos& VisualEndOfRunL( |
|
1000 const TTmDocPos& aStart, const TTmDocPos& aEnd, |
|
1001 TVisualEnd aDirection); |
|
1002 void TextMoveVertically(); |
|
1003 inline void DontDrawOldPictureFrame(); |
|
1004 |
|
1005 // inquiry functions |
|
1006 inline TBool IsSelection() const; |
|
1007 inline TBool IsSelectionToDraw() const; |
|
1008 TBool IsPictureFrame() const; |
|
1009 TBool IsNewPictureFrame() const; |
|
1010 inline const TTmDocPos& TmDocPos() const; |
|
1011 inline TInt DocPos() const; |
|
1012 inline TBool DrawHighlight() const; |
|
1013 inline TBool DrawOldPictureFrame() const; |
|
1014 inline TBool DrawNewPictureFrame() const; |
|
1015 TBool GetCursor(TTmCursorPlacement aPlacement,TPoint& aOrigin,TInt& aWidth,TInt& aAscent,TInt& aDescent) const; |
|
1016 TPosHint PositioningHint() const { return iPositioningHint; } |
|
1017 void SetPositioningHint (TPosHint aHint) |
|
1018 {iPositioningHint = aHint;} |
|
1019 |
|
1020 TTmPosInfo2& ChoosePosition(TTmPosInfo2& aPreferred, |
|
1021 TTmPosInfo2& aBackup); |
|
1022 |
|
1023 private: |
|
1024 enum |
|
1025 { |
|
1026 EFAbove = -1, |
|
1027 EFInside = 0, |
|
1028 EFBelow = 1 |
|
1029 }; |
|
1030 |
|
1031 // bit values for iFlags |
|
1032 enum |
|
1033 { |
|
1034 EDrawHighlight = 1, |
|
1035 EDrawOldPictureFrame = 2, |
|
1036 EDrawNewPictureFrame = 4, |
|
1037 EReturnPreviousHighlight = 8, |
|
1038 ESelected = 16 |
|
1039 }; |
|
1040 |
|
1041 TInt ViewTopOfLineL(const TTmDocPos& aDocPos,TInt& aYPos); |
|
1042 void CheckSelection(TBool aSelect); |
|
1043 void CheckNullSelection(); |
|
1044 inline void UpdateLatentY(TInt aY); |
|
1045 TInt CheckCursorOnScreenL(TInt& aY); |
|
1046 TBool LeftRightL(TTmPosInfo2& aPos, TTmLineInfo& aLine, TMovementType& aMove); |
|
1047 void StartEnd(TTmPosInfo2& aPos, TTmLineInfo& aLine, TMovementType& aMove); |
|
1048 void UpDownL(TTmPosInfo2& aPos, TTmLineInfo& aLine, TMovementType& aMove); |
|
1049 TInt PageScrollL(TMovementType& aMove); |
|
1050 TInt DoSetDocPosL(const TTmDocPos& aDocPos); |
|
1051 TInt DoSetVisibleDocPosL(const TTmDocPos& aDocPos); |
|
1052 void DoSetXyPos(TPoint& aXy); |
|
1053 void SetPictureFrame(const TTmDocPos& aDocPos,TInt aAnchor,const TRect& aPictureRect); |
|
1054 inline TBool CalculateCursorPos(TPoint& aCurPos); |
|
1055 |
|
1056 TTmDocPos iDocPos; |
|
1057 TInt iAnchor; |
|
1058 TInt iOldDocPos; |
|
1059 TInt iOldAnchor; |
|
1060 TUint iFlags; |
|
1061 TInt iLatentX; |
|
1062 TInt iLatentY; |
|
1063 CTextLayout* iLayout; |
|
1064 TPosHint iPositioningHint; |
|
1065 }; |
|
1066 |
|
1067 // inline functions |
|
1068 inline const CTmTextLayout& CTextLayout::TagmaTextLayout() const |
|
1069 { |
|
1070 return iText; |
|
1071 } |
|
1072 |
|
1073 inline void CTextLayout::GetOrigin(TPoint& aPoint) const |
|
1074 { |
|
1075 aPoint.iX = 0; |
|
1076 aPoint.iY = -iBandTop; |
|
1077 } |
|
1078 |
|
1079 inline CTextLayout::TTagmaForwarder::TTagmaForwarder(const CTextLayout& aLayout): |
|
1080 iLayout(aLayout) |
|
1081 { |
|
1082 } |
|
1083 |
|
1084 inline const CTmTextLayout& CTextLayout::TTagmaForwarder::TextLayout() const |
|
1085 { |
|
1086 return iLayout.TagmaTextLayout(); |
|
1087 } |
|
1088 |
|
1089 inline void CTextLayout::TTagmaForwarder::GetOrigin(TPoint& aPoint) const |
|
1090 { |
|
1091 iLayout.GetOrigin(aPoint); |
|
1092 } |
|
1093 |
|
1094 inline const TTmHighlightExtensions& CTextLayout::HighlightExtensions() const |
|
1095 { |
|
1096 return iHighlightExtensions; |
|
1097 } |
|
1098 |
|
1099 /** |
|
1100 Dangerous function. Makes scroll operations set the top of the screen flush to |
|
1101 the top of a line. In general this might scroll the cursor off the screen. |
|
1102 */ |
|
1103 void CTextLayout::RestrictScrollToTopsOfLines(TBool a) |
|
1104 { |
|
1105 if (a) |
|
1106 iScrollFlags |= EFScrollOnlyToTopsOfLines; |
|
1107 else |
|
1108 iScrollFlags &= ~EFScrollOnlyToTopsOfLines; |
|
1109 } |
|
1110 |
|
1111 /**Constructs a fully initialized TViewYPosQualifier object. The hotspot is |
|
1112 initialized to be the baseline of the line, the screen is not filled, and the |
|
1113 top line is not forced to be fully visible. */ |
|
1114 inline TViewYPosQualifier::TViewYPosQualifier(): |
|
1115 iHotSpot(EFViewBaseLine), |
|
1116 iFillScreen(EFalse), |
|
1117 iFullyVisible(EFViewDontForceLineFullyVisible) |
|
1118 { |
|
1119 } |
|
1120 |
|
1121 |
|
1122 /**Constructs a TViewRectChanges object, initializing its iScrollAtTop and |
|
1123 iScrollAtBottom members to zero. */ |
|
1124 inline TViewRectChanges::TViewRectChanges(): |
|
1125 iScrollAtTop(0), |
|
1126 iScrollAtBottom(0) |
|
1127 { |
|
1128 } |
|
1129 |
|
1130 /**Constructs the TCursorSelection object initialising the cursor and anchor |
|
1131 positions to zero. */ |
|
1132 inline TCursorSelection::TCursorSelection(): |
|
1133 iCursorPos(0), |
|
1134 iAnchorPos(0) |
|
1135 { |
|
1136 } |
|
1137 |
|
1138 /** Constructs the TCursorSelection object with a cursor and anchor position. |
|
1139 @param aCursorPos The cursor position. |
|
1140 @param aAnchorPos The anchor position. */ |
|
1141 inline TCursorSelection::TCursorSelection(TInt aCursorPos,TInt aAnchorPos): |
|
1142 iCursorPos(aCursorPos), |
|
1143 iAnchorPos(aAnchorPos) |
|
1144 { |
|
1145 } |
|
1146 |
|
1147 /** Sets the cursor and anchor positions for the selection. |
|
1148 @param aCursorPos The new cursor position. |
|
1149 @param aAnchorPos The new anchor position. */ |
|
1150 inline void TCursorSelection::SetSelection(TInt aCursorPos,TInt aAnchorPos) |
|
1151 { |
|
1152 iCursorPos = aCursorPos; |
|
1153 iAnchorPos = aAnchorPos; |
|
1154 } |
|
1155 |
|
1156 /** Gets the lesser of the cursor and anchor positions. |
|
1157 @return The lesser of the cursor and anchor positions. */ |
|
1158 inline TInt TCursorSelection::LowerPos() const |
|
1159 { |
|
1160 return Min(iCursorPos,iAnchorPos); |
|
1161 } |
|
1162 |
|
1163 /** Gets the greater of the cursor and anchor positions. |
|
1164 @return The greater of the cursor and anchor positions. */ |
|
1165 inline TInt TCursorSelection::HigherPos() const |
|
1166 { |
|
1167 return Max(iCursorPos,iAnchorPos); |
|
1168 } |
|
1169 |
|
1170 /** Returns the number of characters in the selected range. |
|
1171 @return The length of the selection. */ |
|
1172 inline TInt TCursorSelection::Length() const |
|
1173 { |
|
1174 return Abs(iCursorPos - iAnchorPos); |
|
1175 } |
|
1176 |
|
1177 /** Constructs the TCursorPosition object, initializing its members |
|
1178 iAnchor, iOldDocPos, iOldAnchor, iFlags, iLatentX, iLatentY to |
|
1179 zero, iLayout to NULL, and iPositioningHint to undefined. |
|
1180 */ |
|
1181 inline TCursorPosition::TCursorPosition(): |
|
1182 iAnchor(0), |
|
1183 iOldDocPos(0), |
|
1184 iOldAnchor(0), |
|
1185 iFlags(0), |
|
1186 iLatentX(0), |
|
1187 iLatentY(0), |
|
1188 iLayout(NULL), |
|
1189 iPositioningHint(EPosHintUndefined) |
|
1190 { |
|
1191 } |
|
1192 |
|
1193 /** Sets the text layout which TCursorPosition is related. |
|
1194 @param aLayout The text layout. |
|
1195 */ |
|
1196 inline void TCursorPosition::SetLayout(CTextLayout *aLayout) |
|
1197 { |
|
1198 iLayout = aLayout; |
|
1199 } |
|
1200 |
|
1201 /** Tests whether there is currently a selected region. |
|
1202 @return True if there is a selected region. False if not. */ |
|
1203 inline TBool TCursorPosition::IsSelection() const |
|
1204 { |
|
1205 return iFlags & ESelected; |
|
1206 } |
|
1207 |
|
1208 /** Tests whether there is currently a highlighted region being drawn. |
|
1209 @return True if there is a selected region. False if not. */ |
|
1210 inline TBool TCursorPosition::IsSelectionToDraw() const |
|
1211 { |
|
1212 return iFlags & (EDrawHighlight | EDrawOldPictureFrame | EDrawNewPictureFrame); |
|
1213 } |
|
1214 |
|
1215 /** Sets the flag which directs <code>GetSelection()</code> and |
|
1216 <code>IsPictureFrame()</code> to operate on the previous highlight |
|
1217 instead of the current highlight. |
|
1218 */ |
|
1219 inline void TCursorPosition::SetToPreviousHighlight() |
|
1220 { |
|
1221 iFlags |= EReturnPreviousHighlight; |
|
1222 } |
|
1223 |
|
1224 /** Clears the special flag set in <code>SetToPreviousHighlight()</code> |
|
1225 so that <code>GetSelection()</code> and <code>IsPictureFrame()</code> |
|
1226 will operate on the current highlight. |
|
1227 */ |
|
1228 inline void TCursorPosition::SetToCurrentHighlight() |
|
1229 { |
|
1230 iFlags &= ~EReturnPreviousHighlight; |
|
1231 } |
|
1232 |
|
1233 /** Removes the selection, and redraws the affected part of the screen. |
|
1234 */ |
|
1235 inline void TCursorPosition::CancelHighlight() |
|
1236 { |
|
1237 iFlags &= ~(ESelected | EDrawHighlight | EDrawOldPictureFrame | EDrawNewPictureFrame); |
|
1238 } |
|
1239 |
|
1240 /** Sets the latent horizontal text cursor position. This is the horizontal |
|
1241 coordinate to which the text cursor will be moved. |
|
1242 @param aX The horizontal coordinate to which the text cursor should be moved |
|
1243 */ |
|
1244 inline void TCursorPosition::UpdateLatentX(TInt aX) |
|
1245 { |
|
1246 iLatentX = aX; |
|
1247 } |
|
1248 |
|
1249 /** Sets the latent vertical text cursor position. This is the vertical |
|
1250 coordinate to which the text cursor will be moved. |
|
1251 @param aY The vertical coordinate to which the text cursor should be moved |
|
1252 */ |
|
1253 inline void TCursorPosition::UpdateLatentY(TInt aY) |
|
1254 { |
|
1255 iLatentY = aY; |
|
1256 } |
|
1257 |
|
1258 /** Caculate x-y position of the cursor |
|
1259 If ETrue is returned, places the position of the intersection of |
|
1260 the character edge with the baseline in aPos |
|
1261 @param aPos On return, stores the position of the intersection of |
|
1262 the character edge with the baseline |
|
1263 @return ETrue if the document is in the formatted text, otherwise EFalse. |
|
1264 */ |
|
1265 inline TBool TCursorPosition::CalculateCursorPos(TPoint& aPos) |
|
1266 { |
|
1267 TTmPosInfo2 pos_info; |
|
1268 TBool result = iLayout->FindDocPos(iDocPos,pos_info); |
|
1269 aPos = pos_info.iEdge; |
|
1270 return result; |
|
1271 } |
|
1272 |
|
1273 /** Gets the document position, the structure for holding a raw document |
|
1274 position that can be converted to or from an x-y position and compared |
|
1275 ordinally, which cannot be done with the more abstract TTmDocPosSpec class. |
|
1276 @return the document position |
|
1277 */ |
|
1278 inline const TTmDocPos& TCursorPosition::TmDocPos() const |
|
1279 { |
|
1280 return iDocPos; |
|
1281 } |
|
1282 /** Gets the edge position in the document. |
|
1283 @return the edge position in the document. |
|
1284 */ |
|
1285 inline TInt TCursorPosition::DocPos() const |
|
1286 { |
|
1287 return iDocPos.iPos; |
|
1288 } |
|
1289 |
|
1290 /** Sets the document position, the structure for holding a raw document |
|
1291 position that can be converted to or from an x-y position and compared |
|
1292 ordinally, which cannot be done with the more abstract TTmDocPosSpec class. |
|
1293 @param aDocPos the document position |
|
1294 */ |
|
1295 inline void TCursorPosition::SetDocPos(const TTmDocPos& aDocPos) |
|
1296 { |
|
1297 iDocPos = aDocPos; |
|
1298 } |
|
1299 |
|
1300 /** Tests whether the highlighted region needs to be drawn. |
|
1301 The function will be called by CTextView::UpdateHighlightL() |
|
1302 to correct the highlight after a cursor movement |
|
1303 @return True if the highlighted region needs to be drawn. False if not. */ |
|
1304 inline TBool TCursorPosition::DrawHighlight() const |
|
1305 { |
|
1306 return iFlags & EDrawHighlight; |
|
1307 } |
|
1308 |
|
1309 /** Tests whether there is a previous picture frame that needs to be drawn. |
|
1310 The function will be called by CTextView::UpdateHighlightL() |
|
1311 to correct the highlight after a cursor movement |
|
1312 @return True if there is a previous picture frame that needs to be drawn. False if not. */ |
|
1313 inline TBool TCursorPosition::DrawOldPictureFrame() const |
|
1314 { |
|
1315 return iFlags & EDrawOldPictureFrame; |
|
1316 } |
|
1317 |
|
1318 /** Tests whether there is a new picture frame that needs to be drawn. |
|
1319 The function will be called by CTextView::UpdateHighlightL() |
|
1320 to correct the highlight after a cursor movement |
|
1321 @return True if there is a new picture frame that needs to be drawn. False if not. */ |
|
1322 inline TBool TCursorPosition::DrawNewPictureFrame() const |
|
1323 { |
|
1324 return iFlags & EDrawNewPictureFrame; |
|
1325 } |
|
1326 |
|
1327 /** Sets to not draw the previous picture frame |
|
1328 */ |
|
1329 inline void TCursorPosition::DontDrawOldPictureFrame() |
|
1330 { |
|
1331 iFlags &= ~EDrawOldPictureFrame; |
|
1332 } |
|
1333 |
|
1334 #endif |