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