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
;
102 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
;
103 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer
;
104 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
;
107 * Flags determining the available space, passed to Layout
110 #define wxRICHTEXT_FIXED_WIDTH 0x01
111 #define wxRICHTEXT_FIXED_HEIGHT 0x02
112 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
113 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
115 // Only lay out the part of the buffer that lies within
116 // the rect passed to Layout.
117 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
120 * Flags to pass to Draw
123 // Ignore paragraph cache optimization, e.g. for printing purposes
124 // where one line may be drawn higher (on the next page) compared
125 // with the previous line
126 #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
129 * Flags returned from hit-testing
132 // The point was not on this object
133 #define wxRICHTEXT_HITTEST_NONE 0x01
134 // The point was before the position returned from HitTest
135 #define wxRICHTEXT_HITTEST_BEFORE 0x02
136 // The point was after the position returned from HitTest
137 #define wxRICHTEXT_HITTEST_AFTER 0x04
138 // The point was on the position returned from HitTest
139 #define wxRICHTEXT_HITTEST_ON 0x08
142 * Flags for GetRangeSize
145 #define wxRICHTEXT_FORMATTED 0x01
146 #define wxRICHTEXT_UNFORMATTED 0x02
149 * Flags for SetStyle/SetListStyle
152 #define wxRICHTEXT_SETSTYLE_NONE 0x00
154 // Specifies that this operation should be undoable
155 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
157 // Specifies that the style should not be applied if the
158 // combined style at this point is already the style in question.
159 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
161 // Specifies that the style should only be applied to paragraphs,
162 // and not the content. This allows content styling to be
163 // preserved independently from that of e.g. a named paragraph style.
164 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
166 // Specifies that the style should only be applied to characters,
167 // and not the paragraph. This allows content styling to be
168 // preserved independently from that of e.g. a named paragraph style.
169 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
171 // For SetListStyle only: specifies starting from the given number, otherwise
172 // deduces number from existing attributes
173 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
175 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
176 // the current indentation will be used
177 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
180 * Flags for text insertion
183 #define wxRICHTEXT_INSERT_NONE 0x00
184 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
187 * Extra formatting flags not in wxTextAttr
190 #define wxTEXT_ATTR_PARA_SPACING_AFTER 0x00000800
191 #define wxTEXT_ATTR_PARA_SPACING_BEFORE 0x00001000
192 #define wxTEXT_ATTR_LINE_SPACING 0x00002000
193 #define wxTEXT_ATTR_CHARACTER_STYLE_NAME 0x00004000
194 #define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME 0x00008000
195 #define wxTEXT_ATTR_LIST_STYLE_NAME 0x00010000
196 #define wxTEXT_ATTR_BULLET_STYLE 0x00020000
197 #define wxTEXT_ATTR_BULLET_NUMBER 0x00040000
198 #define wxTEXT_ATTR_BULLET_TEXT 0x00080000
199 #define wxTEXT_ATTR_BULLET_NAME 0x00100000
200 #define wxTEXT_ATTR_URL 0x00200000
203 * Styles for wxTextAttrEx::SetBulletStyle
206 #define wxTEXT_ATTR_BULLET_STYLE_NONE 0x00000000
207 #define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x00000001
208 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x00000002
209 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x00000004
210 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x00000008
211 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x00000010
212 #define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x00000020
213 #define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x00000040
214 #define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x00000080
215 #define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x00000100
216 #define wxTEXT_ATTR_BULLET_STYLE_STANDARD 0x00000200
217 #define wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS 0x00000400
218 #define wxTEXT_ATTR_BULLET_STYLE_OUTLINE 0x00000800
220 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT 0x00000000
221 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT 0x00001000
222 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE 0x00002000
225 * Line spacing values
228 #define wxTEXT_ATTR_LINE_SPACING_NORMAL 10
229 #define wxTEXT_ATTR_LINE_SPACING_HALF 15
230 #define wxTEXT_ATTR_LINE_SPACING_TWICE 20
233 * Character and paragraph combined styles
236 #define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR | wxTEXT_ATTR_CHARACTER_STYLE_NAME | wxTEXT_ATTR_URL)
238 #define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
239 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
240 wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_TEXT|wxTEXT_ATTR_BULLET_NAME|\
241 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME)
243 #define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
246 * wxRichTextRange class declaration
247 * This stores beginning and end positions for a range of data.
250 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
255 wxRichTextRange() { m_start
= 0; m_end
= 0; }
256 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
257 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
258 ~wxRichTextRange() {}
260 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
261 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
262 bool operator !=(const wxRichTextRange
& range
) const { return (m_start
!= range
.m_start
&& m_end
!= range
.m_end
); }
263 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
264 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
266 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
268 void SetStart(long start
) { m_start
= start
; }
269 long GetStart() const { return m_start
; }
271 void SetEnd(long end
) { m_end
= end
; }
272 long GetEnd() const { return m_end
; }
274 /// Returns true if this range is completely outside 'range'
275 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
277 /// Returns true if this range is completely within 'range'
278 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
280 /// Returns true if the given position is within this range. Allow
281 /// for the possibility of an empty range - assume the position
282 /// is within this empty range. NO, I think we should not match with an empty range.
283 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
284 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
286 /// Limit this range to be within 'range'
287 bool LimitTo(const wxRichTextRange
& range
) ;
289 /// Gets the length of the range
290 long GetLength() const { return m_end
- m_start
+ 1; }
292 /// Swaps the start and end
293 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
295 /// Convert to internal form: (n, n) is the range of a single character.
296 wxRichTextRange
ToInternal() const { return wxRichTextRange(m_start
, m_end
-1); }
298 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
299 wxRichTextRange
FromInternal() const { return wxRichTextRange(m_start
, m_end
+1); }
306 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
307 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
310 * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
313 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx
: public wxTextAttr
317 wxTextAttrEx(const wxTextAttrEx
& attr
);
318 wxTextAttrEx(const wxTextAttr
& attr
) { Init(); (*this) = attr
; }
319 wxTextAttrEx() { Init(); }
321 // Initialise this object
325 void Copy(const wxTextAttrEx
& attr
);
327 // Assignment from a wxTextAttrEx object
328 void operator= (const wxTextAttrEx
& attr
);
330 // Assignment from a wxTextAttr object
331 void operator= (const wxTextAttr
& attr
);
334 bool operator== (const wxTextAttrEx
& attr
) const;
337 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME
); }
338 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
); }
339 void SetListStyleName(const wxString
& name
) { m_listStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME
); }
340 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER
); }
341 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE
); }
342 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING
); }
343 void SetBulletStyle(int style
) { m_bulletStyle
= style
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE
); }
344 void SetBulletNumber(int n
) { m_bulletNumber
= n
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER
); }
345 void SetBulletText(const wxString
& text
) { m_bulletText
= text
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_TEXT
); }
346 void SetBulletName(const wxString
& name
) { m_bulletName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NAME
); }
347 void SetBulletFont(const wxString
& bulletFont
) { m_bulletFont
= bulletFont
; }
348 void SetURL(const wxString
& url
) { m_urlTarget
= url
; SetFlags(GetFlags() | wxTEXT_ATTR_URL
); }
350 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
351 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
352 const wxString
& GetListStyleName() const { return m_listStyleName
; }
353 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
354 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
355 int GetLineSpacing() const { return m_lineSpacing
; }
356 int GetBulletStyle() const { return m_bulletStyle
; }
357 int GetBulletNumber() const { return m_bulletNumber
; }
358 const wxString
& GetBulletText() const { return m_bulletText
; }
359 const wxString
& GetBulletName() const { return m_bulletName
; }
360 const wxString
& GetBulletFont() const { return m_bulletFont
; }
361 const wxString
& GetURL() const { return m_urlTarget
; }
363 bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
364 bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE
) != 0; }
365 bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC
) != 0; }
366 bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
367 bool HasFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE
) != 0; }
369 bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER
); }
370 bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE
); }
371 bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING
); }
372 bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME
) || !m_characterStyleName
.IsEmpty(); }
373 bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) || !m_paragraphStyleName
.IsEmpty(); }
374 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME
) || !m_listStyleName
.IsEmpty(); }
375 bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE
); }
376 bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER
); }
377 bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT
); }
378 bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME
); }
379 bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL
); }
381 // Is this a character style?
382 bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER
)); }
383 bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH
)); }
385 // returns false if we have any attributes set, true otherwise
386 bool IsDefault() const
388 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
389 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
390 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
391 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
392 !HasBulletNumber() && !HasBulletStyle() && !HasBulletText() && !HasBulletName() && !HasURL();
395 // return the attribute having the valid font and colours: it uses the
396 // attributes set in attr and falls back first to attrDefault and then to
397 // the text control font/colours for those attributes which are not set
398 static wxTextAttrEx
CombineEx(const wxTextAttrEx
& attr
,
399 const wxTextAttrEx
& attrDef
,
400 const wxTextCtrlBase
*text
);
404 int m_paragraphSpacingAfter
;
405 int m_paragraphSpacingBefore
;
409 wxString m_bulletText
;
410 wxString m_bulletFont
;
411 wxString m_bulletName
;
412 wxString m_urlTarget
;
415 wxString m_characterStyleName
;
418 wxString m_paragraphStyleName
;
421 wxString m_listStyleName
;
425 * wxRichTextAttr stores attributes without a wxFont object, so is a much more
426 * efficient way to query styles.
429 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
433 wxRichTextAttr(const wxTextAttrEx
& attr
);
434 wxRichTextAttr(const wxRichTextAttr
& attr
);
435 wxRichTextAttr() { Init(); }
436 wxRichTextAttr(const wxColour
& colText
,
437 const wxColour
& colBack
= wxNullColour
,
438 wxTextAttrAlignment alignment
= wxTEXT_ALIGNMENT_DEFAULT
);
440 // Initialise this object.
444 void Copy(const wxRichTextAttr
& attr
);
446 // Assignment from a wxRichTextAttr object.
447 void operator= (const wxRichTextAttr
& attr
);
449 // Assignment from a wxTextAttrEx object.
450 void operator= (const wxTextAttrEx
& attr
);
453 bool operator== (const wxRichTextAttr
& attr
) const;
455 // Making a wxTextAttrEx object.
456 operator wxTextAttrEx () const ;
458 // Copy to a wxTextAttr
459 void CopyTo(wxTextAttrEx
& attr
) const;
461 // Create font from font attributes.
462 wxFont
CreateFont() const;
464 // Get attributes from font.
465 bool GetFontAttributes(const wxFont
& font
);
468 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; m_flags
|= wxTEXT_ATTR_TEXT_COLOUR
; }
469 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; m_flags
|= wxTEXT_ATTR_BACKGROUND_COLOUR
; }
470 void SetAlignment(wxTextAttrAlignment alignment
) { m_textAlignment
= alignment
; m_flags
|= wxTEXT_ATTR_ALIGNMENT
; }
471 void SetTabs(const wxArrayInt
& tabs
) { m_tabs
= tabs
; m_flags
|= wxTEXT_ATTR_TABS
; }
472 void SetLeftIndent(int indent
, int subIndent
= 0) { m_leftIndent
= indent
; m_leftSubIndent
= subIndent
; m_flags
|= wxTEXT_ATTR_LEFT_INDENT
; }
473 void SetRightIndent(int indent
) { m_rightIndent
= indent
; m_flags
|= wxTEXT_ATTR_RIGHT_INDENT
; }
475 void SetFontSize(int pointSize
) { m_fontSize
= pointSize
; m_flags
|= wxTEXT_ATTR_FONT_SIZE
; }
476 void SetFontStyle(int fontStyle
) { m_fontStyle
= fontStyle
; m_flags
|= wxTEXT_ATTR_FONT_ITALIC
; }
477 void SetFontWeight(int fontWeight
) { m_fontWeight
= fontWeight
; m_flags
|= wxTEXT_ATTR_FONT_WEIGHT
; }
478 void SetFontFaceName(const wxString
& faceName
) { m_fontFaceName
= faceName
; m_flags
|= wxTEXT_ATTR_FONT_FACE
; }
479 void SetFontUnderlined(bool underlined
) { m_fontUnderlined
= underlined
; m_flags
|= wxTEXT_ATTR_FONT_UNDERLINE
; }
481 void SetFlags(long flags
) { m_flags
= flags
; }
483 void SetCharacterStyleName(const wxString
& name
) { m_characterStyleName
= name
; m_flags
|= wxTEXT_ATTR_CHARACTER_STYLE_NAME
; }
484 void SetParagraphStyleName(const wxString
& name
) { m_paragraphStyleName
= name
; m_flags
|= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
; }
485 void SetListStyleName(const wxString
& name
) { m_listStyleName
= name
; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME
); }
486 void SetParagraphSpacingAfter(int spacing
) { m_paragraphSpacingAfter
= spacing
; m_flags
|= wxTEXT_ATTR_PARA_SPACING_AFTER
; }
487 void SetParagraphSpacingBefore(int spacing
) { m_paragraphSpacingBefore
= spacing
; m_flags
|= wxTEXT_ATTR_PARA_SPACING_BEFORE
; }
488 void SetLineSpacing(int spacing
) { m_lineSpacing
= spacing
; m_flags
|= wxTEXT_ATTR_LINE_SPACING
; }
489 void SetBulletStyle(int style
) { m_bulletStyle
= style
; m_flags
|= wxTEXT_ATTR_BULLET_STYLE
; }
490 void SetBulletNumber(int n
) { m_bulletNumber
= n
; m_flags
|= wxTEXT_ATTR_BULLET_NUMBER
; }
491 void SetBulletText(const wxString
& text
) { m_bulletText
= text
; m_flags
|= wxTEXT_ATTR_BULLET_TEXT
; }
492 void SetBulletFont(const wxString
& bulletFont
) { m_bulletFont
= bulletFont
; }
493 void SetBulletName(const wxString
& name
) { m_bulletName
= name
; m_flags
|= wxTEXT_ATTR_BULLET_NAME
; }
494 void SetURL(const wxString
& url
) { m_urlTarget
= url
; m_flags
|= wxTEXT_ATTR_URL
; }
496 const wxColour
& GetTextColour() const { return m_colText
; }
497 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
498 wxTextAttrAlignment
GetAlignment() const { return m_textAlignment
; }
499 const wxArrayInt
& GetTabs() const { return m_tabs
; }
500 long GetLeftIndent() const { return m_leftIndent
; }
501 long GetLeftSubIndent() const { return m_leftSubIndent
; }
502 long GetRightIndent() const { return m_rightIndent
; }
503 long GetFlags() const { return m_flags
; }
505 int GetFontSize() const { return m_fontSize
; }
506 int GetFontStyle() const { return m_fontStyle
; }
507 int GetFontWeight() const { return m_fontWeight
; }
508 bool GetFontUnderlined() const { return m_fontUnderlined
; }
509 const wxString
& GetFontFaceName() const { return m_fontFaceName
; }
511 const wxString
& GetCharacterStyleName() const { return m_characterStyleName
; }
512 const wxString
& GetParagraphStyleName() const { return m_paragraphStyleName
; }
513 const wxString
& GetListStyleName() const { return m_listStyleName
; }
514 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter
; }
515 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore
; }
516 int GetLineSpacing() const { return m_lineSpacing
; }
517 int GetBulletStyle() const { return m_bulletStyle
; }
518 int GetBulletNumber() const { return m_bulletNumber
; }
519 const wxString
& GetBulletText() const { return m_bulletText
; }
520 const wxString
& GetBulletFont() const { return m_bulletFont
; }
521 const wxString
& GetBulletName() const { return m_bulletName
; }
522 const wxString
& GetURL() const { return m_urlTarget
; }
525 bool HasTextColour() const { return m_colText
.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR
) ; }
526 bool HasBackgroundColour() const { return m_colBack
.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR
) ; }
527 bool HasAlignment() const { return (m_textAlignment
!= wxTEXT_ALIGNMENT_DEFAULT
) || ((m_flags
& wxTEXT_ATTR_ALIGNMENT
) != 0) ; }
528 bool HasTabs() const { return (m_flags
& wxTEXT_ATTR_TABS
) != 0 ; }
529 bool HasLeftIndent() const { return (m_flags
& wxTEXT_ATTR_LEFT_INDENT
) != 0 ; }
530 bool HasRightIndent() const { return (m_flags
& wxTEXT_ATTR_RIGHT_INDENT
) != 0 ; }
531 bool HasWeight() const { return (m_flags
& wxTEXT_ATTR_FONT_WEIGHT
) != 0; }
532 bool HasSize() const { return (m_flags
& wxTEXT_ATTR_FONT_SIZE
) != 0; }
533 bool HasItalic() const { return (m_flags
& wxTEXT_ATTR_FONT_ITALIC
) != 0; }
534 bool HasUnderlined() const { return (m_flags
& wxTEXT_ATTR_FONT_UNDERLINE
) != 0; }
535 bool HasFaceName() const { return (m_flags
& wxTEXT_ATTR_FONT_FACE
) != 0; }
536 bool HasFont() const { return (m_flags
& (wxTEXT_ATTR_FONT
)) != 0; }
538 bool HasParagraphSpacingAfter() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) != 0; }
539 bool HasParagraphSpacingBefore() const { return (m_flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) != 0; }
540 bool HasLineSpacing() const { return (m_flags
& wxTEXT_ATTR_LINE_SPACING
) != 0; }
541 bool HasCharacterStyleName() const { return (m_flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) != 0 || !m_characterStyleName
.IsEmpty(); }
542 bool HasParagraphStyleName() const { return (m_flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) != 0 || !m_paragraphStyleName
.IsEmpty(); }
543 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME
) || !m_listStyleName
.IsEmpty(); }
544 bool HasBulletStyle() const { return (m_flags
& wxTEXT_ATTR_BULLET_STYLE
) != 0; }
545 bool HasBulletNumber() const { return (m_flags
& wxTEXT_ATTR_BULLET_NUMBER
) != 0; }
546 bool HasBulletText() const { return (m_flags
& wxTEXT_ATTR_BULLET_TEXT
) != 0; }
547 bool HasBulletName() const { return (m_flags
& wxTEXT_ATTR_BULLET_NAME
) != 0; }
548 bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL
); }
550 bool HasFlag(long flag
) const { return (m_flags
& flag
) != 0; }
552 // Is this a character style?
553 bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER
)); }
554 bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH
)); }
556 // returns false if we have any attributes set, true otherwise
557 bool IsDefault() const
559 return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
560 !HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
561 !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
562 !HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
563 !HasBulletNumber() && !HasBulletStyle() && !HasBulletText() && !HasBulletName() && !HasURL();
566 // return the attribute having the valid font and colours: it uses the
567 // attributes set in attr and falls back first to attrDefault and then to
568 // the text control font/colours for those attributes which are not set
569 static wxRichTextAttr
Combine(const wxRichTextAttr
& attr
,
570 const wxRichTextAttr
& attrDef
,
571 const wxTextCtrlBase
*text
);
576 wxArrayInt m_tabs
; // array of int: tab stops in 1/10 mm
577 int m_leftIndent
; // left indent in 1/10 mm
578 int m_leftSubIndent
; // left indent for all but the first
579 // line in a paragraph relative to the
580 // first line, in 1/10 mm
581 int m_rightIndent
; // right indent in 1/10 mm
582 wxTextAttrAlignment m_textAlignment
;
584 int m_paragraphSpacingAfter
;
585 int m_paragraphSpacingBefore
;
589 wxString m_bulletText
;
590 wxString m_bulletFont
;
591 wxString m_bulletName
;
592 wxString m_urlTarget
;
600 bool m_fontUnderlined
;
601 wxString m_fontFaceName
;
604 wxString m_characterStyleName
;
607 wxString m_paragraphStyleName
;
610 wxString m_listStyleName
;
614 * wxRichTextObject class declaration
615 * This is the base for drawable objects.
618 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
620 DECLARE_CLASS(wxRichTextObject
)
624 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
625 virtual ~wxRichTextObject();
629 /// Draw the item, within the given range. Some objects may ignore the range (for
630 /// example paragraphs) while others must obey it (lines, to implement wrapping)
631 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
) = 0;
633 /// Lay the item out at the specified position with the given size constraint.
634 /// Layout must set the cached size.
635 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
637 /// Hit-testing: returns a flag indicating hit test details, plus
638 /// information about position
639 virtual int HitTest(wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pt
), long& WXUNUSED(textPosition
)) { return false; }
641 /// Finds the absolute position and row height for the given character position
642 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
644 /// Get the best size, i.e. the ideal starting size for this object irrespective
645 /// of available space. For a short text string, it will be the size that exactly encloses
646 /// the text. For a longer string, it might use the parent width for example.
647 virtual wxSize
GetBestSize() const { return m_size
; }
649 /// Get the object size for the given range. Returns false if the range
650 /// is invalid for this object.
651 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const = 0;
653 /// Do a split, returning an object containing the second part, and setting
654 /// the first part in 'this'.
655 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
657 /// Calculate range. By default, guess that the object is 1 unit long.
658 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
661 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
663 /// Returns true if the object is empty
664 virtual bool IsEmpty() const { return false; }
666 /// Get any text in this object for the given range
667 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
669 /// Returns true if this object can merge itself with the given one.
670 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
672 /// Returns true if this object merged itself with the given one.
673 /// The calling code will then delete the given object.
674 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
676 /// Dump to output stream for debugging
677 virtual void Dump(wxTextOutputStream
& stream
);
681 /// Get/set the cached object size as calculated by Layout.
682 virtual wxSize
GetCachedSize() const { return m_size
; }
683 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
685 /// Get/set the object position
686 virtual wxPoint
GetPosition() const { return m_pos
; }
687 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
689 /// Get the rectangle enclosing the object
690 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
693 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
696 const wxRichTextRange
& GetRange() const { return m_range
; }
697 wxRichTextRange
& GetRange() { return m_range
; }
699 /// Get/set dirty flag (whether the object needs Layout to be called)
700 virtual bool GetDirty() const { return m_dirty
; }
701 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
703 /// Is this composite?
704 virtual bool IsComposite() const { return false; }
706 /// Get/set the parent.
707 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
708 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
710 /// Set the margin around the object
711 virtual void SetMargins(int margin
);
712 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
713 virtual int GetLeftMargin() const { return m_leftMargin
; }
714 virtual int GetRightMargin() const { return m_rightMargin
; }
715 virtual int GetTopMargin() const { return m_topMargin
; }
716 virtual int GetBottomMargin() const { return m_bottomMargin
; }
718 /// Set attributes object
719 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
720 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
721 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
723 /// Set/get stored descent
724 void SetDescent(int descent
) { m_descent
= descent
; }
725 int GetDescent() const { return m_descent
; }
727 /// Gets the containing buffer
728 wxRichTextBuffer
* GetBuffer() const;
733 virtual wxRichTextObject
* Clone() const { return NULL
; }
736 void Copy(const wxRichTextObject
& obj
);
738 /// Reference-counting allows us to use the same object in multiple
739 /// lists (not yet used)
740 void Reference() { m_refCount
++; }
743 /// Convert units in tenths of a millimetre to device units
744 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
);
745 static int ConvertTenthsMMToPixels(int ppi
, int units
);
750 int m_descent
; // Descent for this object (if any)
753 wxRichTextObject
* m_parent
;
755 /// The range of this object (start position to end position)
756 wxRichTextRange m_range
;
765 wxTextAttrEx m_attributes
;
768 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
771 * wxRichTextCompositeObject class declaration
772 * Objects of this class can contain other objects.
775 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
777 DECLARE_CLASS(wxRichTextCompositeObject
)
781 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
782 virtual ~wxRichTextCompositeObject();
786 /// Hit-testing: returns a flag indicating hit test details, plus
787 /// information about position
788 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
790 /// Finds the absolute position and row height for the given character position
791 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
794 virtual void CalculateRange(long start
, long& end
);
797 virtual bool DeleteRange(const wxRichTextRange
& range
);
799 /// Get any text in this object for the given range
800 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
802 /// Dump to output stream for debugging
803 virtual void Dump(wxTextOutputStream
& stream
);
808 wxRichTextObjectList
& GetChildren() { return m_children
; }
809 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
811 /// Get the child count
812 size_t GetChildCount() const ;
814 /// Get the nth child
815 wxRichTextObject
* GetChild(size_t n
) const ;
817 /// Get/set dirty flag
818 virtual bool GetDirty() const { return m_dirty
; }
819 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
821 /// Is this composite?
822 virtual bool IsComposite() const { return true; }
824 /// Returns true if the buffer is empty
825 virtual bool IsEmpty() const { return GetChildCount() == 0; }
830 void Copy(const wxRichTextCompositeObject
& obj
);
833 void operator= (const wxRichTextCompositeObject
& obj
) { Copy(obj
); }
835 /// Append a child, returning the position
836 size_t AppendChild(wxRichTextObject
* child
) ;
838 /// Insert the child in front of the given object, or at the beginning
839 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
842 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
844 /// Delete all children
845 bool DeleteChildren() ;
847 /// Recursively merge all pieces that can be merged.
851 wxRichTextObjectList m_children
;
855 * wxRichTextBox class declaration
856 * This defines a 2D space to lay out objects
859 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextCompositeObject
861 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
865 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
866 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
871 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
874 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
876 /// Get/set the object size for the given range. Returns false if the range
877 /// is invalid for this object.
878 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
885 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
888 void Copy(const wxRichTextBox
& obj
);
894 * wxRichTextParagraphBox class declaration
895 * This box knows how to lay out paragraphs.
898 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextBox
900 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
904 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
905 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
): wxRichTextBox() { Init(); Copy(obj
); }
910 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
913 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
915 /// Get/set the object size for the given range. Returns false if the range
916 /// is invalid for this object.
917 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
920 virtual bool DeleteRange(const wxRichTextRange
& range
);
922 /// Get any text in this object for the given range
923 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
927 /// Associate a control with the buffer, for operations that for example require refreshing the window.
928 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
930 /// Get the associated control.
931 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
933 /// Get/set whether the last paragraph is partial or complete
934 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
935 bool GetPartialParagraph() const { return m_partialParagraph
; }
937 /// If this is a buffer, returns the current style sheet. The base layout box
938 /// class doesn't have an associated style sheet.
939 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return NULL
; }
943 /// Initialize the object.
946 /// Clear all children
947 virtual void Clear();
949 /// Clear and initialize with one blank paragraph
950 virtual void Reset();
952 /// Convenience function to add a paragraph of text
953 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
);
955 /// Convenience function to add an image
956 virtual wxRichTextRange
AddImage(const wxImage
& image
, wxTextAttrEx
* paraStyle
= NULL
);
958 /// Adds multiple paragraphs, based on newlines.
959 virtual wxRichTextRange
AddParagraphs(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
);
961 /// Get the line at the given position. If caretPosition is true, the position is
962 /// a caret position, which is normally a smaller number.
963 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
965 /// Get the line at the given y pixel position, or the last line.
966 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
968 /// Get the paragraph at the given character or caret position
969 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
971 /// Get the line size at the given position
972 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
974 /// Given a position, get the number of the visible line (potentially many to a paragraph),
975 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
976 /// that indicates whether the caret is being shown at the end of the previous line or at the start
977 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
979 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
981 /// Given a line number, get the corresponding wxRichTextLine object.
982 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
984 /// Get the leaf object in a paragraph at this position.
985 /// Given a line number, get the corresponding wxRichTextLine object.
986 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
988 /// Get the paragraph by number
989 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
991 /// Get the paragraph for a given line
992 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
994 /// Get the length of the paragraph
995 virtual int GetParagraphLength(long paragraphNumber
) const;
997 /// Get the number of paragraphs
998 virtual int GetParagraphCount() const { return GetChildCount(); }
1000 /// Get the number of visible lines
1001 virtual int GetLineCount() const;
1003 /// Get the text of the paragraph
1004 virtual wxString
GetParagraphText(long paragraphNumber
) const;
1006 /// Convert zero-based line column and paragraph number to a position.
1007 virtual long XYToPosition(long x
, long y
) const;
1009 /// Convert zero-based position to line column and paragraph number
1010 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1012 /// Set text attributes: character and/or paragraph styles.
1013 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1014 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttrEx
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1016 /// Get the conbined text attributes for this position.
1017 virtual bool GetStyle(long position
, wxTextAttrEx
& style
);
1018 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
1020 /// Get the content (uncombined) attributes for this position.
1021 virtual bool GetUncombinedStyle(long position
, wxTextAttrEx
& style
);
1022 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
1024 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1025 /// context attributes.
1026 virtual bool DoGetStyle(long position
, wxTextAttrEx
& style
, bool combineStyles
= true);
1028 /// Get the combined style for a range - if any attribute is different within the range,
1029 /// that attribute is not present within the flags
1030 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttrEx
& style
);
1032 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1034 bool CollectStyle(wxTextAttrEx
& currentStyle
, const wxTextAttrEx
& style
, long& multipleStyleAttributes
);
1037 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1038 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1040 /// Clear list for given range
1041 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1043 /// Number/renumber any list elements in the given range.
1044 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1045 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1046 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1048 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1049 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1050 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1051 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1053 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1054 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1055 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);
1057 /// Fills in the attributes for numbering a paragraph after previousParagraph.
1058 virtual bool FindNextParagraphNumber(wxRichTextParagraph
* previousParagraph
, wxRichTextAttr
& attr
) const;
1060 /// Test if this whole range has character attributes of the specified kind. If any
1061 /// of the attributes are different within the range, the test fails. You
1062 /// can use this to implement, for example, bold button updating. style must have
1063 /// flags indicating which attributes are of interest.
1064 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
1065 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1067 /// Test if this whole range has paragraph attributes of the specified kind. If any
1068 /// of the attributes are different within the range, the test fails. You
1069 /// can use this to implement, for example, centering button updating. style must have
1070 /// flags indicating which attributes are of interest.
1071 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const;
1072 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1075 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1077 /// Insert fragment into this box at the given position. If partialParagraph is true,
1078 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1080 virtual bool InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
);
1082 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1083 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
);
1085 /// Apply the style sheet to the buffer, for example if the styles have changed.
1086 virtual bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1089 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
1092 void operator= (const wxRichTextParagraphLayoutBox
& obj
) { Copy(obj
); }
1094 /// Calculate ranges
1095 virtual void UpdateRanges() { long end
; CalculateRange(0, end
); }
1097 /// Get all the text
1098 virtual wxString
GetText() const;
1100 /// Set default style for new content. Setting it to a default attribute
1101 /// makes new content take on the 'basic' style.
1102 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
1104 /// Get default style
1105 virtual const wxTextAttrEx
& GetDefaultStyle() const { return m_defaultAttributes
; }
1107 /// Set basic (overall) style
1108 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { m_attributes
= style
; }
1109 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { style
.CopyTo(m_attributes
); }
1111 /// Get basic (overall) style
1112 virtual const wxTextAttrEx
& GetBasicStyle() const { return m_attributes
; }
1114 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1115 void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1117 /// Get invalid range, rounding to entire paragraphs if argument is true.
1118 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
1121 wxRichTextCtrl
* m_ctrl
;
1122 wxTextAttrEx m_defaultAttributes
;
1124 /// The invalidated range that will need full layout
1125 wxRichTextRange m_invalidRange
;
1127 // Is the last paragraph partial or complete?
1128 bool m_partialParagraph
;
1132 * wxRichTextLine class declaration
1133 * This object represents a line in a paragraph, and stores
1134 * offsets from the start of the paragraph representing the
1135 * start and end positions of the line.
1138 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1143 wxRichTextLine(wxRichTextParagraph
* parent
);
1144 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
1145 virtual ~wxRichTextLine() {}
1152 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1153 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
1155 /// Get the parent paragraph
1156 wxRichTextParagraph
* GetParent() { return m_parent
; }
1159 const wxRichTextRange
& GetRange() const { return m_range
; }
1160 wxRichTextRange
& GetRange() { return m_range
; }
1162 /// Get the absolute range
1163 wxRichTextRange
GetAbsoluteRange() const;
1165 /// Get/set the line size as calculated by Layout.
1166 virtual wxSize
GetSize() const { return m_size
; }
1167 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
1169 /// Get/set the object position relative to the parent
1170 virtual wxPoint
GetPosition() const { return m_pos
; }
1171 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1173 /// Get the absolute object position
1174 virtual wxPoint
GetAbsolutePosition() const;
1176 /// Get the rectangle enclosing the line
1177 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1179 /// Set/get stored descent
1180 void SetDescent(int descent
) { m_descent
= descent
; }
1181 int GetDescent() const { return m_descent
; }
1186 void Init(wxRichTextParagraph
* parent
);
1189 void Copy(const wxRichTextLine
& obj
);
1192 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1196 /// The range of the line (start position to end position)
1197 /// This is relative to the parent paragraph.
1198 wxRichTextRange m_range
;
1200 /// Size and position measured relative to top of paragraph
1204 /// Maximum descent for this line (location of text baseline)
1207 // The parent object
1208 wxRichTextParagraph
* m_parent
;
1211 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
1214 * wxRichTextParagraph class declaration
1215 * This object represents a single paragraph (or in a straight text editor, a line).
1218 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextBox
1220 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
1224 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1225 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1226 virtual ~wxRichTextParagraph();
1227 wxRichTextParagraph(const wxRichTextParagraph
& obj
): wxRichTextBox() { Copy(obj
); }
1232 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1234 /// Lay the item out
1235 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1237 /// Get/set the object size for the given range. Returns false if the range
1238 /// is invalid for this object.
1239 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1241 /// Finds the absolute position and row height for the given character position
1242 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1244 /// Hit-testing: returns a flag indicating hit test details, plus
1245 /// information about position
1246 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1249 virtual void CalculateRange(long start
, long& end
);
1253 /// Get the cached lines
1254 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
1259 void Copy(const wxRichTextParagraph
& obj
);
1262 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
1264 /// Clear the cached lines
1269 /// Apply paragraph styles such as centering to the wrapped lines
1270 virtual void ApplyParagraphStyle(const wxTextAttrEx
& attr
, const wxRect
& rect
);
1272 /// Insert text at the given position
1273 virtual bool InsertText(long pos
, const wxString
& text
);
1275 /// Split an object at this position if necessary, and return
1276 /// the previous object, or NULL if inserting at beginning.
1277 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
1279 /// Move content to a list from this point
1280 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
1282 /// Add content back from list
1283 virtual void MoveFromList(wxList
& list
);
1285 /// Get the plain text searching from the start or end of the range.
1286 /// The resulting string may be shorter than the range given.
1287 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
1289 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1291 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
);
1293 /// Find the object at the given position
1294 wxRichTextObject
* FindObjectAtPosition(long position
);
1296 /// Get the bullet text for this paragraph.
1297 wxString
GetBulletText();
1299 /// Allocate or reuse a line object
1300 wxRichTextLine
* AllocateLine(int pos
);
1302 /// Clear remaining unused line objects, if any
1303 bool ClearUnusedLines(int lineCount
);
1305 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1306 /// retrieve the actual style.
1307 wxTextAttrEx
GetCombinedAttributes(const wxTextAttrEx
& contentStyle
) const;
1309 /// Get combined attributes of the base style and paragraph style.
1310 wxTextAttrEx
GetCombinedAttributes() const;
1312 /// Create default tabstop array
1313 static void InitDefaultTabs();
1315 /// Clear default tabstop array
1316 static void ClearDefaultTabs();
1318 /// Get default tabstop array
1319 static const wxArrayInt
& GetDefaultTabs() { return sm_defaultTabs
; }
1322 /// The lines that make up the wrapped paragraph
1323 wxRichTextLineList m_cachedLines
;
1325 /// Default tabstops
1326 static wxArrayInt sm_defaultTabs
;
1330 * wxRichTextPlainText class declaration
1331 * This object represents a single piece of text.
1334 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
1336 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
1340 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxTextAttrEx
* style
= NULL
);
1341 wxRichTextPlainText(const wxRichTextPlainText
& obj
): wxRichTextObject() { Copy(obj
); }
1346 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1348 /// Lay the item out
1349 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1351 /// Get/set the object size for the given range. Returns false if the range
1352 /// is invalid for this object.
1353 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
/* = wxPoint(0,0)*/) const;
1355 /// Get any text in this object for the given range
1356 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1358 /// Do a split, returning an object containing the second part, and setting
1359 /// the first part in 'this'.
1360 virtual wxRichTextObject
* DoSplit(long pos
);
1363 virtual void CalculateRange(long start
, long& end
);
1366 virtual bool DeleteRange(const wxRichTextRange
& range
);
1368 /// Returns true if the object is empty
1369 virtual bool IsEmpty() const { return m_text
.empty(); }
1371 /// Returns true if this object can merge itself with the given one.
1372 virtual bool CanMerge(wxRichTextObject
* object
) const;
1374 /// Returns true if this object merged itself with the given one.
1375 /// The calling code will then delete the given object.
1376 virtual bool Merge(wxRichTextObject
* object
);
1378 /// Dump to output stream for debugging
1379 virtual void Dump(wxTextOutputStream
& stream
);
1384 const wxString
& GetText() const { return m_text
; }
1387 void SetText(const wxString
& text
) { m_text
= text
; }
1392 void Copy(const wxRichTextPlainText
& obj
);
1395 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
1397 bool DrawTabbedString(wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
, wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
1404 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1407 class WXDLLIMPEXP_BASE wxDataInputStream
;
1408 class WXDLLIMPEXP_BASE wxDataOutputStream
;
1410 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
1413 wxRichTextImageBlock();
1414 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
1415 virtual ~wxRichTextImageBlock();
1420 // Load the original image into a memory block.
1421 // If the image is not a JPEG, we must convert it into a JPEG
1422 // to conserve space.
1423 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1424 // load the image a 2nd time.
1425 virtual bool MakeImageBlock(const wxString
& filename
, int imageType
, wxImage
& image
, bool convertToJPEG
= true);
1427 // Make an image block from the wxImage in the given
1429 virtual bool MakeImageBlock(wxImage
& image
, int imageType
, int quality
= 80);
1432 bool Write(const wxString
& filename
);
1434 // Write data in hex to a stream
1435 bool WriteHex(wxOutputStream
& stream
);
1437 // Read data in hex from a stream
1438 bool ReadHex(wxInputStream
& stream
, int length
, int imageType
);
1440 // Copy from 'block'
1441 void Copy(const wxRichTextImageBlock
& block
);
1443 // Load a wxImage from the block
1444 bool Load(wxImage
& image
);
1447 void operator=(const wxRichTextImageBlock
& block
);
1451 unsigned char* GetData() const { return m_data
; }
1452 size_t GetDataSize() const { return m_dataSize
; }
1453 int GetImageType() const { return m_imageType
; }
1455 void SetData(unsigned char* image
) { m_data
= image
; }
1456 void SetDataSize(size_t size
) { m_dataSize
= size
; }
1457 void SetImageType(int imageType
) { m_imageType
= imageType
; }
1459 bool Ok() const { return IsOk(); }
1460 bool IsOk() const { return GetData() != NULL
; }
1462 // Gets the extension for the block's type
1463 wxString
GetExtension() const;
1467 // Allocate and read from stream as a block of memory
1468 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
1469 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
1471 // Write memory block to stream
1472 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
1474 // Write memory block to file
1475 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
1478 // Size in bytes of the image stored.
1479 // This is in the raw, original form such as a JPEG file.
1480 unsigned char* m_data
;
1482 int m_imageType
; // wxWin type id
1487 * wxRichTextImage class declaration
1488 * This object represents an image.
1491 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextObject
1493 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
1497 wxRichTextImage(wxRichTextObject
* parent
= NULL
): wxRichTextObject(parent
) { }
1498 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
);
1499 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
);
1500 wxRichTextImage(const wxRichTextImage
& obj
): wxRichTextObject() { Copy(obj
); }
1505 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1507 /// Lay the item out
1508 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1510 /// Get the object size for the given range. Returns false if the range
1511 /// is invalid for this object.
1512 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0)) const;
1514 /// Returns true if the object is empty
1515 virtual bool IsEmpty() const { return !m_image
.Ok(); }
1520 const wxImage
& GetImage() const { return m_image
; }
1523 void SetImage(const wxImage
& image
) { m_image
= image
; }
1525 /// Get the image block containing the raw data
1526 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
1531 void Copy(const wxRichTextImage
& obj
);
1534 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
1536 /// Load wxImage from the block
1537 virtual bool LoadFromBlock();
1539 /// Make block from the wxImage
1540 virtual bool MakeBlock();
1543 // TODO: reduce the multiple representations of data
1546 wxRichTextImageBlock m_imageBlock
;
1551 * wxRichTextBuffer class declaration
1552 * This is a kind of box, used to represent the whole buffer
1555 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
;
1556 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1558 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
1560 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
1564 wxRichTextBuffer() { Init(); }
1565 wxRichTextBuffer(const wxRichTextBuffer
& obj
): wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
1566 virtual ~wxRichTextBuffer() ;
1570 /// Gets the command processor
1571 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
1573 /// Set style sheet, if any.
1574 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
1575 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
1577 /// Set style sheet and notify of the change
1578 bool SetStyleSheetAndNotify(wxRichTextStyleSheet
* sheet
);
1580 /// Push style sheet to top of stack
1581 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1583 /// Pop style sheet from top of stack
1584 wxRichTextStyleSheet
* PopStyleSheet();
1591 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1592 virtual void ResetAndClearCommands();
1595 virtual bool LoadFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1598 virtual bool SaveFile(const wxString
& filename
, int type
= wxRICHTEXT_TYPE_ANY
);
1600 /// Load from a stream
1601 virtual bool LoadFile(wxInputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1603 /// Save to a stream
1604 virtual bool SaveFile(wxOutputStream
& stream
, int type
= wxRICHTEXT_TYPE_ANY
);
1606 /// Set the handler flags, controlling loading and saving
1607 void SetHandlerFlags(int flags
) { m_handlerFlags
= flags
; }
1609 /// Get the handler flags, controlling loading and saving
1610 int GetHandlerFlags() const { return m_handlerFlags
; }
1612 /// Convenience function to add a paragraph of text
1613 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttrEx
* paraStyle
= NULL
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
, paraStyle
); }
1615 /// Begin collapsing undo/redo commands. Note that this may not work properly
1616 /// if combining commands that delete or insert content, changing ranges for
1617 /// subsequent actions.
1618 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1620 /// End collapsing undo/redo commands
1621 virtual bool EndBatchUndo();
1623 /// Collapsing commands?
1624 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
1626 /// Submit immediately, or delay according to whether collapsing is on
1627 virtual bool SubmitAction(wxRichTextAction
* action
);
1629 /// Get collapsed command
1630 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
1632 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1633 /// differently by each command. If not dealt with by a command implementation, then
1634 /// it will be implemented automatically by not storing the command in the undo history
1635 /// when the action is submitted to the command processor.
1636 virtual bool BeginSuppressUndo();
1638 /// End suppressing undo/redo commands.
1639 virtual bool EndSuppressUndo();
1641 /// Collapsing commands?
1642 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
1644 /// Copy the range to the clipboard
1645 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
1647 /// Paste the clipboard content to the buffer
1648 virtual bool PasteFromClipboard(long position
);
1650 /// Can we paste from the clipboard?
1651 virtual bool CanPasteFromClipboard() const;
1653 /// Begin using a style
1654 virtual bool BeginStyle(const wxTextAttrEx
& style
);
1657 virtual bool EndStyle();
1660 virtual bool EndAllStyles();
1662 /// Clear the style stack
1663 virtual void ClearStyleStack();
1665 /// Get the size of the style stack, for example to check correct nesting
1666 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
1668 /// Begin using bold
1672 bool EndBold() { return EndStyle(); }
1674 /// Begin using italic
1677 /// End using italic
1678 bool EndItalic() { return EndStyle(); }
1680 /// Begin using underline
1681 bool BeginUnderline();
1683 /// End using underline
1684 bool EndUnderline() { return EndStyle(); }
1686 /// Begin using point size
1687 bool BeginFontSize(int pointSize
);
1689 /// End using point size
1690 bool EndFontSize() { return EndStyle(); }
1692 /// Begin using this font
1693 bool BeginFont(const wxFont
& font
);
1695 /// End using a font
1696 bool EndFont() { return EndStyle(); }
1698 /// Begin using this colour
1699 bool BeginTextColour(const wxColour
& colour
);
1701 /// End using a colour
1702 bool EndTextColour() { return EndStyle(); }
1704 /// Begin using alignment
1705 bool BeginAlignment(wxTextAttrAlignment alignment
);
1708 bool EndAlignment() { return EndStyle(); }
1710 /// Begin left indent
1711 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
1714 bool EndLeftIndent() { return EndStyle(); }
1716 /// Begin right indent
1717 bool BeginRightIndent(int rightIndent
);
1719 /// End right indent
1720 bool EndRightIndent() { return EndStyle(); }
1722 /// Begin paragraph spacing
1723 bool BeginParagraphSpacing(int before
, int after
);
1725 /// End paragraph spacing
1726 bool EndParagraphSpacing() { return EndStyle(); }
1728 /// Begin line spacing
1729 bool BeginLineSpacing(int lineSpacing
);
1731 /// End line spacing
1732 bool EndLineSpacing() { return EndStyle(); }
1734 /// Begin numbered bullet
1735 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
1737 /// End numbered bullet
1738 bool EndNumberedBullet() { return EndStyle(); }
1740 /// Begin symbol bullet
1741 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
1743 /// End symbol bullet
1744 bool EndSymbolBullet() { return EndStyle(); }
1746 /// Begin standard bullet
1747 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
1749 /// End standard bullet
1750 bool EndStandardBullet() { return EndStyle(); }
1752 /// Begin named character style
1753 bool BeginCharacterStyle(const wxString
& characterStyle
);
1755 /// End named character style
1756 bool EndCharacterStyle() { return EndStyle(); }
1758 /// Begin named paragraph style
1759 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
1761 /// End named character style
1762 bool EndParagraphStyle() { return EndStyle(); }
1764 /// Begin named list style
1765 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
1767 /// End named character style
1768 bool EndListStyle() { return EndStyle(); }
1771 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
);
1774 bool EndURL() { return EndStyle(); }
1778 /// Add an event handler
1779 bool AddEventHandler(wxEvtHandler
* handler
);
1781 /// Remove an event handler
1782 bool RemoveEventHandler(wxEvtHandler
* handler
, bool deleteHandler
= false);
1784 /// Clear event handlers
1785 void ClearEventHandlers();
1787 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
1788 /// otherwise will stop at the first successful one.
1789 bool SendEvent(wxEvent
& event
, bool sendToAll
= true);
1794 void Copy(const wxRichTextBuffer
& obj
);
1797 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
1799 /// Submit command to insert paragraphs
1800 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1802 /// Submit command to insert the given text
1803 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1805 /// Submit command to insert a newline
1806 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1808 /// Submit command to insert the given image
1809 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1811 /// Submit command to delete this range
1812 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, long initialCaretPosition
, long newCaretPositon
, wxRichTextCtrl
* ctrl
);
1815 void Modify(bool modify
= true) { m_modified
= modify
; }
1816 bool IsModified() const { return m_modified
; }
1818 /// Get the style that is appropriate for a new paragraph at this position.
1819 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1821 wxRichTextAttr
GetStyleForNewParagraph(long pos
, bool caretPosition
= false) const;
1823 /// Dumps contents of buffer for debugging purposes
1824 virtual void Dump();
1825 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
1827 /// Returns the file handlers
1828 static wxList
& GetHandlers() { return sm_handlers
; }
1830 /// Adds a handler to the end
1831 static void AddHandler(wxRichTextFileHandler
*handler
);
1833 /// Inserts a handler at the front
1834 static void InsertHandler(wxRichTextFileHandler
*handler
);
1836 /// Removes a handler
1837 static bool RemoveHandler(const wxString
& name
);
1839 /// Finds a handler by name
1840 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
1842 /// Finds a handler by extension and type
1843 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, int imageType
);
1845 /// Finds a handler by filename or, if supplied, type
1846 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
, int imageType
);
1848 /// Finds a handler by type
1849 static wxRichTextFileHandler
*FindHandler(int imageType
);
1851 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1852 /// will be filled with the file type corresponding to each filter. This can be
1853 /// used to determine the type to pass to LoadFile given a selected filter.
1854 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
1856 /// Clean up handlers
1857 static void CleanUpHandlers();
1859 /// Initialise the standard handlers
1860 static void InitStandardHandlers();
1863 static wxRichTextRenderer
* GetRenderer() { return sm_renderer
; }
1865 /// Set renderer, deleting old one
1866 static void SetRenderer(wxRichTextRenderer
* renderer
);
1868 /// Minimum margin between bullet and paragraph in 10ths of a mm
1869 static int GetBulletRightMargin() { return sm_bulletRightMargin
; }
1870 static void SetBulletRightMargin(int margin
) { sm_bulletRightMargin
= margin
; }
1872 /// Factor to multiply by character height to get a reasonable bullet size
1873 static float GetBulletProportion() { return sm_bulletProportion
; }
1874 static void SetBulletProportion(float prop
) { sm_bulletProportion
= prop
; }
1876 /// Scale factor for calculating dimensions
1877 double GetScale() const { return m_scale
; }
1878 void SetScale(double scale
) { m_scale
= scale
; }
1882 /// Command processor
1883 wxCommandProcessor
* m_commandProcessor
;
1885 /// Has been modified?
1888 /// Collapsed command stack
1889 int m_batchedCommandDepth
;
1891 /// Name for collapsed command
1892 wxString m_batchedCommandsName
;
1894 /// Current collapsed command accumulating actions
1895 wxRichTextCommand
* m_batchedCommand
;
1897 /// Whether to suppress undo
1900 /// Style sheet, if any
1901 wxRichTextStyleSheet
* m_styleSheet
;
1903 /// List of event handlers that will be notified of events
1904 wxList m_eventHandlers
;
1906 /// Stack of attributes for convenience functions
1907 wxList m_attributeStack
;
1909 /// Flags to be passed to handlers
1913 static wxList sm_handlers
;
1916 static wxRichTextRenderer
* sm_renderer
;
1918 /// Minimum margin between bullet and paragraph in 10ths of a mm
1919 static int sm_bulletRightMargin
;
1921 /// Factor to multiply by character height to get a reasonable bullet size
1922 static float sm_bulletProportion
;
1924 /// Scaling factor in use: needed to calculate correct dimensions when printing
1929 * The command identifiers
1933 enum wxRichTextCommandId
1937 wxRICHTEXT_CHANGE_STYLE
1941 * Command classes for undo/redo
1945 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
;
1946 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
1949 // Ctor for one action
1950 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1951 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1953 // Ctor for multiple actions
1954 wxRichTextCommand(const wxString
& name
);
1956 virtual ~wxRichTextCommand();
1961 void AddAction(wxRichTextAction
* action
);
1962 void ClearActions();
1964 wxList
& GetActions() { return m_actions
; }
1972 * wxRichTextAction class declaration
1973 * There can be more than one action in a command.
1976 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
1979 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1980 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1982 virtual ~wxRichTextAction();
1987 /// Update the control appearance
1988 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false);
1990 /// Replace the buffer paragraphs with the given fragment.
1991 void ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
);
1993 /// Get the fragments
1994 wxRichTextParagraphLayoutBox
& GetNewParagraphs() { return m_newParagraphs
; }
1995 wxRichTextParagraphLayoutBox
& GetOldParagraphs() { return m_oldParagraphs
; }
1997 /// Set/get the position used for e.g. insertion
1998 void SetPosition(long pos
) { m_position
= pos
; }
1999 long GetPosition() const { return m_position
; }
2001 /// Set/get the range for e.g. deletion
2002 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
2003 const wxRichTextRange
& GetRange() const { return m_range
; }
2006 const wxString
& GetName() const { return m_name
; }
2013 wxRichTextBuffer
* m_buffer
;
2016 wxRichTextCtrl
* m_ctrl
;
2018 // Stores the new paragraphs
2019 wxRichTextParagraphLayoutBox m_newParagraphs
;
2021 // Stores the old paragraphs
2022 wxRichTextParagraphLayoutBox m_oldParagraphs
;
2024 // The affected range
2025 wxRichTextRange m_range
;
2027 // The insertion point for this command
2030 // Ignore 1st 'Do' operation because we already did it
2033 // The command identifier
2034 wxRichTextCommandId m_cmdId
;
2041 // Include style sheet when loading and saving
2042 #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
2044 // Save images to memory file system in HTML handler
2045 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
2047 // Save images to files in HTML handler
2048 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
2050 // Save images as inline base64 data in HTML handler
2051 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
2054 * wxRichTextFileHandler
2055 * Base class for file handlers
2058 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
2060 DECLARE_CLASS(wxRichTextFileHandler
)
2062 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
2063 : m_name(name
), m_extension(ext
), m_type(type
), m_flags(0), m_visible(true)
2067 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
2068 { return DoLoadFile(buffer
, stream
); }
2069 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
2070 { return DoSaveFile(buffer
, stream
); }
2073 bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
2074 bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
2076 /// Can we handle this filename (if using files)? By default, checks the extension.
2077 virtual bool CanHandle(const wxString
& filename
) const;
2079 /// Can we save using this handler?
2080 virtual bool CanSave() const { return false; }
2082 /// Can we load using this handler?
2083 virtual bool CanLoad() const { return false; }
2085 /// Should this handler be visible to the user?
2086 virtual bool IsVisible() const { return m_visible
; }
2087 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
2089 /// The name of the nandler
2090 void SetName(const wxString
& name
) { m_name
= name
; }
2091 wxString
GetName() const { return m_name
; }
2093 /// The default extension to recognise
2094 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
2095 wxString
GetExtension() const { return m_extension
; }
2097 /// The handler type
2098 void SetType(int type
) { m_type
= type
; }
2099 int GetType() const { return m_type
; }
2101 /// Flags controlling how loading and saving is done
2102 void SetFlags(int flags
) { m_flags
= flags
; }
2103 int GetFlags() const { return m_flags
; }
2105 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
2106 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
2107 const wxString
& GetEncoding() const { return m_encoding
; }
2112 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
2113 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
2117 wxString m_encoding
;
2118 wxString m_extension
;
2125 * wxRichTextPlainTextHandler
2126 * Plain text handler
2129 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
2131 DECLARE_CLASS(wxRichTextPlainTextHandler
)
2133 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"), const wxString
& ext
= wxT("txt"), int type
= wxRICHTEXT_TYPE_TEXT
)
2134 : wxRichTextFileHandler(name
, ext
, type
)
2137 /// Can we save using this handler?
2138 virtual bool CanSave() const { return true; }
2140 /// Can we load using this handler?
2141 virtual bool CanLoad() const { return true; }
2146 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
2147 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
2155 * The data object for a wxRichTextBuffer
2158 class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject
: public wxDataObjectSimple
2161 // ctor doesn't copy the pointer, so it shouldn't go away while this object
2163 wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
= (wxRichTextBuffer
*) NULL
);
2164 virtual ~wxRichTextBufferDataObject();
2166 // after a call to this function, the buffer is owned by the caller and it
2167 // is responsible for deleting it
2168 wxRichTextBuffer
* GetRichTextBuffer();
2170 // Returns the id for the new data format
2171 static const wxChar
* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId
; }
2173 // base class pure virtuals
2175 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
2176 virtual size_t GetDataSize() const;
2177 virtual bool GetDataHere(void *pBuf
) const;
2178 virtual bool SetData(size_t len
, const void *buf
);
2182 virtual size_t GetDataSize(const wxDataFormat
&) const { return GetDataSize(); }
2183 virtual bool GetDataHere(const wxDataFormat
&, void *buf
) const { return GetDataHere(buf
); }
2184 virtual bool SetData(const wxDataFormat
&, size_t len
, const void *buf
) { return SetData(len
, buf
); }
2187 wxDataFormat m_formatRichTextBuffer
; // our custom format
2188 wxRichTextBuffer
* m_richTextBuffer
; // our data
2189 static const wxChar
* ms_richTextBufferFormatId
; // our format id
2195 * wxRichTextRenderer isolates common drawing functionality
2198 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer
: public wxObject
2201 wxRichTextRenderer() {}
2202 virtual ~wxRichTextRenderer() {}
2204 /// Draw a standard bullet, as specified by the value of GetBulletName
2205 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
) = 0;
2207 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2208 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
, const wxString
& text
) = 0;
2210 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2211 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
) = 0;
2213 /// Enumerate the standard bullet names currently supported
2214 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
) = 0;
2218 * wxRichTextStdRenderer: standard renderer
2221 class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer
: public wxRichTextRenderer
2224 wxRichTextStdRenderer() {}
2226 /// Draw a standard bullet, as specified by the value of GetBulletName
2227 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
);
2229 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2230 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
, const wxString
& text
);
2232 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2233 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
);
2235 /// Enumerate the standard bullet names currently supported
2236 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
);
2244 inline bool wxRichTextHasStyle(int flags
, int style
)
2246 return ((flags
& style
) == style
);
2249 /// Compare two attribute objects
2250 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
);
2251 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
2253 /// Compare two attribute objects, but take into account the flags
2254 /// specifying attributes of interest.
2255 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
, int flags
);
2256 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxRichTextAttr
& attr2
, int flags
);
2258 /// Apply one style to another
2259 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxTextAttrEx
& style
);
2260 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxTextAttrEx
& style
);
2261 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
= NULL
);
2262 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
= NULL
);
2265 WXDLLIMPEXP_RICHTEXT
bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
);
2267 /// Set the font without changing the font attributes
2268 WXDLLIMPEXP_RICHTEXT
void wxSetFontPreservingStyles(wxTextAttr
& attr
, const wxFont
& font
);
2270 /// Convert a decimal to Roman numerals
2271 WXDLLIMPEXP_RICHTEXT wxString
wxRichTextDecimalToRoman(long n
);
2273 WXDLLIMPEXP_RICHTEXT
void wxRichTextModuleInit();
2279 // _WX_RICHTEXTBUFFER_H_