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 is a single box representing the document, and this box is
26 a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph
27 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.
37 Note that internally, a range (5,5) represents a range of one character.
38 In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection
39 as (5,6). A paragraph with one character might have an internal range of (0, 1)
40 since the end of the paragraph takes up one position.
45 When Layout is called on an object, it is given a size which the object
46 must limit itself to, or one or more flexible directions (vertical
47 or horizontal). So for example a centered paragraph is given the page
48 width to play with (minus any margins), but can extend indefinitely
49 in the vertical direction. The implementation of Layout can then
50 cache the calculated size and position within the parent.
63 #include "wx/textctrl.h"
64 #include "wx/bitmap.h"
66 #include "wx/cmdproc.h"
67 #include "wx/txtstrm.h"
70 #include "wx/dataobj.h"
73 // Experimental dynamic styles to avoid user-specific character styles from being
74 // overwritten by paragraph styles.
75 #define wxRICHTEXT_USE_DYNAMIC_STYLES 1
81 #define wxRICHTEXT_TYPE_ANY 0
82 #define wxRICHTEXT_TYPE_TEXT 1
83 #define wxRICHTEXT_TYPE_XML 2
84 #define wxRICHTEXT_TYPE_HTML 3
85 #define wxRICHTEXT_TYPE_RTF 4
86 #define wxRICHTEXT_TYPE_PDF 5
89 * Forward declarations
92 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl
;
93 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
;
94 class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject
;
95 class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList
;
96 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
;
97 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
;
98 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
;
99 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet
;
100 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx
;
101 class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition
;
104 * Flags determining the available space, passed to Layout
107 #define wxRICHTEXT_FIXED_WIDTH 0x01
108 #define wxRICHTEXT_FIXED_HEIGHT 0x02
109 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
110 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
112 // Only lay out the part of the buffer that lies within
113 // the rect passed to Layout.
114 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
117 * Flags returned from hit-testing
120 // The point was not on this object
121 #define wxRICHTEXT_HITTEST_NONE 0x01
122 // The point was before the position returned from HitTest
123 #define wxRICHTEXT_HITTEST_BEFORE 0x02
124 // The point was after the position returned from HitTest
125 #define wxRICHTEXT_HITTEST_AFTER 0x04
126 // The point was on the position returned from HitTest
127 #define wxRICHTEXT_HITTEST_ON 0x08
130 * Flags for GetRangeSize
133 #define wxRICHTEXT_FORMATTED 0x01
134 #define wxRICHTEXT_UNFORMATTED 0x02
137 * Flags for SetStyle/SetListStyle
140 #define wxRICHTEXT_SETSTYLE_NONE 0x00
142 // Specifies that this operation should be undoable
143 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
145 // Specifies that the style should not be applied if the
146 // combined style at this point is already the style in question.
147 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
149 // Specifies that the style should only be applied to paragraphs,
150 // and not the content. This allows content styling to be
151 // preserved independently from that of e.g. a named paragraph style.
152 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
154 // Specifies that the style should only be applied to characters,
155 // and not the paragraph. This allows content styling to be
156 // preserved independently from that of e.g. a named paragraph style.
157 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
159 // For SetListStyle only: specifies starting from the given number, otherwise
160 // deduces number from existing attributes
161 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
163 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
164 // the current indentation will be used
165 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
168 * Flags for text insertion
171 #define wxRICHTEXT_INSERT_NONE 0x00
172 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
175 * Extra formatting flags not in wxTextAttr
178 #define wxTEXT_ATTR_PARA_SPACING_AFTER 0x00000800
179 #define wxTEXT_ATTR_PARA_SPACING_BEFORE 0x00001000
180 #define wxTEXT_ATTR_LINE_SPACING 0x00002000
181 #define wxTEXT_ATTR_CHARACTER_STYLE_NAME 0x00004000
182 #define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME 0x00008000
183 #define wxTEXT_ATTR_LIST_STYLE_NAME 0x00010000
184 #define wxTEXT_ATTR_BULLET_STYLE 0x00020000
185 #define wxTEXT_ATTR_BULLET_NUMBER 0x00040000
186 #define wxTEXT_ATTR_BULLET_SYMBOL 0x00080000
187 #define wxTEXT_ATTR_BULLET_NAME 0x00100000
190 * Styles for wxTextAttrEx::SetBulletStyle
193 #define wxTEXT_ATTR_BULLET_STYLE_NONE 0x0000
194 #define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x0001
195 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x0002
196 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x0004
197 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x0008
198 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x0010
199 #define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x0020
200 #define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x0040
201 #define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x0080
202 #define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x0100
203 #define wxTEXT_ATTR_BULLET_STYLE_STANDARD 0x0200
206 * Line spacing values
209 #define wxTEXT_ATTR_LINE_SPACING_NORMAL 10
210 #define wxTEXT_ATTR_LINE_SPACING_HALF 15
211 #define wxTEXT_ATTR_LINE_SPACING_TWICE 20
214 * wxRichTextRange class declaration
215 * This stores beginning and end positions for a range of data.
218 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
223 wxRichTextRange() { m_start
= 0; m_end
= 0; }
224 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
225 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
226 ~wxRichTextRange() {}
228 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
229 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
230 bool operator !=(const wxRichTextRange
& range
) const { return (m_start
!= range
.m_start
&& m_end
!= range
.m_end
); }
231 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
232 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
234 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
236 void SetStart(long start
) { m_start
= start
; }
237 long GetStart() const { return m_start
; }
239 void SetEnd(long end
) { m_end
= end
; }
240 long GetEnd() const { return m_end
; }
242 /// Returns true if this range is completely outside 'range'
243 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
245 /// Returns true if this range is completely within 'range'
246 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
248 /// Returns true if the given position is within this range. Allow
249 /// for the possibility of an empty range - assume the position
250 /// is within this empty range. NO, I think we should not match with an empty range.
251 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
252 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
254 /// Limit this range to be within 'range'
255 bool LimitTo(const wxRichTextRange
& range
) ;
257 /// Gets the length of the range
258 long GetLength() const { return m_end
- m_start
+ 1; }
260 /// Swaps the start and end
261 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
263 /// Convert to internal form: (n, n) is the range of a single character.
264 wxRichTextRange
ToInternal() const { return wxRichTextRange(m_start
, m_end
-1); }
266 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
267 wxRichTextRange
FromInternal() const { return wxRichTextRange(m_start
, m_end
+1); }
274 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
275 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
278 * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
281 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx
: public wxTextAttr
285 wxTextAttrEx(const wxTextAttrEx
& attr
);
286 wxTextAttrEx(const wxTextAttr
& attr
) { Init(); (*this) = attr
; }
287 wxTextAttrEx() { Init(); }
289 // Initialise this object
292 // Assignment from a wxTextAttrEx object
293 void operator= (const wxTextAttrEx
& attr
);
295 // Assignment from a wxTextAttr object
296 void operator= (const wxTextAttr
& attr
);
299 bool operator== (const wxTextAttrEx
& attr
) const;
302 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME
); }
303 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
); }
304 void SetListStyleName(const wxString
& name
) { m_listStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME
); }
305 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER
); }
306 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE
); }
307 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING
); }
308 void SetBulletStyle(int style
) { m_bulletStyle
= style
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE
); }
309 void SetBulletNumber(int n
) { m_bulletNumber
= n
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER
); }
310 void SetBulletSymbol(wxChar symbol
) { m_bulletSymbol
= symbol
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_SYMBOL
); }
311 void SetBulletName(const wxString
& name
) { m_bulletName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NAME
); }
312 void SetBulletFont(const wxString
& bulletFont
) { m_bulletFont
= bulletFont
; }
314 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
315 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
316 const wxString
& GetListStyleName() const { return m_listStyleName
; }
317 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
318 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
319 int GetLineSpacing() const { return m_lineSpacing
; }
320 int GetBulletStyle() const { return m_bulletStyle
; }
321 int GetBulletNumber() const { return m_bulletNumber
; }
322 wxChar
GetBulletSymbol() const { return m_bulletSymbol
; }
323 const wxString
& GetBulletName() const { return m_bulletName
; }
324 const wxString
& GetBulletFont() const { return m_bulletFont
; }
326 bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
327 bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE
) != 0; }
328 bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC
) != 0; }
329 bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
330 bool HasFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE
) != 0; }
332 bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER
); }
333 bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE
); }
334 bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING
); }
335 bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME
) || !m_characterStyleName
.IsEmpty(); }
336 bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) || !m_paragraphStyleName
.IsEmpty(); }
337 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME
) || !m_listStyleName
.IsEmpty(); }
338 bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE
); }
339 bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER
); }
340 bool HasBulletSymbol() const { return HasFlag(wxTEXT_ATTR_BULLET_SYMBOL
); }
341 bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME
); }
343 // Is this a character style?
344 bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT
| wxTEXT_ATTR_BACKGROUND_COLOUR
| wxTEXT_ATTR_TEXT_COLOUR
))); }
345 bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_TABS
|
346 wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|wxTEXT_ATTR_LINE_SPACING
|
347 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_BULLET_NAME
))); }
349 // returns false if we have any attributes set, true otherwise
350 bool IsDefault() const
352 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
353 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
354 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
355 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
356 !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol() && !HasBulletName();
359 // return the attribute having the valid font and colours: it uses the
360 // attributes set in attr and falls back first to attrDefault and then to
361 // the text control font/colours for those attributes which are not set
362 static wxTextAttrEx
CombineEx(const wxTextAttrEx
& attr
,
363 const wxTextAttrEx
& attrDef
,
364 const wxTextCtrlBase
*text
);
368 int m_paragraphSpacingAfter
;
369 int m_paragraphSpacingBefore
;
373 wxChar m_bulletSymbol
;
374 wxString m_bulletFont
;
375 wxString m_bulletName
;
378 wxString m_characterStyleName
;
381 wxString m_paragraphStyleName
;
384 wxString m_listStyleName
;
388 * wxRichTextAttr stores attributes without a wxFont object, so is a much more
389 * efficient way to query styles.
392 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
396 wxRichTextAttr(const wxTextAttrEx
& attr
);
397 wxRichTextAttr() { Init(); }
398 wxRichTextAttr(const wxColour
& colText
,
399 const wxColour
& colBack
= wxNullColour
,
400 wxTextAttrAlignment alignment
= wxTEXT_ALIGNMENT_DEFAULT
);
402 // Initialise this object.
405 // Assignment from a wxRichTextAttr object.
406 void operator= (const wxRichTextAttr
& attr
);
408 // Assignment from a wxTextAttrEx object.
409 void operator= (const wxTextAttrEx
& attr
);
412 bool operator== (const wxRichTextAttr
& attr
) const;
414 // Making a wxTextAttrEx object.
415 operator wxTextAttrEx () const ;
417 // Copy to a wxTextAttr
418 void CopyTo(wxTextAttrEx
& attr
) const;
420 // Create font from font attributes.
421 wxFont
CreateFont() const;
423 // Get attributes from font.
424 bool GetFontAttributes(const wxFont
& font
);
427 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; m_flags
|= wxTEXT_ATTR_TEXT_COLOUR
; }
428 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; m_flags
|= wxTEXT_ATTR_BACKGROUND_COLOUR
; }
429 void SetAlignment(wxTextAttrAlignment alignment
) { m_textAlignment
= alignment
; m_flags
|= wxTEXT_ATTR_ALIGNMENT
; }
430 void SetTabs(const wxArrayInt
& tabs
) { m_tabs
= tabs
; m_flags
|= wxTEXT_ATTR_TABS
; }
431 void SetLeftIndent(int indent
, int subIndent
= 0) { m_leftIndent
= indent
; m_leftSubIndent
= subIndent
; m_flags
|= wxTEXT_ATTR_LEFT_INDENT
; }
432 void SetRightIndent(int indent
) { m_rightIndent
= indent
; m_flags
|= wxTEXT_ATTR_RIGHT_INDENT
; }
434 void SetFontSize(int pointSize
) { m_fontSize
= pointSize
; m_flags
|= wxTEXT_ATTR_FONT_SIZE
; }
435 void SetFontStyle(int fontStyle
) { m_fontStyle
= fontStyle
; m_flags
|= wxTEXT_ATTR_FONT_ITALIC
; }
436 void SetFontWeight(int fontWeight
) { m_fontWeight
= fontWeight
; m_flags
|= wxTEXT_ATTR_FONT_WEIGHT
; }
437 void SetFontFaceName(const wxString
& faceName
) { m_fontFaceName
= faceName
; m_flags
|= wxTEXT_ATTR_FONT_FACE
; }
438 void SetFontUnderlined(bool underlined
) { m_fontUnderlined
= underlined
; m_flags
|= wxTEXT_ATTR_FONT_UNDERLINE
; }
440 void SetFlags(long flags
) { m_flags
= flags
; }
442 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; m_flags
|= wxTEXT_ATTR_CHARACTER_STYLE_NAME
; }
443 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; m_flags
|= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
; }
444 void SetListStyleName(const wxString
& name
) { m_listStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME
); }
445 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; m_flags
|= wxTEXT_ATTR_PARA_SPACING_AFTER
; }
446 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; m_flags
|= wxTEXT_ATTR_PARA_SPACING_BEFORE
; }
447 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; m_flags
|= wxTEXT_ATTR_LINE_SPACING
; }
448 void SetBulletStyle(int style
) { m_bulletStyle
= style
; m_flags
|= wxTEXT_ATTR_BULLET_STYLE
; }
449 void SetBulletNumber(int n
) { m_bulletNumber
= n
; m_flags
|= wxTEXT_ATTR_BULLET_NUMBER
; }
450 void SetBulletSymbol(wxChar symbol
) { m_bulletSymbol
= symbol
; m_flags
|= wxTEXT_ATTR_BULLET_NUMBER
; }
451 void SetBulletFont(const wxString
& bulletFont
) { m_bulletFont
= bulletFont
; }
452 void SetBulletName(const wxString
& name
) { m_bulletName
= name
; }
454 const wxColour
& GetTextColour() const { return m_colText
; }
455 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
456 wxTextAttrAlignment
GetAlignment() const { return m_textAlignment
; }
457 const wxArrayInt
& GetTabs() const { return m_tabs
; }
458 long GetLeftIndent() const { return m_leftIndent
; }
459 long GetLeftSubIndent() const { return m_leftSubIndent
; }
460 long GetRightIndent() const { return m_rightIndent
; }
461 long GetFlags() const { return m_flags
; }
463 int GetFontSize() const { return m_fontSize
; }
464 int GetFontStyle() const { return m_fontStyle
; }
465 int GetFontWeight() const { return m_fontWeight
; }
466 bool GetFontUnderlined() const { return m_fontUnderlined
; }
467 const wxString
& GetFontFaceName() const { return m_fontFaceName
; }
469 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
470 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
471 const wxString
& GetListStyleName() const { return m_listStyleName
; }
472 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
473 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
474 int GetLineSpacing() const { return m_lineSpacing
; }
475 int GetBulletStyle() const { return m_bulletStyle
; }
476 int GetBulletNumber() const { return m_bulletNumber
; }
477 wxChar
GetBulletSymbol() const { return m_bulletSymbol
; }
478 const wxString
& GetBulletFont() const { return m_bulletFont
; }
479 const wxString
& GetBulletName() const { return m_bulletName
; }
482 bool HasTextColour() const { return m_colText
.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR
) ; }
483 bool HasBackgroundColour() const { return m_colBack
.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR
) ; }
484 bool HasAlignment() const { return (m_textAlignment
!= wxTEXT_ALIGNMENT_DEFAULT
) || ((m_flags
& wxTEXT_ATTR_ALIGNMENT
) != 0) ; }
485 bool HasTabs() const { return (m_flags
& wxTEXT_ATTR_TABS
) != 0 ; }
486 bool HasLeftIndent() const { return (m_flags
& wxTEXT_ATTR_LEFT_INDENT
) != 0 ; }
487 bool HasRightIndent() const { return (m_flags
& wxTEXT_ATTR_RIGHT_INDENT
) != 0 ; }
488 bool HasWeight() const { return (m_flags
& wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
489 bool HasSize() const { return (m_flags
& wxTEXT_ATTR_FONT_SIZE
) != 0; }
490 bool HasItalic() const { return (m_flags
& wxTEXT_ATTR_FONT_ITALIC
) != 0; }
491 bool HasUnderlined() const { return (m_flags
& wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
492 bool HasFaceName() const { return (m_flags
& wxTEXT_ATTR_FONT_FACE
) != 0; }
493 bool HasFont() const { return (m_flags
& (wxTEXT_ATTR_FONT
)) != 0; }
495 bool HasParagraphSpacingAfter() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) != 0; }
496 bool HasParagraphSpacingBefore() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) != 0; }
497 bool HasLineSpacing() const { return (m_flags
& wxTEXT_ATTR_LINE_SPACING
) != 0; }
498 bool HasCharacterStyleName() const { return (m_flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) != 0 || !m_characterStyleName
.IsEmpty(); }
499 bool HasParagraphStyleName() const { return (m_flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) != 0 || !m_paragraphStyleName
.IsEmpty(); }
500 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME
) || !m_listStyleName
.IsEmpty(); }
501 bool HasBulletStyle() const { return (m_flags
& wxTEXT_ATTR_BULLET_STYLE
) != 0; }
502 bool HasBulletNumber() const { return (m_flags
& wxTEXT_ATTR_BULLET_NUMBER
) != 0; }
503 bool HasBulletSymbol() const { return (m_flags
& wxTEXT_ATTR_BULLET_SYMBOL
) != 0; }
504 bool HasBulletName() const { return (m_flags
& wxTEXT_ATTR_BULLET_NAME
) != 0; }
506 bool HasFlag(long flag
) const { return (m_flags
& flag
) != 0; }
508 // Is this a character style?
509 bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT
| wxTEXT_ATTR_BACKGROUND_COLOUR
| wxTEXT_ATTR_TEXT_COLOUR
))); }
510 bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT
|wxTEXT_ATTR_LEFT_INDENT
|wxTEXT_ATTR_RIGHT_INDENT
|wxTEXT_ATTR_TABS
|
511 wxTEXT_ATTR_PARA_SPACING_BEFORE
|wxTEXT_ATTR_PARA_SPACING_AFTER
|wxTEXT_ATTR_LINE_SPACING
|
512 wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_BULLET_NAME
))); }
514 // returns false if we have any attributes set, true otherwise
515 bool IsDefault() const
517 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
518 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
519 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
520 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
521 !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol() && !HasBulletName();
524 // return the attribute having the valid font and colours: it uses the
525 // attributes set in attr and falls back first to attrDefault and then to
526 // the text control font/colours for those attributes which are not set
527 static wxRichTextAttr
Combine(const wxRichTextAttr
& attr
,
528 const wxRichTextAttr
& attrDef
,
529 const wxTextCtrlBase
*text
);
534 wxArrayInt m_tabs
; // array of int: tab stops in 1/10 mm
535 int m_leftIndent
; // left indent in 1/10 mm
536 int m_leftSubIndent
; // left indent for all but the first
537 // line in a paragraph relative to the
538 // first line, in 1/10 mm
539 int m_rightIndent
; // right indent in 1/10 mm
540 wxTextAttrAlignment m_textAlignment
;
542 int m_paragraphSpacingAfter
;
543 int m_paragraphSpacingBefore
;
547 wxChar m_bulletSymbol
;
548 wxString m_bulletFont
;
549 wxString m_bulletName
;
557 bool m_fontUnderlined
;
558 wxString m_fontFaceName
;
561 wxString m_characterStyleName
;
564 wxString m_paragraphStyleName
;
567 wxString m_listStyleName
;
570 #define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR | wxTEXT_ATTR_CHARACTER_STYLE_NAME)
572 #define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
573 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
574 wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_BULLET_NAME|\
575 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME)
577 #define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
580 * wxRichTextObject class declaration
581 * This is the base for drawable objects.
584 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
586 DECLARE_CLASS(wxRichTextObject
)
590 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
591 virtual ~wxRichTextObject();
595 /// Draw the item, within the given range. Some objects may ignore the range (for
596 /// example paragraphs) while others must obey it (lines, to implement wrapping)
597 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
) = 0;
599 /// Lay the item out at the specified position with the given size constraint.
600 /// Layout must set the cached size.
601 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
603 /// Hit-testing: returns a flag indicating hit test details, plus
604 /// information about position
605 virtual int HitTest(wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pt
), long& WXUNUSED(textPosition
)) { return false; }
607 /// Finds the absolute position and row height for the given character position
608 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
610 /// Get the best size, i.e. the ideal starting size for this object irrespective
611 /// of available space. For a short text string, it will be the size that exactly encloses
612 /// the text. For a longer string, it might use the parent width for example.
613 virtual wxSize
GetBestSize() const { return m_size
; }
615 /// Get the object size for the given range. Returns false if the range
616 /// is invalid for this object.
617 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const = 0;
619 /// Do a split, returning an object containing the second part, and setting
620 /// the first part in 'this'.
621 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
623 /// Calculate range. By default, guess that the object is 1 unit long.
624 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
627 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
629 /// Returns true if the object is empty
630 virtual bool IsEmpty() const { return false; }
632 /// Get any text in this object for the given range
633 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
635 /// Returns true if this object can merge itself with the given one.
636 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
638 /// Returns true if this object merged itself with the given one.
639 /// The calling code will then delete the given object.
640 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
642 /// Dump to output stream for debugging
643 virtual void Dump(wxTextOutputStream
& stream
);
647 /// Get/set the cached object size as calculated by Layout.
648 virtual wxSize
GetCachedSize() const { return m_size
; }
649 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
651 /// Get/set the object position
652 virtual wxPoint
GetPosition() const { return m_pos
; }
653 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
655 /// Get the rectangle enclosing the object
656 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
659 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
662 const wxRichTextRange
& GetRange() const { return m_range
; }
663 wxRichTextRange
& GetRange() { return m_range
; }
665 /// Get/set dirty flag (whether the object needs Layout to be called)
666 virtual bool GetDirty() const { return m_dirty
; }
667 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
669 /// Is this composite?
670 virtual bool IsComposite() const { return false; }
672 /// Get/set the parent.
673 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
674 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
676 /// Set the margin around the object
677 virtual void SetMargins(int margin
);
678 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
679 virtual int GetLeftMargin() const { return m_leftMargin
; }
680 virtual int GetRightMargin() const { return m_rightMargin
; }
681 virtual int GetTopMargin() const { return m_topMargin
; }
682 virtual int GetBottomMargin() const { return m_bottomMargin
; }
684 /// Set attributes object
685 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
686 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
687 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
689 /// Set/get stored descent
690 void SetDescent(int descent
) { m_descent
= descent
; }
691 int GetDescent() const { return m_descent
; }
696 virtual wxRichTextObject
* Clone() const { return NULL
; }
699 void Copy(const wxRichTextObject
& obj
);
701 /// Reference-counting allows us to use the same object in multiple
702 /// lists (not yet used)
703 void Reference() { m_refCount
++; }
706 /// Convert units in tends of a millimetre to device units
707 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
);
712 int m_descent
; // Descent for this object (if any)
715 wxRichTextObject
* m_parent
;
717 /// The range of this object (start position to end position)
718 wxRichTextRange m_range
;
727 wxTextAttrEx m_attributes
;
730 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
733 * wxRichTextCompositeObject class declaration
734 * Objects of this class can contain other objects.
737 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
739 DECLARE_CLASS(wxRichTextCompositeObject
)
743 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
744 virtual ~wxRichTextCompositeObject();
748 /// Hit-testing: returns a flag indicating hit test details, plus
749 /// information about position
750 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
752 /// Finds the absolute position and row height for the given character position
753 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
756 virtual void CalculateRange(long start
, long& end
);
759 virtual bool DeleteRange(const wxRichTextRange
& range
);
761 /// Get any text in this object for the given range
762 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
764 /// Dump to output stream for debugging
765 virtual void Dump(wxTextOutputStream
& stream
);
770 wxRichTextObjectList
& GetChildren() { return m_children
; }
771 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
773 /// Get the child count
774 size_t GetChildCount() const ;
776 /// Get the nth child
777 wxRichTextObject
* GetChild(size_t n
) const ;
779 /// Get/set dirty flag
780 virtual bool GetDirty() const { return m_dirty
; }
781 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
783 /// Is this composite?
784 virtual bool IsComposite() const { return true; }
786 /// Returns true if the buffer is empty
787 virtual bool IsEmpty() const { return GetChildCount() == 0; }
792 void Copy(const wxRichTextCompositeObject
& obj
);
795 void operator= (const wxRichTextCompositeObject
& obj
) { Copy(obj
); }
797 /// Append a child, returning the position
798 size_t AppendChild(wxRichTextObject
* child
) ;
800 /// Insert the child in front of the given object, or at the beginning
801 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
804 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
806 /// Delete all children
807 bool DeleteChildren() ;
809 /// Recursively merge all pieces that can be merged.
813 wxRichTextObjectList m_children
;
817 * wxRichTextBox class declaration
818 * This defines a 2D space to lay out objects
821 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextCompositeObject
823 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
827 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
828 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
833 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
836 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
838 /// Get/set the object size for the given range. Returns false if the range
839 /// is invalid for this object.
840 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
847 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
850 void Copy(const wxRichTextBox
& obj
);
856 * wxRichTextParagraphBox class declaration
857 * This box knows how to lay out paragraphs.
860 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextBox
862 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
866 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
867 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
): wxRichTextBox() { Init(); Copy(obj
); }
872 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
875 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
877 /// Get/set the object size for the given range. Returns false if the range
878 /// is invalid for this object.
879 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
882 virtual bool DeleteRange(const wxRichTextRange
& range
);
884 /// Get any text in this object for the given range
885 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
889 /// Associate a control with the buffer, for operations that for example require refreshing the window.
890 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
892 /// Get the associated control.
893 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
895 /// Get/set whether the last paragraph is partial or complete
896 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
897 bool GetPartialParagraph() const { return m_partialParagraph
; }
899 /// If this is a buffer, returns the current style sheet. The base layout box
900 /// class doesn't have an associated style sheet.
901 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return NULL
; }
905 /// Initialize the object.
908 /// Clear all children
909 virtual void Clear();
911 /// Clear and initialize with one blank paragraph
912 virtual void Reset();
914 /// Convenience function to add a paragraph of text
915 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
);
917 /// Convenience function to add an image
918 virtual wxRichTextRange
AddImage(const wxImage
& image
, wxTextAttrEx
* paraStyle
= NULL
);
920 /// Adds multiple paragraphs, based on newlines.
921 virtual wxRichTextRange
AddParagraphs(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
);
923 /// Get the line at the given position. If caretPosition is true, the position is
924 /// a caret position, which is normally a smaller number.
925 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
927 /// Get the line at the given y pixel position, or the last line.
928 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
930 /// Get the paragraph at the given character or caret position
931 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
933 /// Get the line size at the given position
934 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
936 /// Given a position, get the number of the visible line (potentially many to a paragraph),
937 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
938 /// that indicates whether the caret is being shown at the end of the previous line or at the start
939 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
941 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
943 /// Given a line number, get the corresponding wxRichTextLine object.
944 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
946 /// Get the leaf object in a paragraph at this position.
947 /// Given a line number, get the corresponding wxRichTextLine object.
948 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
950 /// Get the paragraph by number
951 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
953 /// Get the paragraph for a given line
954 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
956 /// Get the length of the paragraph
957 virtual int GetParagraphLength(long paragraphNumber
) const;
959 /// Get the number of paragraphs
960 virtual int GetParagraphCount() const { return GetChildCount(); }
962 /// Get the number of visible lines
963 virtual int GetLineCount() const;
965 /// Get the text of the paragraph
966 virtual wxString
GetParagraphText(long paragraphNumber
) const;
968 /// Convert zero-based line column and paragraph number to a position.
969 virtual long XYToPosition(long x
, long y
) const;
971 /// Convert zero-based position to line column and paragraph number
972 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
974 /// Set text attributes: character and/or paragraph styles.
975 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
976 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttrEx
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
978 /// Get the conbined text attributes for this position.
979 virtual bool GetStyle(long position
, wxTextAttrEx
& style
);
980 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
982 /// Get the content (uncombined) attributes for this position.
983 virtual bool GetUncombinedStyle(long position
, wxTextAttrEx
& style
);
984 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
986 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
987 /// context attributes.
988 virtual bool DoGetStyle(long position
, wxTextAttrEx
& style
, bool combineStyles
= true);
990 /// Get the combined style for a range - if any attribute is different within the range,
991 /// that attribute is not present within the flags
992 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttrEx
& style
);
994 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
996 bool CollectStyle(wxTextAttrEx
& currentStyle
, const wxTextAttrEx
& style
, long& multipleStyleAttributes
);
999 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1000 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1002 /// Clear list for given range
1003 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1005 /// Number/renumber any list elements in the given range.
1006 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1007 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1008 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1010 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1011 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1012 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1013 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1015 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1016 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1017 virtual bool DoNumberList(const wxRichTextRange
& range
, const wxRichTextRange
& promotionRange
, int promoteBy
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1019 /// Test if this whole range has character attributes of the specified kind. If any
1020 /// of the attributes are different within the range, the test fails. You
1021 /// can use this to implement, for example, bold button updating. style must have
1022 /// flags indicating which attributes are of interest.
1023 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
1024 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1026 /// Test if this whole range has paragraph attributes of the specified kind. If any
1027 /// of the attributes are different within the range, the test fails. You
1028 /// can use this to implement, for example, centering button updating. style must have
1029 /// flags indicating which attributes are of interest.
1030 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
1031 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1034 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1036 /// Insert fragment into this box at the given position. If partialParagraph is true,
1037 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1039 virtual bool InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
);
1041 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1042 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
);
1044 /// Apply the style sheet to the buffer, for example if the styles have changed.
1045 virtual bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1048 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
1051 void operator= (const wxRichTextParagraphLayoutBox
& obj
) { Copy(obj
); }
1053 /// Calculate ranges
1054 virtual void UpdateRanges() { long end
; CalculateRange(0, end
); }
1056 /// Get all the text
1057 virtual wxString
GetText() const;
1059 /// Set default style for new content. Setting it to a default attribute
1060 /// makes new content take on the 'basic' style.
1061 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
1063 /// Get default style
1064 virtual const wxTextAttrEx
& GetDefaultStyle() const { return m_defaultAttributes
; }
1066 /// Set basic (overall) style
1067 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { m_attributes
= style
; }
1068 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { style
.CopyTo(m_attributes
); }
1070 /// Get basic (overall) style
1071 virtual const wxTextAttrEx
& GetBasicStyle() const { return m_attributes
; }
1073 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1074 void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1076 /// Get invalid range, rounding to entire paragraphs if argument is true.
1077 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
1080 wxRichTextCtrl
* m_ctrl
;
1081 wxTextAttrEx m_defaultAttributes
;
1083 /// The invalidated range that will need full layout
1084 wxRichTextRange m_invalidRange
;
1086 // Is the last paragraph partial or complete?
1087 bool m_partialParagraph
;
1091 * wxRichTextLine class declaration
1092 * This object represents a line in a paragraph, and stores
1093 * offsets from the start of the paragraph representing the
1094 * start and end positions of the line.
1097 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1102 wxRichTextLine(wxRichTextParagraph
* parent
);
1103 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
1104 virtual ~wxRichTextLine() {}
1111 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1112 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
1114 /// Get the parent paragraph
1115 wxRichTextParagraph
* GetParent() { return m_parent
; }
1118 const wxRichTextRange
& GetRange() const { return m_range
; }
1119 wxRichTextRange
& GetRange() { return m_range
; }
1121 /// Get the absolute range
1122 wxRichTextRange
GetAbsoluteRange() const;
1124 /// Get/set the line size as calculated by Layout.
1125 virtual wxSize
GetSize() const { return m_size
; }
1126 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
1128 /// Get/set the object position relative to the parent
1129 virtual wxPoint
GetPosition() const { return m_pos
; }
1130 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1132 /// Get the absolute object position
1133 virtual wxPoint
GetAbsolutePosition() const;
1135 /// Get the rectangle enclosing the line
1136 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1138 /// Set/get stored descent
1139 void SetDescent(int descent
) { m_descent
= descent
; }
1140 int GetDescent() const { return m_descent
; }
1145 void Init(wxRichTextParagraph
* parent
);
1148 void Copy(const wxRichTextLine
& obj
);
1151 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1155 /// The range of the line (start position to end position)
1156 /// This is relative to the parent paragraph.
1157 wxRichTextRange m_range
;
1159 /// Size and position measured relative to top of paragraph
1163 /// Maximum descent for this line (location of text baseline)
1166 // The parent object
1167 wxRichTextParagraph
* m_parent
;
1170 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
1173 * wxRichTextParagraph class declaration
1174 * This object represents a single paragraph (or in a straight text editor, a line).
1177 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextBox
1179 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
1183 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1184 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1185 virtual ~wxRichTextParagraph();
1186 wxRichTextParagraph(const wxRichTextParagraph
& obj
): wxRichTextBox() { Copy(obj
); }
1191 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1193 /// Lay the item out
1194 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1196 /// Get/set the object size for the given range. Returns false if the range
1197 /// is invalid for this object.
1198 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1200 /// Finds the absolute position and row height for the given character position
1201 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1203 /// Hit-testing: returns a flag indicating hit test details, plus
1204 /// information about position
1205 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1208 virtual void CalculateRange(long start
, long& end
);
1212 /// Get the cached lines
1213 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
1218 void Copy(const wxRichTextParagraph
& obj
);
1221 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
1223 /// Clear the cached lines
1228 /// Apply paragraph styles such as centering to the wrapped lines
1229 virtual void ApplyParagraphStyle(const wxTextAttrEx
& attr
, const wxRect
& rect
);
1231 /// Insert text at the given position
1232 virtual bool InsertText(long pos
, const wxString
& text
);
1234 /// Split an object at this position if necessary, and return
1235 /// the previous object, or NULL if inserting at beginning.
1236 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
1238 /// Move content to a list from this point
1239 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
1241 /// Add content back from list
1242 virtual void MoveFromList(wxList
& list
);
1244 /// Get the plain text searching from the start or end of the range.
1245 /// The resulting string may be shorter than the range given.
1246 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
1248 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1250 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
);
1252 /// Find the object at the given position
1253 wxRichTextObject
* FindObjectAtPosition(long position
);
1255 /// Get the bullet text for this paragraph.
1256 wxString
GetBulletText();
1258 /// Allocate or reuse a line object
1259 wxRichTextLine
* AllocateLine(int pos
);
1261 /// Clear remaining unused line objects, if any
1262 bool ClearUnusedLines(int lineCount
);
1264 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1265 /// retrieve the actual style.
1266 wxTextAttrEx
GetCombinedAttributes(const wxTextAttrEx
& contentStyle
) const;
1268 /// Get combined attributes of the base style and paragraph style.
1269 wxTextAttrEx
GetCombinedAttributes() const;
1271 /// Create default tabstop array
1272 static void InitDefaultTabs();
1274 /// Clear default tabstop array
1275 static void ClearDefaultTabs();
1277 /// Get default tabstop array
1278 static const wxArrayInt
& GetDefaultTabs() { return sm_defaultTabs
; }
1281 /// The lines that make up the wrapped paragraph
1282 wxRichTextLineList m_cachedLines
;
1284 /// Default tabstops
1285 static wxArrayInt sm_defaultTabs
;
1289 * wxRichTextPlainText class declaration
1290 * This object represents a single piece of text.
1293 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
1295 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
1299 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1300 wxRichTextPlainText(const wxRichTextPlainText
& obj
): wxRichTextObject() { Copy(obj
); }
1305 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1307 /// Lay the item out
1308 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1310 /// Get/set the object size for the given range. Returns false if the range
1311 /// is invalid for this object.
1312 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
/* = wxPoint(0,0)*/) const;
1314 /// Get any text in this object for the given range
1315 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1317 /// Do a split, returning an object containing the second part, and setting
1318 /// the first part in 'this'.
1319 virtual wxRichTextObject
* DoSplit(long pos
);
1322 virtual void CalculateRange(long start
, long& end
);
1325 virtual bool DeleteRange(const wxRichTextRange
& range
);
1327 /// Returns true if the object is empty
1328 virtual bool IsEmpty() const { return m_text
.empty(); }
1330 /// Returns true if this object can merge itself with the given one.
1331 virtual bool CanMerge(wxRichTextObject
* object
) const;
1333 /// Returns true if this object merged itself with the given one.
1334 /// The calling code will then delete the given object.
1335 virtual bool Merge(wxRichTextObject
* object
);
1337 /// Dump to output stream for debugging
1338 virtual void Dump(wxTextOutputStream
& stream
);
1343 const wxString
& GetText() const { return m_text
; }
1346 void SetText(const wxString
& text
) { m_text
= text
; }
1351 void Copy(const wxRichTextPlainText
& obj
);
1354 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
1356 bool DrawTabbedString(wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
, wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
1363 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1366 class WXDLLIMPEXP_BASE wxDataInputStream
;
1367 class WXDLLIMPEXP_BASE wxDataOutputStream
;
1369 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
1372 wxRichTextImageBlock();
1373 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
1374 virtual ~wxRichTextImageBlock();
1379 // Load the original image into a memory block.
1380 // If the image is not a JPEG, we must convert it into a JPEG
1381 // to conserve space.
1382 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1383 // load the image a 2nd time.
1384 virtual bool MakeImageBlock(const wxString
& filename
, int imageType
, wxImage
& image
, bool convertToJPEG
= true);
1386 // Make an image block from the wxImage in the given
1388 virtual bool MakeImageBlock(wxImage
& image
, int imageType
, int quality
= 80);
1391 bool Write(const wxString
& filename
);
1393 // Write data in hex to a stream
1394 bool WriteHex(wxOutputStream
& stream
);
1396 // Read data in hex from a stream
1397 bool ReadHex(wxInputStream
& stream
, int length
, int imageType
);
1399 // Copy from 'block'
1400 void Copy(const wxRichTextImageBlock
& block
);
1402 // Load a wxImage from the block
1403 bool Load(wxImage
& image
);
1406 void operator=(const wxRichTextImageBlock
& block
);
1410 unsigned char* GetData() const { return m_data
; }
1411 size_t GetDataSize() const { return m_dataSize
; }
1412 int GetImageType() const { return m_imageType
; }
1414 void SetData(unsigned char* image
) { m_data
= image
; }
1415 void SetDataSize(size_t size
) { m_dataSize
= size
; }
1416 void SetImageType(int imageType
) { m_imageType
= imageType
; }
1418 bool Ok() const { return IsOk(); }
1419 bool IsOk() const { return GetData() != NULL
; }
1423 /// Allocate and read from stream as a block of memory
1424 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
1425 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
1427 // Write memory block to stream
1428 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
1430 // Write memory block to file
1431 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
1434 // Size in bytes of the image stored.
1435 // This is in the raw, original form such as a JPEG file.
1436 unsigned char* m_data
;
1438 int m_imageType
; // wxWin type id
1443 * wxRichTextImage class declaration
1444 * This object represents an image.
1447 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextObject
1449 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
1453 wxRichTextImage(wxRichTextObject
* parent
= NULL
): wxRichTextObject(parent
) { }
1454 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
);
1455 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
);
1456 wxRichTextImage(const wxRichTextImage
& obj
): wxRichTextObject() { Copy(obj
); }
1461 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1463 /// Lay the item out
1464 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1466 /// Get the object size for the given range. Returns false if the range
1467 /// is invalid for this object.
1468 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1470 /// Returns true if the object is empty
1471 virtual bool IsEmpty() const { return !m_image
.Ok(); }
1476 const wxImage
& GetImage() const { return m_image
; }
1479 void SetImage(const wxImage
& image
) { m_image
= image
; }
1481 /// Get the image block containing the raw data
1482 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
1487 void Copy(const wxRichTextImage
& obj
);
1490 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
1492 /// Load wxImage from the block
1493 virtual bool LoadFromBlock();
1495 /// Make block from the wxImage
1496 virtual bool MakeBlock();
1499 // TODO: reduce the multiple representations of data
1502 wxRichTextImageBlock m_imageBlock
;
1507 * wxRichTextBuffer class declaration
1508 * This is a kind of box, used to represent the whole buffer
1511 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
;
1512 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1514 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
1516 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
1520 wxRichTextBuffer() { Init(); }
1521 wxRichTextBuffer(const wxRichTextBuffer
& obj
): wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
1522 virtual ~wxRichTextBuffer() ;
1526 /// Gets the command processor
1527 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
1529 /// Set style sheet, if any.
1530 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
1531 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
1533 /// Push style sheet to top of stack
1534 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1536 /// Pop style sheet from top of stack
1537 wxRichTextStyleSheet
* PopStyleSheet();
1544 /// Clears the buffer and resets the command processor
1545 virtual void Clear();
1547 /// The same as Clear, and adds an empty paragraph.
1548 virtual void Reset();
1551 virtual bool LoadFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1554 virtual bool SaveFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1556 /// Load from a stream
1557 virtual bool LoadFile(wxInputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1559 /// Save to a stream
1560 virtual bool SaveFile(wxOutputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1562 /// Convenience function to add a paragraph of text
1563 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
, paraStyle
); }
1565 /// Begin collapsing undo/redo commands. Note that this may not work properly
1566 /// if combining commands that delete or insert content, changing ranges for
1567 /// subsequent actions.
1568 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1570 /// End collapsing undo/redo commands
1571 virtual bool EndBatchUndo();
1573 /// Collapsing commands?
1574 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
1576 /// Submit immediately, or delay according to whether collapsing is on
1577 virtual bool SubmitAction(wxRichTextAction
* action
);
1579 /// Get collapsed command
1580 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
1582 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1583 /// differently by each command. If not dealt with by a command implementation, then
1584 /// it will be implemented automatically by not storing the command in the undo history
1585 /// when the action is submitted to the command processor.
1586 virtual bool BeginSuppressUndo();
1588 /// End suppressing undo/redo commands.
1589 virtual bool EndSuppressUndo();
1591 /// Collapsing commands?
1592 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
1594 /// Copy the range to the clipboard
1595 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
1597 /// Paste the clipboard content to the buffer
1598 virtual bool PasteFromClipboard(long position
);
1600 /// Can we paste from the clipboard?
1601 virtual bool CanPasteFromClipboard() const;
1603 /// Begin using a style
1604 virtual bool BeginStyle(const wxTextAttrEx
& style
);
1607 virtual bool EndStyle();
1610 virtual bool EndAllStyles();
1612 /// Clear the style stack
1613 virtual void ClearStyleStack();
1615 /// Get the size of the style stack, for example to check correct nesting
1616 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
1618 /// Begin using bold
1622 bool EndBold() { return EndStyle(); }
1624 /// Begin using italic
1627 /// End using italic
1628 bool EndItalic() { return EndStyle(); }
1630 /// Begin using underline
1631 bool BeginUnderline();
1633 /// End using underline
1634 bool EndUnderline() { return EndStyle(); }
1636 /// Begin using point size
1637 bool BeginFontSize(int pointSize
);
1639 /// End using point size
1640 bool EndFontSize() { return EndStyle(); }
1642 /// Begin using this font
1643 bool BeginFont(const wxFont
& font
);
1645 /// End using a font
1646 bool EndFont() { return EndStyle(); }
1648 /// Begin using this colour
1649 bool BeginTextColour(const wxColour
& colour
);
1651 /// End using a colour
1652 bool EndTextColour() { return EndStyle(); }
1654 /// Begin using alignment
1655 bool BeginAlignment(wxTextAttrAlignment alignment
);
1658 bool EndAlignment() { return EndStyle(); }
1660 /// Begin left indent
1661 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
1664 bool EndLeftIndent() { return EndStyle(); }
1666 /// Begin right indent
1667 bool BeginRightIndent(int rightIndent
);
1669 /// End right indent
1670 bool EndRightIndent() { return EndStyle(); }
1672 /// Begin paragraph spacing
1673 bool BeginParagraphSpacing(int before
, int after
);
1675 /// End paragraph spacing
1676 bool EndParagraphSpacing() { return EndStyle(); }
1678 /// Begin line spacing
1679 bool BeginLineSpacing(int lineSpacing
);
1681 /// End line spacing
1682 bool EndLineSpacing() { return EndStyle(); }
1684 /// Begin numbered bullet
1685 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
1687 /// End numbered bullet
1688 bool EndNumberedBullet() { return EndStyle(); }
1690 /// Begin symbol bullet
1691 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
1693 /// End symbol bullet
1694 bool EndSymbolBullet() { return EndStyle(); }
1696 /// Begin standard bullet
1697 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
1699 /// End standard bullet
1700 bool EndStandardBullet() { return EndStyle(); }
1702 /// Begin named character style
1703 bool BeginCharacterStyle(const wxString
& characterStyle
);
1705 /// End named character style
1706 bool EndCharacterStyle() { return EndStyle(); }
1708 /// Begin named paragraph style
1709 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
1711 /// End named character style
1712 bool EndParagraphStyle() { return EndStyle(); }
1714 /// Begin named list style
1715 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
1717 /// End named character style
1718 bool EndListStyle() { return EndStyle(); }
1723 void Copy(const wxRichTextBuffer
& obj
);
1726 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
1728 /// Submit command to insert paragraphs
1729 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1731 /// Submit command to insert the given text
1732 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1734 /// Submit command to insert a newline
1735 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1737 /// Submit command to insert the given image
1738 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1740 /// Submit command to delete this range
1741 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, long initialCaretPosition
, long newCaretPositon
, wxRichTextCtrl
* ctrl
);
1744 void Modify(bool modify
= true) { m_modified
= modify
; }
1745 bool IsModified() const { return m_modified
; }
1747 /// Get the style that is appropriate for a new paragraph at this position.
1748 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1750 wxRichTextAttr
GetStyleForNewParagraph(long pos
, bool caretPosition
= false) const;
1752 /// Dumps contents of buffer for debugging purposes
1753 virtual void Dump();
1754 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
1756 /// Returns the file handlers
1757 static wxList
& GetHandlers() { return sm_handlers
; }
1759 /// Adds a handler to the end
1760 static void AddHandler(wxRichTextFileHandler
*handler
);
1762 /// Inserts a handler at the front
1763 static void InsertHandler(wxRichTextFileHandler
*handler
);
1765 /// Removes a handler
1766 static bool RemoveHandler(const wxString
& name
);
1768 /// Finds a handler by name
1769 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
1771 /// Finds a handler by extension and type
1772 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, int imageType
);
1774 /// Finds a handler by filename or, if supplied, type
1775 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
, int imageType
);
1777 /// Finds a handler by type
1778 static wxRichTextFileHandler
*FindHandler(int imageType
);
1780 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1781 /// will be filled with the file type corresponding to each filter. This can be
1782 /// used to determine the type to pass to LoadFile given a selected filter.
1783 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
1785 /// Clean up handlers
1786 static void CleanUpHandlers();
1788 /// Initialise the standard handlers
1789 static void InitStandardHandlers();
1793 /// Command processor
1794 wxCommandProcessor
* m_commandProcessor
;
1796 /// Has been modified?
1799 /// Collapsed command stack
1800 int m_batchedCommandDepth
;
1802 /// Name for collapsed command
1803 wxString m_batchedCommandsName
;
1805 /// Current collapsed command accumulating actions
1806 wxRichTextCommand
* m_batchedCommand
;
1808 /// Whether to suppress undo
1811 /// Style sheet, if any
1812 wxRichTextStyleSheet
* m_styleSheet
;
1814 /// Stack of attributes for convenience functions
1815 wxList m_attributeStack
;
1818 static wxList sm_handlers
;
1822 * The command identifiers
1826 enum wxRichTextCommandId
1830 wxRICHTEXT_CHANGE_STYLE
1834 * Command classes for undo/redo
1838 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1839 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
1842 // Ctor for one action
1843 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1844 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1846 // Ctor for multiple actions
1847 wxRichTextCommand(const wxString
& name
);
1849 virtual ~wxRichTextCommand();
1854 void AddAction(wxRichTextAction
* action
);
1855 void ClearActions();
1857 wxList
& GetActions() { return m_actions
; }
1865 * wxRichTextAction class declaration
1866 * There can be more than one action in a command.
1869 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
1872 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1873 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1875 virtual ~wxRichTextAction();
1880 /// Update the control appearance
1881 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false);
1883 /// Replace the buffer paragraphs with the given fragment.
1884 void ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
);
1886 /// Get the fragments
1887 wxRichTextParagraphLayoutBox
& GetNewParagraphs() { return m_newParagraphs
; }
1888 wxRichTextParagraphLayoutBox
& GetOldParagraphs() { return m_oldParagraphs
; }
1890 /// Set/get the position used for e.g. insertion
1891 void SetPosition(long pos
) { m_position
= pos
; }
1892 long GetPosition() const { return m_position
; }
1894 /// Set/get the range for e.g. deletion
1895 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1896 const wxRichTextRange
& GetRange() const { return m_range
; }
1899 const wxString
& GetName() const { return m_name
; }
1906 wxRichTextBuffer
* m_buffer
;
1909 wxRichTextCtrl
* m_ctrl
;
1911 // Stores the new paragraphs
1912 wxRichTextParagraphLayoutBox m_newParagraphs
;
1914 // Stores the old paragraphs
1915 wxRichTextParagraphLayoutBox m_oldParagraphs
;
1917 // The affected range
1918 wxRichTextRange m_range
;
1920 // The insertion point for this command
1923 // Ignore 1st 'Do' operation because we already did it
1926 // The command identifier
1927 wxRichTextCommandId m_cmdId
;
1931 * wxRichTextFileHandler
1932 * Base class for file handlers
1935 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
1937 DECLARE_CLASS(wxRichTextFileHandler
)
1939 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
1940 : m_name(name
), m_extension(ext
), m_type(type
), m_visible(true)
1944 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
1945 { return DoLoadFile(buffer
, stream
); }
1946 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
1947 { return DoSaveFile(buffer
, stream
); }
1950 bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1951 bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1953 /// Can we handle this filename (if using files)? By default, checks the extension.
1954 virtual bool CanHandle(const wxString
& filename
) const;
1956 /// Can we save using this handler?
1957 virtual bool CanSave() const { return false; }
1959 /// Can we load using this handler?
1960 virtual bool CanLoad() const { return false; }
1962 /// Should this handler be visible to the user?
1963 virtual bool IsVisible() const { return m_visible
; }
1964 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
1966 /// The name of the nandler
1967 void SetName(const wxString
& name
) { m_name
= name
; }
1968 wxString
GetName() const { return m_name
; }
1970 /// The default extension to recognise
1971 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
1972 wxString
GetExtension() const { return m_extension
; }
1974 /// The handler type
1975 void SetType(int type
) { m_type
= type
; }
1976 int GetType() const { return m_type
; }
1978 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
1979 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
1980 const wxString
& GetEncoding() const { return m_encoding
; }
1985 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
1986 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
1990 wxString m_encoding
;
1991 wxString m_extension
;
1997 * wxRichTextPlainTextHandler
1998 * Plain text handler
2001 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
2003 DECLARE_CLASS(wxRichTextPlainTextHandler
)
2005 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"), const wxString
& ext
= wxT("txt"), int type
= wxRICHTEXT_TYPE_TEXT
)
2006 : wxRichTextFileHandler(name
, ext
, type
)
2009 /// Can we save using this handler?
2010 virtual bool CanSave() const { return true; }
2012 /// Can we load using this handler?
2013 virtual bool CanLoad() const { return true; }
2018 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
2019 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
2027 * The data object for a wxRichTextBuffer
2030 class wxRichTextBufferDataObject
: public wxDataObjectSimple
2033 // ctor doesn't copy the pointer, so it shouldn't go away while this object
2035 wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
= (wxRichTextBuffer
*) NULL
);
2036 virtual ~wxRichTextBufferDataObject();
2038 // after a call to this function, the buffer is owned by the caller and it
2039 // is responsible for deleting it
2040 wxRichTextBuffer
* GetRichTextBuffer();
2042 // Returns the id for the new data format
2043 static const wxChar
* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId
; }
2045 // base class pure virtuals
2047 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
2048 virtual size_t GetDataSize() const;
2049 virtual bool GetDataHere(void *pBuf
) const;
2050 virtual bool SetData(size_t len
, const void *buf
);
2054 virtual size_t GetDataSize(const wxDataFormat
&) const { return GetDataSize(); }
2055 virtual bool GetDataHere(const wxDataFormat
&, void *buf
) const { return GetDataHere(buf
); }
2056 virtual bool SetData(const wxDataFormat
&, size_t len
, const void *buf
) { return SetData(len
, buf
); }
2059 wxDataFormat m_formatRichTextBuffer
; // our custom format
2060 wxRichTextBuffer
* m_richTextBuffer
; // our data
2061 static const wxChar
* ms_richTextBufferFormatId
; // our format id
2071 inline bool wxRichTextHasStyle(int flags
, int style
)
2073 return ((flags
& style
) == style
);
2076 /// Compare two attribute objects
2077 bool wxTextAttrEq(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
);
2078 bool wxTextAttrEq(const wxTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
2080 /// Compare two attribute objects, but take into account the flags
2081 /// specifying attributes of interest.
2082 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
, int flags
);
2083 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxRichTextAttr
& attr2
, int flags
);
2085 /// Apply one style to another
2086 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxTextAttrEx
& style
);
2087 bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxTextAttrEx
& style
);
2088 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
= NULL
);
2091 bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
);
2093 /// Set the font without changing the font attributes
2094 void wxSetFontPreservingStyles(wxTextAttr
& attr
, const wxFont
& font
);
2096 /// Convert a decimal to Roman numerals
2097 wxString
wxRichTextDecimalToRoman(long n
);
2100 WXDLLIMPEXP_RICHTEXT
void wxRichTextModuleInit();
2106 // _WX_RICHTEXTBUFFER_H_