1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/richtext/richtextbuffer.h
3 // Purpose:     Buffer for wxRichTextCtrl
4 // Author:      Julian Smart
5 // Modified by:
6 // Created:     2005-09-30
7 // RCS-ID:      $Id: richtextbuffer.h 64777 2010-06-28 21:21:53Z JS $
8 // Copyright:   (c) Julian Smart
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_RICHTEXTBUFFER_H_
13 #define _WX_RICHTEXTBUFFER_H_
14 
15 /*
16 
17   Data structures
18   ===============
19 
20   Data is represented by a hierarchy of objects, all derived from
21   wxRichTextObject.
22 
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.
28 
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.
36 
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.
41 
42   Layout
43   ======
44 
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.
51 
52  */
53 
54 /*!
55  * Includes
56  */
57 
58 #include "wx/defs.h"
59 
60 #if wxUSE_RICHTEXT
61 
62 #include "wx/list.h"
63 #include "wx/textctrl.h"
64 #include "wx/bitmap.h"
65 #include "wx/image.h"
66 #include "wx/cmdproc.h"
67 #include "wx/txtstrm.h"
68 
69 #if wxUSE_DATAOBJ
70 #include "wx/dataobj.h"
71 #endif
72 
73 // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a
74 // caret reliably without using wxClientDC in case there
75 // are platform-specific problems with the generic caret.
76 #if defined(__WXGTK__) || (defined(wxMAC_USE_CORE_GRAPHICS) && wxMAC_USE_CORE_GRAPHICS)
77 #define wxRICHTEXT_USE_OWN_CARET 1
78 #else
79 #define wxRICHTEXT_USE_OWN_CARET 0
80 #endif
81 
82 // Switch off for binary compatibility, on for faster drawing
83 #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0
84 
85 /*!
86  * Special characters
87  */
88 
89 extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar;
90 
91 /*!
92  * File types
93  */
94 
95 #define wxRICHTEXT_TYPE_ANY             0
96 #define wxRICHTEXT_TYPE_TEXT            1
97 #define wxRICHTEXT_TYPE_XML             2
98 #define wxRICHTEXT_TYPE_HTML            3
99 #define wxRICHTEXT_TYPE_RTF             4
100 #define wxRICHTEXT_TYPE_PDF             5
101 
102 /*!
103  * Forward declarations
104  */
105 
106 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl;
107 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject;
108 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject;
109 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList;
110 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine;
111 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph;
112 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler;
113 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet;
114 class WXDLLIMPEXP_FWD_RICHTEXT wxTextAttrEx;
115 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition;
116 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent;
117 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer;
118 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
119 
120 /*!
121  * Flags determining the available space, passed to Layout
122  */
123 
124 #define wxRICHTEXT_FIXED_WIDTH      0x01
125 #define wxRICHTEXT_FIXED_HEIGHT     0x02
126 #define wxRICHTEXT_VARIABLE_WIDTH   0x04
127 #define wxRICHTEXT_VARIABLE_HEIGHT  0x08
128 
129 // Only lay out the part of the buffer that lies within
130 // the rect passed to Layout.
131 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
132 
133 /*!
134  * Flags to pass to Draw
135  */
136 
137 // Ignore paragraph cache optimization, e.g. for printing purposes
138 // where one line may be drawn higher (on the next page) compared
139 // with the previous line
140 #define wxRICHTEXT_DRAW_IGNORE_CACHE    0x01
141 
142 /*!
143  * Flags returned from hit-testing
144  */
145 
146 // The point was not on this object
147 #define wxRICHTEXT_HITTEST_NONE     0x01
148 // The point was before the position returned from HitTest
149 #define wxRICHTEXT_HITTEST_BEFORE   0x02
150 // The point was after the position returned from HitTest
151 #define wxRICHTEXT_HITTEST_AFTER    0x04
152 // The point was on the position returned from HitTest
153 #define wxRICHTEXT_HITTEST_ON       0x08
154 // The point was on space outside content
155 #define wxRICHTEXT_HITTEST_OUTSIDE  0x10
156 
157 /*!
158  * Flags for GetRangeSize
159  */
160 
161 #define wxRICHTEXT_FORMATTED        0x01
162 #define wxRICHTEXT_UNFORMATTED      0x02
163 #define wxRICHTEXT_CACHE_SIZE       0x04
164 #define wxRICHTEXT_HEIGHT_ONLY      0x08
165 
166 /*!
167  * Flags for SetStyle/SetListStyle
168  */
169 
170 #define wxRICHTEXT_SETSTYLE_NONE            0x00
171 
172 // Specifies that this operation should be undoable
173 #define wxRICHTEXT_SETSTYLE_WITH_UNDO       0x01
174 
175 // Specifies that the style should not be applied if the
176 // combined style at this point is already the style in question.
177 #define wxRICHTEXT_SETSTYLE_OPTIMIZE        0x02
178 
179 // Specifies that the style should only be applied to paragraphs,
180 // and not the content. This allows content styling to be
181 // preserved independently from that of e.g. a named paragraph style.
182 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
183 
184 // Specifies that the style should only be applied to characters,
185 // and not the paragraph. This allows content styling to be
186 // preserved independently from that of e.g. a named paragraph style.
187 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
188 
189 // For SetListStyle only: specifies starting from the given number, otherwise
190 // deduces number from existing attributes
191 #define wxRICHTEXT_SETSTYLE_RENUMBER        0x10
192 
193 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
194 // the current indentation will be used
195 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL   0x20
196 
197 // Resets the existing style before applying the new style
198 #define wxRICHTEXT_SETSTYLE_RESET           0x40
199 
200 // Removes the given style instead of applying it
201 #define wxRICHTEXT_SETSTYLE_REMOVE          0x80
202 
203 /*!
204  * Flags for text insertion
205  */
206 
207 #define wxRICHTEXT_INSERT_NONE                              0x00
208 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE     0x01
209 #define wxRICHTEXT_INSERT_INTERACTIVE                       0x02
210 
211 /*!
212  * Extra formatting flags not in wxTextAttr
213  */
214 
215 #define wxTEXT_ATTR_PARA_SPACING_AFTER      0x00000800
216 #define wxTEXT_ATTR_PARA_SPACING_BEFORE     0x00001000
217 #define wxTEXT_ATTR_LINE_SPACING            0x00002000
218 #define wxTEXT_ATTR_CHARACTER_STYLE_NAME    0x00004000
219 #define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME    0x00008000
220 #define wxTEXT_ATTR_LIST_STYLE_NAME         0x00010000
221 #define wxTEXT_ATTR_BULLET_STYLE            0x00020000
222 #define wxTEXT_ATTR_BULLET_NUMBER           0x00040000
223 #define wxTEXT_ATTR_BULLET_TEXT             0x00080000
224 #define wxTEXT_ATTR_BULLET_NAME             0x00100000
225 #define wxTEXT_ATTR_URL                     0x00200000
226 #define wxTEXT_ATTR_PAGE_BREAK              0x00400000
227 #define wxTEXT_ATTR_EFFECTS                 0x00800000
228 #define wxTEXT_ATTR_OUTLINE_LEVEL           0x01000000
229 
230 // A special flag telling the buffer to keep the first paragraph style
231 // as-is, when deleting a paragraph marker. In future we might pass a
232 // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
233 #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE   0x10000000
234 
235 /*!
236  * Styles for wxTextAttrEx::SetBulletStyle
237  */
238 
239 #define wxTEXT_ATTR_BULLET_STYLE_NONE               0x00000000
240 #define wxTEXT_ATTR_BULLET_STYLE_ARABIC             0x00000001
241 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER      0x00000002
242 #define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER      0x00000004
243 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER        0x00000008
244 #define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER        0x00000010
245 #define wxTEXT_ATTR_BULLET_STYLE_SYMBOL             0x00000020
246 #define wxTEXT_ATTR_BULLET_STYLE_BITMAP             0x00000040
247 #define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES        0x00000080
248 #define wxTEXT_ATTR_BULLET_STYLE_PERIOD             0x00000100
249 #define wxTEXT_ATTR_BULLET_STYLE_STANDARD           0x00000200
250 #define wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS  0x00000400
251 #define wxTEXT_ATTR_BULLET_STYLE_OUTLINE            0x00000800
252 
253 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT         0x00000000
254 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT        0x00001000
255 #define wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE       0x00002000
256 
257 /*!
258  * Styles for wxTextAttrEx::SetTextEffects
259  */
260 
261 #define wxTEXT_ATTR_EFFECT_NONE                     0x00000000
262 #define wxTEXT_ATTR_EFFECT_CAPITALS                 0x00000001
263 #define wxTEXT_ATTR_EFFECT_SMALL_CAPITALS           0x00000002
264 #define wxTEXT_ATTR_EFFECT_STRIKETHROUGH            0x00000004
265 #define wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH     0x00000008
266 #define wxTEXT_ATTR_EFFECT_SHADOW                   0x00000010
267 #define wxTEXT_ATTR_EFFECT_EMBOSS                   0x00000020
268 #define wxTEXT_ATTR_EFFECT_OUTLINE                  0x00000040
269 #define wxTEXT_ATTR_EFFECT_ENGRAVE                  0x00000080
270 #define wxTEXT_ATTR_EFFECT_SUPERSCRIPT              0x00000100
271 #define wxTEXT_ATTR_EFFECT_SUBSCRIPT                0x00000200
272 
273 /*!
274  * Line spacing values
275  */
276 
277 #define wxTEXT_ATTR_LINE_SPACING_NORMAL         10
278 #define wxTEXT_ATTR_LINE_SPACING_HALF           15
279 #define wxTEXT_ATTR_LINE_SPACING_TWICE          20
280 
281 /*!
282  * Character and paragraph combined styles
283  */
284 
285 #define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS|wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL)
286 
287 #define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
288     wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
289     wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_TEXT|wxTEXT_ATTR_BULLET_NAME|\
290     wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL|wxTEXT_ATTR_PAGE_BREAK)
291 
292 #define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
293 
294 /*!
295  * Default superscript/subscript font multiplication factor
296  */
297 
298 #define wxSCRIPT_MUL_FACTOR             1.5
299 
300 /*!
301  * wxRichTextRange class declaration
302  * This stores beginning and end positions for a range of data.
303  */
304 
305 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
306 {
307 public:
308 // Constructors
309 
wxRichTextRange()310     wxRichTextRange() { m_start = 0; m_end = 0; }
wxRichTextRange(long start,long end)311     wxRichTextRange(long start, long end) { m_start = start; m_end = end; }
wxRichTextRange(const wxRichTextRange & range)312     wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
~wxRichTextRange()313     ~wxRichTextRange() {}
314 
315     void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
316     bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); }
317     bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start || m_end != range.m_end); }
318     wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); }
319     wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); }
320 
SetRange(long start,long end)321     void SetRange(long start, long end) { m_start = start; m_end = end; }
322 
SetStart(long start)323     void SetStart(long start) { m_start = start; }
GetStart()324     long GetStart() const { return m_start; }
325 
SetEnd(long end)326     void SetEnd(long end) { m_end = end; }
GetEnd()327     long GetEnd() const { return m_end; }
328 
329     /// Returns true if this range is completely outside 'range'
IsOutside(const wxRichTextRange & range)330     bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; }
331 
332     /// Returns true if this range is completely within 'range'
IsWithin(const wxRichTextRange & range)333     bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; }
334 
335     /// Returns true if the given position is within this range. Allow
336     /// for the possibility of an empty range - assume the position
337     /// is within this empty range. NO, I think we should not match with an empty range.
338     // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
Contains(long pos)339     bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; }
340 
341     /// Limit this range to be within 'range'
342     bool LimitTo(const wxRichTextRange& range) ;
343 
344     /// Gets the length of the range
GetLength()345     long GetLength() const { return m_end - m_start + 1; }
346 
347     /// Swaps the start and end
Swap()348     void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; }
349 
350     /// Convert to internal form: (n, n) is the range of a single character.
ToInternal()351     wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); }
352 
353     /// Convert from internal to public API form: (n, n+1) is the range of a single character.
FromInternal()354     wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); }
355 
356 protected:
357     long m_start;
358     long m_end;
359 };
360 
361 #define wxRICHTEXT_ALL  wxRichTextRange(-2, -2)
362 #define wxRICHTEXT_NONE  wxRichTextRange(-1, -1)
363 
364 /*!
365  * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
366  */
367 
368 class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr
369 {
370 public:
371     // ctors
372     wxTextAttrEx(const wxTextAttrEx& attr);
wxTextAttrEx(const wxTextAttr & attr)373     wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
wxTextAttrEx()374     wxTextAttrEx() { Init(); }
375 
376     // Initialise this object
377     void Init();
378 
379     // Copy
380     void Copy(const wxTextAttrEx& attr);
381 
382     // Assignment from a wxTextAttrEx object
383     void operator= (const wxTextAttrEx& attr);
384 
385     // Assignment from a wxTextAttr object
386     void operator= (const wxTextAttr& attr);
387 
388     // Equality test
389     bool operator== (const wxTextAttrEx& attr) const;
390 
391     // setters
SetCharacterStyleName(const wxString & name)392     void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME); }
SetParagraphStyleName(const wxString & name)393     void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); }
SetListStyleName(const wxString & name)394     void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
SetParagraphSpacingAfter(int spacing)395     void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER); }
SetParagraphSpacingBefore(int spacing)396     void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE); }
SetLineSpacing(int spacing)397     void SetLineSpacing(int spacing) { m_lineSpacing = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING); }
SetBulletStyle(int style)398     void SetBulletStyle(int style) { m_bulletStyle = style; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE); }
SetBulletNumber(int n)399     void SetBulletNumber(int n) { m_bulletNumber = n; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER); }
SetBulletText(const wxString & text)400     void SetBulletText(const wxString& text) { m_bulletText = text; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_TEXT); }
SetBulletName(const wxString & name)401     void SetBulletName(const wxString& name) { m_bulletName = name; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NAME); }
SetBulletFont(const wxString & bulletFont)402     void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
SetURL(const wxString & url)403     void SetURL(const wxString& url) { m_urlTarget = url; SetFlags(GetFlags() | wxTEXT_ATTR_URL); }
404     void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); }
SetTextEffects(int effects)405     void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); }
SetTextEffectFlags(int effects)406     void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; }
SetOutlineLevel(int level)407     void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); }
408 
GetCharacterStyleName()409     const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
GetParagraphStyleName()410     const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
GetListStyleName()411     const wxString& GetListStyleName() const { return m_listStyleName; }
GetParagraphSpacingAfter()412     int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
GetParagraphSpacingBefore()413     int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
GetLineSpacing()414     int GetLineSpacing() const { return m_lineSpacing; }
GetBulletStyle()415     int GetBulletStyle() const { return m_bulletStyle; }
GetBulletNumber()416     int GetBulletNumber() const { return m_bulletNumber; }
GetBulletText()417     const wxString& GetBulletText() const { return m_bulletText; }
GetBulletName()418     const wxString& GetBulletName() const { return m_bulletName; }
GetBulletFont()419     const wxString& GetBulletFont() const { return m_bulletFont; }
GetURL()420     const wxString& GetURL() const { return m_urlTarget; }
GetTextEffects()421     int GetTextEffects() const { return m_textEffects; }
GetTextEffectFlags()422     int GetTextEffectFlags() const { return m_textEffectFlags; }
GetOutlineLevel()423     int GetOutlineLevel() const { return m_outlineLevel; }
424 
HasFontWeight()425     bool HasFontWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
HasFontSize()426     bool HasFontSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; }
HasFontItalic()427     bool HasFontItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; }
HasFontUnderlined()428     bool HasFontUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
HasFontFaceName()429     bool HasFontFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE) != 0; }
430 
HasParagraphSpacingAfter()431     bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); }
HasParagraphSpacingBefore()432     bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); }
HasLineSpacing()433     bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); }
HasCharacterStyleName()434     bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) && !m_characterStyleName.IsEmpty(); }
HasParagraphStyleName()435     bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && !m_paragraphStyleName.IsEmpty(); }
HasListStyleName()436     bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
HasBulletStyle()437     bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
HasBulletNumber()438     bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
HasBulletText()439     bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT); }
HasBulletName()440     bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME); }
HasURL()441     bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); }
HasPageBreak()442     bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); }
HasTextEffects()443     bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); }
HasTextEffect(int effect)444     bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); }
HasOutlineLevel()445     bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); }
446 
447     // Is this a character style?
IsCharacterStyle()448     bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); }
IsParagraphStyle()449     bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); }
450 
451     // returns false if we have any attributes set, true otherwise
IsDefault()452     bool IsDefault() const
453     {
454         return (GetFlags() == 0);
455     }
456 
457     // return the attribute having the valid font and colours: it uses the
458     // attributes set in attr and falls back first to attrDefault and then to
459     // the text control font/colours for those attributes which are not set
460     static wxTextAttrEx CombineEx(const wxTextAttrEx& attr,
461                               const wxTextAttrEx& attrDef,
462                               const wxTextCtrlBase *text);
463 
464 private:
465     // Paragraph styles
466     int                 m_paragraphSpacingAfter;
467     int                 m_paragraphSpacingBefore;
468     int                 m_lineSpacing;
469     int                 m_bulletStyle;
470     int                 m_bulletNumber;
471     int                 m_textEffects;
472     int                 m_textEffectFlags;
473     int                 m_outlineLevel;
474     wxString            m_bulletText;
475     wxString            m_bulletFont;
476     wxString            m_bulletName;
477     wxString            m_urlTarget;
478 
479     // Character style
480     wxString            m_characterStyleName;
481 
482     // Paragraph style
483     wxString            m_paragraphStyleName;
484 
485     // List style
486     wxString            m_listStyleName;
487 };
488 
489 /*!
490  * wxRichTextAttr stores attributes without a wxFont object, so is a much more
491  * efficient way to query styles.
492  */
493 
494 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
495 {
496 public:
497     // ctors
498     wxRichTextAttr(const wxTextAttrEx& attr);
499     wxRichTextAttr(const wxRichTextAttr& attr);
wxRichTextAttr()500     wxRichTextAttr() { Init(); }
501     wxRichTextAttr(const wxColour& colText,
502                const wxColour& colBack = wxNullColour,
503                wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
504 
505     // Initialise this object.
506     void Init();
507 
508     // Copy
509     void Copy(const wxRichTextAttr& attr);
510 
511     // Assignment from a wxRichTextAttr object.
512     void operator= (const wxRichTextAttr& attr);
513 
514     // Assignment from a wxTextAttrEx object.
515     void operator= (const wxTextAttrEx& attr);
516 
517     // Equality test
518     bool operator== (const wxRichTextAttr& attr) const;
519 
520     // Making a wxTextAttrEx object.
521     operator wxTextAttrEx () const ;
522 
523     // Create font from font attributes.
524     wxFont CreateFont() const;
525 
526     // Get attributes from font.
527     bool GetFontAttributes(const wxFont& font);
528 
529     // setters
SetTextColour(const wxColour & colText)530     void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; }
SetBackgroundColour(const wxColour & colBack)531     void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; }
SetAlignment(wxTextAttrAlignment alignment)532     void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; }
SetTabs(const wxArrayInt & tabs)533     void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; }
534     void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; }
SetRightIndent(int indent)535     void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; }
536 
SetFontSize(int pointSize)537     void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; }
SetFontStyle(int fontStyle)538     void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; }
SetFontWeight(int fontWeight)539     void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; }
SetFontFaceName(const wxString & faceName)540     void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
SetFontUnderlined(bool underlined)541     void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
542 
SetFlags(long flags)543     void SetFlags(long flags) { m_flags = flags; }
544 
SetCharacterStyleName(const wxString & name)545     void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; }
SetParagraphStyleName(const wxString & name)546     void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; }
SetListStyleName(const wxString & name)547     void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
SetParagraphSpacingAfter(int spacing)548     void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; }
SetParagraphSpacingBefore(int spacing)549     void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; }
SetLineSpacing(int spacing)550     void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; }
SetBulletStyle(int style)551     void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; }
SetBulletNumber(int n)552     void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
SetBulletText(const wxString & text)553     void SetBulletText(const wxString& text) { m_bulletText = text; m_flags |= wxTEXT_ATTR_BULLET_TEXT; }
SetBulletFont(const wxString & bulletFont)554     void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
SetBulletName(const wxString & name)555     void SetBulletName(const wxString& name) { m_bulletName = name; m_flags |= wxTEXT_ATTR_BULLET_NAME; }
SetURL(const wxString & url)556     void SetURL(const wxString& url) { m_urlTarget = url; m_flags |= wxTEXT_ATTR_URL; }
557     void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); }
SetTextEffects(int effects)558     void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); }
SetTextEffectFlags(int effects)559     void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; }
SetOutlineLevel(int level)560     void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); }
561 
GetTextColour()562     const wxColour& GetTextColour() const { return m_colText; }
GetBackgroundColour()563     const wxColour& GetBackgroundColour() const { return m_colBack; }
GetAlignment()564     wxTextAttrAlignment GetAlignment() const { return m_textAlignment; }
GetTabs()565     const wxArrayInt& GetTabs() const { return m_tabs; }
GetLeftIndent()566     long GetLeftIndent() const { return m_leftIndent; }
GetLeftSubIndent()567     long GetLeftSubIndent() const { return m_leftSubIndent; }
GetRightIndent()568     long GetRightIndent() const { return m_rightIndent; }
GetFlags()569     long GetFlags() const { return m_flags; }
570 
GetFontSize()571     int GetFontSize() const { return m_fontSize; }
GetFontStyle()572     int GetFontStyle() const { return m_fontStyle; }
GetFontWeight()573     int GetFontWeight() const { return m_fontWeight; }
GetFontUnderlined()574     bool GetFontUnderlined() const { return m_fontUnderlined; }
GetFontFaceName()575     const wxString& GetFontFaceName() const { return m_fontFaceName; }
576 
GetCharacterStyleName()577     const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
GetParagraphStyleName()578     const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
GetListStyleName()579     const wxString& GetListStyleName() const { return m_listStyleName; }
GetParagraphSpacingAfter()580     int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
GetParagraphSpacingBefore()581     int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
GetLineSpacing()582     int GetLineSpacing() const { return m_lineSpacing; }
GetBulletStyle()583     int GetBulletStyle() const { return m_bulletStyle; }
GetBulletNumber()584     int GetBulletNumber() const { return m_bulletNumber; }
GetBulletText()585     const wxString& GetBulletText() const { return m_bulletText; }
GetBulletFont()586     const wxString& GetBulletFont() const { return m_bulletFont; }
GetBulletName()587     const wxString& GetBulletName() const { return m_bulletName; }
GetURL()588     const wxString& GetURL() const { return m_urlTarget; }
GetTextEffects()589     int GetTextEffects() const { return m_textEffects; }
GetTextEffectFlags()590     int GetTextEffectFlags() const { return m_textEffectFlags; }
GetOutlineLevel()591     int GetOutlineLevel() const { return m_outlineLevel; }
592 
593     // accessors
HasTextColour()594     bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
HasBackgroundColour()595     bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; }
HasAlignment()596     bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) && ((m_flags & wxTEXT_ATTR_ALIGNMENT) != 0) ; }
HasTabs()597     bool HasTabs() const { return (m_flags & wxTEXT_ATTR_TABS) != 0 ; }
HasLeftIndent()598     bool HasLeftIndent() const { return (m_flags & wxTEXT_ATTR_LEFT_INDENT) != 0 ; }
HasRightIndent()599     bool HasRightIndent() const { return (m_flags & wxTEXT_ATTR_RIGHT_INDENT) != 0 ; }
HasFontWeight()600     bool HasFontWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
HasFontSize()601     bool HasFontSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
HasFontItalic()602     bool HasFontItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
HasFontUnderlined()603     bool HasFontUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
HasFontFaceName()604     bool HasFontFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; }
HasFont()605     bool HasFont() const { return (m_flags & (wxTEXT_ATTR_FONT)) != 0; }
606 
HasParagraphSpacingAfter()607     bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; }
HasParagraphSpacingBefore()608     bool HasParagraphSpacingBefore() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) != 0; }
HasLineSpacing()609     bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; }
HasCharacterStyleName()610     bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0 && !m_characterStyleName.IsEmpty(); }
HasParagraphStyleName()611     bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0 && !m_paragraphStyleName.IsEmpty(); }
HasListStyleName()612     bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
HasBulletStyle()613     bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
HasBulletNumber()614     bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
HasBulletText()615     bool HasBulletText() const { return (m_flags & wxTEXT_ATTR_BULLET_TEXT) != 0; }
HasBulletName()616     bool HasBulletName() const { return (m_flags & wxTEXT_ATTR_BULLET_NAME) != 0; }
HasURL()617     bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); }
HasPageBreak()618     bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); }
HasTextEffects()619     bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); }
HasTextEffect(int effect)620     bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); }
HasOutlineLevel()621     bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); }
622 
HasFlag(long flag)623     bool HasFlag(long flag) const { return (m_flags & flag) != 0; }
624 
625     // Is this a character style?
IsCharacterStyle()626     bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); }
IsParagraphStyle()627     bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); }
628 
629     // returns false if we have any attributes set, true otherwise
IsDefault()630     bool IsDefault() const
631     {
632         return GetFlags() == 0;
633     }
634 
635     // Merges the given attributes. Does not affect 'this'. If compareWith
636     // is non-NULL, then it will be used to mask out those attributes that are the same in style
637     // and compareWith, for situations where we don't want to explicitly set inherited attributes.
638     bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL);
639 
640     // Merges the given attributes and returns the result. Does not affect 'this'. If compareWith
641     // is non-NULL, then it will be used to mask out those attributes that are the same in style
642     // and compareWith, for situations where we don't want to explicitly set inherited attributes.
643     wxRichTextAttr Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const;
644 
645 private:
646     long                m_flags;
647 
648     // Paragraph styles
649     wxArrayInt          m_tabs; // array of int: tab stops in 1/10 mm
650     int                 m_leftIndent; // left indent in 1/10 mm
651     int                 m_leftSubIndent; // left indent for all but the first
652                                          // line in a paragraph relative to the
653                                          // first line, in 1/10 mm
654     int                 m_rightIndent; // right indent in 1/10 mm
655     wxTextAttrAlignment m_textAlignment;
656 
657     int                 m_paragraphSpacingAfter;
658     int                 m_paragraphSpacingBefore;
659     int                 m_lineSpacing;
660     int                 m_bulletStyle;
661     int                 m_bulletNumber;
662     int                 m_textEffects;
663     int                 m_textEffectFlags;
664     int                 m_outlineLevel;
665     wxString            m_bulletText;
666     wxString            m_bulletFont;
667     wxString            m_bulletName;
668     wxString            m_urlTarget;
669 
670     // Character styles
671     wxColour            m_colText,
672                         m_colBack;
673     int                 m_fontSize;
674     int                 m_fontStyle;
675     int                 m_fontWeight;
676     bool                m_fontUnderlined;
677     wxString            m_fontFaceName;
678 
679     // Character style
680     wxString            m_characterStyleName;
681 
682     // Paragraph style
683     wxString            m_paragraphStyleName;
684 
685     // List style
686     wxString            m_listStyleName;
687 };
688 
689 /*!
690  * wxRichTextObject class declaration
691  * This is the base for drawable objects.
692  */
693 
694 class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject
695 {
696     DECLARE_CLASS(wxRichTextObject)
697 public:
698 // Constructors
699 
700     wxRichTextObject(wxRichTextObject* parent = NULL);
701     virtual ~wxRichTextObject();
702 
703 // Overrideables
704 
705     /// Draw the item, within the given range. Some objects may ignore the range (for
706     /// example paragraphs) while others must obey it (lines, to implement wrapping)
707     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style) = 0;
708 
709     /// Lay the item out at the specified position with the given size constraint.
710     /// Layout must set the cached size.
711     virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0;
712 
713     /// Hit-testing: returns a flag indicating hit test details, plus
714     /// information about position
HitTest(wxDC & WXUNUSED (dc),const wxPoint & WXUNUSED (pt),long & WXUNUSED (textPosition))715     virtual int HitTest(wxDC& WXUNUSED(dc), const wxPoint& WXUNUSED(pt), long& WXUNUSED(textPosition)) { return false; }
716 
717     /// Finds the absolute position and row height for the given character position
FindPosition(wxDC & WXUNUSED (dc),long WXUNUSED (index),wxPoint & WXUNUSED (pt),int * WXUNUSED (height),bool WXUNUSED (forceLineStart))718     virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; }
719 
720     /// Get the best size, i.e. the ideal starting size for this object irrespective
721     /// of available space. For a short text string, it will be the size that exactly encloses
722     /// the text. For a longer string, it might use the parent width for example.
GetBestSize()723     virtual wxSize GetBestSize() const { return m_size; }
724 
725     /// Get the object size for the given range. Returns false if the range
726     /// is invalid for this object.
727     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const  = 0;
728 
729     /// Do a split, returning an object containing the second part, and setting
730     /// the first part in 'this'.
DoSplit(long WXUNUSED (pos))731     virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; }
732 
733     /// Calculate range. By default, guess that the object is 1 unit long.
CalculateRange(long start,long & end)734     virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); }
735 
736     /// Delete range
DeleteRange(const wxRichTextRange & WXUNUSED (range))737     virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; }
738 
739     /// Returns true if the object is empty
IsEmpty()740     virtual bool IsEmpty() const { return false; }
741 
742     /// Get any text in this object for the given range
GetTextForRange(const wxRichTextRange & WXUNUSED (range))743     virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; }
744 
745     /// Returns true if this object can merge itself with the given one.
CanMerge(wxRichTextObject * WXUNUSED (object))746     virtual bool CanMerge(wxRichTextObject* WXUNUSED(object)) const { return false; }
747 
748     /// Returns true if this object merged itself with the given one.
749     /// The calling code will then delete the given object.
Merge(wxRichTextObject * WXUNUSED (object))750     virtual bool Merge(wxRichTextObject* WXUNUSED(object)) { return false; }
751 
752     /// Dump to output stream for debugging
753     virtual void Dump(wxTextOutputStream& stream);
754 
755 // Accessors
756 
757     /// Get/set the cached object size as calculated by Layout.
GetCachedSize()758     virtual wxSize GetCachedSize() const { return m_size; }
SetCachedSize(const wxSize & sz)759     virtual void SetCachedSize(const wxSize& sz) { m_size = sz; }
760 
761     /// Get/set the object position
GetPosition()762     virtual wxPoint GetPosition() const { return m_pos; }
SetPosition(const wxPoint & pos)763     virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
764 
765     /// Get the rectangle enclosing the object
GetRect()766     virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
767 
768     /// Set the range
SetRange(const wxRichTextRange & range)769     void SetRange(const wxRichTextRange& range) { m_range = range; }
770 
771     /// Get the range
GetRange()772     const wxRichTextRange& GetRange() const { return m_range; }
GetRange()773     wxRichTextRange& GetRange() { return m_range; }
774 
775     /// Get/set dirty flag (whether the object needs Layout to be called)
GetDirty()776     virtual bool GetDirty() const { return m_dirty; }
SetDirty(bool dirty)777     virtual void SetDirty(bool dirty) { m_dirty = dirty; }
778 
779     /// Is this composite?
IsComposite()780     virtual bool IsComposite() const { return false; }
781 
782     /// Get/set the parent.
GetParent()783     virtual wxRichTextObject* GetParent() const { return m_parent; }
SetParent(wxRichTextObject * parent)784     virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; }
785 
786     /// Set the margin around the object
787     virtual void SetMargins(int margin);
788     virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin);
GetLeftMargin()789     virtual int GetLeftMargin() const { return m_leftMargin; }
GetRightMargin()790     virtual int GetRightMargin() const { return m_rightMargin; }
GetTopMargin()791     virtual int GetTopMargin() const { return m_topMargin; }
GetBottomMargin()792     virtual int GetBottomMargin() const { return m_bottomMargin; }
793 
794     /// Set attributes object
SetAttributes(const wxTextAttrEx & attr)795     void SetAttributes(const wxTextAttrEx& attr) { m_attributes = attr; }
GetAttributes()796     const wxTextAttrEx& GetAttributes() const { return m_attributes; }
GetAttributes()797     wxTextAttrEx& GetAttributes() { return m_attributes; }
798 
799     /// Set/get stored descent
SetDescent(int descent)800     void SetDescent(int descent) { m_descent = descent; }
GetDescent()801     int GetDescent() const { return m_descent; }
802 
803     /// Gets the containing buffer
804     wxRichTextBuffer* GetBuffer() const;
805 
806 // Operations
807 
808     /// Clone the object
Clone()809     virtual wxRichTextObject* Clone() const { return NULL; }
810 
811     /// Copy
812     void Copy(const wxRichTextObject& obj);
813 
814     /// Reference-counting allows us to use the same object in multiple
815     /// lists (not yet used)
Reference()816     void Reference() { m_refCount ++; }
817     void Dereference();
818 
819     /// Convert units in tenths of a millimetre to device units
820     int ConvertTenthsMMToPixels(wxDC& dc, int units);
821     static int ConvertTenthsMMToPixels(int ppi, int units);
822 
823 protected:
824     wxSize                  m_size;
825     wxPoint                 m_pos;
826     int                     m_descent; // Descent for this object (if any)
827     bool                    m_dirty;
828     int                     m_refCount;
829     wxRichTextObject*       m_parent;
830 
831     /// The range of this object (start position to end position)
832     wxRichTextRange         m_range;
833 
834     /// Margins
835     int                     m_leftMargin;
836     int                     m_rightMargin;
837     int                     m_topMargin;
838     int                     m_bottomMargin;
839 
840     /// Attributes
841     wxTextAttrEx            m_attributes;
842 };
843 
844 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
845 
846 /*!
847  * wxRichTextCompositeObject class declaration
848  * Objects of this class can contain other objects.
849  */
850 
851 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject
852 {
853     DECLARE_CLASS(wxRichTextCompositeObject)
854 public:
855 // Constructors
856 
857     wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
858     virtual ~wxRichTextCompositeObject();
859 
860 // Overrideables
861 
862     /// Hit-testing: returns a flag indicating hit test details, plus
863     /// information about position
864     virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition);
865 
866     /// Finds the absolute position and row height for the given character position
867     virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart);
868 
869     /// Calculate range
870     virtual void CalculateRange(long start, long& end);
871 
872     /// Delete range
873     virtual bool DeleteRange(const wxRichTextRange& range);
874 
875     /// Get any text in this object for the given range
876     virtual wxString GetTextForRange(const wxRichTextRange& range) const;
877 
878     /// Dump to output stream for debugging
879     virtual void Dump(wxTextOutputStream& stream);
880 
881 // Accessors
882 
883     /// Get the children
GetChildren()884     wxRichTextObjectList& GetChildren() { return m_children; }
GetChildren()885     const wxRichTextObjectList& GetChildren() const { return m_children; }
886 
887     /// Get the child count
888     size_t GetChildCount() const ;
889 
890     /// Get the nth child
891     wxRichTextObject* GetChild(size_t n) const ;
892 
893     /// Get/set dirty flag
GetDirty()894     virtual bool GetDirty() const { return m_dirty; }
SetDirty(bool dirty)895     virtual void SetDirty(bool dirty) { m_dirty = dirty; }
896 
897     /// Is this composite?
IsComposite()898     virtual bool IsComposite() const { return true; }
899 
900     /// Returns true if the buffer is empty
IsEmpty()901     virtual bool IsEmpty() const { return GetChildCount() == 0; }
902 
903 // Operations
904 
905     /// Copy
906     void Copy(const wxRichTextCompositeObject& obj);
907 
908     /// Assignment
909     void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); }
910 
911     /// Append a child, returning the position
912     size_t AppendChild(wxRichTextObject* child) ;
913 
914     /// Insert the child in front of the given object, or at the beginning
915     bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ;
916 
917     /// Delete the child
918     bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ;
919 
920     /// Delete all children
921     bool DeleteChildren() ;
922 
923     /// Recursively merge all pieces that can be merged.
924     bool Defragment();
925 
926 protected:
927     wxRichTextObjectList    m_children;
928 };
929 
930 /*!
931  * wxRichTextBox class declaration
932  * This defines a 2D space to lay out objects
933  */
934 
935 class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject
936 {
937     DECLARE_DYNAMIC_CLASS(wxRichTextBox)
938 public:
939 // Constructors
940 
941     wxRichTextBox(wxRichTextObject* parent = NULL);
wxRichTextBox(const wxRichTextBox & obj)942     wxRichTextBox(const wxRichTextBox& obj): wxRichTextCompositeObject() { Copy(obj); }
943 
944 // Overrideables
945 
946     /// Draw the item
947     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
948 
949     /// Lay the item out
950     virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
951 
952     /// Get/set the object size for the given range. Returns false if the range
953     /// is invalid for this object.
954     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
955 
956 // Accessors
957 
958 // Operations
959 
960     /// Clone
Clone()961     virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); }
962 
963     /// Copy
964     void Copy(const wxRichTextBox& obj);
965 
966 protected:
967 };
968 
969 /*!
970  * wxRichTextParagraphBox class declaration
971  * This box knows how to lay out paragraphs.
972  */
973 
974 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox
975 {
976     DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)
977 public:
978 // Constructors
979 
980     wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox & obj)981     wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextBox() { Init(); Copy(obj); }
982 
983 // Overrideables
984 
985     /// Draw the item
986     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
987 
988     /// Lay the item out
989     virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
990 
991     /// Get/set the object size for the given range. Returns false if the range
992     /// is invalid for this object.
993     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
994 
995     /// Delete range
996     virtual bool DeleteRange(const wxRichTextRange& range);
997 
998     /// Get any text in this object for the given range
999     virtual wxString GetTextForRange(const wxRichTextRange& range) const;
1000 
1001 // Accessors
1002 
1003     /// Associate a control with the buffer, for operations that for example require refreshing the window.
SetRichTextCtrl(wxRichTextCtrl * ctrl)1004     void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; }
1005 
1006     /// Get the associated control.
GetRichTextCtrl()1007     wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; }
1008 
1009     /// Get/set whether the last paragraph is partial or complete
SetPartialParagraph(bool partialPara)1010     void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
GetPartialParagraph()1011     bool GetPartialParagraph() const { return m_partialParagraph; }
1012 
1013     /// If this is a buffer, returns the current style sheet. The base layout box
1014     /// class doesn't have an associated style sheet.
GetStyleSheet()1015     virtual wxRichTextStyleSheet* GetStyleSheet() const { return NULL; }
1016 
1017 // Operations
1018 
1019     /// Initialize the object.
1020     void Init();
1021 
1022     /// Clear all children
1023     virtual void Clear();
1024 
1025     /// Clear and initialize with one blank paragraph
1026     virtual void Reset();
1027 
1028     /// Convenience function to add a paragraph of text
1029     virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL);
1030 
1031     /// Convenience function to add an image
1032     virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL);
1033 
1034     /// Adds multiple paragraphs, based on newlines.
1035     virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL);
1036 
1037     /// Get the line at the given position. If caretPosition is true, the position is
1038     /// a caret position, which is normally a smaller number.
1039     virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const;
1040 
1041     /// Get the line at the given y pixel position, or the last line.
1042     virtual wxRichTextLine* GetLineAtYPosition(int y) const;
1043 
1044     /// Get the paragraph at the given character or caret position
1045     virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const;
1046 
1047     /// Get the line size at the given position
1048     virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const;
1049 
1050     /// Given a position, get the number of the visible line (potentially many to a paragraph),
1051     /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
1052     /// that indicates whether the caret is being shown at the end of the previous line or at the start
1053     /// of the next, since the caret can be shown at 2 visible positions for the same underlying
1054     /// position.
1055     virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const;
1056 
1057     /// Given a line number, get the corresponding wxRichTextLine object.
1058     virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const;
1059 
1060     /// Get the leaf object in a paragraph at this position.
1061     /// Given a line number, get the corresponding wxRichTextLine object.
1062     virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
1063 
1064     /// Get the paragraph by number
1065     virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
1066 
1067     /// Get the paragraph for a given line
1068     virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
1069 
1070     /// Get the length of the paragraph
1071     virtual int GetParagraphLength(long paragraphNumber) const;
1072 
1073     /// Get the number of paragraphs
GetParagraphCount()1074     virtual int GetParagraphCount() const { return wx_static_cast(int, GetChildCount()); }
1075 
1076     /// Get the number of visible lines
1077     virtual int GetLineCount() const;
1078 
1079     /// Get the text of the paragraph
1080     virtual wxString GetParagraphText(long paragraphNumber) const;
1081 
1082     /// Convert zero-based line column and paragraph number to a position.
1083     virtual long XYToPosition(long x, long y) const;
1084 
1085     /// Convert zero-based position to line column and paragraph number
1086     virtual bool PositionToXY(long pos, long* x, long* y) const;
1087 
1088     /// Set text attributes: character and/or paragraph styles.
1089     virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1090     virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1091 
1092     /// Get the conbined text attributes for this position.
1093     virtual bool GetStyle(long position, wxTextAttrEx& style);
1094     virtual bool GetStyle(long position, wxRichTextAttr& style);
1095 
1096     /// Get the content (uncombined) attributes for this position.
1097     virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
1098     virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
1099 
1100     /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1101     /// context attributes.
1102     virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true);
1103 
1104     /// Get the combined style for a range - if any attribute is different within the range,
1105     /// that attribute is not present within the flags
1106     virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style);
1107 
1108     /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1109     /// content.
1110     bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes);
1111 
1112     /// Set list style
1113     virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1114     virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1115 
1116     /// Clear list for given range
1117     virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1118 
1119     /// Number/renumber any list elements in the given range.
1120     /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1121     virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1122     virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1123 
1124     /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1125     /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1126     virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
1127     virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
1128 
1129     /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1130     /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1131     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);
1132 
1133     /// Fills in the attributes for numbering a paragraph after previousParagraph.
1134     virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const;
1135 
1136     /// Test if this whole range has character attributes of the specified kind. If any
1137     /// of the attributes are different within the range, the test fails. You
1138     /// can use this to implement, for example, bold button updating. style must have
1139     /// flags indicating which attributes are of interest.
1140     virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1141     virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1142 
1143     /// Test if this whole range has paragraph attributes of the specified kind. If any
1144     /// of the attributes are different within the range, the test fails. You
1145     /// can use this to implement, for example, centering button updating. style must have
1146     /// flags indicating which attributes are of interest.
1147     virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1148     virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1149 
1150     /// Clone
Clone()1151     virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1152 
1153     /// Insert fragment into this box at the given position. If partialParagraph is true,
1154     /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1155     /// marker.
1156     virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
1157 
1158     /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1159     virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment);
1160 
1161     /// Apply the style sheet to the buffer, for example if the styles have changed.
1162     virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
1163 
1164     /// Copy
1165     void Copy(const wxRichTextParagraphLayoutBox& obj);
1166 
1167     /// Assignment
1168     void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); }
1169 
1170     /// Calculate ranges
UpdateRanges()1171     virtual void UpdateRanges() { long end; CalculateRange(0, end); }
1172 
1173     /// Get all the text
1174     virtual wxString GetText() const;
1175 
1176     /// Set default style for new content. Setting it to a default attribute
1177     /// makes new content take on the 'basic' style.
1178     virtual bool SetDefaultStyle(const wxTextAttrEx& style);
1179 
1180     /// Get default style
GetDefaultStyle()1181     virtual const wxTextAttrEx& GetDefaultStyle() const { return m_defaultAttributes; }
1182 
1183     /// Set basic (overall) style
SetBasicStyle(const wxTextAttrEx & style)1184     virtual void SetBasicStyle(const wxTextAttrEx& style) { m_attributes = style; }
SetBasicStyle(const wxRichTextAttr & style)1185     virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; }
1186 
1187     /// Get basic (overall) style
GetBasicStyle()1188     virtual const wxTextAttrEx& GetBasicStyle() const { return m_attributes; }
1189 
1190     /// Invalidate the buffer. With no argument, invalidates whole buffer.
1191     void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
1192 
1193     /// Get invalid range, rounding to entire paragraphs if argument is true.
1194     wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
1195 
1196 protected:
1197     wxRichTextCtrl* m_ctrl;
1198     wxTextAttrEx    m_defaultAttributes;
1199 
1200     /// The invalidated range that will need full layout
1201     wxRichTextRange m_invalidRange;
1202 
1203     // Is the last paragraph partial or complete?
1204     bool            m_partialParagraph;
1205 };
1206 
1207 /*!
1208  * wxRichTextLine class declaration
1209  * This object represents a line in a paragraph, and stores
1210  * offsets from the start of the paragraph representing the
1211  * start and end positions of the line.
1212  */
1213 
1214 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1215 {
1216 public:
1217 // Constructors
1218 
1219     wxRichTextLine(wxRichTextParagraph* parent);
wxRichTextLine(const wxRichTextLine & obj)1220     wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); }
~wxRichTextLine()1221     virtual ~wxRichTextLine() {}
1222 
1223 // Overrideables
1224 
1225 // Accessors
1226 
1227     /// Set the range
SetRange(const wxRichTextRange & range)1228     void SetRange(const wxRichTextRange& range) { m_range = range; }
SetRange(long from,long to)1229     void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); }
1230 
1231     /// Get the parent paragraph
GetParent()1232     wxRichTextParagraph* GetParent() { return m_parent; }
1233 
1234     /// Get the range
GetRange()1235     const wxRichTextRange& GetRange() const { return m_range; }
GetRange()1236     wxRichTextRange& GetRange() { return m_range; }
1237 
1238     /// Get the absolute range
1239     wxRichTextRange GetAbsoluteRange() const;
1240 
1241     /// Get/set the line size as calculated by Layout.
GetSize()1242     virtual wxSize GetSize() const { return m_size; }
SetSize(const wxSize & sz)1243     virtual void SetSize(const wxSize& sz) { m_size = sz; }
1244 
1245     /// Get/set the object position relative to the parent
GetPosition()1246     virtual wxPoint GetPosition() const { return m_pos; }
SetPosition(const wxPoint & pos)1247     virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
1248 
1249     /// Get the absolute object position
1250     virtual wxPoint GetAbsolutePosition() const;
1251 
1252     /// Get the rectangle enclosing the line
GetRect()1253     virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1254 
1255     /// Set/get stored descent
SetDescent(int descent)1256     void SetDescent(int descent) { m_descent = descent; }
GetDescent()1257     int GetDescent() const { return m_descent; }
1258 
1259 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
GetObjectSizes()1260     wxArrayInt& GetObjectSizes() { return m_objectSizes; }
GetObjectSizes()1261     const wxArrayInt& GetObjectSizes() const { return m_objectSizes; }
1262 #endif
1263 
1264 // Operations
1265 
1266     /// Initialisation
1267     void Init(wxRichTextParagraph* parent);
1268 
1269     /// Copy
1270     void Copy(const wxRichTextLine& obj);
1271 
1272     /// Clone
Clone()1273     virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); }
1274 
1275 protected:
1276 
1277     /// The range of the line (start position to end position)
1278     /// This is relative to the parent paragraph.
1279     wxRichTextRange     m_range;
1280 
1281     /// Size and position measured relative to top of paragraph
1282     wxPoint             m_pos;
1283     wxSize              m_size;
1284 
1285     /// Maximum descent for this line (location of text baseline)
1286     int                 m_descent;
1287 
1288     // The parent object
1289     wxRichTextParagraph* m_parent;
1290 
1291     // Sizes of the objects within a line so we don't have to get text extents
1292 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1293     wxArrayInt          m_objectSizes;
1294 #endif
1295 };
1296 
1297 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT );
1298 
1299 /*!
1300  * wxRichTextParagraph class declaration
1301  * This object represents a single paragraph (or in a straight text editor, a line).
1302  */
1303 
1304 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextBox
1305 {
1306     DECLARE_DYNAMIC_CLASS(wxRichTextParagraph)
1307 public:
1308 // Constructors
1309 
1310     wxRichTextParagraph(wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
1311     wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxTextAttrEx* paraStyle = NULL, wxTextAttrEx* charStyle = NULL);
1312     virtual ~wxRichTextParagraph();
wxRichTextParagraph(const wxRichTextParagraph & obj)1313     wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextBox() { Copy(obj); }
1314 
1315 // Overrideables
1316 
1317     /// Draw the item
1318     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1319 
1320     /// Lay the item out
1321     virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
1322 
1323     /// Get/set the object size for the given range. Returns false if the range
1324     /// is invalid for this object.
1325     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
1326 
1327     /// Finds the absolute position and row height for the given character position
1328     virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart);
1329 
1330     /// Hit-testing: returns a flag indicating hit test details, plus
1331     /// information about position
1332     virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition);
1333 
1334     /// Calculate range
1335     virtual void CalculateRange(long start, long& end);
1336 
1337 // Accessors
1338 
1339     /// Get the cached lines
GetLines()1340     wxRichTextLineList& GetLines() { return m_cachedLines; }
1341 
1342 // Operations
1343 
1344     /// Copy
1345     void Copy(const wxRichTextParagraph& obj);
1346 
1347     /// Clone
Clone()1348     virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); }
1349 
1350     /// Clear the cached lines
1351     void ClearLines();
1352 
1353 // Implementation
1354 
1355     /// Apply paragraph styles such as centering to the wrapped lines
1356     virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect);
1357 
1358     /// Insert text at the given position
1359     virtual bool InsertText(long pos, const wxString& text);
1360 
1361     /// Split an object at this position if necessary, and return
1362     /// the previous object, or NULL if inserting at beginning.
1363     virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL);
1364 
1365     /// Move content to a list from this point
1366     virtual void MoveToList(wxRichTextObject* obj, wxList& list);
1367 
1368     /// Add content back from list
1369     virtual void MoveFromList(wxList& list);
1370 
1371     /// Get the plain text searching from the start or end of the range.
1372     /// The resulting string may be shorter than the range given.
1373     bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true);
1374 
1375     /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1376     /// of the split.
1377     bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition);
1378 
1379     /// Find the object at the given position
1380     wxRichTextObject* FindObjectAtPosition(long position);
1381 
1382     /// Get the bullet text for this paragraph.
1383     wxString GetBulletText();
1384 
1385     /// Allocate or reuse a line object
1386     wxRichTextLine* AllocateLine(int pos);
1387 
1388     /// Clear remaining unused line objects, if any
1389     bool ClearUnusedLines(int lineCount);
1390 
1391     /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1392     /// retrieve the actual style.
1393     wxTextAttrEx GetCombinedAttributes(const wxTextAttrEx& contentStyle) const;
1394 
1395     /// Get combined attributes of the base style and paragraph style.
1396     wxTextAttrEx GetCombinedAttributes() const;
1397 
1398     /// Get the first position from pos that has a line break character.
1399     long GetFirstLineBreakPosition(long pos);
1400 
1401     /// Create default tabstop array
1402     static void InitDefaultTabs();
1403 
1404     /// Clear default tabstop array
1405     static void ClearDefaultTabs();
1406 
1407     /// Get default tabstop array
GetDefaultTabs()1408     static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; }
1409 
1410 protected:
1411     /// The lines that make up the wrapped paragraph
1412     wxRichTextLineList m_cachedLines;
1413 
1414     /// Default tabstops
1415     static wxArrayInt  sm_defaultTabs;
1416 };
1417 
1418 /*!
1419  * wxRichTextPlainText class declaration
1420  * This object represents a single piece of text.
1421  */
1422 
1423 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject
1424 {
1425     DECLARE_DYNAMIC_CLASS(wxRichTextPlainText)
1426 public:
1427 // Constructors
1428 
1429     wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
wxRichTextPlainText(const wxRichTextPlainText & obj)1430     wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); }
1431 
1432 // Overrideables
1433 
1434     /// Draw the item
1435     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1436 
1437     /// Lay the item out
1438     virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
1439 
1440     /// Get/set the object size for the given range. Returns false if the range
1441     /// is invalid for this object.
1442     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position/* = wxPoint(0,0)*/) const;
1443 
1444     /// Get any text in this object for the given range
1445     virtual wxString GetTextForRange(const wxRichTextRange& range) const;
1446 
1447     /// Do a split, returning an object containing the second part, and setting
1448     /// the first part in 'this'.
1449     virtual wxRichTextObject* DoSplit(long pos);
1450 
1451     /// Calculate range
1452     virtual void CalculateRange(long start, long& end);
1453 
1454     /// Delete range
1455     virtual bool DeleteRange(const wxRichTextRange& range);
1456 
1457     /// Returns true if the object is empty
IsEmpty()1458     virtual bool IsEmpty() const { return m_text.empty(); }
1459 
1460     /// Returns true if this object can merge itself with the given one.
1461     virtual bool CanMerge(wxRichTextObject* object) const;
1462 
1463     /// Returns true if this object merged itself with the given one.
1464     /// The calling code will then delete the given object.
1465     virtual bool Merge(wxRichTextObject* object);
1466 
1467     /// Dump to output stream for debugging
1468     virtual void Dump(wxTextOutputStream& stream);
1469 
1470     /// Get the first position from pos that has a line break character.
1471     long GetFirstLineBreakPosition(long pos);
1472 
1473 // Accessors
1474 
1475     /// Get the text
GetText()1476     const wxString& GetText() const { return m_text; }
1477 
1478     /// Set the text
SetText(const wxString & text)1479     void SetText(const wxString& text) { m_text = text; }
1480 
1481 // Operations
1482 
1483     /// Copy
1484     void Copy(const wxRichTextPlainText& obj);
1485 
1486     /// Clone
Clone()1487     virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
1488 private:
1489     bool DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected);
1490 
1491 protected:
1492     wxString    m_text;
1493 };
1494 
1495 /*!
1496  * wxRichTextImageBlock stores information about an image, in binary in-memory form
1497  */
1498 
1499 class WXDLLIMPEXP_FWD_BASE wxDataInputStream;
1500 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream;
1501 
1502 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject
1503 {
1504 public:
1505     wxRichTextImageBlock();
1506     wxRichTextImageBlock(const wxRichTextImageBlock& block);
1507     virtual ~wxRichTextImageBlock();
1508 
1509     void Init();
1510     void Clear();
1511 
1512     // Load the original image into a memory block.
1513     // If the image is not a JPEG, we must convert it into a JPEG
1514     // to conserve space.
1515     // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1516     // load the image a 2nd time.
1517     virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true);
1518 
1519     // Make an image block from the wxImage in the given
1520     // format.
1521     virtual bool MakeImageBlock(wxImage& image, int imageType, int quality = 80);
1522 
1523     // Write to a file
1524     bool Write(const wxString& filename);
1525 
1526     // Write data in hex to a stream
1527     bool WriteHex(wxOutputStream& stream);
1528 
1529     // Read data in hex from a stream
1530     bool ReadHex(wxInputStream& stream, int length, int imageType);
1531 
1532     // Copy from 'block'
1533     void Copy(const wxRichTextImageBlock& block);
1534 
1535     // Load a wxImage from the block
1536     bool Load(wxImage& image);
1537 
1538 //// Operators
1539     void operator=(const wxRichTextImageBlock& block);
1540 
1541 //// Accessors
1542 
GetData()1543     unsigned char* GetData() const { return m_data; }
GetDataSize()1544     size_t GetDataSize() const { return m_dataSize; }
GetImageType()1545     int GetImageType() const { return m_imageType; }
1546 
SetData(unsigned char * image)1547     void SetData(unsigned char* image) { m_data = image; }
SetDataSize(size_t size)1548     void SetDataSize(size_t size) { m_dataSize = size; }
SetImageType(int imageType)1549     void SetImageType(int imageType) { m_imageType = imageType; }
1550 
Ok()1551     bool Ok() const { return IsOk(); }
IsOk()1552     bool IsOk() const { return GetData() != NULL; }
1553 
1554     // Gets the extension for the block's type
1555     wxString GetExtension() const;
1556 
1557 /// Implementation
1558 
1559     // Allocate and read from stream as a block of memory
1560     static unsigned char* ReadBlock(wxInputStream& stream, size_t size);
1561     static unsigned char* ReadBlock(const wxString& filename, size_t size);
1562 
1563     // Write memory block to stream
1564     static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size);
1565 
1566     // Write memory block to file
1567     static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size);
1568 
1569 protected:
1570     // Size in bytes of the image stored.
1571     // This is in the raw, original form such as a JPEG file.
1572     unsigned char*      m_data;
1573     size_t              m_dataSize;
1574     int                 m_imageType; // wxWin type id
1575 };
1576 
1577 
1578 /*!
1579  * wxRichTextImage class declaration
1580  * This object represents an image.
1581  */
1582 
1583 class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
1584 {
DECLARE_DYNAMIC_CLASS(wxRichTextImage)1585     DECLARE_DYNAMIC_CLASS(wxRichTextImage)
1586 public:
1587 // Constructors
1588 
1589     wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { }
1590     wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
1591     wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
wxRichTextImage(const wxRichTextImage & obj)1592     wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject() { Copy(obj); }
1593 
1594 // Overrideables
1595 
1596     /// Draw the item
1597     virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1598 
1599     /// Lay the item out
1600     virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
1601 
1602     /// Get the object size for the given range. Returns false if the range
1603     /// is invalid for this object.
1604     virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
1605 
1606     /// Returns true if the object is empty
IsEmpty()1607     virtual bool IsEmpty() const { return !m_image.Ok(); }
1608 
1609 // Accessors
1610 
1611     /// Get the image
GetImage()1612     const wxImage& GetImage() const { return m_image; }
1613 
1614     /// Set the image
SetImage(const wxImage & image)1615     void SetImage(const wxImage& image) { m_image = image; }
1616 
1617     /// Get the image block containing the raw data
GetImageBlock()1618     wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; }
1619 
1620 // Operations
1621 
1622     /// Copy
1623     void Copy(const wxRichTextImage& obj);
1624 
1625     /// Clone
Clone()1626     virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); }
1627 
1628     /// Load wxImage from the block
1629     virtual bool LoadFromBlock();
1630 
1631     /// Make block from the wxImage
1632     virtual bool MakeBlock();
1633 
1634 protected:
1635     // TODO: reduce the multiple representations of data
1636     wxImage                 m_image;
1637     wxBitmap                m_bitmap;
1638     wxRichTextImageBlock    m_imageBlock;
1639 };
1640 
1641 
1642 /*!
1643  * wxRichTextBuffer class declaration
1644  * This is a kind of box, used to represent the whole buffer
1645  */
1646 
1647 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand;
1648 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction;
1649 
1650 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox
1651 {
DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)1652     DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
1653 public:
1654 // Constructors
1655 
1656     wxRichTextBuffer() { Init(); }
wxRichTextBuffer(const wxRichTextBuffer & obj)1657     wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
1658     virtual ~wxRichTextBuffer() ;
1659 
1660 // Accessors
1661 
1662     /// Gets the command processor
GetCommandProcessor()1663     wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; }
1664 
1665     /// Set style sheet, if any.
SetStyleSheet(wxRichTextStyleSheet * styleSheet)1666     void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
GetStyleSheet()1667     virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
1668 
1669     /// Set style sheet and notify of the change
1670     bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet);
1671 
1672     /// Push style sheet to top of stack
1673     bool PushStyleSheet(wxRichTextStyleSheet* styleSheet);
1674 
1675     /// Pop style sheet from top of stack
1676     wxRichTextStyleSheet* PopStyleSheet();
1677 
1678 // Operations
1679 
1680     /// Initialisation
1681     void Init();
1682 
1683     /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1684     virtual void ResetAndClearCommands();
1685 
1686     /// Load a file
1687     virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1688 
1689     /// Save a file
1690     virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1691 
1692     /// Load from a stream
1693     virtual bool LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
1694 
1695     /// Save to a stream
1696     virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
1697 
1698     /// Set the handler flags, controlling loading and saving
SetHandlerFlags(int flags)1699     void SetHandlerFlags(int flags) { m_handlerFlags = flags; }
1700 
1701     /// Get the handler flags, controlling loading and saving
GetHandlerFlags()1702     int GetHandlerFlags() const { return m_handlerFlags; }
1703 
1704     /// Convenience function to add a paragraph of text
1705     virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); }
1706 
1707     /// Begin collapsing undo/redo commands. Note that this may not work properly
1708     /// if combining commands that delete or insert content, changing ranges for
1709     /// subsequent actions.
1710     virtual bool BeginBatchUndo(const wxString& cmdName);
1711 
1712     /// End collapsing undo/redo commands
1713     virtual bool EndBatchUndo();
1714 
1715     /// Collapsing commands?
BatchingUndo()1716     virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; }
1717 
1718     /// Submit immediately, or delay according to whether collapsing is on
1719     virtual bool SubmitAction(wxRichTextAction* action);
1720 
1721     /// Get collapsed command
GetBatchedCommand()1722     virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; }
1723 
1724     /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1725     /// differently by each command. If not dealt with by a command implementation, then
1726     /// it will be implemented automatically by not storing the command in the undo history
1727     /// when the action is submitted to the command processor.
1728     virtual bool BeginSuppressUndo();
1729 
1730     /// End suppressing undo/redo commands.
1731     virtual bool EndSuppressUndo();
1732 
1733     /// Collapsing commands?
SuppressingUndo()1734     virtual bool SuppressingUndo() const { return m_suppressUndo > 0; }
1735 
1736     /// Copy the range to the clipboard
1737     virtual bool CopyToClipboard(const wxRichTextRange& range);
1738 
1739     /// Paste the clipboard content to the buffer
1740     virtual bool PasteFromClipboard(long position);
1741 
1742     /// Can we paste from the clipboard?
1743     virtual bool CanPasteFromClipboard() const;
1744 
1745     /// Begin using a style
1746     virtual bool BeginStyle(const wxTextAttrEx& style);
1747 
1748     /// End the style
1749     virtual bool EndStyle();
1750 
1751     /// End all styles
1752     virtual bool EndAllStyles();
1753 
1754     /// Clear the style stack
1755     virtual void ClearStyleStack();
1756 
1757     /// Get the size of the style stack, for example to check correct nesting
GetStyleStackSize()1758     virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); }
1759 
1760     /// Begin using bold
1761     bool BeginBold();
1762 
1763     /// End using bold
EndBold()1764     bool EndBold() { return EndStyle(); }
1765 
1766     /// Begin using italic
1767     bool BeginItalic();
1768 
1769     /// End using italic
EndItalic()1770     bool EndItalic() { return EndStyle(); }
1771 
1772     /// Begin using underline
1773     bool BeginUnderline();
1774 
1775     /// End using underline
EndUnderline()1776     bool EndUnderline() { return EndStyle(); }
1777 
1778     /// Begin using point size
1779     bool BeginFontSize(int pointSize);
1780 
1781     /// End using point size
EndFontSize()1782     bool EndFontSize() { return EndStyle(); }
1783 
1784     /// Begin using this font
1785     bool BeginFont(const wxFont& font);
1786 
1787     /// End using a font
EndFont()1788     bool EndFont() { return EndStyle(); }
1789 
1790     /// Begin using this colour
1791     bool BeginTextColour(const wxColour& colour);
1792 
1793     /// End using a colour
EndTextColour()1794     bool EndTextColour() { return EndStyle(); }
1795 
1796     /// Begin using alignment
1797     bool BeginAlignment(wxTextAttrAlignment alignment);
1798 
1799     /// End alignment
EndAlignment()1800     bool EndAlignment() { return EndStyle(); }
1801 
1802     /// Begin left indent
1803     bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
1804 
1805     /// End left indent
EndLeftIndent()1806     bool EndLeftIndent() { return EndStyle(); }
1807 
1808     /// Begin right indent
1809     bool BeginRightIndent(int rightIndent);
1810 
1811     /// End right indent
EndRightIndent()1812     bool EndRightIndent() { return EndStyle(); }
1813 
1814     /// Begin paragraph spacing
1815     bool BeginParagraphSpacing(int before, int after);
1816 
1817     /// End paragraph spacing
EndParagraphSpacing()1818     bool EndParagraphSpacing() { return EndStyle(); }
1819 
1820     /// Begin line spacing
1821     bool BeginLineSpacing(int lineSpacing);
1822 
1823     /// End line spacing
EndLineSpacing()1824     bool EndLineSpacing() { return EndStyle(); }
1825 
1826     /// Begin numbered bullet
1827     bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
1828 
1829     /// End numbered bullet
EndNumberedBullet()1830     bool EndNumberedBullet() { return EndStyle(); }
1831 
1832     /// Begin symbol bullet
1833     bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
1834 
1835     /// End symbol bullet
EndSymbolBullet()1836     bool EndSymbolBullet() { return EndStyle(); }
1837 
1838     /// Begin standard bullet
1839     bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD);
1840 
1841     /// End standard bullet
EndStandardBullet()1842     bool EndStandardBullet() { return EndStyle(); }
1843 
1844     /// Begin named character style
1845     bool BeginCharacterStyle(const wxString& characterStyle);
1846 
1847     /// End named character style
EndCharacterStyle()1848     bool EndCharacterStyle() { return EndStyle(); }
1849 
1850     /// Begin named paragraph style
1851     bool BeginParagraphStyle(const wxString& paragraphStyle);
1852 
1853     /// End named character style
EndParagraphStyle()1854     bool EndParagraphStyle() { return EndStyle(); }
1855 
1856     /// Begin named list style
1857     bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1);
1858 
1859     /// End named character style
EndListStyle()1860     bool EndListStyle() { return EndStyle(); }
1861 
1862     /// Begin URL
1863     bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString);
1864 
1865     /// End URL
EndURL()1866     bool EndURL() { return EndStyle(); }
1867 
1868 // Event handling
1869 
1870     /// Add an event handler
1871     bool AddEventHandler(wxEvtHandler* handler);
1872 
1873     /// Remove an event handler
1874     bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false);
1875 
1876     /// Clear event handlers
1877     void ClearEventHandlers();
1878 
1879     /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
1880     /// otherwise will stop at the first successful one.
1881     bool SendEvent(wxEvent& event, bool sendToAll = true);
1882 
1883 // Implementation
1884 
1885     /// Copy
1886     void Copy(const wxRichTextBuffer& obj);
1887 
1888     /// Clone
Clone()1889     virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
1890 
1891     /// Submit command to insert paragraphs
1892     bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
1893 
1894     /// Submit command to insert the given text
1895     bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
1896 
1897     /// Submit command to insert a newline
1898     bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
1899 
1900     /// Submit command to insert the given image
1901     bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0);
1902 
1903     /// Submit command to delete this range
1904     bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl);
1905 
1906     /// Mark modified
1907     void Modify(bool modify = true) { m_modified = modify; }
IsModified()1908     bool IsModified() const { return m_modified; }
1909 
1910     /// Get the style that is appropriate for a new paragraph at this position.
1911     /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1912     /// style.
1913     wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const;
1914 
1915     /// Dumps contents of buffer for debugging purposes
1916     virtual void Dump();
Dump(wxTextOutputStream & stream)1917     virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
1918 
1919     /// Returns the file handlers
GetHandlers()1920     static wxList& GetHandlers() { return sm_handlers; }
1921 
1922     /// Adds a handler to the end
1923     static void AddHandler(wxRichTextFileHandler *handler);
1924 
1925     /// Inserts a handler at the front
1926     static void InsertHandler(wxRichTextFileHandler *handler);
1927 
1928     /// Removes a handler
1929     static bool RemoveHandler(const wxString& name);
1930 
1931     /// Finds a handler by name
1932     static wxRichTextFileHandler *FindHandler(const wxString& name);
1933 
1934     /// Finds a handler by extension and type
1935     static wxRichTextFileHandler *FindHandler(const wxString& extension, int imageType);
1936 
1937     /// Finds a handler by filename or, if supplied, type
1938     static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, int imageType);
1939 
1940     /// Finds a handler by type
1941     static wxRichTextFileHandler *FindHandler(int imageType);
1942 
1943     /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1944     /// will be filled with the file type corresponding to each filter. This can be
1945     /// used to determine the type to pass to LoadFile given a selected filter.
1946     static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL);
1947 
1948     /// Clean up handlers
1949     static void CleanUpHandlers();
1950 
1951     /// Initialise the standard handlers
1952     static void InitStandardHandlers();
1953 
1954     /// Get renderer
GetRenderer()1955     static wxRichTextRenderer* GetRenderer() { return sm_renderer; }
1956 
1957     /// Set renderer, deleting old one
1958     static void SetRenderer(wxRichTextRenderer* renderer);
1959 
1960     /// Minimum margin between bullet and paragraph in 10ths of a mm
GetBulletRightMargin()1961     static int GetBulletRightMargin() { return sm_bulletRightMargin; }
SetBulletRightMargin(int margin)1962     static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; }
1963 
1964     /// Factor to multiply by character height to get a reasonable bullet size
GetBulletProportion()1965     static float GetBulletProportion() { return sm_bulletProportion; }
SetBulletProportion(float prop)1966     static void SetBulletProportion(float prop) { sm_bulletProportion = prop; }
1967 
1968     /// Scale factor for calculating dimensions
GetScale()1969     double GetScale() const { return m_scale; }
SetScale(double scale)1970     void SetScale(double scale) { m_scale = scale; }
1971 
1972 protected:
1973 
1974     /// Command processor
1975     wxCommandProcessor*     m_commandProcessor;
1976 
1977     /// Has been modified?
1978     bool                    m_modified;
1979 
1980     /// Collapsed command stack
1981     int                     m_batchedCommandDepth;
1982 
1983     /// Name for collapsed command
1984     wxString                m_batchedCommandsName;
1985 
1986     /// Current collapsed command accumulating actions
1987     wxRichTextCommand*      m_batchedCommand;
1988 
1989     /// Whether to suppress undo
1990     int                     m_suppressUndo;
1991 
1992     /// Style sheet, if any
1993     wxRichTextStyleSheet*   m_styleSheet;
1994 
1995     /// List of event handlers that will be notified of events
1996     wxList                  m_eventHandlers;
1997 
1998     /// Stack of attributes for convenience functions
1999     wxList                  m_attributeStack;
2000 
2001     /// Flags to be passed to handlers
2002     int                     m_handlerFlags;
2003 
2004     /// File handlers
2005     static wxList           sm_handlers;
2006 
2007     /// Renderer
2008     static wxRichTextRenderer* sm_renderer;
2009 
2010     /// Minimum margin between bullet and paragraph in 10ths of a mm
2011     static int              sm_bulletRightMargin;
2012 
2013     /// Factor to multiply by character height to get a reasonable bullet size
2014     static float            sm_bulletProportion;
2015 
2016     /// Scaling factor in use: needed to calculate correct dimensions when printing
2017     double                  m_scale;
2018 };
2019 
2020 /*!
2021  * The command identifiers
2022  *
2023  */
2024 
2025 enum wxRichTextCommandId
2026 {
2027     wxRICHTEXT_INSERT,
2028     wxRICHTEXT_DELETE,
2029     wxRICHTEXT_CHANGE_STYLE
2030 };
2031 
2032 /*!
2033  * Command classes for undo/redo
2034  *
2035  */
2036 
2037 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction;
2038 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand
2039 {
2040 public:
2041     // Ctor for one action
2042     wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
2043         wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
2044 
2045     // Ctor for multiple actions
2046     wxRichTextCommand(const wxString& name);
2047 
2048     virtual ~wxRichTextCommand();
2049 
2050     bool Do();
2051     bool Undo();
2052 
2053     void AddAction(wxRichTextAction* action);
2054     void ClearActions();
2055 
GetActions()2056     wxList& GetActions() { return m_actions; }
2057 
2058 protected:
2059 
2060     wxList  m_actions;
2061 };
2062 
2063 /*!
2064  * wxRichTextAction class declaration
2065  * There can be more than one action in a command.
2066  */
2067 
2068 class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject
2069 {
2070 public:
2071     wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
2072         wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
2073 
2074     virtual ~wxRichTextAction();
2075 
2076     bool Do();
2077     bool Undo();
2078 
2079     /// Update the control appearance
2080     void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false,
2081                             wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL);
2082 
2083     /// Replace the buffer paragraphs with the given fragment.
2084     void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment);
2085 
2086 #if wxABI_VERSION >= 20808
2087     // Create arrays to be used in refresh optimization
2088     void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions);
2089 #endif
2090 
2091     /// Get the fragments
GetNewParagraphs()2092     wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; }
GetOldParagraphs()2093     wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; }
2094 
2095     /// Set/get the position used for e.g. insertion
SetPosition(long pos)2096     void SetPosition(long pos) { m_position = pos; }
GetPosition()2097     long GetPosition() const { return m_position; }
2098 
2099     /// Set/get the range for e.g. deletion
SetRange(const wxRichTextRange & range)2100     void SetRange(const wxRichTextRange& range) { m_range = range; }
GetRange()2101     const wxRichTextRange& GetRange() const { return m_range; }
2102 
2103     /// Get name
GetName()2104     const wxString& GetName() const { return m_name; }
2105 
2106 protected:
2107     // Action name
2108     wxString                        m_name;
2109 
2110     // Buffer
2111     wxRichTextBuffer*               m_buffer;
2112 
2113     // Control
2114     wxRichTextCtrl*                 m_ctrl;
2115 
2116     // Stores the new paragraphs
2117     wxRichTextParagraphLayoutBox    m_newParagraphs;
2118 
2119     // Stores the old paragraphs
2120     wxRichTextParagraphLayoutBox    m_oldParagraphs;
2121 
2122     // The affected range
2123     wxRichTextRange                 m_range;
2124 
2125     // The insertion point for this command
2126     long                            m_position;
2127 
2128     // Ignore 1st 'Do' operation because we already did it
2129     bool                            m_ignoreThis;
2130 
2131     // The command identifier
2132     wxRichTextCommandId             m_cmdId;
2133 };
2134 
2135 /*!
2136  * Handler flags
2137  */
2138 
2139 // Include style sheet when loading and saving
2140 #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET       0x0001
2141 
2142 // Save images to memory file system in HTML handler
2143 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY    0x0010
2144 
2145 // Save images to files in HTML handler
2146 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES     0x0020
2147 
2148 // Save images as inline base64 data in HTML handler
2149 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64    0x0040
2150 
2151 // Don't write header and footer (or BODY), so we can include the fragment
2152 // in a larger document
2153 #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER         0x0080
2154 
2155 // Convert the more common face names to names that will work on the current platform
2156 // in a larger document
2157 #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES        0x0100
2158 
2159 /*!
2160  * wxRichTextFileHandler
2161  * Base class for file handlers
2162  */
2163 
2164 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject
2165 {
DECLARE_CLASS(wxRichTextFileHandler)2166     DECLARE_CLASS(wxRichTextFileHandler)
2167 public:
2168     wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0)
2169         : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true)
2170         { }
2171 
2172 #if wxUSE_STREAMS
LoadFile(wxRichTextBuffer * buffer,wxInputStream & stream)2173     bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
2174     { return DoLoadFile(buffer, stream); }
SaveFile(wxRichTextBuffer * buffer,wxOutputStream & stream)2175     bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
2176     { return DoSaveFile(buffer, stream); }
2177 #endif
2178 
2179     bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
2180     bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
2181 
2182     /// Can we handle this filename (if using files)? By default, checks the extension.
2183     virtual bool CanHandle(const wxString& filename) const;
2184 
2185     /// Can we save using this handler?
CanSave()2186     virtual bool CanSave() const { return false; }
2187 
2188     /// Can we load using this handler?
CanLoad()2189     virtual bool CanLoad() const { return false; }
2190 
2191     /// Should this handler be visible to the user?
IsVisible()2192     virtual bool IsVisible() const { return m_visible; }
SetVisible(bool visible)2193     virtual void SetVisible(bool visible) { m_visible = visible; }
2194 
2195     /// The name of the nandler
SetName(const wxString & name)2196     void SetName(const wxString& name) { m_name = name; }
GetName()2197     wxString GetName() const { return m_name; }
2198 
2199     /// The default extension to recognise
SetExtension(const wxString & ext)2200     void SetExtension(const wxString& ext) { m_extension = ext; }
GetExtension()2201     wxString GetExtension() const { return m_extension; }
2202 
2203     /// The handler type
SetType(int type)2204     void SetType(int type) { m_type = type; }
GetType()2205     int GetType() const { return m_type; }
2206 
2207     /// Flags controlling how loading and saving is done
SetFlags(int flags)2208     void SetFlags(int flags) { m_flags = flags; }
GetFlags()2209     int GetFlags() const { return m_flags; }
2210 
2211     /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
SetEncoding(const wxString & encoding)2212     void SetEncoding(const wxString& encoding) { m_encoding = encoding; }
GetEncoding()2213     const wxString& GetEncoding() const { return m_encoding; }
2214 
2215 protected:
2216 
2217 #if wxUSE_STREAMS
2218     virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0;
2219     virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0;
2220 #endif
2221 
2222     wxString  m_name;
2223     wxString  m_encoding;
2224     wxString  m_extension;
2225     int       m_type;
2226     int       m_flags;
2227     bool      m_visible;
2228 };
2229 
2230 /*!
2231  * wxRichTextPlainTextHandler
2232  * Plain text handler
2233  */
2234 
2235 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler
2236 {
DECLARE_CLASS(wxRichTextPlainTextHandler)2237     DECLARE_CLASS(wxRichTextPlainTextHandler)
2238 public:
2239     wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), const wxString& ext = wxT("txt"), int type = wxRICHTEXT_TYPE_TEXT)
2240         : wxRichTextFileHandler(name, ext, type)
2241         { }
2242 
2243     /// Can we save using this handler?
CanSave()2244     virtual bool CanSave() const { return true; }
2245 
2246     /// Can we load using this handler?
CanLoad()2247     virtual bool CanLoad() const { return true; }
2248 
2249 protected:
2250 
2251 #if wxUSE_STREAMS
2252     virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
2253     virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
2254 #endif
2255 
2256 };
2257 
2258 #if wxUSE_DATAOBJ
2259 
2260 /*!
2261  * The data object for a wxRichTextBuffer
2262  */
2263 
2264 class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple
2265 {
2266 public:
2267     // ctor doesn't copy the pointer, so it shouldn't go away while this object
2268     // is alive
2269     wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = (wxRichTextBuffer*) NULL);
2270     virtual ~wxRichTextBufferDataObject();
2271 
2272     // after a call to this function, the buffer is owned by the caller and it
2273     // is responsible for deleting it
2274     wxRichTextBuffer* GetRichTextBuffer();
2275 
2276     // Returns the id for the new data format
GetRichTextBufferFormatId()2277     static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; }
2278 
2279     // base class pure virtuals
2280 
2281     virtual wxDataFormat GetPreferredFormat(Direction dir) const;
2282     virtual size_t GetDataSize() const;
2283     virtual bool GetDataHere(void *pBuf) const;
2284     virtual bool SetData(size_t len, const void *buf);
2285 
2286     // prevent warnings
2287 
GetDataSize(const wxDataFormat &)2288     virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); }
GetDataHere(const wxDataFormat &,void * buf)2289     virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); }
SetData(const wxDataFormat &,size_t len,const void * buf)2290     virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); }
2291 
2292 private:
2293     wxDataFormat            m_formatRichTextBuffer;     // our custom format
2294     wxRichTextBuffer*       m_richTextBuffer;           // our data
2295     static const wxChar*    ms_richTextBufferFormatId;  // our format id
2296 };
2297 
2298 #endif
2299 
2300 /*!
2301  * wxRichTextRenderer isolates common drawing functionality
2302  */
2303 
2304 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject
2305 {
2306 public:
wxRichTextRenderer()2307     wxRichTextRenderer() {}
~wxRichTextRenderer()2308     virtual ~wxRichTextRenderer() {}
2309 
2310     /// Draw a standard bullet, as specified by the value of GetBulletName
2311     virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
2312 
2313     /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2314     virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) = 0;
2315 
2316     /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2317     virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
2318 
2319     /// Enumerate the standard bullet names currently supported
2320     virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0;
2321 };
2322 
2323 /*!
2324  * wxRichTextStdRenderer: standard renderer
2325  */
2326 
2327 class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer
2328 {
2329 public:
wxRichTextStdRenderer()2330     wxRichTextStdRenderer() {}
2331 
2332     /// Draw a standard bullet, as specified by the value of GetBulletName
2333     virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
2334 
2335     /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2336     virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text);
2337 
2338     /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2339     virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
2340 
2341     /// Enumerate the standard bullet names currently supported
2342     virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames);
2343 };
2344 
2345 /*!
2346  * Utilities
2347  *
2348  */
2349 
wxRichTextHasStyle(int flags,int style)2350 inline bool wxRichTextHasStyle(int flags, int style)
2351 {
2352     return ((flags & style) == style);
2353 }
2354 
2355 /// Compare two attribute objects
2356 WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2);
2357 WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxTextAttr& attr1, const wxRichTextAttr& attr2);
2358 
2359 /// Compare two attribute objects, but take into account the flags
2360 /// specifying attributes of interest.
2361 WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, int flags);
2362 WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2, int flags);
2363 
2364 /// Apply one style to another
2365 WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style);
2366 WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style);
2367 WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
2368 WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
2369 
2370 // Remove attributes
2371 WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style);
2372 
2373 /// Combine two bitlists
2374 WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB);
2375 
2376 /// Compare two bitlists
2377 WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags);
2378 
2379 /// Split into paragraph and character styles
2380 WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxTextAttrEx& style, wxTextAttrEx& parStyle, wxTextAttrEx& charStyle);
2381 
2382 /// Compare tabs
2383 WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2);
2384 
2385 /// Set the font without changing the font attributes
2386 WXDLLIMPEXP_RICHTEXT void wxSetFontPreservingStyles(wxTextAttr& attr, const wxFont& font);
2387 
2388 /// Convert a decimal to Roman numerals
2389 WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n);
2390 
2391 WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit();
2392 
2393 #endif
2394     // wxUSE_RICHTEXT
2395 
2396 #endif
2397     // _WX_RICHTEXTBUFFER_H_
2398 
2399