1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextbuffer.h
3 // Purpose: Buffer for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTBUFFER_H_
13 #define _WX_RICHTEXTBUFFER_H_
20 Data is represented by a hierarchy of objects, all derived from
23 The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox.
24 These boxes will allow flexible placement of text boxes on a page, but
25 for now there will be a single box representing the document,
26 and this box will a wxRichTextParagraphLayoutBox which contains further
27 wxRichTextParagraph objects, each of which can include text and images.
29 Each object maintains a range (start and end position) measured
30 from the start of the main parent box.
31 A paragraph object knows its range, and a text fragment knows its range
32 too. So, a character or image in a page has a position relative to the
33 start of the document, and a character in an embedded text box has
34 a position relative to that text box. For now, we will not be dealing with
35 embedded objects but it's something to bear in mind for later.
40 When Layout is called on an object, it is given a size which the object
41 must limit itself to, or one or more flexible directions (vertical
42 or horizontal). So for example a centered paragraph is given the page
43 width to play with (minus any margins), but can extend indefinitely
44 in the vertical direction. The implementation of Layout can then
45 cache the calculated size and position within the parent.
47 Note that position and size should be calculated separately, because
48 for example inserting a paragraph may result in the following paragraphs
49 moving down, but not changing in size.
51 Need to determine how objects specify their position. Absolute coordinates,
52 or relative to last object? May be hard to determine that. So should probably
53 be in absolute coordinates, in which case we'll need a Move virtual function
54 that allows quick movement of all elements without layout.
56 Let's work through a simple example of layout. Say we're laying out
57 a document with the buffer as the top box, with a wxRichTextParagraphLayoutBox
58 inside that that consists of wxRichTextParagraph objects.
60 We're in a mode whereby changes of window size change the width of the
61 page (useful for text editors, as opposed to word processors). The
64 We pass (600, -1) to the top-level Layout (i.e. restrict size in horizontal
65 direction only). The wxRichTextBuffer box doesn't currently have
66 well-defined layout behaviour so we simply assume it has one child
67 that fills its parent (later we can define sizer-like box layout behaviour).
68 So it passes the same dimensions to the child, which is a wxRichTextParagraphLayoutBox.
69 This then looks at each child in turn (wxRichTextParagraph) and determines
70 the size the paragraph will take up, setting the cached size, and
71 splitting the paragraph into lines.
73 When the layout for one paragraph returns, the next paragraph is
74 fed the position of the previous, so it can position itself.
76 Each time Layout is called, the cached list of lines for each paragraph
77 is recreated, since it can change for example if the parent object width
83 Each object can report its size for a given range. It's important that
84 it can report a partial size, so that wrapping can be implemented,
85 hit test calculations performed, etc. So GetRangeSize must be implemented
99 #include "wx/textctrl.h"
100 #include "wx/bitmap.h"
101 #include "wx/image.h"
102 #include "wx/cmdproc.h"
103 #include "wx/txtstrm.h"
109 #define wxRICHTEXT_TYPE_ANY 0
110 #define wxRICHTEXT_TYPE_TEXT 1
111 #define wxRICHTEXT_TYPE_XML 2
112 #define wxRICHTEXT_TYPE_HTML 3
113 #define wxRICHTEXT_TYPE_RTF 4
114 #define wxRICHTEXT_TYPE_PDF 5
117 * Forward declarations
120 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl
;
121 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
;
122 class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject
;
123 class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList
;
124 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
;
125 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
;
126 class WXDLLIMPEXP_RICHTEXT wxRichTextFragment
;
127 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
;
128 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet
;
129 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx
;
132 * Flags determining the available space, passed to Layout
135 #define wxRICHTEXT_FIXED_WIDTH 0x01
136 #define wxRICHTEXT_FIXED_HEIGHT 0x02
137 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
138 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
140 // Only lay out the part of the buffer that lies within
141 // the rect passed to Layout.
142 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
145 * Flags returned from hit-testing
148 // The point was not on this object
149 #define wxRICHTEXT_HITTEST_NONE 0x01
150 // The point was before the position returned from HitTest
151 #define wxRICHTEXT_HITTEST_BEFORE 0x02
152 // The point was after the position returned from HitTest
153 #define wxRICHTEXT_HITTEST_AFTER 0x04
154 // The point was on the position returned from HitTest
155 #define wxRICHTEXT_HITTEST_ON 0x08
158 * Flags for GetRangeSize
161 #define wxRICHTEXT_FORMATTED 0x01
162 #define wxRICHTEXT_UNFORMATTED 0x02
165 * Extra formatting flags not in wxTextAttr
168 #define wxTEXT_ATTR_PARA_SPACING_AFTER 0x00000800
169 #define wxTEXT_ATTR_PARA_SPACING_BEFORE 0x00001000
170 #define wxTEXT_ATTR_LINE_SPACING 0x00002000
171 #define wxTEXT_ATTR_CHARACTER_STYLE_NAME 0x00004000
172 #define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME 0x00008000
173 #define wxTEXT_ATTR_BULLET_STYLE 0x00010000
174 #define wxTEXT_ATTR_BULLET_NUMBER 0x00020000
175 #define wxTEXT_ATTR_BULLET_SYMBOL 0x00040000
178 * Styles for wxTextAttrEx::SetBulletStyle
181 #define wxTEXT_ATTR_BULLET_STYLE_NONE 0x0000
182 #define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x0001
183 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x0002
184 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x0004
185 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x0008
186 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x0010
187 #define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x0020
188 #define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x0040
189 #define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x0080
190 #define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x0100
193 * Line spacing values
196 #define wxTEXT_ATTR_LINE_SPACING_NORMAL 10
197 #define wxTEXT_ATTR_LINE_SPACING_HALF 15
198 #define wxTEXT_ATTR_LINE_SPACING_TWICE 20
201 * wxRichTextRange class declaration
202 * This stores beginning and end positions for a range of data.
205 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
210 wxRichTextRange() { m_start
= 0; m_end
= 0; }
211 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
212 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
213 ~wxRichTextRange() {}
215 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
216 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
217 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
218 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
220 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
222 void SetStart(long start
) { m_start
= start
; }
223 long GetStart() const { return m_start
; }
225 void SetEnd(long end
) { m_end
= end
; }
226 long GetEnd() const { return m_end
; }
228 /// Returns true if this range is completely outside 'range'
229 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
231 /// Returns true if this range is completely within 'range'
232 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
234 /// Returns true if the given position is within this range. Allow
235 /// for the possibility of an empty range - assume the position
236 /// is within this empty range. NO, I think we should not match with an empty range.
237 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
238 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
240 /// Limit this range to be within 'range'
241 bool LimitTo(const wxRichTextRange
& range
) ;
243 /// Gets the length of the range
244 long GetLength() const { return m_end
- m_start
+ 1; }
246 /// Swaps the start and end
247 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
254 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
255 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
258 * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
261 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx
: public wxTextAttr
265 wxTextAttrEx(const wxTextAttrEx
& attr
);
266 wxTextAttrEx(const wxTextAttr
& attr
) { Init(); (*this) = attr
; }
267 wxTextAttrEx() { Init(); }
269 // Initialise this object.
272 // Assignment from a wxTextAttrEx object
273 void operator= (const wxTextAttrEx
& attr
);
275 // Assignment from a wxTextAttr object.
276 void operator= (const wxTextAttr
& attr
);
279 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; }
280 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; }
281 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; }
282 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; }
283 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; }
284 void SetBulletStyle(int style
) { m_bulletStyle
= style
; }
285 void SetBulletNumber(int n
) { m_bulletNumber
= n
; }
286 void SetBulletSymbol(wxChar symbol
) { m_bulletSymbol
= symbol
; }
288 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
289 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
290 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
291 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
292 int GetLineSpacing() const { return m_lineSpacing
; }
293 int GetBulletStyle() const { return m_bulletStyle
; }
294 int GetBulletNumber() const { return m_bulletNumber
; }
295 wxChar
GetBulletSymbol() const { return m_bulletSymbol
; }
297 bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
298 bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE
) != 0; }
299 bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC
) != 0; }
300 bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
301 bool HasFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE
) != 0; }
303 bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER
); }
304 bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE
); }
305 bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING
); }
306 bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME
); }
307 bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
); }
308 bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE
); }
309 bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER
); }
310 bool HasBulletSymbol() const { return HasFlag(wxTEXT_ATTR_BULLET_SYMBOL
); }
312 // Is this a character style?
313 bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT
| wxTEXT_ATTR_BACKGROUND_COLOUR
| wxTEXT_ATTR_TEXT_COLOUR
))); }
314 bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_TABS
|
315 wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|wxTEXT_ATTR_LINE_SPACING
|
316 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
))); }
318 // returns false if we have any attributes set, true otherwise
319 bool IsDefault() const
321 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
322 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
323 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
324 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
327 // return the attribute having the valid font and colours: it uses the
328 // attributes set in attr and falls back first to attrDefault and then to
329 // the text control font/colours for those attributes which are not set
330 static wxTextAttrEx
CombineEx(const wxTextAttrEx
& attr
,
331 const wxTextAttrEx
& attrDef
,
332 const wxTextCtrlBase
*text
);
336 int m_paragraphSpacingAfter
;
337 int m_paragraphSpacingBefore
;
341 wxChar m_bulletSymbol
;
344 wxString m_characterStyleName
;
347 wxString m_paragraphStyleName
;
351 * wxRichTextAttr stores attributes without a wxFont object, so is a much more
352 * efficient way to query styles.
355 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
359 wxRichTextAttr(const wxTextAttrEx
& attr
);
360 wxRichTextAttr() { Init(); }
361 wxRichTextAttr(const wxColour
& colText
,
362 const wxColour
& colBack
= wxNullColour
,
363 wxTextAttrAlignment alignment
= wxTEXT_ALIGNMENT_DEFAULT
);
365 // Initialise this object.
368 // Assignment from a wxRichTextAttr object.
369 void operator= (const wxRichTextAttr
& attr
);
371 // Assignment from a wxTextAttrEx object.
372 void operator= (const wxTextAttrEx
& attr
);
374 // Making a wxTextAttrEx object.
375 operator wxTextAttrEx () const ;
377 // Copy to a wxTextAttr
378 void CopyTo(wxTextAttrEx
& attr
) const;
380 // Create font from font attributes.
381 wxFont
CreateFont() const;
383 // Get attributes from font.
384 bool GetFontAttributes(const wxFont
& font
);
387 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; m_flags
|= wxTEXT_ATTR_TEXT_COLOUR
; }
388 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; m_flags
|= wxTEXT_ATTR_BACKGROUND_COLOUR
; }
389 void SetAlignment(wxTextAttrAlignment alignment
) { m_textAlignment
= alignment
; m_flags
|= wxTEXT_ATTR_ALIGNMENT
; }
390 void SetTabs(const wxArrayInt
& tabs
) { m_tabs
= tabs
; m_flags
|= wxTEXT_ATTR_TABS
; }
391 void SetLeftIndent(int indent
, int subIndent
= 0) { m_leftIndent
= indent
; m_leftSubIndent
= subIndent
; m_flags
|= wxTEXT_ATTR_LEFT_INDENT
; }
392 void SetRightIndent(int indent
) { m_rightIndent
= indent
; m_flags
|= wxTEXT_ATTR_RIGHT_INDENT
; }
394 void SetFontSize(int pointSize
) { m_fontSize
= pointSize
; m_flags
|= wxTEXT_ATTR_FONT_SIZE
; }
395 void SetFontStyle(int fontStyle
) { m_fontStyle
= fontStyle
; m_flags
|= wxTEXT_ATTR_FONT_ITALIC
; }
396 void SetFontWeight(int fontWeight
) { m_fontWeight
= fontWeight
; m_flags
|= wxTEXT_ATTR_FONT_WEIGHT
; }
397 void SetFontFaceName(const wxString
& faceName
) { m_fontFaceName
= faceName
; m_flags
|= wxTEXT_ATTR_FONT_FACE
; }
398 void SetFontUnderlined(bool underlined
) { m_fontUnderlined
= underlined
; m_flags
|= wxTEXT_ATTR_FONT_UNDERLINE
; }
400 void SetFlags(long flags
) { m_flags
= flags
; }
402 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; }
403 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; }
404 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; }
405 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; }
406 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; }
407 void SetBulletStyle(int style
) { m_bulletStyle
= style
; }
408 void SetBulletNumber(int n
) { m_bulletNumber
= n
; }
409 void SetBulletSymbol(wxChar symbol
) { m_bulletSymbol
= symbol
; }
411 const wxColour
& GetTextColour() const { return m_colText
; }
412 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
413 wxTextAttrAlignment
GetAlignment() const { return m_textAlignment
; }
414 const wxArrayInt
& GetTabs() const { return m_tabs
; }
415 long GetLeftIndent() const { return m_leftIndent
; }
416 long GetLeftSubIndent() const { return m_leftSubIndent
; }
417 long GetRightIndent() const { return m_rightIndent
; }
418 long GetFlags() const { return m_flags
; }
420 int GetFontSize() const { return m_fontSize
; }
421 int GetFontStyle() const { return m_fontStyle
; }
422 int GetFontWeight() const { return m_fontWeight
; }
423 bool GetFontUnderlined() const { return m_fontUnderlined
; }
424 const wxString
& GetFontFaceName() const { return m_fontFaceName
; }
426 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
427 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
428 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
429 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
430 int GetLineSpacing() const { return m_lineSpacing
; }
431 int GetBulletStyle() const { return m_bulletStyle
; }
432 int GetBulletNumber() const { return m_bulletNumber
; }
433 wxChar
GetBulletSymbol() const { return m_bulletSymbol
; }
436 bool HasTextColour() const { return m_colText
.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR
) ; }
437 bool HasBackgroundColour() const { return m_colBack
.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR
) ; }
438 bool HasAlignment() const { return (m_textAlignment
!= wxTEXT_ALIGNMENT_DEFAULT
) || ((m_flags
& wxTEXT_ATTR_ALIGNMENT
) != 0) ; }
439 bool HasTabs() const { return (m_flags
& wxTEXT_ATTR_TABS
) != 0 ; }
440 bool HasLeftIndent() const { return (m_flags
& wxTEXT_ATTR_LEFT_INDENT
) != 0 ; }
441 bool HasRightIndent() const { return (m_flags
& wxTEXT_ATTR_RIGHT_INDENT
) != 0 ; }
442 bool HasWeight() const { return (m_flags
& wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
443 bool HasSize() const { return (m_flags
& wxTEXT_ATTR_FONT_SIZE
) != 0; }
444 bool HasItalic() const { return (m_flags
& wxTEXT_ATTR_FONT_ITALIC
) != 0; }
445 bool HasUnderlined() const { return (m_flags
& wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
446 bool HasFaceName() const { return (m_flags
& wxTEXT_ATTR_FONT_FACE
) != 0; }
447 bool HasFont() const { return (m_flags
& (wxTEXT_ATTR_FONT
)) != 0; }
449 bool HasParagraphSpacingAfter() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) != 0; }
450 bool HasParagraphSpacingBefore() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) != 0; }
451 bool HasLineSpacing() const { return (m_flags
& wxTEXT_ATTR_LINE_SPACING
) != 0; }
452 bool HasCharacterStyleName() const { return (m_flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) != 0; }
453 bool HasParagraphStyleName() const { return (m_flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) != 0; }
454 bool HasBulletStyle() const { return (m_flags
& wxTEXT_ATTR_BULLET_STYLE
) != 0; }
455 bool HasBulletNumber() const { return (m_flags
& wxTEXT_ATTR_BULLET_NUMBER
) != 0; }
456 bool HasBulletSymbol() const { return (m_flags
& wxTEXT_ATTR_BULLET_SYMBOL
) != 0; }
458 bool HasFlag(long flag
) const { return (m_flags
& flag
) != 0; }
460 // Is this a character style?
461 bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT
| wxTEXT_ATTR_BACKGROUND_COLOUR
| wxTEXT_ATTR_TEXT_COLOUR
))); }
462 bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_TABS
|
463 wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|wxTEXT_ATTR_LINE_SPACING
|
464 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
))); }
466 // returns false if we have any attributes set, true otherwise
467 bool IsDefault() const
469 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
470 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
471 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
472 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
475 // return the attribute having the valid font and colours: it uses the
476 // attributes set in attr and falls back first to attrDefault and then to
477 // the text control font/colours for those attributes which are not set
478 static wxRichTextAttr
Combine(const wxRichTextAttr
& attr
,
479 const wxRichTextAttr
& attrDef
,
480 const wxTextCtrlBase
*text
);
485 wxArrayInt m_tabs
; // array of int: tab stops in 1/10 mm
486 int m_leftIndent
; // left indent in 1/10 mm
487 int m_leftSubIndent
; // left indent for all but the first
488 // line in a paragraph relative to the
489 // first line, in 1/10 mm
490 int m_rightIndent
; // right indent in 1/10 mm
491 wxTextAttrAlignment m_textAlignment
;
493 int m_paragraphSpacingAfter
;
494 int m_paragraphSpacingBefore
;
498 wxChar m_bulletSymbol
;
506 bool m_fontUnderlined
;
507 wxString m_fontFaceName
;
510 wxString m_characterStyleName
;
513 wxString m_paragraphStyleName
;
516 #define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR)
518 #define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
519 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
520 wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL)
522 #define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
525 * wxRichTextObject class declaration
526 * This is the base for drawable objects.
529 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
531 DECLARE_CLASS(wxRichTextObject
)
535 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
540 /// Draw the item, within the given range. Some objects may ignore the range (for
541 /// example paragraphs) while others must obey it (lines, to implement wrapping)
542 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
) = 0;
544 /// Lay the item out at the specified position with the given size constraint.
545 /// Layout must set the cached size.
546 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
548 /// Hit-testing: returns a flag indicating hit test details, plus
549 /// information about position
550 virtual int HitTest(wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pt
), long& WXUNUSED(textPosition
)) { return false; }
552 /// Finds the absolute position and row height for the given character position
553 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
555 /// Get the best size, i.e. the ideal starting size for this object irrespective
556 /// of available space. For a short text string, it will be the size that exactly encloses
557 /// the text. For a longer string, it might use the parent width for example.
558 virtual wxSize
GetBestSize() const { return m_size
; }
560 /// Get the object size for the given range. Returns false if the range
561 /// is invalid for this object.
562 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const = 0;
564 /// Do a split, returning an object containing the second part, and setting
565 /// the first part in 'this'.
566 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
568 /// Calculate range. By default, guess that the object is 1 unit long.
569 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
572 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
574 /// Returns true if the object is empty
575 virtual bool IsEmpty() const { return false; }
577 /// Get any text in this object for the given range
578 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
580 /// Returns true if this object can merge itself with the given one.
581 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
583 /// Returns true if this object merged itself with the given one.
584 /// The calling code will then delete the given object.
585 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
587 /// Dump to output stream for debugging
588 virtual void Dump(wxTextOutputStream
& stream
);
592 /// Get/set the cached object size as calculated by Layout.
593 virtual wxSize
GetCachedSize() const { return m_size
; }
594 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
596 /// Get/set the object position
597 virtual wxPoint
GetPosition() const { return m_pos
; }
598 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
600 /// Get the rectangle enclosing the object
601 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
604 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
607 const wxRichTextRange
& GetRange() const { return m_range
; }
608 wxRichTextRange
& GetRange() { return m_range
; }
610 /// Get/set dirty flag (whether the object needs Layout to be called)
611 virtual bool GetDirty() const { return m_dirty
; }
612 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
614 /// Is this composite?
615 virtual bool IsComposite() const { return false; }
617 /// Get/set the parent.
618 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
619 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
621 /// Set the margin around the object
622 virtual void SetMargins(int margin
);
623 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
624 virtual int GetLeftMargin() const { return m_leftMargin
; }
625 virtual int GetRightMargin() const { return m_rightMargin
; }
626 virtual int GetTopMargin() const { return m_topMargin
; }
627 virtual int GetBottomMargin() const { return m_bottomMargin
; }
629 /// Set attributes object
630 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
631 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
632 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
634 /// Set/get stored descent
635 void SetDescent(int descent
) { m_descent
= descent
; }
636 int GetDescent() const { return m_descent
; }
641 virtual wxRichTextObject
* Clone() const { return NULL
; }
644 void Copy(const wxRichTextObject
& obj
);
646 /// Reference-counting allows us to use the same object in multiple
647 /// lists (not yet used)
648 void Reference() { m_refCount
++; }
651 /// Convert units in tends of a millimetre to device units
652 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
);
657 int m_descent
; // Descent for this object (if any)
660 wxRichTextObject
* m_parent
;
662 /// The range of this object (start position to end position)
663 wxRichTextRange m_range
;
672 wxTextAttrEx m_attributes
;
675 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
678 * wxRichTextCompositeObject class declaration
679 * Objects of this class can contain other objects.
682 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
684 DECLARE_CLASS(wxRichTextCompositeObject
)
688 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
689 ~wxRichTextCompositeObject();
693 /// Hit-testing: returns a flag indicating hit test details, plus
694 /// information about position
695 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
697 /// Finds the absolute position and row height for the given character position
698 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
701 virtual void CalculateRange(long start
, long& end
);
704 virtual bool DeleteRange(const wxRichTextRange
& range
);
706 /// Get any text in this object for the given range
707 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
709 /// Dump to output stream for debugging
710 virtual void Dump(wxTextOutputStream
& stream
);
715 wxRichTextObjectList
& GetChildren() { return m_children
; }
716 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
718 /// Get the child count
719 size_t GetChildCount() const ;
721 /// Get the nth child
722 wxRichTextObject
* GetChild(size_t n
) const ;
724 /// Get/set dirty flag
725 virtual bool GetDirty() const { return m_dirty
; }
726 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
728 /// Is this composite?
729 virtual bool IsComposite() const { return true; }
731 /// Returns true if the buffer is empty
732 virtual bool IsEmpty() const { return GetChildCount() == 0; }
737 void Copy(const wxRichTextCompositeObject
& obj
);
739 /// Append a child, returning the position
740 size_t AppendChild(wxRichTextObject
* child
) ;
742 /// Insert the child in front of the given object, or at the beginning
743 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
746 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
748 /// Delete all children
749 bool DeleteChildren() ;
751 /// Recursively merge all pieces that can be merged.
755 wxRichTextObjectList m_children
;
759 * wxRichTextBox class declaration
760 * This defines a 2D space to lay out objects
763 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextCompositeObject
765 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
769 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
770 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
775 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
778 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
780 /// Get/set the object size for the given range. Returns false if the range
781 /// is invalid for this object.
782 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
789 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
792 void Copy(const wxRichTextBox
& obj
);
798 * wxRichTextParagraphBox class declaration
799 * This box knows how to lay out paragraphs.
802 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextBox
804 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
808 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
809 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
):wxRichTextBox() { Init(); Copy(obj
); }
814 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
817 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
819 /// Get/set the object size for the given range. Returns false if the range
820 /// is invalid for this object.
821 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
824 virtual bool DeleteRange(const wxRichTextRange
& range
);
826 /// Get any text in this object for the given range
827 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
831 /// Associate a control with the buffer, for operations that for example require refreshing the window.
832 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
834 /// Get the associated control.
835 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
839 /// Initialize the object.
842 /// Clear all children
843 virtual void Clear();
845 /// Clear and initialize with one blank paragraph
846 virtual void Reset();
848 /// Convenience function to add a paragraph of text
849 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
851 /// Convenience function to add an image
852 virtual wxRichTextRange
AddImage(const wxImage
& image
);
854 /// Adds multiple paragraphs, based on newlines.
855 virtual wxRichTextRange
AddParagraphs(const wxString
& text
);
857 /// Get the line at the given position. If caretPosition is true, the position is
858 /// a caret position, which is normally a smaller number.
859 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
861 /// Get the line at the given y pixel position, or the last line.
862 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
864 /// Get the paragraph at the given character or caret position
865 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
867 /// Get the line size at the given position
868 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
870 /// Given a position, get the number of the visible line (potentially many to a paragraph),
871 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
872 /// that indicates whether the caret is being shown at the end of the previous line or at the start
873 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
875 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
877 /// Given a line number, get the corresponding wxRichTextLine object.
878 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
880 /// Get the leaf object in a paragraph at this position.
881 /// Given a line number, get the corresponding wxRichTextLine object.
882 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
884 /// Get the paragraph by number
885 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
887 /// Get the paragraph for a given line
888 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
890 /// Get the length of the paragraph
891 virtual int GetParagraphLength(long paragraphNumber
) const;
893 /// Get the number of paragraphs
894 virtual int GetParagraphCount() const { return GetChildCount(); }
896 /// Get the number of visible lines
897 virtual int GetLineCount() const;
899 /// Get the text of the paragraph
900 virtual wxString
GetParagraphText(long paragraphNumber
) const;
902 /// Convert zero-based line column and paragraph number to a position.
903 virtual long XYToPosition(long x
, long y
) const;
905 /// Convert zero-based position to line column and paragraph number
906 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
908 /// Set text attributes: character and/or paragraph styles.
909 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, bool withUndo
= true);
910 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttrEx
& style
, bool withUndo
= true);
912 /// Get the text attributes for this position.
913 virtual bool GetStyle(long position
, wxTextAttrEx
& style
) const;
914 virtual bool GetStyle(long position
, wxRichTextAttr
& style
) const;
916 /// Test if this whole range has character attributes of the specified kind. If any
917 /// of the attributes are different within the range, the test fails. You
918 /// can use this to implement, for example, bold button updating. style must have
919 /// flags indicating which attributes are of interest.
920 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
921 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
923 /// Test if this whole range has paragraph attributes of the specified kind. If any
924 /// of the attributes are different within the range, the test fails. You
925 /// can use this to implement, for example, centering button updating. style must have
926 /// flags indicating which attributes are of interest.
927 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
928 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
931 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
933 /// Insert fragment into this box at the given position. If partialParagraph is true,
934 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
936 virtual bool InsertFragment(long position
, wxRichTextFragment
& fragment
);
938 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
939 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextFragment
& fragment
);
942 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
945 virtual void UpdateRanges() { long end
; CalculateRange(0, end
); }
948 virtual wxString
GetText() const;
950 /// Set default style for new content. Setting it to a default attribute
951 /// makes new content take on the 'basic' style.
952 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
954 /// Get default style
955 virtual const wxTextAttrEx
& GetDefaultStyle() const { return m_defaultAttributes
; }
957 /// Set basic (overall) style
958 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { m_attributes
= style
; }
959 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { style
.CopyTo(m_attributes
); }
961 /// Get basic (overall) style
962 virtual const wxTextAttrEx
& GetBasicStyle() const { return m_attributes
; }
964 /// Invalidate the buffer. With no argument, invalidates whole buffer.
965 void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
967 /// Get invalid range, rounding to entire paragraphs if argument is true.
968 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
971 wxRichTextCtrl
* m_ctrl
;
972 wxTextAttrEx m_defaultAttributes
;
974 /// The invalidated range that will need full layout
975 wxRichTextRange m_invalidRange
;
979 * wxRichTextFragment class declaration
980 * This is a lind of paragraph layout box used for storing
981 * paragraphs for Undo/Redo, for example.
984 class WXDLLIMPEXP_RICHTEXT wxRichTextFragment
: public wxRichTextParagraphLayoutBox
986 DECLARE_DYNAMIC_CLASS(wxRichTextFragment
)
990 wxRichTextFragment() { Init(); }
991 wxRichTextFragment(const wxRichTextFragment
& obj
):wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
995 /// Get/set whether the last paragraph is partial or complete
996 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
997 bool GetPartialParagraph() const { return m_partialParagraph
; }
1007 void Copy(const wxRichTextFragment
& obj
);
1010 virtual wxRichTextObject
* Clone() const { return new wxRichTextFragment(*this); }
1014 // Is the last paragraph partial or complete?
1015 bool m_partialParagraph
;
1019 * wxRichTextLine class declaration
1020 * This object represents a line in a paragraph, and stores
1021 * offsets from the start of the paragraph representing the
1022 * start and end positions of the line.
1025 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1030 wxRichTextLine(wxRichTextParagraph
* parent
);
1031 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
1032 virtual ~wxRichTextLine() {}
1039 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1040 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
1042 /// Get the parent paragraph
1043 wxRichTextParagraph
* GetParent() { return m_parent
; }
1046 const wxRichTextRange
& GetRange() const { return m_range
; }
1047 wxRichTextRange
& GetRange() { return m_range
; }
1049 /// Get the absolute range
1050 wxRichTextRange
GetAbsoluteRange() const;
1052 /// Get/set the line size as calculated by Layout.
1053 virtual wxSize
GetSize() const { return m_size
; }
1054 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
1056 /// Get/set the object position relative to the parent
1057 virtual wxPoint
GetPosition() const { return m_pos
; }
1058 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1060 /// Get the absolute object position
1061 virtual wxPoint
GetAbsolutePosition() const;
1063 /// Get the rectangle enclosing the line
1064 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1066 /// Set/get stored descent
1067 void SetDescent(int descent
) { m_descent
= descent
; }
1068 int GetDescent() const { return m_descent
; }
1073 void Init(wxRichTextParagraph
* parent
);
1076 void Copy(const wxRichTextLine
& obj
);
1079 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1083 /// The range of the line (start position to end position)
1084 /// This is relative to the parent paragraph.
1085 wxRichTextRange m_range
;
1087 /// Size and position measured relative to top of paragraph
1091 /// Maximum descent for this line (location of text baseline)
1094 // The parent object
1095 wxRichTextParagraph
* m_parent
;
1098 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
1101 * wxRichTextParagraph class declaration
1102 * This object represents a single paragraph (or in a straight text editor, a line).
1105 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextBox
1107 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
1111 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1112 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1113 ~wxRichTextParagraph();
1114 wxRichTextParagraph(const wxRichTextParagraph
& obj
):wxRichTextBox() { Copy(obj
); }
1119 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1121 /// Lay the item out
1122 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1124 /// Get/set the object size for the given range. Returns false if the range
1125 /// is invalid for this object.
1126 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1128 /// Finds the absolute position and row height for the given character position
1129 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1131 /// Hit-testing: returns a flag indicating hit test details, plus
1132 /// information about position
1133 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1136 virtual void CalculateRange(long start
, long& end
);
1140 /// Get the cached lines
1141 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
1146 void Copy(const wxRichTextParagraph
& obj
);
1149 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
1151 /// Clear the cached lines
1156 /// Apply paragraph styles such as centering to the wrapped lines
1157 virtual void ApplyParagraphStyle(const wxRect
& rect
);
1159 /// Insert text at the given position
1160 virtual bool InsertText(long pos
, const wxString
& text
);
1162 /// Split an object at this position if necessary, and return
1163 /// the previous object, or NULL if inserting at beginning.
1164 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
1166 /// Move content to a list from this point
1167 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
1169 /// Add content back from list
1170 virtual void MoveFromList(wxList
& list
);
1172 /// Get the plain text searching from the start or end of the range.
1173 /// The resulting string may be shorter than the range given.
1174 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
1176 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1178 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
);
1180 /// Find the object at the given position
1181 wxRichTextObject
* FindObjectAtPosition(long position
);
1183 /// Get the bullet text for this paragraph.
1184 wxString
GetBulletText();
1186 /// Allocate or reuse a line object
1187 wxRichTextLine
* AllocateLine(int pos
);
1189 /// Clear remaining unused line objects, if any
1190 bool ClearUnusedLines(int lineCount
);
1193 /// The lines that make up the wrapped paragraph
1194 wxRichTextLineList m_cachedLines
;
1198 * wxRichTextPlainText class declaration
1199 * This object represents a single piece of text.
1202 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
1204 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
1208 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1209 wxRichTextPlainText(const wxRichTextPlainText
& obj
):wxRichTextObject() { Copy(obj
); }
1214 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1216 /// Lay the item out
1217 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1219 /// Get/set the object size for the given range. Returns false if the range
1220 /// is invalid for this object.
1221 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
/* = wxPoint(0,0)*/) const;
1223 /// Get any text in this object for the given range
1224 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1226 /// Do a split, returning an object containing the second part, and setting
1227 /// the first part in 'this'.
1228 virtual wxRichTextObject
* DoSplit(long pos
);
1231 virtual void CalculateRange(long start
, long& end
);
1234 virtual bool DeleteRange(const wxRichTextRange
& range
);
1236 /// Returns true if the object is empty
1237 virtual bool IsEmpty() const { return m_text
.empty(); }
1239 /// Returns true if this object can merge itself with the given one.
1240 virtual bool CanMerge(wxRichTextObject
* object
) const;
1242 /// Returns true if this object merged itself with the given one.
1243 /// The calling code will then delete the given object.
1244 virtual bool Merge(wxRichTextObject
* object
);
1246 /// Dump to output stream for debugging
1247 virtual void Dump(wxTextOutputStream
& stream
);
1252 const wxString
& GetText() const { return m_text
; }
1255 void SetText(const wxString
& text
) { m_text
= text
; }
1260 void Copy(const wxRichTextPlainText
& obj
);
1263 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
1265 bool DrawTabbedString(wxDC
& dc
,const wxRect
& rect
,wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
1272 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1275 class WXDLLIMPEXP_BASE wxDataInputStream
;
1276 class WXDLLIMPEXP_BASE wxDataOutputStream
;
1278 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
1281 wxRichTextImageBlock();
1282 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
1283 ~wxRichTextImageBlock();
1288 // Load the original image into a memory block.
1289 // If the image is not a JPEG, we must convert it into a JPEG
1290 // to conserve space.
1291 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1292 // load the image a 2nd time.
1293 virtual bool MakeImageBlock(const wxString
& filename
, int imageType
, wxImage
& image
, bool convertToJPEG
= true);
1295 // Make an image block from the wxImage in the given
1297 virtual bool MakeImageBlock(wxImage
& image
, int imageType
, int quality
= 80);
1300 bool Write(const wxString
& filename
);
1302 // Write data in hex to a stream
1303 bool WriteHex(wxOutputStream
& stream
);
1305 // Read data in hex from a stream
1306 bool ReadHex(wxInputStream
& stream
, int length
, int imageType
);
1308 // Copy from 'block'
1309 void Copy(const wxRichTextImageBlock
& block
);
1311 // Load a wxImage from the block
1312 bool Load(wxImage
& image
);
1315 void operator=(const wxRichTextImageBlock
& block
);
1319 unsigned char* GetData() const { return m_data
; }
1320 size_t GetDataSize() const { return m_dataSize
; }
1321 int GetImageType() const { return m_imageType
; }
1323 void SetData(unsigned char* image
) { m_data
= image
; }
1324 void SetDataSize(size_t size
) { m_dataSize
= size
; }
1325 void SetImageType(int imageType
) { m_imageType
= imageType
; }
1327 bool Ok() const { return GetData() != NULL
; }
1331 /// Allocate and read from stream as a block of memory
1332 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
1333 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
1335 // Write memory block to stream
1336 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
1338 // Write memory block to file
1339 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
1342 // Size in bytes of the image stored.
1343 // This is in the raw, original form such as a JPEG file.
1344 unsigned char* m_data
;
1346 int m_imageType
; // wxWin type id
1351 * wxRichTextImage class declaration
1352 * This object represents an image.
1355 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextObject
1357 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
1361 wxRichTextImage(wxRichTextObject
* parent
= NULL
):wxRichTextObject(parent
) { }
1362 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
);
1363 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
);
1364 wxRichTextImage(const wxRichTextImage
& obj
):wxRichTextObject() { Copy(obj
); }
1369 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1371 /// Lay the item out
1372 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1374 /// Get the object size for the given range. Returns false if the range
1375 /// is invalid for this object.
1376 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1378 /// Returns true if the object is empty
1379 virtual bool IsEmpty() const { return !m_image
.Ok(); }
1384 const wxImage
& GetImage() const { return m_image
; }
1387 void SetImage(const wxImage
& image
) { m_image
= image
; }
1389 /// Get the image block containing the raw data
1390 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
1395 void Copy(const wxRichTextImage
& obj
);
1398 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
1400 /// Load wxImage from the block
1401 virtual bool LoadFromBlock();
1403 /// Make block from the wxImage
1404 virtual bool MakeBlock();
1407 // TODO: reduce the multiple representations of data
1410 wxRichTextImageBlock m_imageBlock
;
1415 * wxRichTextBuffer class declaration
1416 * This is a kind of box, used to represent the whole buffer
1419 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
;
1420 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1422 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
1424 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
1428 wxRichTextBuffer() { Init(); }
1429 wxRichTextBuffer(const wxRichTextBuffer
& obj
):wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
1430 ~wxRichTextBuffer() ;
1434 /// Gets the command processor
1435 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
1437 /// Set style sheet, if any.
1438 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
1439 wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
1446 /// Clears the buffer and resets the command processor
1447 virtual void Clear();
1449 /// The same as Clear, and adds an empty paragraph.
1450 virtual void Reset();
1453 virtual bool LoadFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1456 virtual bool SaveFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1458 /// Load from a stream
1459 virtual bool LoadFile(wxInputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1461 /// Save to a stream
1462 virtual bool SaveFile(wxOutputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1464 /// Convenience function to add a paragraph of text
1465 virtual wxRichTextRange
AddParagraph(const wxString
& text
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
); }
1467 /// Begin collapsing undo/redo commands. Note that this may not work properly
1468 /// if combining commands that delete or insert content, changing ranges for
1469 /// subsequent actions.
1470 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1472 /// End collapsing undo/redo commands
1473 virtual bool EndBatchUndo();
1475 /// Collapsing commands?
1476 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
1478 /// Submit immediately, or delay according to whether collapsing is on
1479 virtual bool SubmitAction(wxRichTextAction
* action
);
1481 /// Get collapsed command
1482 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
1484 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1485 /// differently by each command. If not dealt with by a command implementation, then
1486 /// it will be implemented automatically by not storing the command in the undo history
1487 /// when the action is submitted to the command processor.
1488 virtual bool BeginSuppressUndo();
1490 /// End suppressing undo/redo commands.
1491 virtual bool EndSuppressUndo();
1493 /// Collapsing commands?
1494 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
1496 /// Copy the range to the clipboard
1497 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
1499 /// Paste the clipboard content to the buffer
1500 virtual bool PasteFromClipboard(long position
);
1502 /// Can we paste from the clipboard?
1503 virtual bool CanPasteFromClipboard() const;
1505 /// Begin using a style
1506 virtual bool BeginStyle(const wxTextAttrEx
& style
);
1509 virtual bool EndStyle();
1512 virtual bool EndAllStyles();
1514 /// Clear the style stack
1515 virtual void ClearStyleStack();
1517 /// Get the size of the style stack, for example to check correct nesting
1518 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
1520 /// Begin using bold
1524 bool EndBold() { return EndStyle(); }
1526 /// Begin using italic
1529 /// End using italic
1530 bool EndItalic() { return EndStyle(); }
1532 /// Begin using underline
1533 bool BeginUnderline();
1535 /// End using underline
1536 bool EndUnderline() { return EndStyle(); }
1538 /// Begin using point size
1539 bool BeginFontSize(int pointSize
);
1541 /// End using point size
1542 bool EndFontSize() { return EndStyle(); }
1544 /// Begin using this font
1545 bool BeginFont(const wxFont
& font
);
1547 /// End using a font
1548 bool EndFont() { return EndStyle(); }
1550 /// Begin using this colour
1551 bool BeginTextColour(const wxColour
& colour
);
1553 /// End using a colour
1554 bool EndTextColour() { return EndStyle(); }
1556 /// Begin using alignment
1557 bool BeginAlignment(wxTextAttrAlignment alignment
);
1560 bool EndAlignment() { return EndStyle(); }
1562 /// Begin left indent
1563 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
1566 bool EndLeftIndent() { return EndStyle(); }
1568 /// Begin right indent
1569 bool BeginRightIndent(int rightIndent
);
1571 /// End right indent
1572 bool EndRightIndent() { return EndStyle(); }
1574 /// Begin paragraph spacing
1575 bool BeginParagraphSpacing(int before
, int after
);
1577 /// End paragraph spacing
1578 bool EndParagraphSpacing() { return EndStyle(); }
1580 /// Begin line spacing
1581 bool BeginLineSpacing(int lineSpacing
);
1583 /// End line spacing
1584 bool EndLineSpacing() { return EndStyle(); }
1586 /// Begin numbered bullet
1587 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
1589 /// End numbered bullet
1590 bool EndNumberedBullet() { return EndStyle(); }
1592 /// Begin symbol bullet
1593 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
1595 /// End symbol bullet
1596 bool EndSymbolBullet() { return EndStyle(); }
1598 /// Begin named character style
1599 bool BeginCharacterStyle(const wxString
& characterStyle
);
1601 /// End named character style
1602 bool EndCharacterStyle() { return EndStyle(); }
1604 /// Begin named paragraph style
1605 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
1607 /// End named character style
1608 bool EndParagraphStyle() { return EndStyle(); }
1613 void Copy(const wxRichTextBuffer
& obj
) { wxRichTextBox::Copy(obj
); }
1616 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
1618 /// Submit command to insert the given text
1619 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
);
1621 /// Submit command to insert a newline
1622 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
);
1624 /// Submit command to insert the given image
1625 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
);
1627 /// Submit command to delete this range
1628 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, long initialCaretPosition
, long newCaretPositon
, wxRichTextCtrl
* ctrl
);
1631 void Modify(bool modify
= true) { m_modified
= modify
; }
1632 bool IsModified() const { return m_modified
; }
1634 /// Dumps contents of buffer for debugging purposes
1635 virtual void Dump();
1636 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
1638 /// Returns the file handlers
1639 static wxList
& GetHandlers() { return sm_handlers
; }
1641 /// Adds a handler to the end
1642 static void AddHandler(wxRichTextFileHandler
*handler
);
1644 /// Inserts a handler at the front
1645 static void InsertHandler(wxRichTextFileHandler
*handler
);
1647 /// Removes a handler
1648 static bool RemoveHandler(const wxString
& name
);
1650 /// Finds a handler by name
1651 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
1653 /// Finds a handler by extension and type
1654 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, int imageType
);
1656 /// Finds a handler by filename or, if supplied, type
1657 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
, int imageType
);
1659 /// Finds a handler by type
1660 static wxRichTextFileHandler
*FindHandler(int imageType
);
1662 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1663 /// will be filled with the file type corresponding to each filter. This can be
1664 /// used to determine the type to pass to LoadFile given a selected filter.
1665 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
1667 /// Clean up handlers
1668 static void CleanUpHandlers();
1670 /// Initialise the standard handlers
1671 static void InitStandardHandlers();
1675 /// Command processor
1676 wxCommandProcessor
* m_commandProcessor
;
1678 /// Has been modified?
1681 /// Collapsed command stack
1682 int m_batchedCommandDepth
;
1684 /// Name for collapsed command
1685 wxString m_batchedCommandsName
;
1687 /// Current collapsed command accumulating actions
1688 wxRichTextCommand
* m_batchedCommand
;
1690 /// Whether to suppress undo
1693 /// Style sheet, if any
1694 wxRichTextStyleSheet
* m_styleSheet
;
1696 /// Stack of attributes for convenience functions
1697 wxList m_attributeStack
;
1700 static wxList sm_handlers
;
1704 * The command identifiers
1708 enum wxRichTextCommandId
1712 wxRICHTEXT_CHANGE_STYLE
1716 * Command classes for undo/redo
1720 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1721 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
1724 // Ctor for one action
1725 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1726 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1728 // Ctor for multiple actions
1729 wxRichTextCommand(const wxString
& name
);
1731 ~wxRichTextCommand();
1736 void AddAction(wxRichTextAction
* action
);
1737 void ClearActions();
1739 wxList
& GetActions() { return m_actions
; }
1747 * wxRichTextAction class declaration
1748 * There can be more than one action in a command.
1751 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
1754 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1755 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1757 ~wxRichTextAction();
1762 /// Update the control appearance
1763 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false);
1765 /// Replace the buffer paragraphs with the given fragment.
1766 void ApplyParagraphs(const wxRichTextFragment
& fragment
);
1768 /// Get the fragments
1769 wxRichTextFragment
& GetNewParagraphs() { return m_newParagraphs
; }
1770 wxRichTextFragment
& GetOldParagraphs() { return m_oldParagraphs
; }
1772 /// Set/get the position used for e.g. insertion
1773 void SetPosition(long pos
) { m_position
= pos
; }
1774 long GetPosition() const { return m_position
; }
1776 /// Set/get the range for e.g. deletion
1777 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1778 const wxRichTextRange
& GetRange() const { return m_range
; }
1781 const wxString
& GetName() const { return m_name
; }
1788 wxRichTextBuffer
* m_buffer
;
1791 wxRichTextCtrl
* m_ctrl
;
1793 // Stores the new paragraphs
1794 wxRichTextFragment m_newParagraphs
;
1796 // Stores the old paragraphs
1797 wxRichTextFragment m_oldParagraphs
;
1799 // The affected range
1800 wxRichTextRange m_range
;
1802 // The insertion point for this command
1805 // Ignore 1st 'Do' operation because we already did it
1808 // The command identifier
1809 wxRichTextCommandId m_cmdId
;
1813 * wxRichTextFileHandler
1814 * Base class for file handlers
1817 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
1819 DECLARE_CLASS(wxRichTextFileHandler
)
1821 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
1822 : m_name(name
), m_extension(ext
), m_type(type
), m_visible(true)
1826 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
1827 { return DoLoadFile(buffer
, stream
); }
1828 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
1829 { return DoSaveFile(buffer
, stream
); }
1832 bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1833 bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1835 /// Can we handle this filename (if using files)? By default, checks the extension.
1836 virtual bool CanHandle(const wxString
& filename
) const;
1838 /// Can we save using this handler?
1839 virtual bool CanSave() const { return false; }
1841 /// Can we load using this handler?
1842 virtual bool CanLoad() const { return false; }
1844 /// Should this handler be visible to the user?
1845 virtual bool IsVisible() const { return m_visible
; }
1846 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
1848 /// The name of the nandler
1849 void SetName(const wxString
& name
) { m_name
= name
; }
1850 wxString
GetName() const { return m_name
; }
1852 /// The default extension to recognise
1853 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
1854 wxString
GetExtension() const { return m_extension
; }
1856 /// The handler type
1857 void SetType(int type
) { m_type
= type
; }
1858 int GetType() const { return m_type
; }
1860 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
1861 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
1862 const wxString
& GetEncoding() const { return m_encoding
; }
1867 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
1868 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
1872 wxString m_encoding
;
1873 wxString m_extension
;
1879 * wxRichTextPlainTextHandler
1880 * Plain text handler
1883 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
1885 DECLARE_CLASS(wxRichTextPlainTextHandler
)
1887 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"), const wxString
& ext
= wxT("txt"), int type
= wxRICHTEXT_TYPE_TEXT
)
1888 : wxRichTextFileHandler(name
, ext
, type
)
1891 /// Can we save using this handler?
1892 virtual bool CanSave() const { return true; }
1894 /// Can we load using this handler?
1895 virtual bool CanLoad() const { return true; }
1900 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
1901 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
1911 inline bool wxRichTextHasStyle(int flags
, int style
)
1913 return ((flags
& style
) == style
);
1916 /// Compare two attribute objects
1917 bool wxTextAttrEq(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
);
1918 bool wxTextAttrEq(const wxTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
1920 /// Compare two attribute objects, but take into account the flags
1921 /// specifying attributes of interest.
1922 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
, int flags
);
1923 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxRichTextAttr
& attr2
, int flags
);
1925 /// Apply one style to another
1926 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxTextAttrEx
& style
);
1927 bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxTextAttrEx
& style
);
1928 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxRichTextAttr
& style
);
1934 // _WX_RICHTEXTBUFFER_H_