]>
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" | |
bec80f4f | 68 | #include "wx/variant.h" |
5d7836c4 | 69 | |
0ca07313 JS |
70 | #if wxUSE_DATAOBJ |
71 | #include "wx/dataobj.h" | |
72 | #endif | |
73 | ||
44cc96a8 | 74 | // Compatibility |
bec80f4f | 75 | //#define wxRichTextAttr wxTextAttr |
44cc96a8 JS |
76 | #define wxTextAttrEx wxTextAttr |
77 | ||
a188ac29 | 78 | // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a |
749414f7 | 79 | // caret reliably without using wxClientDC in case there |
1c13f06e | 80 | // are platform-specific problems with the generic caret. |
749414f7 | 81 | #if defined(__WXGTK__) || defined(__WXMAC__) |
a188ac29 JS |
82 | #define wxRICHTEXT_USE_OWN_CARET 1 |
83 | #else | |
1c13f06e | 84 | #define wxRICHTEXT_USE_OWN_CARET 0 |
a188ac29 | 85 | #endif |
1c13f06e JS |
86 | |
87 | // Switch off for binary compatibility, on for faster drawing | |
5cb0b827 JS |
88 | // Note: this seems to be buggy (overzealous use of extents) so |
89 | // don't use for now | |
90 | #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0 | |
1c13f06e | 91 | |
bec80f4f JS |
92 | // The following two symbols determine whether an output implementation |
93 | // is present. To switch the relevant one on, set wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT in | |
94 | // richtextxml.cpp. By default, the faster direct output implementation is used. | |
95 | ||
96 | // Include the wxXmlDocument implementation for output | |
97 | #define wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT 1 | |
98 | ||
99 | // Include the faster, direct implementation for output | |
100 | #define wxRICHTEXT_HAVE_DIRECT_OUTPUT 1 | |
101 | ||
603f702b | 102 | /* |
ff76711f JS |
103 | * Special characters |
104 | */ | |
105 | ||
106 | extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar; | |
107 | ||
5d7836c4 | 108 | /*! |
f632e27b | 109 | * File types in wxRichText context. |
5d7836c4 | 110 | */ |
d75a69e8 FM |
111 | enum wxRichTextFileType |
112 | { | |
113 | wxRICHTEXT_TYPE_ANY = 0, | |
114 | wxRICHTEXT_TYPE_TEXT, | |
115 | wxRICHTEXT_TYPE_XML, | |
116 | wxRICHTEXT_TYPE_HTML, | |
117 | wxRICHTEXT_TYPE_RTF, | |
118 | wxRICHTEXT_TYPE_PDF | |
119 | }; | |
5d7836c4 | 120 | |
603f702b | 121 | /* |
5d7836c4 JS |
122 | * Forward declarations |
123 | */ | |
124 | ||
b5dbe15d VS |
125 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl; |
126 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject; | |
cdaed652 | 127 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage; |
b5dbe15d VS |
128 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject; |
129 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList; | |
130 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine; | |
131 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph; | |
132 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler; | |
133 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet; | |
b5dbe15d VS |
134 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition; |
135 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent; | |
136 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer; | |
137 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; | |
bec80f4f | 138 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextXMLHandler; |
603f702b JS |
139 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraphLayoutBox; |
140 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImageBlock; | |
bec80f4f JS |
141 | class WXDLLIMPEXP_FWD_XML wxXmlNode; |
142 | class wxRichTextFloatCollector; | |
5d7836c4 JS |
143 | |
144 | /*! | |
145 | * Flags determining the available space, passed to Layout | |
146 | */ | |
147 | ||
148 | #define wxRICHTEXT_FIXED_WIDTH 0x01 | |
149 | #define wxRICHTEXT_FIXED_HEIGHT 0x02 | |
150 | #define wxRICHTEXT_VARIABLE_WIDTH 0x04 | |
151 | #define wxRICHTEXT_VARIABLE_HEIGHT 0x08 | |
152 | ||
4d551ad5 JS |
153 | // Only lay out the part of the buffer that lies within |
154 | // the rect passed to Layout. | |
155 | #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10 | |
156 | ||
603f702b | 157 | /* |
44219ff0 JS |
158 | * Flags to pass to Draw |
159 | */ | |
160 | ||
161 | // Ignore paragraph cache optimization, e.g. for printing purposes | |
162 | // where one line may be drawn higher (on the next page) compared | |
163 | // with the previous line | |
164 | #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01 | |
603f702b JS |
165 | #define wxRICHTEXT_DRAW_SELECTED 0x02 |
166 | #define wxRICHTEXT_DRAW_PRINT 0x04 | |
167 | #define wxRICHTEXT_DRAW_GUIDELINES 0x08 | |
44219ff0 | 168 | |
603f702b JS |
169 | /* |
170 | * Flags returned from hit-testing, or passed to hit-test function. | |
5d7836c4 | 171 | */ |
f632e27b FM |
172 | enum wxRichTextHitTestFlags |
173 | { | |
174 | // The point was not on this object | |
175 | wxRICHTEXT_HITTEST_NONE = 0x01, | |
176 | ||
177 | // The point was before the position returned from HitTest | |
178 | wxRICHTEXT_HITTEST_BEFORE = 0x02, | |
179 | ||
180 | // The point was after the position returned from HitTest | |
181 | wxRICHTEXT_HITTEST_AFTER = 0x04, | |
5d7836c4 | 182 | |
f632e27b FM |
183 | // The point was on the position returned from HitTest |
184 | wxRICHTEXT_HITTEST_ON = 0x08, | |
185 | ||
186 | // The point was on space outside content | |
603f702b JS |
187 | wxRICHTEXT_HITTEST_OUTSIDE = 0x10, |
188 | ||
189 | // Only do hit-testing at the current level (don't traverse into top-level objects) | |
190 | wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS = 0x20 | |
f632e27b | 191 | }; |
5d7836c4 JS |
192 | |
193 | /*! | |
194 | * Flags for GetRangeSize | |
195 | */ | |
196 | ||
197 | #define wxRICHTEXT_FORMATTED 0x01 | |
198 | #define wxRICHTEXT_UNFORMATTED 0x02 | |
2f45f554 | 199 | #define wxRICHTEXT_CACHE_SIZE 0x04 |
4f3d5bc0 | 200 | #define wxRICHTEXT_HEIGHT_ONLY 0x08 |
5d7836c4 | 201 | |
59509217 | 202 | /*! |
38f833b1 | 203 | * Flags for SetStyle/SetListStyle |
59509217 JS |
204 | */ |
205 | ||
206 | #define wxRICHTEXT_SETSTYLE_NONE 0x00 | |
207 | ||
208 | // Specifies that this operation should be undoable | |
209 | #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01 | |
210 | ||
211 | // Specifies that the style should not be applied if the | |
212 | // combined style at this point is already the style in question. | |
213 | #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02 | |
214 | ||
215 | // Specifies that the style should only be applied to paragraphs, | |
216 | // and not the content. This allows content styling to be | |
217 | // preserved independently from that of e.g. a named paragraph style. | |
218 | #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04 | |
219 | ||
220 | // Specifies that the style should only be applied to characters, | |
221 | // and not the paragraph. This allows content styling to be | |
222 | // preserved independently from that of e.g. a named paragraph style. | |
223 | #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08 | |
224 | ||
38f833b1 JS |
225 | // For SetListStyle only: specifies starting from the given number, otherwise |
226 | // deduces number from existing attributes | |
227 | #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10 | |
228 | ||
229 | // For SetListStyle only: specifies the list level for all paragraphs, otherwise | |
230 | // the current indentation will be used | |
231 | #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20 | |
232 | ||
523d2f14 JS |
233 | // Resets the existing style before applying the new style |
234 | #define wxRICHTEXT_SETSTYLE_RESET 0x40 | |
235 | ||
aeb6ebe2 JS |
236 | // Removes the given style instead of applying it |
237 | #define wxRICHTEXT_SETSTYLE_REMOVE 0x80 | |
238 | ||
fe5aa22c | 239 | /*! |
603f702b | 240 | * Flags for object insertion |
fe5aa22c JS |
241 | */ |
242 | ||
243 | #define wxRICHTEXT_INSERT_NONE 0x00 | |
244 | #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01 | |
c025e094 | 245 | #define wxRICHTEXT_INSERT_INTERACTIVE 0x02 |
fe5aa22c | 246 | |
6c0ea513 JS |
247 | // A special flag telling the buffer to keep the first paragraph style |
248 | // as-is, when deleting a paragraph marker. In future we might pass a | |
249 | // flag to InsertFragment and DeleteRange to indicate the appropriate mode. | |
250 | #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000 | |
251 | ||
30bf7630 JS |
252 | /*! |
253 | * Default superscript/subscript font multiplication factor | |
254 | */ | |
255 | ||
256 | #define wxSCRIPT_MUL_FACTOR 1.5 | |
257 | ||
24777478 | 258 | typedef unsigned short wxTextAttrDimensionFlags; |
cdaed652 | 259 | |
603f702b | 260 | // Miscellaneous text box flags |
24777478 JS |
261 | enum wxTextBoxAttrFlags |
262 | { | |
263 | wxTEXT_BOX_ATTR_FLOAT = 0x00000001, | |
264 | wxTEXT_BOX_ATTR_CLEAR = 0x00000002, | |
603f702b JS |
265 | wxTEXT_BOX_ATTR_COLLAPSE_BORDERS = 0x00000004, |
266 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT = 0x00000004 | |
24777478 | 267 | }; |
cdaed652 | 268 | |
24777478 JS |
269 | // Whether a value is present, used in dimension flags |
270 | enum wxTextAttrValueFlags | |
271 | { | |
603f702b JS |
272 | wxTEXT_ATTR_VALUE_VALID = 0x1000, |
273 | wxTEXT_ATTR_VALUE_VALID_MASK = 0x1000 | |
24777478 | 274 | }; |
cdaed652 | 275 | |
24777478 JS |
276 | // Units - included in the dimension value |
277 | enum wxTextAttrUnits | |
278 | { | |
279 | wxTEXT_ATTR_UNITS_TENTHS_MM = 0x0001, | |
280 | wxTEXT_ATTR_UNITS_PIXELS = 0x0002, | |
281 | wxTEXT_ATTR_UNITS_PERCENTAGE = 0x0004, | |
282 | wxTEXT_ATTR_UNITS_POINTS = 0x0008, | |
283 | ||
284 | wxTEXT_ATTR_UNITS_MASK = 0x000F | |
285 | }; | |
286 | ||
287 | // Position - included in the dimension flags | |
288 | enum wxTextBoxAttrPosition | |
289 | { | |
290 | wxTEXT_BOX_ATTR_POSITION_STATIC = 0x0000, // Default is static, i.e. as per normal layout | |
603f702b | 291 | wxTEXT_BOX_ATTR_POSITION_RELATIVE = 0x0010, // Relative to the relevant edge |
24777478 JS |
292 | wxTEXT_BOX_ATTR_POSITION_ABSOLUTE = 0x0020, |
293 | ||
294 | wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0 | |
295 | }; | |
296 | ||
297 | // Dimension, including units and position | |
6ffb5e91 | 298 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimension |
cdaed652 VZ |
299 | { |
300 | public: | |
24777478 | 301 | wxTextAttrDimension() { Reset(); } |
603f702b JS |
302 | wxTextAttrDimension(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { m_value = value; m_flags = units|wxTEXT_ATTR_VALUE_VALID; } |
303 | ||
24777478 JS |
304 | void Reset() { m_value = 0; m_flags = 0; } |
305 | ||
306 | // Partial equality test | |
307 | bool EqPartial(const wxTextAttrDimension& dim) const; | |
308 | ||
309 | // Apply | |
310 | bool Apply(const wxTextAttrDimension& dim, const wxTextAttrDimension* compareWith = NULL); | |
311 | ||
312 | // Collects the attributes that are common to a range of content, building up a note of | |
313 | // which attributes are absent in some objects and which clash in some objects. | |
314 | void CollectCommonAttributes(const wxTextAttrDimension& attr, wxTextAttrDimension& clashingAttr, wxTextAttrDimension& absentAttr); | |
315 | ||
316 | bool operator==(const wxTextAttrDimension& dim) const { return m_value == dim.m_value && m_flags == dim.m_flags; } | |
603f702b | 317 | |
24777478 JS |
318 | int GetValue() const { return m_value; } |
319 | float GetValueMM() const { return float(m_value) / 10.0; } | |
603f702b JS |
320 | void SetValueMM(float value) { m_value = (int) ((value * 10.0) + 0.5); m_flags |= wxTEXT_ATTR_VALUE_VALID; } |
321 | void SetValue(int value) { m_value = value; m_flags |= wxTEXT_ATTR_VALUE_VALID; } | |
322 | void SetValue(int value, wxTextAttrDimensionFlags flags) { SetValue(value); m_flags = flags; } | |
323 | void SetValue(int value, wxTextAttrUnits units) { m_value = value; m_flags = units | wxTEXT_ATTR_VALUE_VALID; } | |
bec80f4f | 324 | void SetValue(const wxTextAttrDimension& dim) { (*this) = dim; } |
603f702b | 325 | |
24777478 JS |
326 | wxTextAttrUnits GetUnits() const { return (wxTextAttrUnits) (m_flags & wxTEXT_ATTR_UNITS_MASK); } |
327 | void SetUnits(wxTextAttrUnits units) { m_flags &= ~wxTEXT_ATTR_UNITS_MASK; m_flags |= units; } | |
603f702b | 328 | |
24777478 JS |
329 | wxTextBoxAttrPosition GetPosition() const { return (wxTextBoxAttrPosition) (m_flags & wxTEXT_BOX_ATTR_POSITION_MASK); } |
330 | void SetPosition(wxTextBoxAttrPosition pos) { m_flags &= ~wxTEXT_BOX_ATTR_POSITION_MASK; m_flags |= pos; } | |
603f702b JS |
331 | |
332 | bool IsValid() const { return (m_flags & wxTEXT_ATTR_VALUE_VALID) != 0; } | |
333 | void SetValid(bool b) { m_flags &= ~wxTEXT_ATTR_VALUE_VALID_MASK; m_flags |= (b ? wxTEXT_ATTR_VALUE_VALID : 0); } | |
334 | ||
bec80f4f JS |
335 | wxTextAttrDimensionFlags GetFlags() const { return m_flags; } |
336 | void SetFlags(wxTextAttrDimensionFlags flags) { m_flags = flags; } | |
603f702b | 337 | |
24777478 JS |
338 | int m_value; |
339 | wxTextAttrDimensionFlags m_flags; | |
340 | }; | |
ce00f59b | 341 | |
bec80f4f JS |
342 | // A class for left, right, top and bottom dimensions |
343 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensions | |
24777478 JS |
344 | { |
345 | public: | |
603f702b JS |
346 | wxTextAttrDimensions() {} |
347 | ||
24777478 | 348 | void Reset() { m_left.Reset(); m_top.Reset(); m_right.Reset(); m_bottom.Reset(); } |
603f702b | 349 | |
bec80f4f | 350 | bool operator==(const wxTextAttrDimensions& dims) const { return m_left == dims.m_left && m_top == dims.m_top && m_right == dims.m_right && m_bottom == dims.m_bottom; } |
603f702b | 351 | |
24777478 | 352 | // Partial equality test |
bec80f4f | 353 | bool EqPartial(const wxTextAttrDimensions& dims) const; |
24777478 JS |
354 | |
355 | // Apply border to 'this', but not if the same as compareWith | |
bec80f4f | 356 | bool Apply(const wxTextAttrDimensions& dims, const wxTextAttrDimensions* compareWith = NULL); |
24777478 JS |
357 | |
358 | // Collects the attributes that are common to a range of content, building up a note of | |
359 | // which attributes are absent in some objects and which clash in some objects. | |
bec80f4f | 360 | void CollectCommonAttributes(const wxTextAttrDimensions& attr, wxTextAttrDimensions& clashingAttr, wxTextAttrDimensions& absentAttr); |
24777478 JS |
361 | |
362 | // Remove specified attributes from this object | |
bec80f4f JS |
363 | bool RemoveStyle(const wxTextAttrDimensions& attr); |
364 | ||
365 | const wxTextAttrDimension& GetLeft() const { return m_left; } | |
366 | wxTextAttrDimension& GetLeft() { return m_left; } | |
367 | ||
368 | const wxTextAttrDimension& GetRight() const { return m_right; } | |
369 | wxTextAttrDimension& GetRight() { return m_right; } | |
370 | ||
371 | const wxTextAttrDimension& GetTop() const { return m_top; } | |
372 | wxTextAttrDimension& GetTop() { return m_top; } | |
373 | ||
374 | const wxTextAttrDimension& GetBottom() const { return m_bottom; } | |
375 | wxTextAttrDimension& GetBottom() { return m_bottom; } | |
24777478 JS |
376 | |
377 | wxTextAttrDimension m_left; | |
378 | wxTextAttrDimension m_top; | |
379 | wxTextAttrDimension m_right; | |
380 | wxTextAttrDimension m_bottom; | |
381 | }; | |
382 | ||
603f702b JS |
383 | // A class for width and height |
384 | class WXDLLIMPEXP_RICHTEXT wxTextAttrSize | |
385 | { | |
386 | public: | |
387 | wxTextAttrSize() {} | |
388 | ||
389 | void Reset() { m_width.Reset(); m_height.Reset(); } | |
390 | ||
391 | bool operator==(const wxTextAttrSize& size) const { return m_width == size.m_width && m_height == size.m_height ; } | |
392 | ||
393 | // Partial equality test | |
394 | bool EqPartial(const wxTextAttrSize& dims) const; | |
395 | ||
396 | // Apply border to 'this', but not if the same as compareWith | |
397 | bool Apply(const wxTextAttrSize& dims, const wxTextAttrSize* compareWith = NULL); | |
398 | ||
399 | // Collects the attributes that are common to a range of content, building up a note of | |
400 | // which attributes are absent in some objects and which clash in some objects. | |
401 | void CollectCommonAttributes(const wxTextAttrSize& attr, wxTextAttrSize& clashingAttr, wxTextAttrSize& absentAttr); | |
402 | ||
403 | // Remove specified attributes from this object | |
404 | bool RemoveStyle(const wxTextAttrSize& attr); | |
405 | ||
406 | // Width and height | |
407 | ||
408 | wxTextAttrDimension& GetWidth() { return m_width; } | |
409 | const wxTextAttrDimension& GetWidth() const { return m_width; } | |
410 | ||
411 | void SetWidth(int value, wxTextAttrDimensionFlags flags) { m_width.SetValue(value, flags); } | |
412 | void SetWidth(int value, wxTextAttrUnits units) { m_width.SetValue(value, units); } | |
413 | void SetWidth(const wxTextAttrDimension& dim) { m_width.SetValue(dim); } | |
414 | ||
415 | wxTextAttrDimension& GetHeight() { return m_height; } | |
416 | const wxTextAttrDimension& GetHeight() const { return m_height; } | |
417 | ||
418 | void SetHeight(int value, wxTextAttrDimensionFlags flags) { m_height.SetValue(value, flags); } | |
419 | void SetHeight(int value, wxTextAttrUnits units) { m_height.SetValue(value, units); } | |
420 | void SetHeight(const wxTextAttrDimension& dim) { m_height.SetValue(dim); } | |
421 | ||
422 | wxTextAttrDimension m_width; | |
423 | wxTextAttrDimension m_height; | |
424 | }; | |
425 | ||
bec80f4f JS |
426 | // A class to make it easier to convert dimensions |
427 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensionConverter | |
428 | { | |
429 | public: | |
8995db52 JS |
430 | wxTextAttrDimensionConverter(wxDC& dc, double scale = 1.0, const wxSize& parentSize = wxDefaultSize); |
431 | wxTextAttrDimensionConverter(int ppi, double scale = 1.0, const wxSize& parentSize = wxDefaultSize); | |
603f702b | 432 | |
bec80f4f JS |
433 | int GetPixels(const wxTextAttrDimension& dim, int direction = wxHORIZONTAL) const; |
434 | int GetTenthsMM(const wxTextAttrDimension& dim) const; | |
435 | ||
436 | int ConvertTenthsMMToPixels(int units) const; | |
437 | int ConvertPixelsToTenthsMM(int pixels) const; | |
438 | ||
439 | int m_ppi; | |
440 | double m_scale; | |
441 | wxSize m_parentSize; | |
442 | }; | |
443 | ||
24777478 | 444 | // Border styles |
bec80f4f | 445 | enum wxTextAttrBorderStyle |
24777478 JS |
446 | { |
447 | wxTEXT_BOX_ATTR_BORDER_NONE = 0, | |
448 | wxTEXT_BOX_ATTR_BORDER_SOLID = 1, | |
449 | wxTEXT_BOX_ATTR_BORDER_DOTTED = 2, | |
450 | wxTEXT_BOX_ATTR_BORDER_DASHED = 3, | |
451 | wxTEXT_BOX_ATTR_BORDER_DOUBLE = 4, | |
452 | wxTEXT_BOX_ATTR_BORDER_GROOVE = 5, | |
453 | wxTEXT_BOX_ATTR_BORDER_RIDGE = 6, | |
454 | wxTEXT_BOX_ATTR_BORDER_INSET = 7, | |
455 | wxTEXT_BOX_ATTR_BORDER_OUTSET = 8 | |
456 | }; | |
457 | ||
458 | // Border style presence flags | |
bec80f4f | 459 | enum wxTextAttrBorderFlags |
24777478 JS |
460 | { |
461 | wxTEXT_BOX_ATTR_BORDER_STYLE = 0x0001, | |
462 | wxTEXT_BOX_ATTR_BORDER_COLOUR = 0x0002 | |
463 | }; | |
464 | ||
bec80f4f JS |
465 | // Border width symbols for qualitative widths |
466 | enum wxTextAttrBorderWidth | |
467 | { | |
468 | wxTEXT_BOX_ATTR_BORDER_THIN = -1, | |
469 | wxTEXT_BOX_ATTR_BORDER_MEDIUM = -2, | |
470 | wxTEXT_BOX_ATTR_BORDER_THICK = -3 | |
471 | }; | |
472 | ||
24777478 JS |
473 | // Float styles |
474 | enum wxTextBoxAttrFloatStyle | |
475 | { | |
476 | wxTEXT_BOX_ATTR_FLOAT_NONE = 0, | |
477 | wxTEXT_BOX_ATTR_FLOAT_LEFT = 1, | |
478 | wxTEXT_BOX_ATTR_FLOAT_RIGHT = 2 | |
479 | }; | |
480 | ||
481 | // Clear styles | |
482 | enum wxTextBoxAttrClearStyle | |
483 | { | |
484 | wxTEXT_BOX_ATTR_CLEAR_NONE = 0, | |
485 | wxTEXT_BOX_ATTR_CLEAR_LEFT = 1, | |
486 | wxTEXT_BOX_ATTR_CLEAR_RIGHT = 2, | |
487 | wxTEXT_BOX_ATTR_CLEAR_BOTH = 3 | |
488 | }; | |
489 | ||
490 | // Collapse mode styles. TODO: can they be switched on per side? | |
491 | enum wxTextBoxAttrCollapseMode | |
492 | { | |
493 | wxTEXT_BOX_ATTR_COLLAPSE_NONE = 0, | |
494 | wxTEXT_BOX_ATTR_COLLAPSE_FULL = 1 | |
495 | }; | |
496 | ||
603f702b JS |
497 | // Vertical alignment values |
498 | enum wxTextBoxAttrVerticalAlignment | |
499 | { | |
500 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE = 0, | |
501 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP = 1, | |
502 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE = 2, | |
503 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM = 3 | |
504 | }; | |
505 | ||
24777478 | 506 | // Border |
bec80f4f | 507 | class WXDLLIMPEXP_RICHTEXT wxTextAttrBorder |
24777478 JS |
508 | { |
509 | public: | |
bec80f4f | 510 | wxTextAttrBorder() { Reset(); } |
603f702b | 511 | |
bec80f4f | 512 | bool operator==(const wxTextAttrBorder& border) const |
24777478 JS |
513 | { |
514 | return m_flags == border.m_flags && m_borderStyle == border.m_borderStyle && | |
515 | m_borderColour == border.m_borderColour && m_borderWidth == border.m_borderWidth; | |
516 | } | |
517 | ||
518 | void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); } | |
519 | ||
520 | // Partial equality test | |
bec80f4f | 521 | bool EqPartial(const wxTextAttrBorder& border) const; |
cdaed652 | 522 | |
24777478 | 523 | // Apply border to 'this', but not if the same as compareWith |
bec80f4f | 524 | bool Apply(const wxTextAttrBorder& border, const wxTextAttrBorder* compareWith = NULL); |
24777478 JS |
525 | |
526 | // Remove specified attributes from this object | |
bec80f4f | 527 | bool RemoveStyle(const wxTextAttrBorder& attr); |
24777478 JS |
528 | |
529 | // Collects the attributes that are common to a range of content, building up a note of | |
530 | // which attributes are absent in some objects and which clash in some objects. | |
bec80f4f | 531 | void CollectCommonAttributes(const wxTextAttrBorder& attr, wxTextAttrBorder& clashingAttr, wxTextAttrBorder& absentAttr); |
24777478 JS |
532 | |
533 | void SetStyle(int style) { m_borderStyle = style; m_flags |= wxTEXT_BOX_ATTR_BORDER_STYLE; } | |
534 | int GetStyle() const { return m_borderStyle; } | |
535 | ||
536 | void SetColour(unsigned long colour) { m_borderColour = colour; m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } | |
537 | void SetColour(const wxColour& colour) { m_borderColour = colour.GetRGB(); m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } | |
538 | unsigned long GetColourLong() const { return m_borderColour; } | |
539 | wxColour GetColour() const { return wxColour(m_borderColour); } | |
540 | ||
541 | wxTextAttrDimension& GetWidth() { return m_borderWidth; } | |
542 | const wxTextAttrDimension& GetWidth() const { return m_borderWidth; } | |
543 | void SetWidth(const wxTextAttrDimension& width) { m_borderWidth = width; } | |
603f702b | 544 | void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); } |
24777478 | 545 | |
bec80f4f JS |
546 | bool HasStyle() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_STYLE) != 0; } |
547 | bool HasColour() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_COLOUR) != 0; } | |
603f702b JS |
548 | bool HasWidth() const { return m_borderWidth.IsValid(); } |
549 | ||
550 | bool IsValid() const { return HasWidth(); } | |
551 | void MakeValid() { m_borderWidth.SetValid(true); } | |
552 | ||
24777478 JS |
553 | int GetFlags() const { return m_flags; } |
554 | void SetFlags(int flags) { m_flags = flags; } | |
555 | void AddFlag(int flag) { m_flags |= flag; } | |
556 | void RemoveFlag(int flag) { m_flags &= ~flag; } | |
557 | ||
558 | int m_borderStyle; | |
559 | unsigned long m_borderColour; | |
560 | wxTextAttrDimension m_borderWidth; | |
561 | int m_flags; | |
562 | }; | |
563 | ||
564 | // Borders | |
bec80f4f | 565 | class WXDLLIMPEXP_RICHTEXT wxTextAttrBorders |
24777478 JS |
566 | { |
567 | public: | |
bec80f4f | 568 | wxTextAttrBorders() { } |
ce00f59b | 569 | |
bec80f4f | 570 | bool operator==(const wxTextAttrBorders& borders) const |
24777478 JS |
571 | { |
572 | return m_left == borders.m_left && m_right == borders.m_right && | |
573 | m_top == borders.m_top && m_bottom == borders.m_bottom; | |
574 | } | |
cdaed652 | 575 | |
24777478 JS |
576 | // Set style of all borders |
577 | void SetStyle(int style); | |
ce00f59b | 578 | |
24777478 JS |
579 | // Set colour of all borders |
580 | void SetColour(unsigned long colour); | |
581 | void SetColour(const wxColour& colour); | |
cdaed652 | 582 | |
24777478 JS |
583 | // Set width of all borders |
584 | void SetWidth(const wxTextAttrDimension& width); | |
603f702b JS |
585 | void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); } |
586 | ||
24777478 JS |
587 | // Reset |
588 | void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); } | |
cdaed652 | 589 | |
24777478 | 590 | // Partial equality test |
bec80f4f | 591 | bool EqPartial(const wxTextAttrBorders& borders) const; |
cdaed652 | 592 | |
24777478 | 593 | // Apply border to 'this', but not if the same as compareWith |
bec80f4f | 594 | bool Apply(const wxTextAttrBorders& borders, const wxTextAttrBorders* compareWith = NULL); |
cdaed652 | 595 | |
24777478 | 596 | // Remove specified attributes from this object |
bec80f4f | 597 | bool RemoveStyle(const wxTextAttrBorders& attr); |
cdaed652 | 598 | |
24777478 JS |
599 | // Collects the attributes that are common to a range of content, building up a note of |
600 | // which attributes are absent in some objects and which clash in some objects. | |
bec80f4f | 601 | void CollectCommonAttributes(const wxTextAttrBorders& attr, wxTextAttrBorders& clashingAttr, wxTextAttrBorders& absentAttr); |
603f702b JS |
602 | |
603 | bool IsValid() const { return m_left.IsValid() || m_right.IsValid() || m_top.IsValid() || m_bottom.IsValid(); } | |
cdaed652 | 604 | |
bec80f4f JS |
605 | const wxTextAttrBorder& GetLeft() const { return m_left; } |
606 | wxTextAttrBorder& GetLeft() { return m_left; } | |
603f702b | 607 | |
bec80f4f JS |
608 | const wxTextAttrBorder& GetRight() const { return m_right; } |
609 | wxTextAttrBorder& GetRight() { return m_right; } | |
603f702b | 610 | |
bec80f4f JS |
611 | const wxTextAttrBorder& GetTop() const { return m_top; } |
612 | wxTextAttrBorder& GetTop() { return m_top; } | |
603f702b | 613 | |
bec80f4f JS |
614 | const wxTextAttrBorder& GetBottom() const { return m_bottom; } |
615 | wxTextAttrBorder& GetBottom() { return m_bottom; } | |
603f702b | 616 | |
bec80f4f | 617 | wxTextAttrBorder m_left, m_right, m_top, m_bottom; |
cdaed652 | 618 | |
24777478 JS |
619 | }; |
620 | ||
621 | // ---------------------------------------------------------------------------- | |
622 | // wxTextBoxAttr: a structure containing box attributes | |
623 | // ---------------------------------------------------------------------------- | |
624 | ||
6ffb5e91 | 625 | class WXDLLIMPEXP_RICHTEXT wxTextBoxAttr |
24777478 JS |
626 | { |
627 | public: | |
628 | // ctors | |
629 | wxTextBoxAttr() { Init(); } | |
630 | wxTextBoxAttr(const wxTextBoxAttr& attr) { Init(); (*this) = attr; } | |
631 | ||
603f702b | 632 | /// Initialise this object. |
24777478 JS |
633 | void Init() { Reset(); } |
634 | ||
603f702b | 635 | /// Reset this object. |
24777478 JS |
636 | void Reset(); |
637 | ||
bec80f4f | 638 | // Copy. Unnecessary since we let it do a binary copy |
24777478 JS |
639 | //void Copy(const wxTextBoxAttr& attr); |
640 | ||
641 | // Assignment | |
642 | //void operator= (const wxTextBoxAttr& attr); | |
643 | ||
603f702b | 644 | /// Equality test |
24777478 JS |
645 | bool operator== (const wxTextBoxAttr& attr) const; |
646 | ||
603f702b | 647 | /// Partial equality test, ignoring unset attributes. |
24777478 JS |
648 | bool EqPartial(const wxTextBoxAttr& attr) const; |
649 | ||
603f702b JS |
650 | /// Merges the given attributes. If compareWith |
651 | /// is non-NULL, then it will be used to mask out those attributes that are the same in style | |
652 | /// and compareWith, for situations where we don't want to explicitly set inherited attributes. | |
24777478 | 653 | bool Apply(const wxTextBoxAttr& style, const wxTextBoxAttr* compareWith = NULL); |
603f702b JS |
654 | |
655 | /// Collects the attributes that are common to a range of content, building up a note of | |
656 | /// which attributes are absent in some objects and which clash in some objects. | |
24777478 JS |
657 | void CollectCommonAttributes(const wxTextBoxAttr& attr, wxTextBoxAttr& clashingAttr, wxTextBoxAttr& absentAttr); |
658 | ||
603f702b | 659 | /// Removes the specified attributes from this object |
24777478 JS |
660 | bool RemoveStyle(const wxTextBoxAttr& attr); |
661 | ||
603f702b | 662 | /// Sets the flags. |
24777478 JS |
663 | void SetFlags(int flags) { m_flags = flags; } |
664 | ||
603f702b | 665 | /// Returns the flags. |
24777478 JS |
666 | int GetFlags() const { return m_flags; } |
667 | ||
603f702b | 668 | /// Is this flag present? |
24777478 JS |
669 | bool HasFlag(wxTextBoxAttrFlags flag) const { return (m_flags & flag) != 0; } |
670 | ||
603f702b | 671 | /// Remove this flag |
24777478 JS |
672 | void RemoveFlag(wxTextBoxAttrFlags flag) { m_flags &= ~flag; } |
673 | ||
603f702b | 674 | /// Add this flag |
24777478 JS |
675 | void AddFlag(wxTextBoxAttrFlags flag) { m_flags |= flag; } |
676 | ||
603f702b | 677 | /// Is this default? I.e. no attributes set. |
24777478 JS |
678 | bool IsDefault() const; |
679 | ||
603f702b JS |
680 | /// Get the float mode. |
681 | wxTextBoxAttrFloatStyle GetFloatMode() const { return m_floatMode; } | |
682 | ||
683 | /// Set the float mode. | |
684 | void SetFloatMode(wxTextBoxAttrFloatStyle mode) { m_floatMode = mode; m_flags |= wxTEXT_BOX_ATTR_FLOAT; } | |
685 | ||
686 | /// Do we have a float mode? | |
24777478 | 687 | bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT); } |
603f702b JS |
688 | |
689 | /// Is this object floating? | |
24777478 JS |
690 | bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE; } |
691 | ||
603f702b JS |
692 | /// Returns the clear mode - whether to wrap text after object. Currently unimplemented. |
693 | wxTextBoxAttrClearStyle GetClearMode() const { return m_clearMode; } | |
694 | ||
695 | /// Set the clear mode. Currently unimplemented. | |
696 | void SetClearMode(wxTextBoxAttrClearStyle mode) { m_clearMode = mode; m_flags |= wxTEXT_BOX_ATTR_CLEAR; } | |
697 | ||
698 | /// Do we have a clear mode? | |
24777478 JS |
699 | bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR); } |
700 | ||
603f702b JS |
701 | /// Returns the collapse mode - whether to collapse borders. Currently unimplemented. |
702 | wxTextBoxAttrCollapseMode GetCollapseBorders() const { return m_collapseMode; } | |
703 | ||
704 | /// Sets the collapse mode - whether to collapse borders. Currently unimplemented. | |
705 | void SetCollapseBorders(wxTextBoxAttrCollapseMode collapse) { m_collapseMode = collapse; m_flags |= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS; } | |
706 | ||
707 | /// Do we have a collapse borders flag? | |
24777478 | 708 | bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS); } |
603f702b JS |
709 | |
710 | /// Returns the vertical alignment. | |
711 | wxTextBoxAttrVerticalAlignment GetVerticalAlignment() const { return m_verticalAlignment; } | |
712 | ||
713 | /// Set the vertical alignment. | |
714 | void SetVerticalAlignment(wxTextBoxAttrVerticalAlignment verticalAlignment) { m_verticalAlignment = verticalAlignment; m_flags |= wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT; } | |
715 | ||
716 | /// Do we have a vertical alignment flag? | |
717 | bool HasVerticalAlignment() const { return HasFlag(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT); } | |
718 | ||
719 | /// Gets the margin values. | |
bec80f4f JS |
720 | wxTextAttrDimensions& GetMargins() { return m_margins; } |
721 | const wxTextAttrDimensions& GetMargins() const { return m_margins; } | |
722 | ||
603f702b | 723 | /// Gets the left margin. |
24777478 JS |
724 | wxTextAttrDimension& GetLeftMargin() { return m_margins.m_left; } |
725 | const wxTextAttrDimension& GetLeftMargin() const { return m_margins.m_left; } | |
726 | ||
603f702b | 727 | /// Gets the right margin. |
24777478 JS |
728 | wxTextAttrDimension& GetRightMargin() { return m_margins.m_right; } |
729 | const wxTextAttrDimension& GetRightMargin() const { return m_margins.m_right; } | |
730 | ||
603f702b | 731 | /// Gets the top margin. |
24777478 JS |
732 | wxTextAttrDimension& GetTopMargin() { return m_margins.m_top; } |
733 | const wxTextAttrDimension& GetTopMargin() const { return m_margins.m_top; } | |
603f702b JS |
734 | |
735 | /// Gets the bottom margin. | |
24777478 JS |
736 | wxTextAttrDimension& GetBottomMargin() { return m_margins.m_bottom; } |
737 | const wxTextAttrDimension& GetBottomMargin() const { return m_margins.m_bottom; } | |
738 | ||
603f702b | 739 | /// Returns the position. |
bec80f4f JS |
740 | wxTextAttrDimensions& GetPosition() { return m_position; } |
741 | const wxTextAttrDimensions& GetPosition() const { return m_position; } | |
742 | ||
603f702b | 743 | /// Returns the left position. |
24777478 JS |
744 | wxTextAttrDimension& GetLeft() { return m_position.m_left; } |
745 | const wxTextAttrDimension& GetLeft() const { return m_position.m_left; } | |
746 | ||
603f702b | 747 | /// Returns the right position. |
24777478 JS |
748 | wxTextAttrDimension& GetRight() { return m_position.m_right; } |
749 | const wxTextAttrDimension& GetRight() const { return m_position.m_right; } | |
750 | ||
603f702b | 751 | /// Returns the top position. |
24777478 JS |
752 | wxTextAttrDimension& GetTop() { return m_position.m_top; } |
753 | const wxTextAttrDimension& GetTop() const { return m_position.m_top; } | |
603f702b JS |
754 | |
755 | /// Returns the bottom position. | |
24777478 JS |
756 | wxTextAttrDimension& GetBottom() { return m_position.m_bottom; } |
757 | const wxTextAttrDimension& GetBottom() const { return m_position.m_bottom; } | |
758 | ||
603f702b | 759 | /// Returns the padding values. |
bec80f4f JS |
760 | wxTextAttrDimensions& GetPadding() { return m_padding; } |
761 | const wxTextAttrDimensions& GetPadding() const { return m_padding; } | |
762 | ||
603f702b | 763 | /// Returns the left padding value. |
24777478 JS |
764 | wxTextAttrDimension& GetLeftPadding() { return m_padding.m_left; } |
765 | const wxTextAttrDimension& GetLeftPadding() const { return m_padding.m_left; } | |
603f702b JS |
766 | |
767 | /// Returns the right padding value. | |
24777478 JS |
768 | wxTextAttrDimension& GetRightPadding() { return m_padding.m_right; } |
769 | const wxTextAttrDimension& GetRightPadding() const { return m_padding.m_right; } | |
603f702b JS |
770 | |
771 | /// Returns the top padding value. | |
24777478 JS |
772 | wxTextAttrDimension& GetTopPadding() { return m_padding.m_top; } |
773 | const wxTextAttrDimension& GetTopPadding() const { return m_padding.m_top; } | |
774 | ||
603f702b | 775 | /// Returns the bottom padding value. |
24777478 JS |
776 | wxTextAttrDimension& GetBottomPadding() { return m_padding.m_bottom; } |
777 | const wxTextAttrDimension& GetBottomPadding() const { return m_padding.m_bottom; } | |
24777478 | 778 | |
603f702b | 779 | /// Returns the borders. |
bec80f4f JS |
780 | wxTextAttrBorders& GetBorder() { return m_border; } |
781 | const wxTextAttrBorders& GetBorder() const { return m_border; } | |
24777478 | 782 | |
603f702b | 783 | /// Returns the left border. |
bec80f4f JS |
784 | wxTextAttrBorder& GetLeftBorder() { return m_border.m_left; } |
785 | const wxTextAttrBorder& GetLeftBorder() const { return m_border.m_left; } | |
24777478 | 786 | |
603f702b | 787 | /// Returns the top border. |
bec80f4f JS |
788 | wxTextAttrBorder& GetTopBorder() { return m_border.m_top; } |
789 | const wxTextAttrBorder& GetTopBorder() const { return m_border.m_top; } | |
24777478 | 790 | |
603f702b | 791 | /// Returns the right border. |
bec80f4f JS |
792 | wxTextAttrBorder& GetRightBorder() { return m_border.m_right; } |
793 | const wxTextAttrBorder& GetRightBorder() const { return m_border.m_right; } | |
24777478 | 794 | |
603f702b | 795 | /// Returns the bottom border. |
bec80f4f JS |
796 | wxTextAttrBorder& GetBottomBorder() { return m_border.m_bottom; } |
797 | const wxTextAttrBorder& GetBottomBorder() const { return m_border.m_bottom; } | |
24777478 | 798 | |
603f702b | 799 | /// Returns the outline. |
bec80f4f JS |
800 | wxTextAttrBorders& GetOutline() { return m_outline; } |
801 | const wxTextAttrBorders& GetOutline() const { return m_outline; } | |
24777478 | 802 | |
603f702b | 803 | /// Returns the left outline. |
bec80f4f JS |
804 | wxTextAttrBorder& GetLeftOutline() { return m_outline.m_left; } |
805 | const wxTextAttrBorder& GetLeftOutline() const { return m_outline.m_left; } | |
24777478 | 806 | |
603f702b | 807 | /// Returns the top outline. |
bec80f4f JS |
808 | wxTextAttrBorder& GetTopOutline() { return m_outline.m_top; } |
809 | const wxTextAttrBorder& GetTopOutline() const { return m_outline.m_top; } | |
24777478 | 810 | |
603f702b | 811 | /// Returns the right outline. |
bec80f4f JS |
812 | wxTextAttrBorder& GetRightOutline() { return m_outline.m_right; } |
813 | const wxTextAttrBorder& GetRightOutline() const { return m_outline.m_right; } | |
24777478 | 814 | |
603f702b | 815 | /// Returns the bottom outline. |
bec80f4f JS |
816 | wxTextAttrBorder& GetBottomOutline() { return m_outline.m_bottom; } |
817 | const wxTextAttrBorder& GetBottomOutline() const { return m_outline.m_bottom; } | |
24777478 | 818 | |
603f702b JS |
819 | /// Returns the object size. |
820 | wxTextAttrSize& GetSize() { return m_size; } | |
821 | const wxTextAttrSize& GetSize() const { return m_size; } | |
24777478 | 822 | |
603f702b JS |
823 | /// Sets the object size. |
824 | void SetSize(const wxTextAttrSize& sz) { m_size = sz; } | |
24777478 | 825 | |
603f702b JS |
826 | /// Returns the object width. |
827 | wxTextAttrDimension& GetWidth() { return m_size.m_width; } | |
828 | const wxTextAttrDimension& GetWidth() const { return m_size.m_width; } | |
829 | ||
830 | /// Returns the object height. | |
831 | wxTextAttrDimension& GetHeight() { return m_size.m_height; } | |
832 | const wxTextAttrDimension& GetHeight() const { return m_size.m_height; } | |
24777478 JS |
833 | |
834 | public: | |
835 | ||
603f702b | 836 | int m_flags; |
24777478 | 837 | |
603f702b JS |
838 | wxTextAttrDimensions m_margins; |
839 | wxTextAttrDimensions m_padding; | |
840 | wxTextAttrDimensions m_position; | |
24777478 | 841 | |
603f702b | 842 | wxTextAttrSize m_size; |
24777478 | 843 | |
603f702b JS |
844 | wxTextAttrBorders m_border; |
845 | wxTextAttrBorders m_outline; | |
846 | ||
847 | wxTextBoxAttrFloatStyle m_floatMode; | |
848 | wxTextBoxAttrClearStyle m_clearMode; | |
849 | wxTextBoxAttrCollapseMode m_collapseMode; | |
850 | wxTextBoxAttrVerticalAlignment m_verticalAlignment; | |
24777478 JS |
851 | }; |
852 | ||
853 | // ---------------------------------------------------------------------------- | |
854 | // wxRichTextAttr: an enhanced attribute | |
855 | // ---------------------------------------------------------------------------- | |
856 | ||
857 | class WXDLLIMPEXP_RICHTEXT wxRichTextAttr: public wxTextAttr | |
858 | { | |
859 | public: | |
860 | wxRichTextAttr(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } | |
603f702b | 861 | wxRichTextAttr(const wxRichTextAttr& attr): wxTextAttr() { Copy(attr); } |
24777478 | 862 | wxRichTextAttr() {} |
603f702b | 863 | |
24777478 JS |
864 | // Copy |
865 | void Copy(const wxRichTextAttr& attr); | |
603f702b | 866 | |
24777478 JS |
867 | // Assignment |
868 | void operator=(const wxRichTextAttr& attr) { Copy(attr); } | |
869 | void operator=(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } | |
603f702b | 870 | |
24777478 JS |
871 | // Equality test |
872 | bool operator==(const wxRichTextAttr& attr) const; | |
873 | ||
874 | // Partial equality test taking comparison object into account | |
875 | bool EqPartial(const wxRichTextAttr& attr) const; | |
876 | ||
877 | // Merges the given attributes. If compareWith | |
878 | // is non-NULL, then it will be used to mask out those attributes that are the same in style | |
879 | // and compareWith, for situations where we don't want to explicitly set inherited attributes. | |
880 | bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL); | |
881 | ||
882 | // Collects the attributes that are common to a range of content, building up a note of | |
883 | // which attributes are absent in some objects and which clash in some objects. | |
884 | void CollectCommonAttributes(const wxRichTextAttr& attr, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); | |
885 | ||
886 | // Remove specified attributes from this object | |
887 | bool RemoveStyle(const wxRichTextAttr& attr); | |
888 | ||
889 | wxTextBoxAttr& GetTextBoxAttr() { return m_textBoxAttr; } | |
890 | const wxTextBoxAttr& GetTextBoxAttr() const { return m_textBoxAttr; } | |
891 | void SetTextBoxAttr(const wxTextBoxAttr& attr) { m_textBoxAttr = attr; } | |
603f702b | 892 | |
24777478 | 893 | wxTextBoxAttr m_textBoxAttr; |
cdaed652 VZ |
894 | }; |
895 | ||
bec80f4f JS |
896 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxVariant, wxRichTextVariantArray, WXDLLIMPEXP_RICHTEXT); |
897 | ||
898 | // ---------------------------------------------------------------------------- | |
899 | // wxRichTextProperties - A simple property class using wxVariants | |
900 | // ---------------------------------------------------------------------------- | |
901 | ||
902 | class WXDLLIMPEXP_RICHTEXT wxRichTextProperties: public wxObject | |
903 | { | |
904 | DECLARE_DYNAMIC_CLASS(wxRichTextProperties) | |
905 | public: | |
906 | wxRichTextProperties() {} | |
603f702b | 907 | wxRichTextProperties(const wxRichTextProperties& props): wxObject() { Copy(props); } |
bec80f4f JS |
908 | |
909 | void operator=(const wxRichTextProperties& props) { Copy(props); } | |
910 | bool operator==(const wxRichTextProperties& props) const; | |
911 | void Copy(const wxRichTextProperties& props) { m_properties = props.m_properties; } | |
912 | const wxVariant& operator[](size_t idx) const { return m_properties[idx]; } | |
913 | wxVariant& operator[](size_t idx) { return m_properties[idx]; } | |
914 | void Clear() { m_properties.Clear(); } | |
915 | ||
916 | const wxRichTextVariantArray& GetProperties() const { return m_properties; } | |
917 | wxRichTextVariantArray& GetProperties() { return m_properties; } | |
918 | void SetProperties(const wxRichTextVariantArray& props) { m_properties = props; } | |
919 | ||
920 | wxArrayString GetPropertyNames() const; | |
921 | ||
922 | size_t GetCount() const { return m_properties.GetCount(); } | |
923 | ||
924 | int HasProperty(const wxString& name) const { return Find(name) != -1; } | |
925 | ||
926 | int Find(const wxString& name) const; | |
927 | const wxVariant& GetProperty(const wxString& name) const; | |
928 | wxVariant* FindOrCreateProperty(const wxString& name); | |
929 | ||
930 | wxString GetPropertyString(const wxString& name) const; | |
931 | long GetPropertyLong(const wxString& name) const; | |
932 | bool GetPropertyBool(const wxString& name) const; | |
933 | double GetPropertyDouble(const wxString& name) const; | |
934 | ||
935 | void SetProperty(const wxVariant& variant); | |
936 | void SetProperty(const wxString& name, const wxVariant& variant); | |
937 | void SetProperty(const wxString& name, const wxString& value); | |
938 | void SetProperty(const wxString& name, long value); | |
939 | void SetProperty(const wxString& name, double value); | |
940 | void SetProperty(const wxString& name, bool value); | |
941 | ||
942 | protected: | |
943 | wxRichTextVariantArray m_properties; | |
944 | }; | |
945 | ||
946 | ||
5d7836c4 | 947 | /*! |
44cc96a8 JS |
948 | * wxRichTextFontTable |
949 | * Manages quick access to a pool of fonts for rendering rich text | |
5d7836c4 JS |
950 | */ |
951 | ||
44cc96a8 JS |
952 | class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable: public wxObject |
953 | { | |
954 | public: | |
955 | wxRichTextFontTable(); | |
42688aea | 956 | |
44cc96a8 JS |
957 | wxRichTextFontTable(const wxRichTextFontTable& table); |
958 | virtual ~wxRichTextFontTable(); | |
5d7836c4 | 959 | |
44cc96a8 | 960 | bool IsOk() const { return m_refData != NULL; } |
5d7836c4 | 961 | |
24777478 | 962 | wxFont FindFont(const wxRichTextAttr& fontSpec); |
44cc96a8 | 963 | void Clear(); |
d2d0adc7 | 964 | |
44cc96a8 JS |
965 | void operator= (const wxRichTextFontTable& table); |
966 | bool operator == (const wxRichTextFontTable& table) const; | |
967 | bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); } | |
d2d0adc7 | 968 | |
44cc96a8 | 969 | protected: |
d2d0adc7 | 970 | |
44cc96a8 JS |
971 | DECLARE_DYNAMIC_CLASS(wxRichTextFontTable) |
972 | }; | |
d2d0adc7 | 973 | |
5d7836c4 JS |
974 | /*! |
975 | * wxRichTextRange class declaration | |
976 | * This stores beginning and end positions for a range of data. | |
44cc96a8 | 977 | * TODO: consider renaming wxTextRange and using for all text controls. |
5d7836c4 JS |
978 | */ |
979 | ||
3b2cb431 | 980 | class WXDLLIMPEXP_RICHTEXT wxRichTextRange |
5d7836c4 JS |
981 | { |
982 | public: | |
983 | // Constructors | |
984 | ||
985 | wxRichTextRange() { m_start = 0; m_end = 0; } | |
986 | wxRichTextRange(long start, long end) { m_start = start; m_end = end; } | |
987 | wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } | |
988 | ~wxRichTextRange() {} | |
989 | ||
990 | void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } | |
38113684 | 991 | bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); } |
e0983733 | 992 | bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start || m_end != range.m_end); } |
5d7836c4 JS |
993 | wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); } |
994 | wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); } | |
995 | ||
996 | void SetRange(long start, long end) { m_start = start; m_end = end; } | |
997 | ||
998 | void SetStart(long start) { m_start = start; } | |
999 | long GetStart() const { return m_start; } | |
1000 | ||
1001 | void SetEnd(long end) { m_end = end; } | |
1002 | long GetEnd() const { return m_end; } | |
1003 | ||
1004 | /// Returns true if this range is completely outside 'range' | |
1005 | bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; } | |
1006 | ||
1007 | /// Returns true if this range is completely within 'range' | |
1008 | bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; } | |
1009 | ||
1010 | /// Returns true if the given position is within this range. Allow | |
1011 | /// for the possibility of an empty range - assume the position | |
1012 | /// is within this empty range. NO, I think we should not match with an empty range. | |
1013 | // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); } | |
1014 | bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; } | |
1015 | ||
1016 | /// Limit this range to be within 'range' | |
1017 | bool LimitTo(const wxRichTextRange& range) ; | |
1018 | ||
1019 | /// Gets the length of the range | |
1020 | long GetLength() const { return m_end - m_start + 1; } | |
1021 | ||
1022 | /// Swaps the start and end | |
1023 | void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; } | |
1024 | ||
96c9f0f6 JS |
1025 | /// Convert to internal form: (n, n) is the range of a single character. |
1026 | wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); } | |
1027 | ||
1028 | /// Convert from internal to public API form: (n, n+1) is the range of a single character. | |
1029 | wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); } | |
1030 | ||
5d7836c4 JS |
1031 | protected: |
1032 | long m_start; | |
1033 | long m_end; | |
1034 | }; | |
1035 | ||
603f702b JS |
1036 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextRange, wxRichTextRangeArray, WXDLLIMPEXP_RICHTEXT); |
1037 | ||
1e967276 JS |
1038 | #define wxRICHTEXT_ALL wxRichTextRange(-2, -2) |
1039 | #define wxRICHTEXT_NONE wxRichTextRange(-1, -1) | |
1040 | ||
603f702b JS |
1041 | // ---------------------------------------------------------------------------- |
1042 | // wxRichTextSelection: stores selection information | |
1043 | // ---------------------------------------------------------------------------- | |
1044 | ||
1045 | #define wxRICHTEXT_NO_SELECTION wxRichTextRange(-2, -2) | |
1046 | ||
1047 | class WXDLLIMPEXP_RICHTEXT wxRichTextSelection | |
1048 | { | |
1049 | public: | |
1050 | wxRichTextSelection(const wxRichTextSelection& sel) { Copy(sel); } | |
1051 | wxRichTextSelection(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container) { m_ranges.Add(range); m_container = container; } | |
1052 | wxRichTextSelection() { Reset(); } | |
1053 | ||
1054 | /// Reset the selection | |
1055 | void Reset() { m_ranges.Clear(); m_container = NULL; } | |
1056 | ||
1057 | /// Set the selection | |
1058 | void Set(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container) | |
1059 | { m_ranges.Clear(); m_ranges.Add(range); m_container = container; } | |
1060 | ||
1061 | /// Add a selection | |
1062 | void Add(const wxRichTextRange& range) | |
1063 | { m_ranges.Add(range); } | |
1064 | ||
1065 | /// Set the selections | |
1066 | void Set(const wxRichTextRangeArray& ranges, wxRichTextParagraphLayoutBox* container) | |
1067 | { m_ranges = ranges; m_container = container; } | |
1068 | ||
1069 | /// Copy | |
1070 | void Copy(const wxRichTextSelection& sel) | |
1071 | { m_ranges = sel.m_ranges; m_container = sel.m_container; } | |
1072 | ||
1073 | /// Assignment | |
1074 | void operator=(const wxRichTextSelection& sel) { Copy(sel); } | |
1075 | ||
1076 | /// Equality test | |
1077 | bool operator==(const wxRichTextSelection& sel) const; | |
1078 | ||
1079 | /// Index operator | |
1080 | wxRichTextRange operator[](size_t i) const { return GetRange(i); } | |
1081 | ||
1082 | /// Get the selection ranges | |
1083 | wxRichTextRangeArray& GetRanges() { return m_ranges; } | |
1084 | const wxRichTextRangeArray& GetRanges() const { return m_ranges; } | |
1085 | ||
1086 | /// Set the selection ranges | |
1087 | void SetRanges(const wxRichTextRangeArray& ranges) { m_ranges = ranges; } | |
1088 | ||
1089 | /// Get the number of ranges in the selection | |
1090 | size_t GetCount() const { return m_ranges.GetCount(); } | |
1091 | ||
1092 | /// Get the given range | |
1093 | wxRichTextRange GetRange(size_t i) const { return m_ranges[i]; } | |
1094 | ||
1095 | /// Get the first range if there is one, otherwise wxRICHTEXT_NO_SELECTION. | |
1096 | wxRichTextRange GetRange() const { return (m_ranges.GetCount() > 0) ? (m_ranges[0]) : wxRICHTEXT_NO_SELECTION; } | |
1097 | ||
1098 | /// Set a single range. | |
1099 | void SetRange(const wxRichTextRange& range) { m_ranges.Clear(); m_ranges.Add(range); } | |
1100 | ||
1101 | /// Get the container for which the selection is valid | |
1102 | wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; } | |
1103 | ||
1104 | /// Set the container for which the selection is valid | |
1105 | void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; } | |
1106 | ||
1107 | /// Is the selection valid? | |
1108 | bool IsValid() const { return m_ranges.GetCount() > 0 && GetContainer(); } | |
1109 | ||
1110 | /// Get the selection appropriate to the specified object, if any; returns an empty array if none | |
1111 | /// at the level of the object's container. | |
1112 | wxRichTextRangeArray GetSelectionForObject(wxRichTextObject* obj) const; | |
1113 | ||
1114 | /// Is the given position within the selection? | |
1115 | bool WithinSelection(long pos, wxRichTextObject* obj) const; | |
1116 | ||
1117 | /// Is the given position within the selection? | |
1118 | bool WithinSelection(long pos) const { return WithinSelection(pos, m_ranges); } | |
1119 | ||
1120 | /// Is the given position within the selection range? | |
1121 | static bool WithinSelection(long pos, const wxRichTextRangeArray& ranges); | |
1122 | ||
1123 | /// Is the given range within the selection range? | |
1124 | static bool WithinSelection(const wxRichTextRange& range, const wxRichTextRangeArray& ranges); | |
1125 | ||
1126 | wxRichTextRangeArray m_ranges; | |
1127 | wxRichTextParagraphLayoutBox* m_container; | |
1128 | }; | |
1129 | ||
5d7836c4 JS |
1130 | /*! |
1131 | * wxRichTextObject class declaration | |
1132 | * This is the base for drawable objects. | |
1133 | */ | |
1134 | ||
3b2cb431 | 1135 | class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject |
5d7836c4 JS |
1136 | { |
1137 | DECLARE_CLASS(wxRichTextObject) | |
1138 | public: | |
1139 | // Constructors | |
1140 | ||
1141 | wxRichTextObject(wxRichTextObject* parent = NULL); | |
d3c7fc99 | 1142 | virtual ~wxRichTextObject(); |
5d7836c4 JS |
1143 | |
1144 | // Overrideables | |
1145 | ||
1146 | /// Draw the item, within the given range. Some objects may ignore the range (for | |
1147 | /// example paragraphs) while others must obey it (lines, to implement wrapping) | |
603f702b | 1148 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0; |
5d7836c4 JS |
1149 | |
1150 | /// Lay the item out at the specified position with the given size constraint. | |
1151 | /// Layout must set the cached size. | |
38113684 | 1152 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0; |
5d7836c4 JS |
1153 | |
1154 | /// Hit-testing: returns a flag indicating hit test details, plus | |
603f702b JS |
1155 | /// information about position. contextObj is returned to specify what object |
1156 | /// position is relevant to, since otherwise there's an ambiguity. | |
1157 | /// obj may not a child of contextObj, since we may be referring to the container itself | |
1158 | /// if we have no hit on a child - for example if we click outside an object. | |
1159 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); | |
5d7836c4 JS |
1160 | |
1161 | /// Finds the absolute position and row height for the given character position | |
1162 | virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; } | |
1163 | ||
1164 | /// Get the best size, i.e. the ideal starting size for this object irrespective | |
1165 | /// of available space. For a short text string, it will be the size that exactly encloses | |
1166 | /// the text. For a longer string, it might use the parent width for example. | |
1167 | virtual wxSize GetBestSize() const { return m_size; } | |
1168 | ||
603f702b JS |
1169 | /** |
1170 | Gets the object size for the given range. Returns false if the range | |
1171 | is invalid for this object. | |
1172 | */ | |
1173 | ||
31778480 | 1174 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const = 0; |
5d7836c4 JS |
1175 | |
1176 | /// Do a split, returning an object containing the second part, and setting | |
1177 | /// the first part in 'this'. | |
1178 | virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; } | |
1179 | ||
1180 | /// Calculate range. By default, guess that the object is 1 unit long. | |
1181 | virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); } | |
1182 | ||
1183 | /// Delete range | |
1184 | virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; } | |
1185 | ||
1186 | /// Returns true if the object is empty | |
1187 | virtual bool IsEmpty() const { return false; } | |
1188 | ||
cdaed652 VZ |
1189 | /// Whether this object floatable |
1190 | virtual bool IsFloatable() const { return false; } | |
1191 | ||
1192 | /// Whether this object is currently floating | |
bec80f4f | 1193 | virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); } |
cdaed652 VZ |
1194 | |
1195 | /// Whether this object is a place holding one | |
1196 | // virtual bool IsPlaceHolding() const { return false; } | |
1197 | ||
bec80f4f JS |
1198 | /// The floating direction |
1199 | virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); } | |
cdaed652 | 1200 | |
5d7836c4 JS |
1201 | /// Get any text in this object for the given range |
1202 | virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; } | |
1203 | ||
1204 | /// Returns true if this object can merge itself with the given one. | |
1205 | virtual bool CanMerge(wxRichTextObject* WXUNUSED(object)) const { return false; } | |
1206 | ||
1207 | /// Returns true if this object merged itself with the given one. | |
1208 | /// The calling code will then delete the given object. | |
1209 | virtual bool Merge(wxRichTextObject* WXUNUSED(object)) { return false; } | |
1210 | ||
1211 | /// Dump to output stream for debugging | |
1212 | virtual void Dump(wxTextOutputStream& stream); | |
ce00f59b | 1213 | |
cdaed652 VZ |
1214 | /// Can we edit properties via a GUI? |
1215 | virtual bool CanEditProperties() const { return false; } | |
1216 | ||
1217 | /// Edit properties via a GUI | |
1218 | virtual bool EditProperties(wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; } | |
5d7836c4 | 1219 | |
603f702b JS |
1220 | /// Return the label to be used for the properties context menu item. |
1221 | virtual wxString GetPropertiesMenuLabel() const { return wxEmptyString; } | |
1222 | ||
1223 | /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject | |
1224 | /// is possible. For example, containers supporting text, such as a text box object, can accept the focus, | |
1225 | /// but a table can't (set the focus to individual cells instead). | |
1226 | virtual bool AcceptsFocus() const { return false; } | |
1227 | ||
bec80f4f JS |
1228 | #if wxUSE_XML |
1229 | /// Import this object from XML | |
603f702b | 1230 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
1231 | #endif |
1232 | ||
1233 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
1234 | /// Export this object directly to the given stream. | |
1235 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); | |
1236 | #endif | |
1237 | ||
1238 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
1239 | /// Export this object to the given parent node, usually creating at least one child node. | |
1240 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); | |
1241 | #endif | |
1242 | ||
1243 | /// Does this object take note of paragraph attributes? Text and image objects don't. | |
1244 | virtual bool UsesParagraphAttributes() const { return true; } | |
603f702b | 1245 | |
bec80f4f JS |
1246 | /// What is the XML node name of this object? |
1247 | virtual wxString GetXMLNodeName() const { return wxT("unknown"); } | |
1248 | ||
603f702b JS |
1249 | /// Invalidate the buffer. With no argument, invalidates whole buffer. |
1250 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); | |
1251 | ||
1252 | /// Can this object handle the selections of its children? FOr example, a table. | |
1253 | virtual bool HandlesChildSelections() const { return false; } | |
1254 | ||
1255 | /// Returns a selection object specifying the selections between start and end character positions. | |
1256 | /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table. | |
1257 | virtual wxRichTextSelection GetSelection(long WXUNUSED(start), long WXUNUSED(end)) const { return wxRichTextSelection(); } | |
1258 | ||
5d7836c4 JS |
1259 | // Accessors |
1260 | ||
1261 | /// Get/set the cached object size as calculated by Layout. | |
1262 | virtual wxSize GetCachedSize() const { return m_size; } | |
1263 | virtual void SetCachedSize(const wxSize& sz) { m_size = sz; } | |
1264 | ||
603f702b JS |
1265 | /// Get/set the maximum object size as calculated by Layout. This allows |
1266 | /// us to fit an object to its contents or allocate extra space if required. | |
1267 | virtual wxSize GetMaxSize() const { return m_maxSize; } | |
1268 | virtual void SetMaxSize(const wxSize& sz) { m_maxSize = sz; } | |
1269 | ||
1270 | /// Get/set the minimum object size as calculated by Layout. This allows | |
1271 | /// us to constrain an object to its absolute minimum size if necessary. | |
1272 | virtual wxSize GetMinSize() const { return m_minSize; } | |
1273 | virtual void SetMinSize(const wxSize& sz) { m_minSize = sz; } | |
1274 | ||
1275 | /// Get the 'natural' size for an object. For an image, it would be the | |
1276 | /// image size. | |
1277 | virtual wxTextAttrSize GetNaturalSize() const { return wxTextAttrSize(); } | |
1278 | ||
5d7836c4 JS |
1279 | /// Get/set the object position |
1280 | virtual wxPoint GetPosition() const { return m_pos; } | |
1281 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } | |
1282 | ||
603f702b JS |
1283 | /// Get the absolute object position, by traversing up the child/parent hierarchy |
1284 | /// TODO: may not be needed, if all object positions are in fact relative to the | |
1285 | /// top of the coordinate space. | |
1286 | virtual wxPoint GetAbsolutePosition() const; | |
1287 | ||
5d7836c4 JS |
1288 | /// Get the rectangle enclosing the object |
1289 | virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); } | |
1290 | ||
1291 | /// Set the range | |
1292 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
1293 | ||
1294 | /// Get the range | |
1295 | const wxRichTextRange& GetRange() const { return m_range; } | |
1296 | wxRichTextRange& GetRange() { return m_range; } | |
1297 | ||
603f702b JS |
1298 | /// Set the 'own' range, for a top-level object with its own position space |
1299 | void SetOwnRange(const wxRichTextRange& range) { m_ownRange = range; } | |
1300 | ||
1301 | /// Get own range (valid if top-level) | |
1302 | const wxRichTextRange& GetOwnRange() const { return m_ownRange; } | |
1303 | wxRichTextRange& GetOwnRange() { return m_ownRange; } | |
1304 | ||
1305 | /// Get own range only if a top-level object | |
1306 | wxRichTextRange GetOwnRangeIfTopLevel() const { return IsTopLevel() ? m_ownRange : m_range; } | |
5d7836c4 JS |
1307 | |
1308 | /// Is this composite? | |
1309 | virtual bool IsComposite() const { return false; } | |
1310 | ||
1311 | /// Get/set the parent. | |
1312 | virtual wxRichTextObject* GetParent() const { return m_parent; } | |
1313 | virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; } | |
1314 | ||
603f702b JS |
1315 | /// Get/set the top-level container of this object. |
1316 | /// May return itself if it's a container; use GetParentContainer to return | |
1317 | /// a different container. | |
1318 | virtual wxRichTextParagraphLayoutBox* GetContainer() const; | |
1319 | ||
1320 | /// Get/set the top-level container of this object. | |
1321 | /// Returns a different container than itself, unless there's no parent, in which case it will return NULL. | |
1322 | virtual wxRichTextParagraphLayoutBox* GetParentContainer() const { return GetParent() ? GetParent()->GetContainer() : GetContainer(); } | |
1323 | ||
1324 | /// Set the margin around the object, in pixels | |
5d7836c4 JS |
1325 | virtual void SetMargins(int margin); |
1326 | virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin); | |
603f702b JS |
1327 | virtual int GetLeftMargin() const; |
1328 | virtual int GetRightMargin() const; | |
1329 | virtual int GetTopMargin() const; | |
1330 | virtual int GetBottomMargin() const; | |
1331 | ||
1332 | /// Calculate the available content space in the given rectangle, given the | |
1333 | /// margins, border and padding specified in the object's attributes. | |
1334 | virtual wxRect GetAvailableContentArea(wxDC& dc, const wxRect& outerRect) const; | |
1335 | ||
1336 | /// Lays out the object first with a given amount of space, and then if no width was specified in attr, | |
1337 | /// lays out the object again using the minimum size | |
1338 | virtual bool LayoutToBestSize(wxDC& dc, wxRichTextBuffer* buffer, | |
1339 | const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr, const wxRect& availableParentSpace, int style); | |
5d7836c4 | 1340 | |
bec80f4f | 1341 | /// Set/get attributes object |
24777478 JS |
1342 | void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; } |
1343 | const wxRichTextAttr& GetAttributes() const { return m_attributes; } | |
1344 | wxRichTextAttr& GetAttributes() { return m_attributes; } | |
603f702b | 1345 | |
bec80f4f JS |
1346 | /// Set/get properties |
1347 | wxRichTextProperties& GetProperties() { return m_properties; } | |
1348 | const wxRichTextProperties& GetProperties() const { return m_properties; } | |
1349 | void SetProperties(const wxRichTextProperties& props) { m_properties = props; } | |
5d7836c4 JS |
1350 | |
1351 | /// Set/get stored descent | |
1352 | void SetDescent(int descent) { m_descent = descent; } | |
1353 | int GetDescent() const { return m_descent; } | |
1354 | ||
44219ff0 JS |
1355 | /// Gets the containing buffer |
1356 | wxRichTextBuffer* GetBuffer() const; | |
1357 | ||
603f702b JS |
1358 | /// Sets the identifying name for this object, as a property. |
1359 | void SetName(const wxString& name) { m_properties.SetProperty(wxT("name"), name); } | |
1360 | ||
1361 | /// Gets the identifying name for this object. | |
1362 | wxString GetName() const { return m_properties.GetPropertyString(wxT("name")); } | |
1363 | ||
1364 | /// Is this object top-level, i.e. with its own paragraphs, such as a text box? | |
1365 | virtual bool IsTopLevel() const { return false; } | |
1366 | ||
1367 | /// Returns @true if the object will be shown, @false otherwise. | |
1368 | bool IsShown() const { return m_show; } | |
1369 | ||
5d7836c4 JS |
1370 | // Operations |
1371 | ||
603f702b JS |
1372 | /// Call to show or hide this object. This function does not cause the content to be |
1373 | /// laid out or redrawn. | |
1374 | virtual void Show(bool show) { m_show = show; } | |
1375 | ||
5d7836c4 JS |
1376 | /// Clone the object |
1377 | virtual wxRichTextObject* Clone() const { return NULL; } | |
1378 | ||
1379 | /// Copy | |
1380 | void Copy(const wxRichTextObject& obj); | |
1381 | ||
1382 | /// Reference-counting allows us to use the same object in multiple | |
1383 | /// lists (not yet used) | |
1384 | void Reference() { m_refCount ++; } | |
1385 | void Dereference(); | |
1386 | ||
603f702b JS |
1387 | /// Move the object recursively, by adding the offset from old to new |
1388 | virtual void Move(const wxPoint& pt); | |
1389 | ||
44219ff0 | 1390 | /// Convert units in tenths of a millimetre to device units |
cdaed652 | 1391 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; |
bec80f4f | 1392 | static int ConvertTenthsMMToPixels(int ppi, int units, double scale = 1.0); |
5d7836c4 | 1393 | |
24777478 JS |
1394 | /// Convert units in pixels to tenths of a millimetre |
1395 | int ConvertPixelsToTenthsMM(wxDC& dc, int pixels) const; | |
bec80f4f | 1396 | static int ConvertPixelsToTenthsMM(int ppi, int pixels, double scale = 1.0); |
603f702b | 1397 | |
bec80f4f | 1398 | /// Draw the borders and background for the given rectangle and attributes. |
603f702b JS |
1399 | /// Width and height are taken to be the outer margin size, not the content. |
1400 | static bool DrawBoxAttributes(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, const wxRect& boxRect, int flags = 0); | |
bec80f4f JS |
1401 | |
1402 | /// Draw a border | |
603f702b | 1403 | static bool DrawBorder(wxDC& dc, wxRichTextBuffer* buffer, const wxTextAttrBorders& attr, const wxRect& rect, int flags = 0); |
bec80f4f JS |
1404 | |
1405 | /// Get the various rectangles of the box model in pixels. You can either specify contentRect (inner) | |
1406 | /// or marginRect (outer), and the other must be the default rectangle (no width or height). | |
1407 | /// Note that the outline doesn't affect the position of the rectangle, it's drawn in whatever space | |
1408 | /// is available. | |
603f702b JS |
1409 | static bool GetBoxRects(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, wxRect& marginRect, wxRect& borderRect, wxRect& contentRect, wxRect& paddingRect, wxRect& outlineRect); |
1410 | ||
1411 | /// Get the total margin for the object in pixels, taking into account margin, padding and border size | |
1412 | static bool GetTotalMargin(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, int& leftMargin, int& rightMargin, | |
1413 | int& topMargin, int& bottomMargin); | |
1414 | ||
1415 | /// Returns the rectangle which the child has available to it given restrictions specified in the | |
1416 | /// child attribute, e.g. 50% width of the parent, 400 pixels, x position 20% of the parent, etc. | |
1417 | static wxRect AdjustAvailableSpace(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& parentAttr, const wxRichTextAttr& childAttr, const wxRect& availableParentSpace); | |
24777478 | 1418 | |
5d7836c4 JS |
1419 | protected: |
1420 | wxSize m_size; | |
603f702b JS |
1421 | wxSize m_maxSize; |
1422 | wxSize m_minSize; | |
5d7836c4 JS |
1423 | wxPoint m_pos; |
1424 | int m_descent; // Descent for this object (if any) | |
5d7836c4 | 1425 | int m_refCount; |
603f702b | 1426 | bool m_show; |
5d7836c4 JS |
1427 | wxRichTextObject* m_parent; |
1428 | ||
1429 | /// The range of this object (start position to end position) | |
1430 | wxRichTextRange m_range; | |
1431 | ||
603f702b JS |
1432 | /// The internal range of this object, if it's a top-level object with its own range space |
1433 | wxRichTextRange m_ownRange; | |
5d7836c4 JS |
1434 | |
1435 | /// Attributes | |
24777478 | 1436 | wxRichTextAttr m_attributes; |
603f702b | 1437 | |
bec80f4f JS |
1438 | /// Properties |
1439 | wxRichTextProperties m_properties; | |
5d7836c4 JS |
1440 | }; |
1441 | ||
3b2cb431 | 1442 | WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 JS |
1443 | |
1444 | /*! | |
1445 | * wxRichTextCompositeObject class declaration | |
1446 | * Objects of this class can contain other objects. | |
1447 | */ | |
1448 | ||
3b2cb431 | 1449 | class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject |
5d7836c4 JS |
1450 | { |
1451 | DECLARE_CLASS(wxRichTextCompositeObject) | |
1452 | public: | |
1453 | // Constructors | |
1454 | ||
1455 | wxRichTextCompositeObject(wxRichTextObject* parent = NULL); | |
d3c7fc99 | 1456 | virtual ~wxRichTextCompositeObject(); |
5d7836c4 JS |
1457 | |
1458 | // Overrideables | |
1459 | ||
1460 | /// Hit-testing: returns a flag indicating hit test details, plus | |
1461 | /// information about position | |
603f702b | 1462 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
5d7836c4 JS |
1463 | |
1464 | /// Finds the absolute position and row height for the given character position | |
1465 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); | |
1466 | ||
1467 | /// Calculate range | |
1468 | virtual void CalculateRange(long start, long& end); | |
1469 | ||
1470 | /// Delete range | |
1471 | virtual bool DeleteRange(const wxRichTextRange& range); | |
1472 | ||
1473 | /// Get any text in this object for the given range | |
1474 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
1475 | ||
603f702b JS |
1476 | /// Gets the object size for the given range. Returns false if the range |
1477 | /// is invalid for this object. | |
1478 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; | |
1479 | ||
5d7836c4 JS |
1480 | /// Dump to output stream for debugging |
1481 | virtual void Dump(wxTextOutputStream& stream); | |
1482 | ||
603f702b JS |
1483 | /// Invalidate the buffer. With no argument, invalidates whole buffer. |
1484 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); | |
1485 | ||
5d7836c4 JS |
1486 | // Accessors |
1487 | ||
1488 | /// Get the children | |
1489 | wxRichTextObjectList& GetChildren() { return m_children; } | |
1490 | const wxRichTextObjectList& GetChildren() const { return m_children; } | |
1491 | ||
1492 | /// Get the child count | |
1493 | size_t GetChildCount() const ; | |
1494 | ||
1495 | /// Get the nth child | |
1496 | wxRichTextObject* GetChild(size_t n) const ; | |
1497 | ||
5d7836c4 JS |
1498 | /// Is this composite? |
1499 | virtual bool IsComposite() const { return true; } | |
1500 | ||
1501 | /// Returns true if the buffer is empty | |
1502 | virtual bool IsEmpty() const { return GetChildCount() == 0; } | |
1503 | ||
603f702b JS |
1504 | /// Get the child object at the given character position |
1505 | virtual wxRichTextObject* GetChildAtPosition(long pos) const; | |
1506 | ||
5d7836c4 JS |
1507 | // Operations |
1508 | ||
1509 | /// Copy | |
1510 | void Copy(const wxRichTextCompositeObject& obj); | |
1511 | ||
0ca07313 JS |
1512 | /// Assignment |
1513 | void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); } | |
1514 | ||
5d7836c4 JS |
1515 | /// Append a child, returning the position |
1516 | size_t AppendChild(wxRichTextObject* child) ; | |
1517 | ||
1518 | /// Insert the child in front of the given object, or at the beginning | |
1519 | bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ; | |
1520 | ||
1521 | /// Delete the child | |
1522 | bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ; | |
1523 | ||
1524 | /// Delete all children | |
1525 | bool DeleteChildren() ; | |
1526 | ||
1527 | /// Recursively merge all pieces that can be merged. | |
109bfc88 | 1528 | bool Defragment(const wxRichTextRange& range = wxRICHTEXT_ALL); |
5d7836c4 | 1529 | |
603f702b JS |
1530 | /// Move the object recursively, by adding the offset from old to new |
1531 | virtual void Move(const wxPoint& pt); | |
1532 | ||
5d7836c4 JS |
1533 | protected: |
1534 | wxRichTextObjectList m_children; | |
1535 | }; | |
1536 | ||
5d7836c4 JS |
1537 | /*! |
1538 | * wxRichTextParagraphBox class declaration | |
1539 | * This box knows how to lay out paragraphs. | |
1540 | */ | |
1541 | ||
bec80f4f | 1542 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextCompositeObject |
5d7836c4 JS |
1543 | { |
1544 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox) | |
1545 | public: | |
1546 | // Constructors | |
1547 | ||
1548 | wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL); | |
bec80f4f | 1549 | wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextCompositeObject() { Init(); Copy(obj); } |
cdaed652 | 1550 | ~wxRichTextParagraphLayoutBox(); |
5d7836c4 JS |
1551 | |
1552 | // Overrideables | |
1553 | ||
cdaed652 VZ |
1554 | /// Hit-testing: returns a flag indicating hit test details, plus |
1555 | /// information about position | |
603f702b | 1556 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
cdaed652 | 1557 | |
5d7836c4 | 1558 | /// Draw the item |
603f702b | 1559 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 JS |
1560 | |
1561 | /// Lay the item out | |
38113684 | 1562 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 | 1563 | |
603f702b | 1564 | /// Gets the object size for the given range. Returns false if the range |
5d7836c4 | 1565 | /// is invalid for this object. |
31778480 | 1566 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; |
5d7836c4 JS |
1567 | |
1568 | /// Delete range | |
1569 | virtual bool DeleteRange(const wxRichTextRange& range); | |
1570 | ||
1571 | /// Get any text in this object for the given range | |
1572 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
1573 | ||
bec80f4f JS |
1574 | #if wxUSE_XML |
1575 | /// Import this object from XML | |
603f702b | 1576 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
1577 | #endif |
1578 | ||
1579 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
1580 | /// Export this object directly to the given stream. | |
1581 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); | |
1582 | #endif | |
1583 | ||
1584 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
1585 | /// Export this object to the given parent node, usually creating at least one child node. | |
1586 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); | |
1587 | #endif | |
1588 | ||
1589 | /// What is the XML node name of this object? | |
1590 | virtual wxString GetXMLNodeName() const { return wxT("paragraphlayout"); } | |
1591 | ||
603f702b JS |
1592 | /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject |
1593 | /// is possible. For example, containers supporting text, such as a text box object, can accept the focus, | |
1594 | /// but a table can't (set the focus to individual cells instead). | |
1595 | virtual bool AcceptsFocus() const { return true; } | |
1596 | ||
5d7836c4 JS |
1597 | // Accessors |
1598 | ||
1599 | /// Associate a control with the buffer, for operations that for example require refreshing the window. | |
1600 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; } | |
1601 | ||
1602 | /// Get the associated control. | |
1603 | wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; } | |
1604 | ||
0ca07313 JS |
1605 | /// Get/set whether the last paragraph is partial or complete |
1606 | void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; } | |
1607 | bool GetPartialParagraph() const { return m_partialParagraph; } | |
1608 | ||
603f702b JS |
1609 | /// Returns the style sheet associated with the overall buffer. |
1610 | virtual wxRichTextStyleSheet* GetStyleSheet() const; | |
1611 | ||
1612 | /// Is this object top-level, i.e. with its own paragraphs, such as a text box? | |
1613 | virtual bool IsTopLevel() const { return true; } | |
38f833b1 | 1614 | |
5d7836c4 | 1615 | // Operations |
603f702b JS |
1616 | |
1617 | /// Submit command to insert paragraphs | |
1618 | bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); | |
1619 | ||
1620 | /// Submit command to insert the given text | |
1621 | bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); | |
1622 | ||
1623 | /// Submit command to insert the given text | |
1624 | bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); | |
1625 | ||
1626 | /// Submit command to insert the given image | |
1627 | bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, | |
1628 | wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags, | |
1629 | const wxRichTextAttr& textAttr); | |
1630 | ||
1631 | /// Get the style that is appropriate for a new paragraph at this position. | |
1632 | /// If the previous paragraph has a paragraph style name, look up the next-paragraph | |
1633 | /// style. | |
1634 | wxRichTextAttr GetStyleForNewParagraph(wxRichTextBuffer* buffer, long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const; | |
1635 | ||
1636 | /// Insert an object. | |
1637 | wxRichTextObject* InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); | |
1638 | ||
1639 | /// Submit command to delete this range | |
1640 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer); | |
1641 | ||
cdaed652 | 1642 | /// Draw the floats of this buffer |
603f702b | 1643 | void DrawFloats(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
cdaed652 VZ |
1644 | |
1645 | /// Move an anchored object to another paragraph | |
bec80f4f | 1646 | void MoveAnchoredObjectToParagraph(wxRichTextParagraph* from, wxRichTextParagraph* to, wxRichTextObject* obj); |
5d7836c4 JS |
1647 | |
1648 | /// Initialize the object. | |
1649 | void Init(); | |
1650 | ||
1651 | /// Clear all children | |
1652 | virtual void Clear(); | |
1653 | ||
1654 | /// Clear and initialize with one blank paragraph | |
1655 | virtual void Reset(); | |
1656 | ||
1657 | /// Convenience function to add a paragraph of text | |
24777478 | 1658 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1659 | |
1660 | /// Convenience function to add an image | |
24777478 | 1661 | virtual wxRichTextRange AddImage(const wxImage& image, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1662 | |
1663 | /// Adds multiple paragraphs, based on newlines. | |
24777478 | 1664 | virtual wxRichTextRange AddParagraphs(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1665 | |
1666 | /// Get the line at the given position. If caretPosition is true, the position is | |
1667 | /// a caret position, which is normally a smaller number. | |
1668 | virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const; | |
1669 | ||
1670 | /// Get the line at the given y pixel position, or the last line. | |
1671 | virtual wxRichTextLine* GetLineAtYPosition(int y) const; | |
1672 | ||
1673 | /// Get the paragraph at the given character or caret position | |
1674 | virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const; | |
1675 | ||
1676 | /// Get the line size at the given position | |
1677 | virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const; | |
1678 | ||
1679 | /// Given a position, get the number of the visible line (potentially many to a paragraph), | |
1680 | /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine) | |
1681 | /// that indicates whether the caret is being shown at the end of the previous line or at the start | |
1682 | /// of the next, since the caret can be shown at 2 visible positions for the same underlying | |
1683 | /// position. | |
1684 | virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const; | |
1685 | ||
1686 | /// Given a line number, get the corresponding wxRichTextLine object. | |
1687 | virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const; | |
1688 | ||
1689 | /// Get the leaf object in a paragraph at this position. | |
603f702b | 1690 | /// Given a position, get the corresponding wxRichTextLine object. |
5d7836c4 JS |
1691 | virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; |
1692 | ||
1693 | /// Get the paragraph by number | |
7fe8059f | 1694 | virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; |
5d7836c4 JS |
1695 | |
1696 | /// Get the paragraph for a given line | |
7fe8059f | 1697 | virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; |
5d7836c4 JS |
1698 | |
1699 | /// Get the length of the paragraph | |
1700 | virtual int GetParagraphLength(long paragraphNumber) const; | |
1701 | ||
1702 | /// Get the number of paragraphs | |
42632bce | 1703 | virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); } |
5d7836c4 JS |
1704 | |
1705 | /// Get the number of visible lines | |
1706 | virtual int GetLineCount() const; | |
1707 | ||
1708 | /// Get the text of the paragraph | |
1709 | virtual wxString GetParagraphText(long paragraphNumber) const; | |
1710 | ||
1711 | /// Convert zero-based line column and paragraph number to a position. | |
1712 | virtual long XYToPosition(long x, long y) const; | |
1713 | ||
1714 | /// Convert zero-based position to line column and paragraph number | |
1715 | virtual bool PositionToXY(long pos, long* x, long* y) const; | |
1716 | ||
1717 | /// Set text attributes: character and/or paragraph styles. | |
24777478 | 1718 | virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
5d7836c4 | 1719 | |
603f702b JS |
1720 | /// Set the attributes for the given object only, for example the box attributes for a text box. |
1721 | virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
cdaed652 | 1722 | |
603f702b | 1723 | /// Get the combined text attributes for this position. |
24777478 | 1724 | virtual bool GetStyle(long position, wxRichTextAttr& style); |
5d7836c4 | 1725 | |
fe5aa22c | 1726 | /// Get the content (uncombined) attributes for this position. |
24777478 | 1727 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); |
fe5aa22c JS |
1728 | |
1729 | /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and | |
1730 | /// context attributes. | |
24777478 | 1731 | virtual bool DoGetStyle(long position, wxRichTextAttr& style, bool combineStyles = true); |
fe5aa22c | 1732 | |
59509217 JS |
1733 | /// Get the combined style for a range - if any attribute is different within the range, |
1734 | /// that attribute is not present within the flags | |
24777478 | 1735 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); |
59509217 JS |
1736 | |
1737 | /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of | |
1738 | /// content. | |
24777478 | 1739 | bool CollectStyle(wxRichTextAttr& currentStyle, const wxRichTextAttr& style, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); |
59509217 | 1740 | |
38f833b1 JS |
1741 | /// Set list style |
1742 | virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1743 | virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1744 | ||
1745 | /// Clear list for given range | |
1746 | virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
1747 | ||
1748 | /// Number/renumber any list elements in the given range. | |
1749 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 1750 | virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
38f833b1 JS |
1751 | virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
1752 | ||
1753 | /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 | |
1754 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 1755 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
38f833b1 JS |
1756 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
1757 | ||
1758 | /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously | |
1759 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
1760 | 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); | |
1761 | ||
d2d0adc7 | 1762 | /// Fills in the attributes for numbering a paragraph after previousParagraph. |
24777478 | 1763 | virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const; |
d2d0adc7 | 1764 | |
5d7836c4 JS |
1765 | /// Test if this whole range has character attributes of the specified kind. If any |
1766 | /// of the attributes are different within the range, the test fails. You | |
1767 | /// can use this to implement, for example, bold button updating. style must have | |
1768 | /// flags indicating which attributes are of interest. | |
24777478 | 1769 | virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 JS |
1770 | |
1771 | /// Test if this whole range has paragraph attributes of the specified kind. If any | |
1772 | /// of the attributes are different within the range, the test fails. You | |
1773 | /// can use this to implement, for example, centering button updating. style must have | |
1774 | /// flags indicating which attributes are of interest. | |
24777478 | 1775 | virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 JS |
1776 | |
1777 | /// Clone | |
1778 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); } | |
1779 | ||
1780 | /// Insert fragment into this box at the given position. If partialParagraph is true, | |
1781 | /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph | |
1782 | /// marker. | |
0ca07313 | 1783 | virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 JS |
1784 | |
1785 | /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'. | |
0ca07313 | 1786 | virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 | 1787 | |
fe5aa22c JS |
1788 | /// Apply the style sheet to the buffer, for example if the styles have changed. |
1789 | virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1790 | ||
5d7836c4 JS |
1791 | /// Copy |
1792 | void Copy(const wxRichTextParagraphLayoutBox& obj); | |
1793 | ||
0ca07313 JS |
1794 | /// Assignment |
1795 | void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); } | |
1796 | ||
5d7836c4 | 1797 | /// Calculate ranges |
603f702b | 1798 | virtual void UpdateRanges(); |
5d7836c4 JS |
1799 | |
1800 | /// Get all the text | |
1801 | virtual wxString GetText() const; | |
1802 | ||
1803 | /// Set default style for new content. Setting it to a default attribute | |
1804 | /// makes new content take on the 'basic' style. | |
24777478 | 1805 | virtual bool SetDefaultStyle(const wxRichTextAttr& style); |
5d7836c4 JS |
1806 | |
1807 | /// Get default style | |
24777478 | 1808 | virtual const wxRichTextAttr& GetDefaultStyle() const { return m_defaultAttributes; } |
5d7836c4 JS |
1809 | |
1810 | /// Set basic (overall) style | |
24777478 | 1811 | virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; } |
5d7836c4 JS |
1812 | |
1813 | /// Get basic (overall) style | |
24777478 | 1814 | virtual const wxRichTextAttr& GetBasicStyle() const { return m_attributes; } |
5d7836c4 | 1815 | |
38113684 | 1816 | /// Invalidate the buffer. With no argument, invalidates whole buffer. |
603f702b JS |
1817 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
1818 | ||
1819 | /// Do the (in)validation for this object only | |
1820 | virtual void DoInvalidate(const wxRichTextRange& invalidRange); | |
1821 | ||
1822 | /// Do the (in)validation both up and down the hierarchy | |
1823 | virtual void InvalidateHierarchy(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); | |
ce00f59b | 1824 | |
cdaed652 VZ |
1825 | /// Gather information about floating objects. If untilObj is non-NULL, |
1826 | /// will stop getting information if the current object is this, since we | |
1827 | /// will collect the rest later. | |
603f702b | 1828 | virtual bool UpdateFloatingObjects(const wxRect& availableRect, wxRichTextObject* untilObj = NULL); |
38113684 JS |
1829 | |
1830 | /// Get invalid range, rounding to entire paragraphs if argument is true. | |
1831 | wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const; | |
1832 | ||
603f702b JS |
1833 | /// Does this object need layout? |
1834 | bool IsDirty() const { return m_invalidRange != wxRICHTEXT_NONE; } | |
1835 | ||
cdaed652 VZ |
1836 | /// Get the wxRichTextFloatCollector of this object |
1837 | wxRichTextFloatCollector* GetFloatCollector() { return m_floatCollector; } | |
1838 | ||
603f702b JS |
1839 | /// Get the number of floating objects at this level |
1840 | int GetFloatingObjectCount() const; | |
1841 | ||
1842 | /// Get a list of floating objects | |
1843 | bool GetFloatingObjects(wxRichTextObjectList& objects) const; | |
1844 | ||
5d7836c4 JS |
1845 | protected: |
1846 | wxRichTextCtrl* m_ctrl; | |
24777478 | 1847 | wxRichTextAttr m_defaultAttributes; |
38113684 JS |
1848 | |
1849 | /// The invalidated range that will need full layout | |
0ca07313 | 1850 | wxRichTextRange m_invalidRange; |
5d7836c4 JS |
1851 | |
1852 | // Is the last paragraph partial or complete? | |
0ca07313 | 1853 | bool m_partialParagraph; |
cdaed652 VZ |
1854 | |
1855 | // The floating layout state | |
1856 | wxRichTextFloatCollector* m_floatCollector; | |
5d7836c4 JS |
1857 | }; |
1858 | ||
603f702b JS |
1859 | /** |
1860 | @class wxRichTextBox | |
1861 | ||
1862 | wxRichTextBox is a floating or inline text box, containing paragraphs. | |
bec80f4f JS |
1863 | */ |
1864 | ||
603f702b | 1865 | class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextParagraphLayoutBox |
bec80f4f JS |
1866 | { |
1867 | DECLARE_DYNAMIC_CLASS(wxRichTextBox) | |
1868 | public: | |
1869 | // Constructors | |
1870 | ||
603f702b JS |
1871 | /** |
1872 | Default constructor; optionally pass the parent object. | |
1873 | */ | |
1874 | ||
bec80f4f | 1875 | wxRichTextBox(wxRichTextObject* parent = NULL); |
603f702b JS |
1876 | |
1877 | /** | |
1878 | Copy constructor. | |
1879 | */ | |
1880 | ||
1881 | wxRichTextBox(const wxRichTextBox& obj): wxRichTextParagraphLayoutBox() { Copy(obj); } | |
bec80f4f JS |
1882 | |
1883 | // Overrideables | |
1884 | ||
603f702b JS |
1885 | /** |
1886 | Draws the item. | |
1887 | */ | |
bec80f4f | 1888 | |
603f702b | 1889 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
bec80f4f | 1890 | |
603f702b JS |
1891 | /** |
1892 | Returns the XML node name of this object. | |
1893 | */ | |
1894 | ||
1895 | virtual wxString GetXMLNodeName() const { return wxT("textbox"); } | |
1896 | ||
1897 | /// Can we edit properties via a GUI? | |
1898 | virtual bool CanEditProperties() const { return true; } | |
1899 | ||
1900 | /// Edit properties via a GUI | |
1901 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
1902 | ||
1903 | /// Return the label to be used for the properties context menu item. | |
1904 | virtual wxString GetPropertiesMenuLabel() const { return _("&Box"); } | |
5ad9ae3a | 1905 | |
bec80f4f JS |
1906 | // Accessors |
1907 | ||
1908 | // Operations | |
1909 | ||
603f702b JS |
1910 | /** |
1911 | Makes a clone of this object. | |
1912 | */ | |
bec80f4f JS |
1913 | virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); } |
1914 | ||
603f702b JS |
1915 | /** |
1916 | Copies this object. | |
1917 | */ | |
bec80f4f JS |
1918 | void Copy(const wxRichTextBox& obj); |
1919 | ||
1920 | protected: | |
1921 | }; | |
1922 | ||
5d7836c4 JS |
1923 | /*! |
1924 | * wxRichTextLine class declaration | |
1925 | * This object represents a line in a paragraph, and stores | |
1926 | * offsets from the start of the paragraph representing the | |
1927 | * start and end positions of the line. | |
1928 | */ | |
1929 | ||
3b2cb431 | 1930 | class WXDLLIMPEXP_RICHTEXT wxRichTextLine |
5d7836c4 JS |
1931 | { |
1932 | public: | |
1933 | // Constructors | |
1934 | ||
1935 | wxRichTextLine(wxRichTextParagraph* parent); | |
1e967276 | 1936 | wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); } |
5d7836c4 JS |
1937 | virtual ~wxRichTextLine() {} |
1938 | ||
1939 | // Overrideables | |
1940 | ||
1941 | // Accessors | |
1942 | ||
1943 | /// Set the range | |
1944 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
1945 | void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); } | |
1946 | ||
1947 | /// Get the parent paragraph | |
1948 | wxRichTextParagraph* GetParent() { return m_parent; } | |
1949 | ||
1950 | /// Get the range | |
1951 | const wxRichTextRange& GetRange() const { return m_range; } | |
1952 | wxRichTextRange& GetRange() { return m_range; } | |
1953 | ||
1e967276 JS |
1954 | /// Get the absolute range |
1955 | wxRichTextRange GetAbsoluteRange() const; | |
1956 | ||
5d7836c4 JS |
1957 | /// Get/set the line size as calculated by Layout. |
1958 | virtual wxSize GetSize() const { return m_size; } | |
1959 | virtual void SetSize(const wxSize& sz) { m_size = sz; } | |
1960 | ||
1961 | /// Get/set the object position relative to the parent | |
1962 | virtual wxPoint GetPosition() const { return m_pos; } | |
1963 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } | |
1964 | ||
1965 | /// Get the absolute object position | |
1966 | virtual wxPoint GetAbsolutePosition() const; | |
1967 | ||
1968 | /// Get the rectangle enclosing the line | |
1969 | virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); } | |
1970 | ||
1971 | /// Set/get stored descent | |
1972 | void SetDescent(int descent) { m_descent = descent; } | |
1973 | int GetDescent() const { return m_descent; } | |
1974 | ||
2f45f554 JS |
1975 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING |
1976 | wxArrayInt& GetObjectSizes() { return m_objectSizes; } | |
1977 | const wxArrayInt& GetObjectSizes() const { return m_objectSizes; } | |
1978 | #endif | |
1979 | ||
5d7836c4 JS |
1980 | // Operations |
1981 | ||
1982 | /// Initialisation | |
1e967276 | 1983 | void Init(wxRichTextParagraph* parent); |
5d7836c4 JS |
1984 | |
1985 | /// Copy | |
1986 | void Copy(const wxRichTextLine& obj); | |
1987 | ||
1988 | /// Clone | |
1989 | virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); } | |
1990 | ||
1991 | protected: | |
1992 | ||
1993 | /// The range of the line (start position to end position) | |
1e967276 | 1994 | /// This is relative to the parent paragraph. |
5d7836c4 JS |
1995 | wxRichTextRange m_range; |
1996 | ||
1997 | /// Size and position measured relative to top of paragraph | |
1998 | wxPoint m_pos; | |
1999 | wxSize m_size; | |
2000 | ||
2001 | /// Maximum descent for this line (location of text baseline) | |
2002 | int m_descent; | |
2003 | ||
2004 | // The parent object | |
2005 | wxRichTextParagraph* m_parent; | |
2f45f554 JS |
2006 | |
2007 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING | |
2008 | wxArrayInt m_objectSizes; | |
2009 | #endif | |
5d7836c4 JS |
2010 | }; |
2011 | ||
3b2cb431 | 2012 | WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 JS |
2013 | |
2014 | /*! | |
2015 | * wxRichTextParagraph class declaration | |
2016 | * This object represents a single paragraph (or in a straight text editor, a line). | |
2017 | */ | |
2018 | ||
603f702b | 2019 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextCompositeObject |
5d7836c4 JS |
2020 | { |
2021 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraph) | |
2022 | public: | |
2023 | // Constructors | |
2024 | ||
24777478 JS |
2025 | wxRichTextParagraph(wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
2026 | wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxRichTextAttr* paraStyle = NULL, wxRichTextAttr* charStyle = NULL); | |
d3c7fc99 | 2027 | virtual ~wxRichTextParagraph(); |
603f702b | 2028 | wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextCompositeObject() { Copy(obj); } |
5d7836c4 JS |
2029 | |
2030 | // Overrideables | |
2031 | ||
2032 | /// Draw the item | |
603f702b | 2033 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 JS |
2034 | |
2035 | /// Lay the item out | |
38113684 | 2036 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 | 2037 | |
603f702b | 2038 | /// Gets the object size for the given range. Returns false if the range |
5d7836c4 | 2039 | /// is invalid for this object. |
31778480 | 2040 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; |
5d7836c4 JS |
2041 | |
2042 | /// Finds the absolute position and row height for the given character position | |
2043 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); | |
2044 | ||
2045 | /// Hit-testing: returns a flag indicating hit test details, plus | |
603f702b JS |
2046 | /// information about position and the object that was found. |
2047 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); | |
5d7836c4 JS |
2048 | |
2049 | /// Calculate range | |
2050 | virtual void CalculateRange(long start, long& end); | |
2051 | ||
bec80f4f JS |
2052 | /// What is the XML node name of this object? |
2053 | virtual wxString GetXMLNodeName() const { return wxT("paragraph"); } | |
2054 | ||
5d7836c4 JS |
2055 | // Accessors |
2056 | ||
2057 | /// Get the cached lines | |
2058 | wxRichTextLineList& GetLines() { return m_cachedLines; } | |
2059 | ||
2060 | // Operations | |
2061 | ||
2062 | /// Copy | |
2063 | void Copy(const wxRichTextParagraph& obj); | |
2064 | ||
2065 | /// Clone | |
2066 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); } | |
2067 | ||
2068 | /// Clear the cached lines | |
2069 | void ClearLines(); | |
2070 | ||
2071 | // Implementation | |
2072 | ||
2073 | /// Apply paragraph styles such as centering to the wrapped lines | |
603f702b | 2074 | virtual void ApplyParagraphStyle(wxRichTextLine* line, const wxRichTextAttr& attr, const wxRect& rect, wxDC& dc); |
5d7836c4 JS |
2075 | |
2076 | /// Insert text at the given position | |
2077 | virtual bool InsertText(long pos, const wxString& text); | |
2078 | ||
2079 | /// Split an object at this position if necessary, and return | |
2080 | /// the previous object, or NULL if inserting at beginning. | |
2081 | virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL); | |
2082 | ||
2083 | /// Move content to a list from this point | |
2084 | virtual void MoveToList(wxRichTextObject* obj, wxList& list); | |
2085 | ||
2086 | /// Add content back from list | |
2087 | virtual void MoveFromList(wxList& list); | |
2088 | ||
2089 | /// Get the plain text searching from the start or end of the range. | |
2090 | /// The resulting string may be shorter than the range given. | |
2091 | bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true); | |
2092 | ||
2093 | /// Find a suitable wrap position. wrapPosition is the last position in the line to the left | |
2094 | /// of the split. | |
31778480 | 2095 | bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); |
5d7836c4 JS |
2096 | |
2097 | /// Find the object at the given position | |
2098 | wxRichTextObject* FindObjectAtPosition(long position); | |
2099 | ||
2100 | /// Get the bullet text for this paragraph. | |
2101 | wxString GetBulletText(); | |
2102 | ||
1e967276 JS |
2103 | /// Allocate or reuse a line object |
2104 | wxRichTextLine* AllocateLine(int pos); | |
2105 | ||
2106 | /// Clear remaining unused line objects, if any | |
2107 | bool ClearUnusedLines(int lineCount); | |
2108 | ||
fe5aa22c JS |
2109 | /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically |
2110 | /// retrieve the actual style. | |
603f702b | 2111 | wxRichTextAttr GetCombinedAttributes(const wxRichTextAttr& contentStyle, bool includingBoxAttr = false) const; |
fe5aa22c JS |
2112 | |
2113 | /// Get combined attributes of the base style and paragraph style. | |
603f702b | 2114 | wxRichTextAttr GetCombinedAttributes(bool includingBoxAttr = false) const; |
fe5aa22c | 2115 | |
ff76711f JS |
2116 | /// Get the first position from pos that has a line break character. |
2117 | long GetFirstLineBreakPosition(long pos); | |
2118 | ||
cfa3b256 JS |
2119 | /// Create default tabstop array |
2120 | static void InitDefaultTabs(); | |
2121 | ||
2122 | /// Clear default tabstop array | |
2123 | static void ClearDefaultTabs(); | |
2124 | ||
2125 | /// Get default tabstop array | |
2126 | static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; } | |
2127 | ||
cdaed652 VZ |
2128 | /// Layout the floats object |
2129 | void LayoutFloat(wxDC& dc, const wxRect& rect, int style, wxRichTextFloatCollector* floatCollector); | |
2130 | ||
5d7836c4 JS |
2131 | protected: |
2132 | /// The lines that make up the wrapped paragraph | |
2133 | wxRichTextLineList m_cachedLines; | |
cfa3b256 JS |
2134 | |
2135 | /// Default tabstops | |
2136 | static wxArrayInt sm_defaultTabs; | |
cdaed652 VZ |
2137 | |
2138 | friend class wxRichTextFloatCollector; | |
5d7836c4 JS |
2139 | }; |
2140 | ||
2141 | /*! | |
2142 | * wxRichTextPlainText class declaration | |
2143 | * This object represents a single piece of text. | |
2144 | */ | |
2145 | ||
3b2cb431 | 2146 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject |
5d7836c4 JS |
2147 | { |
2148 | DECLARE_DYNAMIC_CLASS(wxRichTextPlainText) | |
2149 | public: | |
2150 | // Constructors | |
2151 | ||
24777478 | 2152 | wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
0ca07313 | 2153 | wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); } |
5d7836c4 JS |
2154 | |
2155 | // Overrideables | |
2156 | ||
2157 | /// Draw the item | |
603f702b | 2158 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 JS |
2159 | |
2160 | /// Lay the item out | |
38113684 | 2161 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 | 2162 | |
603f702b | 2163 | /// Gets the object size for the given range. Returns false if the range |
5d7836c4 | 2164 | /// is invalid for this object. |
31778480 | 2165 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; |
5d7836c4 JS |
2166 | |
2167 | /// Get any text in this object for the given range | |
2168 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
2169 | ||
2170 | /// Do a split, returning an object containing the second part, and setting | |
2171 | /// the first part in 'this'. | |
2172 | virtual wxRichTextObject* DoSplit(long pos); | |
2173 | ||
2174 | /// Calculate range | |
2175 | virtual void CalculateRange(long start, long& end); | |
2176 | ||
2177 | /// Delete range | |
2178 | virtual bool DeleteRange(const wxRichTextRange& range); | |
2179 | ||
2180 | /// Returns true if the object is empty | |
7fe8059f | 2181 | virtual bool IsEmpty() const { return m_text.empty(); } |
5d7836c4 JS |
2182 | |
2183 | /// Returns true if this object can merge itself with the given one. | |
2184 | virtual bool CanMerge(wxRichTextObject* object) const; | |
2185 | ||
2186 | /// Returns true if this object merged itself with the given one. | |
2187 | /// The calling code will then delete the given object. | |
2188 | virtual bool Merge(wxRichTextObject* object); | |
2189 | ||
2190 | /// Dump to output stream for debugging | |
2191 | virtual void Dump(wxTextOutputStream& stream); | |
2192 | ||
ff76711f JS |
2193 | /// Get the first position from pos that has a line break character. |
2194 | long GetFirstLineBreakPosition(long pos); | |
2195 | ||
bec80f4f JS |
2196 | /// Does this object take note of paragraph attributes? Text and image objects don't. |
2197 | virtual bool UsesParagraphAttributes() const { return false; } | |
2198 | ||
2199 | #if wxUSE_XML | |
2200 | /// Import this object from XML | |
603f702b | 2201 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
2202 | #endif |
2203 | ||
2204 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
2205 | /// Export this object directly to the given stream. | |
2206 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); | |
2207 | #endif | |
2208 | ||
2209 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
2210 | /// Export this object to the given parent node, usually creating at least one child node. | |
2211 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); | |
2212 | #endif | |
2213 | ||
2214 | /// What is the XML node name of this object? | |
2215 | virtual wxString GetXMLNodeName() const { return wxT("text"); } | |
2216 | ||
5d7836c4 JS |
2217 | // Accessors |
2218 | ||
2219 | /// Get the text | |
2220 | const wxString& GetText() const { return m_text; } | |
2221 | ||
2222 | /// Set the text | |
2223 | void SetText(const wxString& text) { m_text = text; } | |
2224 | ||
2225 | // Operations | |
2226 | ||
2227 | /// Copy | |
2228 | void Copy(const wxRichTextPlainText& obj); | |
2229 | ||
2230 | /// Clone | |
2231 | virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); } | |
7f0d9d71 | 2232 | private: |
24777478 | 2233 | bool DrawTabbedString(wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected); |
5d7836c4 JS |
2234 | |
2235 | protected: | |
2236 | wxString m_text; | |
2237 | }; | |
2238 | ||
2239 | /*! | |
2240 | * wxRichTextImageBlock stores information about an image, in binary in-memory form | |
2241 | */ | |
2242 | ||
b5dbe15d VS |
2243 | class WXDLLIMPEXP_FWD_BASE wxDataInputStream; |
2244 | class WXDLLIMPEXP_FWD_BASE wxDataOutputStream; | |
5d7836c4 | 2245 | |
3b2cb431 | 2246 | class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject |
5d7836c4 JS |
2247 | { |
2248 | public: | |
2249 | wxRichTextImageBlock(); | |
2250 | wxRichTextImageBlock(const wxRichTextImageBlock& block); | |
d3c7fc99 | 2251 | virtual ~wxRichTextImageBlock(); |
5d7836c4 JS |
2252 | |
2253 | void Init(); | |
2254 | void Clear(); | |
2255 | ||
2256 | // Load the original image into a memory block. | |
2257 | // If the image is not a JPEG, we must convert it into a JPEG | |
2258 | // to conserve space. | |
2259 | // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to | |
2260 | // load the image a 2nd time. | |
d75a69e8 FM |
2261 | virtual bool MakeImageBlock(const wxString& filename, wxBitmapType imageType, |
2262 | wxImage& image, bool convertToJPEG = true); | |
5d7836c4 JS |
2263 | |
2264 | // Make an image block from the wxImage in the given | |
2265 | // format. | |
d75a69e8 | 2266 | virtual bool MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality = 80); |
ce00f59b | 2267 | |
cdaed652 VZ |
2268 | // Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG) |
2269 | virtual bool MakeImageBlockDefaultQuality(const wxImage& image, wxBitmapType imageType); | |
2270 | ||
2271 | // Makes the image block | |
2272 | virtual bool DoMakeImageBlock(const wxImage& image, wxBitmapType imageType); | |
5d7836c4 JS |
2273 | |
2274 | // Write to a file | |
2275 | bool Write(const wxString& filename); | |
2276 | ||
2277 | // Write data in hex to a stream | |
2278 | bool WriteHex(wxOutputStream& stream); | |
2279 | ||
2280 | // Read data in hex from a stream | |
d75a69e8 | 2281 | bool ReadHex(wxInputStream& stream, int length, wxBitmapType imageType); |
5d7836c4 JS |
2282 | |
2283 | // Copy from 'block' | |
2284 | void Copy(const wxRichTextImageBlock& block); | |
2285 | ||
2286 | // Load a wxImage from the block | |
2287 | bool Load(wxImage& image); | |
2288 | ||
2289 | //// Operators | |
2290 | void operator=(const wxRichTextImageBlock& block); | |
2291 | ||
2292 | //// Accessors | |
2293 | ||
2294 | unsigned char* GetData() const { return m_data; } | |
2295 | size_t GetDataSize() const { return m_dataSize; } | |
d75a69e8 | 2296 | wxBitmapType GetImageType() const { return m_imageType; } |
5d7836c4 JS |
2297 | |
2298 | void SetData(unsigned char* image) { m_data = image; } | |
2299 | void SetDataSize(size_t size) { m_dataSize = size; } | |
d75a69e8 | 2300 | void SetImageType(wxBitmapType imageType) { m_imageType = imageType; } |
5d7836c4 | 2301 | |
b7cacb43 VZ |
2302 | bool Ok() const { return IsOk(); } |
2303 | bool IsOk() const { return GetData() != NULL; } | |
5d7836c4 | 2304 | |
d2d0adc7 JS |
2305 | // Gets the extension for the block's type |
2306 | wxString GetExtension() const; | |
2307 | ||
5d7836c4 JS |
2308 | /// Implementation |
2309 | ||
d2d0adc7 | 2310 | // Allocate and read from stream as a block of memory |
5d7836c4 JS |
2311 | static unsigned char* ReadBlock(wxInputStream& stream, size_t size); |
2312 | static unsigned char* ReadBlock(const wxString& filename, size_t size); | |
2313 | ||
2314 | // Write memory block to stream | |
2315 | static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size); | |
2316 | ||
2317 | // Write memory block to file | |
2318 | static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size); | |
2319 | ||
2320 | protected: | |
2321 | // Size in bytes of the image stored. | |
2322 | // This is in the raw, original form such as a JPEG file. | |
2323 | unsigned char* m_data; | |
2324 | size_t m_dataSize; | |
d75a69e8 | 2325 | wxBitmapType m_imageType; |
5d7836c4 JS |
2326 | }; |
2327 | ||
5d7836c4 JS |
2328 | /*! |
2329 | * wxRichTextImage class declaration | |
2330 | * This object represents an image. | |
2331 | */ | |
2332 | ||
bec80f4f | 2333 | class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject |
5d7836c4 JS |
2334 | { |
2335 | DECLARE_DYNAMIC_CLASS(wxRichTextImage) | |
2336 | public: | |
2337 | // Constructors | |
2338 | ||
bec80f4f | 2339 | wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { } |
24777478 JS |
2340 | wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); |
2341 | wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); | |
bec80f4f | 2342 | wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject(obj) { Copy(obj); } |
5d7836c4 JS |
2343 | |
2344 | // Overrideables | |
2345 | ||
2346 | /// Draw the item | |
603f702b | 2347 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 JS |
2348 | |
2349 | /// Lay the item out | |
38113684 | 2350 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
2351 | |
2352 | /// Get the object size for the given range. Returns false if the range | |
2353 | /// is invalid for this object. | |
31778480 | 2354 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; |
5d7836c4 | 2355 | |
603f702b JS |
2356 | /// Get the 'natural' size for an object. For an image, it would be the |
2357 | /// image size. | |
2358 | virtual wxTextAttrSize GetNaturalSize() const; | |
2359 | ||
bec80f4f JS |
2360 | /// Returns true if the object is empty. An image is never empty; if the image is broken, that's not the same thing as empty. |
2361 | virtual bool IsEmpty() const { return false; /* !m_imageBlock.Ok(); */ } | |
cdaed652 VZ |
2362 | |
2363 | /// Can we edit properties via a GUI? | |
2364 | virtual bool CanEditProperties() const { return true; } | |
2365 | ||
2366 | /// Edit properties via a GUI | |
2367 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
5d7836c4 | 2368 | |
603f702b JS |
2369 | /// Return the label to be used for the properties context menu item. |
2370 | virtual wxString GetPropertiesMenuLabel() const { return _("&Picture"); } | |
2371 | ||
bec80f4f JS |
2372 | /// Does this object take note of paragraph attributes? Text and image objects don't. |
2373 | virtual bool UsesParagraphAttributes() const { return false; } | |
2374 | ||
2375 | #if wxUSE_XML | |
2376 | /// Import this object from XML | |
603f702b | 2377 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
2378 | #endif |
2379 | ||
2380 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
2381 | /// Export this object directly to the given stream. | |
2382 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); | |
2383 | #endif | |
2384 | ||
2385 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
2386 | /// Export this object to the given parent node, usually creating at least one child node. | |
2387 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); | |
2388 | #endif | |
2389 | ||
2390 | // Images can be floatable (optionally). | |
2391 | virtual bool IsFloatable() const { return true; } | |
2392 | ||
2393 | /// What is the XML node name of this object? | |
2394 | virtual wxString GetXMLNodeName() const { return wxT("image"); } | |
2395 | ||
5d7836c4 JS |
2396 | // Accessors |
2397 | ||
cdaed652 VZ |
2398 | /// Get the image cache (scaled bitmap) |
2399 | const wxBitmap& GetImageCache() const { return m_imageCache; } | |
5d7836c4 | 2400 | |
cdaed652 VZ |
2401 | /// Set the image cache |
2402 | void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; } | |
2403 | ||
2404 | /// Reset the image cache | |
2405 | void ResetImageCache() { m_imageCache = wxNullBitmap; } | |
5d7836c4 JS |
2406 | |
2407 | /// Get the image block containing the raw data | |
2408 | wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; } | |
2409 | ||
2410 | // Operations | |
2411 | ||
2412 | /// Copy | |
2413 | void Copy(const wxRichTextImage& obj); | |
2414 | ||
2415 | /// Clone | |
2416 | virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); } | |
2417 | ||
cdaed652 VZ |
2418 | /// Create a cached image at the required size |
2419 | virtual bool LoadImageCache(wxDC& dc, bool resetCache = false); | |
5d7836c4 JS |
2420 | |
2421 | protected: | |
5d7836c4 | 2422 | wxRichTextImageBlock m_imageBlock; |
cdaed652 | 2423 | wxBitmap m_imageCache; |
5d7836c4 JS |
2424 | }; |
2425 | ||
2426 | ||
2427 | /*! | |
2428 | * wxRichTextBuffer class declaration | |
2429 | * This is a kind of box, used to represent the whole buffer | |
2430 | */ | |
2431 | ||
b5dbe15d VS |
2432 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand; |
2433 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; | |
5d7836c4 | 2434 | |
3b2cb431 | 2435 | class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox |
5d7836c4 JS |
2436 | { |
2437 | DECLARE_DYNAMIC_CLASS(wxRichTextBuffer) | |
2438 | public: | |
2439 | // Constructors | |
2440 | ||
2441 | wxRichTextBuffer() { Init(); } | |
0ca07313 | 2442 | wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); } |
d3c7fc99 | 2443 | virtual ~wxRichTextBuffer() ; |
5d7836c4 JS |
2444 | |
2445 | // Accessors | |
2446 | ||
2447 | /// Gets the command processor | |
2448 | wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; } | |
2449 | ||
2450 | /// Set style sheet, if any. | |
2451 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } | |
38f833b1 JS |
2452 | virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } |
2453 | ||
d2d0adc7 JS |
2454 | /// Set style sheet and notify of the change |
2455 | bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet); | |
2456 | ||
38f833b1 JS |
2457 | /// Push style sheet to top of stack |
2458 | bool PushStyleSheet(wxRichTextStyleSheet* styleSheet); | |
2459 | ||
2460 | /// Pop style sheet from top of stack | |
2461 | wxRichTextStyleSheet* PopStyleSheet(); | |
5d7836c4 | 2462 | |
44cc96a8 JS |
2463 | /// Set/get table storing fonts |
2464 | wxRichTextFontTable& GetFontTable() { return m_fontTable; } | |
2465 | const wxRichTextFontTable& GetFontTable() const { return m_fontTable; } | |
2466 | void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; } | |
2467 | ||
5d7836c4 JS |
2468 | // Operations |
2469 | ||
2470 | /// Initialisation | |
2471 | void Init(); | |
2472 | ||
85d8909b JS |
2473 | /// Clears the buffer, adds an empty paragraph, and clears the command processor. |
2474 | virtual void ResetAndClearCommands(); | |
5d7836c4 JS |
2475 | |
2476 | /// Load a file | |
d75a69e8 | 2477 | virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
2478 | |
2479 | /// Save a file | |
d75a69e8 | 2480 | virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
2481 | |
2482 | /// Load from a stream | |
d75a69e8 | 2483 | virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
2484 | |
2485 | /// Save to a stream | |
d75a69e8 | 2486 | virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 | 2487 | |
d2d0adc7 JS |
2488 | /// Set the handler flags, controlling loading and saving |
2489 | void SetHandlerFlags(int flags) { m_handlerFlags = flags; } | |
2490 | ||
2491 | /// Get the handler flags, controlling loading and saving | |
2492 | int GetHandlerFlags() const { return m_handlerFlags; } | |
2493 | ||
5d7836c4 | 2494 | /// Convenience function to add a paragraph of text |
24777478 | 2495 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); } |
5d7836c4 JS |
2496 | |
2497 | /// Begin collapsing undo/redo commands. Note that this may not work properly | |
2498 | /// if combining commands that delete or insert content, changing ranges for | |
2499 | /// subsequent actions. | |
2500 | virtual bool BeginBatchUndo(const wxString& cmdName); | |
2501 | ||
2502 | /// End collapsing undo/redo commands | |
2503 | virtual bool EndBatchUndo(); | |
2504 | ||
2505 | /// Collapsing commands? | |
2506 | virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; } | |
2507 | ||
2508 | /// Submit immediately, or delay according to whether collapsing is on | |
2509 | virtual bool SubmitAction(wxRichTextAction* action); | |
2510 | ||
2511 | /// Get collapsed command | |
2512 | virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; } | |
2513 | ||
2514 | /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented | |
2515 | /// differently by each command. If not dealt with by a command implementation, then | |
2516 | /// it will be implemented automatically by not storing the command in the undo history | |
2517 | /// when the action is submitted to the command processor. | |
2518 | virtual bool BeginSuppressUndo(); | |
2519 | ||
2520 | /// End suppressing undo/redo commands. | |
2521 | virtual bool EndSuppressUndo(); | |
2522 | ||
2523 | /// Collapsing commands? | |
2524 | virtual bool SuppressingUndo() const { return m_suppressUndo > 0; } | |
2525 | ||
2526 | /// Copy the range to the clipboard | |
2527 | virtual bool CopyToClipboard(const wxRichTextRange& range); | |
2528 | ||
2529 | /// Paste the clipboard content to the buffer | |
2530 | virtual bool PasteFromClipboard(long position); | |
2531 | ||
2532 | /// Can we paste from the clipboard? | |
2533 | virtual bool CanPasteFromClipboard() const; | |
2534 | ||
2535 | /// Begin using a style | |
24777478 | 2536 | virtual bool BeginStyle(const wxRichTextAttr& style); |
5d7836c4 JS |
2537 | |
2538 | /// End the style | |
2539 | virtual bool EndStyle(); | |
2540 | ||
2541 | /// End all styles | |
2542 | virtual bool EndAllStyles(); | |
2543 | ||
2544 | /// Clear the style stack | |
2545 | virtual void ClearStyleStack(); | |
2546 | ||
2547 | /// Get the size of the style stack, for example to check correct nesting | |
3b38e2a0 | 2548 | virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); } |
5d7836c4 JS |
2549 | |
2550 | /// Begin using bold | |
2551 | bool BeginBold(); | |
2552 | ||
2553 | /// End using bold | |
2554 | bool EndBold() { return EndStyle(); } | |
2555 | ||
2556 | /// Begin using italic | |
2557 | bool BeginItalic(); | |
2558 | ||
2559 | /// End using italic | |
2560 | bool EndItalic() { return EndStyle(); } | |
2561 | ||
2562 | /// Begin using underline | |
2563 | bool BeginUnderline(); | |
2564 | ||
2565 | /// End using underline | |
2566 | bool EndUnderline() { return EndStyle(); } | |
2567 | ||
2568 | /// Begin using point size | |
2569 | bool BeginFontSize(int pointSize); | |
2570 | ||
2571 | /// End using point size | |
2572 | bool EndFontSize() { return EndStyle(); } | |
2573 | ||
2574 | /// Begin using this font | |
2575 | bool BeginFont(const wxFont& font); | |
2576 | ||
2577 | /// End using a font | |
2578 | bool EndFont() { return EndStyle(); } | |
2579 | ||
2580 | /// Begin using this colour | |
2581 | bool BeginTextColour(const wxColour& colour); | |
2582 | ||
2583 | /// End using a colour | |
2584 | bool EndTextColour() { return EndStyle(); } | |
2585 | ||
2586 | /// Begin using alignment | |
2587 | bool BeginAlignment(wxTextAttrAlignment alignment); | |
2588 | ||
2589 | /// End alignment | |
2590 | bool EndAlignment() { return EndStyle(); } | |
2591 | ||
2592 | /// Begin left indent | |
2593 | bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0); | |
2594 | ||
2595 | /// End left indent | |
2596 | bool EndLeftIndent() { return EndStyle(); } | |
2597 | ||
2598 | /// Begin right indent | |
2599 | bool BeginRightIndent(int rightIndent); | |
2600 | ||
2601 | /// End right indent | |
2602 | bool EndRightIndent() { return EndStyle(); } | |
2603 | ||
2604 | /// Begin paragraph spacing | |
2605 | bool BeginParagraphSpacing(int before, int after); | |
2606 | ||
2607 | /// End paragraph spacing | |
2608 | bool EndParagraphSpacing() { return EndStyle(); } | |
2609 | ||
2610 | /// Begin line spacing | |
2611 | bool BeginLineSpacing(int lineSpacing); | |
2612 | ||
2613 | /// End line spacing | |
2614 | bool EndLineSpacing() { return EndStyle(); } | |
2615 | ||
2616 | /// Begin numbered bullet | |
2617 | bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD); | |
2618 | ||
2619 | /// End numbered bullet | |
2620 | bool EndNumberedBullet() { return EndStyle(); } | |
2621 | ||
2622 | /// Begin symbol bullet | |
d2d0adc7 | 2623 | bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL); |
5d7836c4 JS |
2624 | |
2625 | /// End symbol bullet | |
2626 | bool EndSymbolBullet() { return EndStyle(); } | |
2627 | ||
f089713f JS |
2628 | /// Begin standard bullet |
2629 | bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD); | |
2630 | ||
2631 | /// End standard bullet | |
2632 | bool EndStandardBullet() { return EndStyle(); } | |
2633 | ||
5d7836c4 JS |
2634 | /// Begin named character style |
2635 | bool BeginCharacterStyle(const wxString& characterStyle); | |
2636 | ||
2637 | /// End named character style | |
2638 | bool EndCharacterStyle() { return EndStyle(); } | |
2639 | ||
2640 | /// Begin named paragraph style | |
2641 | bool BeginParagraphStyle(const wxString& paragraphStyle); | |
2642 | ||
2643 | /// End named character style | |
2644 | bool EndParagraphStyle() { return EndStyle(); } | |
f089713f JS |
2645 | |
2646 | /// Begin named list style | |
2647 | bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1); | |
2648 | ||
2649 | /// End named character style | |
2650 | bool EndListStyle() { return EndStyle(); } | |
5d7836c4 | 2651 | |
d2d0adc7 JS |
2652 | /// Begin URL |
2653 | bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString); | |
2654 | ||
2655 | /// End URL | |
2656 | bool EndURL() { return EndStyle(); } | |
2657 | ||
2658 | // Event handling | |
2659 | ||
2660 | /// Add an event handler | |
2661 | bool AddEventHandler(wxEvtHandler* handler); | |
2662 | ||
2663 | /// Remove an event handler | |
2664 | bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false); | |
2665 | ||
2666 | /// Clear event handlers | |
2667 | void ClearEventHandlers(); | |
2668 | ||
2669 | /// Send event to event handlers. If sendToAll is true, will send to all event handlers, | |
2670 | /// otherwise will stop at the first successful one. | |
2671 | bool SendEvent(wxEvent& event, bool sendToAll = true); | |
2672 | ||
5d7836c4 JS |
2673 | // Implementation |
2674 | ||
603f702b JS |
2675 | /// Hit-testing: returns a flag indicating hit test details, plus |
2676 | /// information about position | |
2677 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); | |
2678 | ||
5d7836c4 | 2679 | /// Copy |
0ca07313 | 2680 | void Copy(const wxRichTextBuffer& obj); |
5d7836c4 | 2681 | |
bec80f4f JS |
2682 | /// Assignment |
2683 | void operator= (const wxRichTextBuffer& obj) { Copy(obj); } | |
2684 | ||
5d7836c4 JS |
2685 | /// Clone |
2686 | virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); } | |
2687 | ||
0ca07313 JS |
2688 | /// Submit command to insert paragraphs |
2689 | bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); | |
2690 | ||
5d7836c4 | 2691 | /// Submit command to insert the given text |
fe5aa22c | 2692 | bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 JS |
2693 | |
2694 | /// Submit command to insert a newline | |
fe5aa22c | 2695 | bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 JS |
2696 | |
2697 | /// Submit command to insert the given image | |
24777478 JS |
2698 | bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0, |
2699 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
cdaed652 VZ |
2700 | |
2701 | /// Submit command to insert an object | |
603f702b | 2702 | wxRichTextObject* InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags); |
5d7836c4 JS |
2703 | |
2704 | /// Submit command to delete this range | |
12cc29c5 | 2705 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl); |
5d7836c4 JS |
2706 | |
2707 | /// Mark modified | |
2708 | void Modify(bool modify = true) { m_modified = modify; } | |
2709 | bool IsModified() const { return m_modified; } | |
2710 | ||
2711 | /// Dumps contents of buffer for debugging purposes | |
2712 | virtual void Dump(); | |
2713 | virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); } | |
2714 | ||
2715 | /// Returns the file handlers | |
2716 | static wxList& GetHandlers() { return sm_handlers; } | |
2717 | ||
2718 | /// Adds a handler to the end | |
2719 | static void AddHandler(wxRichTextFileHandler *handler); | |
2720 | ||
2721 | /// Inserts a handler at the front | |
2722 | static void InsertHandler(wxRichTextFileHandler *handler); | |
2723 | ||
2724 | /// Removes a handler | |
2725 | static bool RemoveHandler(const wxString& name); | |
2726 | ||
2727 | /// Finds a handler by name | |
2728 | static wxRichTextFileHandler *FindHandler(const wxString& name); | |
2729 | ||
2730 | /// Finds a handler by extension and type | |
d75a69e8 | 2731 | static wxRichTextFileHandler *FindHandler(const wxString& extension, wxRichTextFileType imageType); |
5d7836c4 JS |
2732 | |
2733 | /// Finds a handler by filename or, if supplied, type | |
d75a69e8 FM |
2734 | static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, |
2735 | wxRichTextFileType imageType); | |
5d7836c4 JS |
2736 | |
2737 | /// Finds a handler by type | |
d75a69e8 | 2738 | static wxRichTextFileHandler *FindHandler(wxRichTextFileType imageType); |
5d7836c4 | 2739 | |
1e967276 JS |
2740 | /// Gets a wildcard incorporating all visible handlers. If 'types' is present, |
2741 | /// will be filled with the file type corresponding to each filter. This can be | |
2742 | /// used to determine the type to pass to LoadFile given a selected filter. | |
2743 | static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL); | |
5d7836c4 JS |
2744 | |
2745 | /// Clean up handlers | |
2746 | static void CleanUpHandlers(); | |
2747 | ||
2748 | /// Initialise the standard handlers | |
2749 | static void InitStandardHandlers(); | |
2750 | ||
d2d0adc7 JS |
2751 | /// Get renderer |
2752 | static wxRichTextRenderer* GetRenderer() { return sm_renderer; } | |
2753 | ||
2754 | /// Set renderer, deleting old one | |
2755 | static void SetRenderer(wxRichTextRenderer* renderer); | |
2756 | ||
2757 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
2758 | static int GetBulletRightMargin() { return sm_bulletRightMargin; } | |
2759 | static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; } | |
2760 | ||
2761 | /// Factor to multiply by character height to get a reasonable bullet size | |
2762 | static float GetBulletProportion() { return sm_bulletProportion; } | |
2763 | static void SetBulletProportion(float prop) { sm_bulletProportion = prop; } | |
44219ff0 JS |
2764 | |
2765 | /// Scale factor for calculating dimensions | |
2766 | double GetScale() const { return m_scale; } | |
2767 | void SetScale(double scale) { m_scale = scale; } | |
2768 | ||
5d7836c4 JS |
2769 | protected: |
2770 | ||
2771 | /// Command processor | |
2772 | wxCommandProcessor* m_commandProcessor; | |
2773 | ||
44cc96a8 JS |
2774 | /// Table storing fonts |
2775 | wxRichTextFontTable m_fontTable; | |
2776 | ||
5d7836c4 JS |
2777 | /// Has been modified? |
2778 | bool m_modified; | |
2779 | ||
2780 | /// Collapsed command stack | |
2781 | int m_batchedCommandDepth; | |
2782 | ||
2783 | /// Name for collapsed command | |
2784 | wxString m_batchedCommandsName; | |
2785 | ||
2786 | /// Current collapsed command accumulating actions | |
2787 | wxRichTextCommand* m_batchedCommand; | |
2788 | ||
2789 | /// Whether to suppress undo | |
2790 | int m_suppressUndo; | |
2791 | ||
2792 | /// Style sheet, if any | |
2793 | wxRichTextStyleSheet* m_styleSheet; | |
2794 | ||
d2d0adc7 JS |
2795 | /// List of event handlers that will be notified of events |
2796 | wxList m_eventHandlers; | |
2797 | ||
5d7836c4 JS |
2798 | /// Stack of attributes for convenience functions |
2799 | wxList m_attributeStack; | |
2800 | ||
d2d0adc7 JS |
2801 | /// Flags to be passed to handlers |
2802 | int m_handlerFlags; | |
2803 | ||
5d7836c4 JS |
2804 | /// File handlers |
2805 | static wxList sm_handlers; | |
d2d0adc7 JS |
2806 | |
2807 | /// Renderer | |
2808 | static wxRichTextRenderer* sm_renderer; | |
2809 | ||
2810 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
2811 | static int sm_bulletRightMargin; | |
2812 | ||
2813 | /// Factor to multiply by character height to get a reasonable bullet size | |
2814 | static float sm_bulletProportion; | |
44219ff0 JS |
2815 | |
2816 | /// Scaling factor in use: needed to calculate correct dimensions when printing | |
2817 | double m_scale; | |
5d7836c4 JS |
2818 | }; |
2819 | ||
603f702b JS |
2820 | /** |
2821 | @class wxRichTextCell | |
2822 | ||
2823 | wxRichTextCell is the cell in a table. | |
2824 | */ | |
2825 | ||
2826 | class WXDLLIMPEXP_RICHTEXT wxRichTextCell: public wxRichTextBox | |
2827 | { | |
2828 | DECLARE_DYNAMIC_CLASS(wxRichTextCell) | |
2829 | public: | |
2830 | // Constructors | |
2831 | ||
2832 | /** | |
2833 | Default constructor; optionally pass the parent object. | |
2834 | */ | |
2835 | ||
2836 | wxRichTextCell(wxRichTextObject* parent = NULL); | |
2837 | ||
2838 | /** | |
2839 | Copy constructor. | |
2840 | */ | |
2841 | ||
2842 | wxRichTextCell(const wxRichTextCell& obj): wxRichTextBox() { Copy(obj); } | |
2843 | ||
2844 | // Overrideables | |
2845 | ||
2846 | /** | |
2847 | Draws the item. | |
2848 | */ | |
2849 | ||
2850 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); | |
2851 | ||
2852 | /** | |
2853 | Returns the XML node name of this object. | |
2854 | */ | |
2855 | ||
2856 | virtual wxString GetXMLNodeName() const { return wxT("cell"); } | |
2857 | ||
2858 | /// Can we edit properties via a GUI? | |
2859 | virtual bool CanEditProperties() const { return true; } | |
2860 | ||
2861 | /// Edit properties via a GUI | |
2862 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
2863 | ||
2864 | /// Return the label to be used for the properties context menu item. | |
2865 | virtual wxString GetPropertiesMenuLabel() const { return _("&Cell"); } | |
2866 | ||
2867 | // Accessors | |
2868 | ||
2869 | // Operations | |
2870 | ||
2871 | /** | |
2872 | Makes a clone of this object. | |
2873 | */ | |
2874 | virtual wxRichTextObject* Clone() const { return new wxRichTextCell(*this); } | |
2875 | ||
2876 | /** | |
2877 | Copies this object. | |
2878 | */ | |
2879 | void Copy(const wxRichTextCell& obj); | |
2880 | ||
2881 | protected: | |
2882 | }; | |
2883 | ||
2884 | /** | |
2885 | @class wxRichTextTable | |
2886 | ||
2887 | wxRichTextTable represents a table with arbitrary columns and rows. | |
2888 | */ | |
2889 | ||
2890 | WX_DEFINE_ARRAY_PTR(wxRichTextObject*, wxRichTextObjectPtrArray); | |
2891 | WX_DECLARE_OBJARRAY(wxRichTextObjectPtrArray, wxRichTextObjectPtrArrayArray); | |
2892 | ||
2893 | class WXDLLIMPEXP_RICHTEXT wxRichTextTable: public wxRichTextBox | |
2894 | { | |
2895 | DECLARE_DYNAMIC_CLASS(wxRichTextTable) | |
2896 | public: | |
2897 | ||
2898 | // Constructors | |
2899 | ||
2900 | /** | |
2901 | Default constructor; optionally pass the parent object. | |
2902 | */ | |
2903 | ||
2904 | wxRichTextTable(wxRichTextObject* parent = NULL); | |
2905 | ||
2906 | /** | |
2907 | Copy constructor. | |
2908 | */ | |
2909 | ||
2910 | wxRichTextTable(const wxRichTextTable& obj): wxRichTextBox() { Copy(obj); } | |
2911 | ||
2912 | // Overrideables | |
2913 | ||
2914 | // Draws the object. | |
2915 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); | |
2916 | ||
2917 | // Returns the XML node name of this object. | |
2918 | virtual wxString GetXMLNodeName() const { return wxT("table"); } | |
2919 | ||
2920 | // Lays the object out. | |
2921 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); | |
2922 | ||
2923 | // Gets the range size. | |
2924 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; | |
2925 | ||
2926 | // Deletes content in the given range. | |
2927 | virtual bool DeleteRange(const wxRichTextRange& range); | |
2928 | ||
2929 | // Gets any text in this object for the given range. | |
2930 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
2931 | ||
2932 | #if wxUSE_XML | |
2933 | // Import this object from XML | |
2934 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); | |
2935 | #endif | |
2936 | ||
2937 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
2938 | // Export this object directly to the given stream. | |
2939 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); | |
2940 | #endif | |
2941 | ||
2942 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
2943 | // Export this object to the given parent node, usually creating at least one child node. | |
2944 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); | |
2945 | #endif | |
2946 | ||
2947 | /// Finds the absolute position and row height for the given character position | |
2948 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); | |
2949 | ||
2950 | /// Calculate range | |
2951 | virtual void CalculateRange(long start, long& end); | |
2952 | ||
2953 | /// Can this object handle the selections of its children? FOr example, a table. | |
2954 | virtual bool HandlesChildSelections() const { return true; } | |
2955 | ||
2956 | /// Returns a selection object specifying the selections between start and end character positions. | |
2957 | /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table. | |
2958 | virtual wxRichTextSelection GetSelection(long start, long end) const; | |
2959 | ||
2960 | /// Can we edit properties via a GUI? | |
2961 | virtual bool CanEditProperties() const { return true; } | |
2962 | ||
2963 | /// Edit properties via a GUI | |
2964 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
2965 | ||
2966 | /// Return the label to be used for the properties context menu item. | |
2967 | virtual wxString GetPropertiesMenuLabel() const { return _("&Table"); } | |
2968 | ||
2969 | /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject | |
2970 | /// is possible. For example, containers supporting text, such as a text box object, can accept the focus, | |
2971 | /// but a table can't (set the focus to individual cells instead). | |
2972 | virtual bool AcceptsFocus() const { return false; } | |
2973 | ||
2974 | // Accessors | |
2975 | ||
2976 | const wxRichTextObjectPtrArrayArray& GetCells() const { return m_cells; } | |
2977 | wxRichTextObjectPtrArrayArray& GetCells() { return m_cells; } | |
2978 | ||
2979 | int GetRowCount() const { return m_rowCount; } | |
2980 | int GetColumnCount() const { return m_colCount; } | |
2981 | ||
2982 | /// Get the cell at the given row/column position | |
2983 | virtual wxRichTextCell* GetCell(int row, int col) const; | |
2984 | ||
2985 | /// Get the cell at the given character position (in the range of the table). | |
2986 | virtual wxRichTextCell* GetCell(long pos) const; | |
2987 | ||
2988 | /// Get the row/column for a given character position | |
2989 | virtual bool GetCellRowColumnPosition(long pos, int& row, int& col) const; | |
2990 | ||
2991 | // Operations | |
2992 | ||
2993 | /** | |
2994 | Clears the table. | |
2995 | */ | |
2996 | ||
2997 | virtual void ClearTable(); | |
2998 | ||
2999 | /** | |
3000 | Creates a table of the given dimensions. | |
3001 | */ | |
3002 | ||
3003 | virtual bool CreateTable(int rows, int cols); | |
3004 | ||
3005 | /** | |
3006 | Sets the attributes for the cells specified by the selection. | |
3007 | */ | |
3008 | ||
3009 | virtual bool SetCellStyle(const wxRichTextSelection& selection, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
3010 | ||
3011 | /** | |
3012 | Deletes rows from the given row position. | |
3013 | */ | |
3014 | ||
3015 | virtual bool DeleteRows(int startRow, int noRows = 1); | |
3016 | ||
3017 | /** | |
3018 | Deletes columns from the given column position. | |
3019 | */ | |
3020 | ||
3021 | virtual bool DeleteColumns(int startCol, int noCols = 1); | |
3022 | ||
3023 | /** | |
3024 | Adds rows from the given row position. | |
3025 | */ | |
3026 | ||
3027 | virtual bool AddRows(int startRow, int noRows = 1, const wxRichTextAttr& attr = wxRichTextAttr()); | |
3028 | ||
3029 | /** | |
3030 | Adds columns from the given column position. | |
3031 | */ | |
3032 | ||
3033 | virtual bool AddColumns(int startCol, int noCols = 1, const wxRichTextAttr& attr = wxRichTextAttr()); | |
3034 | ||
3035 | // Makes a clone of this object. | |
3036 | virtual wxRichTextObject* Clone() const { return new wxRichTextTable(*this); } | |
3037 | ||
3038 | // Copies this object. | |
3039 | void Copy(const wxRichTextTable& obj); | |
3040 | ||
3041 | protected: | |
3042 | ||
3043 | int m_rowCount; | |
3044 | int m_colCount; | |
3045 | ||
3046 | // An array of rows, each of which is a wxRichTextObjectPtrArray containing | |
3047 | // the cell objects. The cell objects are also children of this object. | |
3048 | // Problem: if boxes are immediate children of a box, this will cause problems | |
3049 | // with wxRichTextParagraphLayoutBox functions (and functions elsewhere) that | |
3050 | // expect to find just paragraphs. May have to adjust the way we handle the | |
3051 | // hierarchy to accept non-paragraph objects in a a paragraph layout box. | |
3052 | // We'll be overriding much wxRichTextParagraphLayoutBox functionality so this | |
3053 | // may not be such a problem. Perhaps the table should derive from a different | |
3054 | // class? | |
3055 | wxRichTextObjectPtrArrayArray m_cells; | |
3056 | }; | |
3057 | ||
3058 | ||
5d7836c4 JS |
3059 | /*! |
3060 | * The command identifiers | |
3061 | * | |
3062 | */ | |
3063 | ||
3064 | enum wxRichTextCommandId | |
3065 | { | |
3066 | wxRICHTEXT_INSERT, | |
3067 | wxRICHTEXT_DELETE, | |
603f702b JS |
3068 | wxRICHTEXT_CHANGE_ATTRIBUTES, |
3069 | wxRICHTEXT_CHANGE_STYLE, | |
3070 | wxRICHTEXT_CHANGE_OBJECT | |
3071 | }; | |
3072 | ||
3073 | /*! | |
3074 | * A class for specifying an object anywhere in an object hierarchy, | |
3075 | * without using a pointer, necessary since wxRTC commands may delete | |
3076 | * and recreate sub-objects so physical object addresses change. An array | |
3077 | * of positions (one per hierarchy level) is used. | |
3078 | * | |
3079 | */ | |
3080 | ||
3081 | class WXDLLIMPEXP_RICHTEXT wxRichTextObjectAddress | |
3082 | { | |
3083 | public: | |
3084 | // Creates the address given container and object. | |
3085 | wxRichTextObjectAddress(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj) { Create(topLevelContainer, obj); } | |
3086 | wxRichTextObjectAddress() { Init(); } | |
3087 | wxRichTextObjectAddress(const wxRichTextObjectAddress& address) { Copy(address); } | |
3088 | ||
3089 | void Init() {} | |
3090 | void Copy(const wxRichTextObjectAddress& address) { m_address = address.m_address; } | |
3091 | void operator=(const wxRichTextObjectAddress& address) { Copy(address); } | |
3092 | ||
3093 | wxRichTextObject* GetObject(wxRichTextParagraphLayoutBox* topLevelContainer) const; | |
3094 | bool Create(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj); | |
3095 | ||
3096 | wxArrayInt& GetAddress() { return m_address; } | |
3097 | const wxArrayInt& GetAddress() const { return m_address; } | |
3098 | void SetAddress(const wxArrayInt& address) { m_address = address; } | |
3099 | ||
3100 | protected: | |
3101 | ||
3102 | wxArrayInt m_address; | |
5d7836c4 JS |
3103 | }; |
3104 | ||
3105 | /*! | |
3106 | * Command classes for undo/redo | |
3107 | * | |
3108 | */ | |
3109 | ||
b5dbe15d | 3110 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; |
3b2cb431 | 3111 | class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand |
5d7836c4 JS |
3112 | { |
3113 | public: | |
3114 | // Ctor for one action | |
3115 | wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, | |
603f702b | 3116 | wxRichTextParagraphLayoutBox* container, wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 JS |
3117 | |
3118 | // Ctor for multiple actions | |
3119 | wxRichTextCommand(const wxString& name); | |
3120 | ||
d3c7fc99 | 3121 | virtual ~wxRichTextCommand(); |
5d7836c4 JS |
3122 | |
3123 | bool Do(); | |
3124 | bool Undo(); | |
3125 | ||
3126 | void AddAction(wxRichTextAction* action); | |
3127 | void ClearActions(); | |
3128 | ||
3129 | wxList& GetActions() { return m_actions; } | |
3130 | ||
3131 | protected: | |
3132 | ||
3133 | wxList m_actions; | |
3134 | }; | |
3135 | ||
3136 | /*! | |
3137 | * wxRichTextAction class declaration | |
3138 | * There can be more than one action in a command. | |
3139 | */ | |
3140 | ||
3b2cb431 | 3141 | class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject |
5d7836c4 JS |
3142 | { |
3143 | public: | |
603f702b JS |
3144 | /// Constructor. 'buffer' is the top-level buffer, while 'container' is the object within |
3145 | /// which the action is taking place. In the simplest case, they are the same. | |
3146 | wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, | |
3147 | wxRichTextBuffer* buffer, wxRichTextParagraphLayoutBox* container, | |
7fe8059f | 3148 | wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 | 3149 | |
d3c7fc99 | 3150 | virtual ~wxRichTextAction(); |
5d7836c4 JS |
3151 | |
3152 | bool Do(); | |
3153 | bool Undo(); | |
3154 | ||
3155 | /// Update the control appearance | |
ea160b2e | 3156 | void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false, |
7051fa41 | 3157 | wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL, bool isDoCmd = true); |
5d7836c4 JS |
3158 | |
3159 | /// Replace the buffer paragraphs with the given fragment. | |
0ca07313 | 3160 | void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 JS |
3161 | |
3162 | /// Get the fragments | |
0ca07313 JS |
3163 | wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; } |
3164 | wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; } | |
5d7836c4 | 3165 | |
603f702b JS |
3166 | /// Get the attributes |
3167 | wxRichTextAttr& GetAttributes() { return m_attributes; } | |
3168 | ||
3169 | /// An object to replace the one at the position | |
3170 | /// defined by the container address and the action's range start position. | |
3171 | wxRichTextObject* GetObject() const { return m_object; } | |
3172 | void SetObject(wxRichTextObject* obj) { m_object = obj; m_objectAddress.Create(m_buffer, m_object); } | |
3173 | void MakeObject(wxRichTextObject* obj) { m_objectAddress.Create(m_buffer, obj); } | |
3174 | ||
7051fa41 JS |
3175 | /// Calculate arrays for refresh optimization |
3176 | void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions); | |
3177 | ||
5d7836c4 JS |
3178 | /// Set/get the position used for e.g. insertion |
3179 | void SetPosition(long pos) { m_position = pos; } | |
3180 | long GetPosition() const { return m_position; } | |
3181 | ||
3182 | /// Set/get the range for e.g. deletion | |
3183 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
3184 | const wxRichTextRange& GetRange() const { return m_range; } | |
3185 | ||
603f702b JS |
3186 | /// The address (nested position) of the container within the buffer being manipulated |
3187 | wxRichTextObjectAddress& GetContainerAddress() { return m_containerAddress; } | |
3188 | const wxRichTextObjectAddress& GetContainerAddress() const { return m_containerAddress; } | |
3189 | void SetContainerAddress(const wxRichTextObjectAddress& address) { m_containerAddress = address; } | |
3190 | void SetContainerAddress(wxRichTextParagraphLayoutBox* container, wxRichTextObject* obj) { m_containerAddress.Create(container, obj); } | |
3191 | ||
3192 | /// Returns the container that this action refers to, using the container address and top-level buffer. | |
3193 | wxRichTextParagraphLayoutBox* GetContainer() const; | |
5d7836c4 JS |
3194 | /// Get name |
3195 | const wxString& GetName() const { return m_name; } | |
3196 | ||
3197 | protected: | |
3198 | // Action name | |
3199 | wxString m_name; | |
3200 | ||
3201 | // Buffer | |
3202 | wxRichTextBuffer* m_buffer; | |
3203 | ||
603f702b JS |
3204 | // The address (nested position) of the container being manipulated. |
3205 | // This is necessary because objects are deleted, and we can't | |
3206 | // therefore store actual pointers. | |
3207 | wxRichTextObjectAddress m_containerAddress; | |
3208 | ||
5d7836c4 JS |
3209 | // Control |
3210 | wxRichTextCtrl* m_ctrl; | |
3211 | ||
3212 | // Stores the new paragraphs | |
0ca07313 | 3213 | wxRichTextParagraphLayoutBox m_newParagraphs; |
5d7836c4 JS |
3214 | |
3215 | // Stores the old paragraphs | |
0ca07313 | 3216 | wxRichTextParagraphLayoutBox m_oldParagraphs; |
5d7836c4 | 3217 | |
603f702b JS |
3218 | // Stores an object to replace the one at the position |
3219 | // defined by the container address and the action's range start position. | |
3220 | wxRichTextObject* m_object; | |
3221 | ||
3222 | // Stores the attributes | |
3223 | wxRichTextAttr m_attributes; | |
3224 | ||
3225 | // The address of the object being manipulated (used for changing an individual object or its attributes) | |
3226 | wxRichTextObjectAddress m_objectAddress; | |
3227 | ||
3228 | // Stores the old attributes | |
3229 | // wxRichTextAttr m_oldAttributes; | |
3230 | ||
5d7836c4 JS |
3231 | // The affected range |
3232 | wxRichTextRange m_range; | |
3233 | ||
3234 | // The insertion point for this command | |
3235 | long m_position; | |
3236 | ||
3237 | // Ignore 1st 'Do' operation because we already did it | |
3238 | bool m_ignoreThis; | |
3239 | ||
3240 | // The command identifier | |
3241 | wxRichTextCommandId m_cmdId; | |
3242 | }; | |
3243 | ||
d2d0adc7 JS |
3244 | /*! |
3245 | * Handler flags | |
3246 | */ | |
3247 | ||
3248 | // Include style sheet when loading and saving | |
3249 | #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001 | |
3250 | ||
3251 | // Save images to memory file system in HTML handler | |
3252 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010 | |
3253 | ||
3254 | // Save images to files in HTML handler | |
3255 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020 | |
3256 | ||
3257 | // Save images as inline base64 data in HTML handler | |
3258 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040 | |
3259 | ||
b774c698 JS |
3260 | // Don't write header and footer (or BODY), so we can include the fragment |
3261 | // in a larger document | |
3262 | #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080 | |
3263 | ||
a2beab22 JS |
3264 | // Convert the more common face names to names that will work on the current platform |
3265 | // in a larger document | |
3266 | #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100 | |
3267 | ||
5d7836c4 JS |
3268 | /*! |
3269 | * wxRichTextFileHandler | |
3270 | * Base class for file handlers | |
3271 | */ | |
3272 | ||
3b2cb431 | 3273 | class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject |
5d7836c4 JS |
3274 | { |
3275 | DECLARE_CLASS(wxRichTextFileHandler) | |
3276 | public: | |
3277 | wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0) | |
d8dd214c | 3278 | : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true) |
5d7836c4 JS |
3279 | { } |
3280 | ||
3281 | #if wxUSE_STREAMS | |
7fe8059f WS |
3282 | bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) |
3283 | { return DoLoadFile(buffer, stream); } | |
3284 | bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) | |
3285 | { return DoSaveFile(buffer, stream); } | |
5d7836c4 JS |
3286 | #endif |
3287 | ||
a9b9495b | 3288 | #if wxUSE_FFILE && wxUSE_STREAMS |
fe8b0361 JS |
3289 | virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); |
3290 | virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); | |
a9b9495b | 3291 | #endif // wxUSE_STREAMS && wxUSE_STREAMS |
5d7836c4 JS |
3292 | |
3293 | /// Can we handle this filename (if using files)? By default, checks the extension. | |
3294 | virtual bool CanHandle(const wxString& filename) const; | |
3295 | ||
3296 | /// Can we save using this handler? | |
3297 | virtual bool CanSave() const { return false; } | |
3298 | ||
3299 | /// Can we load using this handler? | |
3300 | virtual bool CanLoad() const { return false; } | |
3301 | ||
3302 | /// Should this handler be visible to the user? | |
3303 | virtual bool IsVisible() const { return m_visible; } | |
3304 | virtual void SetVisible(bool visible) { m_visible = visible; } | |
3305 | ||
b71e9aa4 | 3306 | /// The name of the nandler |
5d7836c4 JS |
3307 | void SetName(const wxString& name) { m_name = name; } |
3308 | wxString GetName() const { return m_name; } | |
3309 | ||
b71e9aa4 | 3310 | /// The default extension to recognise |
5d7836c4 JS |
3311 | void SetExtension(const wxString& ext) { m_extension = ext; } |
3312 | wxString GetExtension() const { return m_extension; } | |
3313 | ||
b71e9aa4 | 3314 | /// The handler type |
5d7836c4 JS |
3315 | void SetType(int type) { m_type = type; } |
3316 | int GetType() const { return m_type; } | |
3317 | ||
d2d0adc7 JS |
3318 | /// Flags controlling how loading and saving is done |
3319 | void SetFlags(int flags) { m_flags = flags; } | |
3320 | int GetFlags() const { return m_flags; } | |
3321 | ||
b71e9aa4 JS |
3322 | /// Encoding to use when saving a file. If empty, a suitable encoding is chosen |
3323 | void SetEncoding(const wxString& encoding) { m_encoding = encoding; } | |
3324 | const wxString& GetEncoding() const { return m_encoding; } | |
3325 | ||
5d7836c4 JS |
3326 | protected: |
3327 | ||
7fe8059f WS |
3328 | #if wxUSE_STREAMS |
3329 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0; | |
3330 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0; | |
3331 | #endif | |
3332 | ||
5d7836c4 | 3333 | wxString m_name; |
b71e9aa4 | 3334 | wxString m_encoding; |
5d7836c4 JS |
3335 | wxString m_extension; |
3336 | int m_type; | |
d2d0adc7 | 3337 | int m_flags; |
5d7836c4 JS |
3338 | bool m_visible; |
3339 | }; | |
3340 | ||
3341 | /*! | |
3342 | * wxRichTextPlainTextHandler | |
3343 | * Plain text handler | |
3344 | */ | |
3345 | ||
3b2cb431 | 3346 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler |
5d7836c4 JS |
3347 | { |
3348 | DECLARE_CLASS(wxRichTextPlainTextHandler) | |
3349 | public: | |
d75a69e8 FM |
3350 | wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), |
3351 | const wxString& ext = wxT("txt"), | |
3352 | wxRichTextFileType type = wxRICHTEXT_TYPE_TEXT) | |
5d7836c4 JS |
3353 | : wxRichTextFileHandler(name, ext, type) |
3354 | { } | |
3355 | ||
5d7836c4 JS |
3356 | /// Can we save using this handler? |
3357 | virtual bool CanSave() const { return true; } | |
3358 | ||
3359 | /// Can we load using this handler? | |
3360 | virtual bool CanLoad() const { return true; } | |
3361 | ||
3362 | protected: | |
3363 | ||
7fe8059f WS |
3364 | #if wxUSE_STREAMS |
3365 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
3366 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
3367 | #endif | |
3368 | ||
5d7836c4 JS |
3369 | }; |
3370 | ||
0ca07313 JS |
3371 | #if wxUSE_DATAOBJ |
3372 | ||
3373 | /*! | |
3374 | * The data object for a wxRichTextBuffer | |
3375 | */ | |
3376 | ||
d2d0adc7 | 3377 | class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple |
0ca07313 JS |
3378 | { |
3379 | public: | |
3380 | // ctor doesn't copy the pointer, so it shouldn't go away while this object | |
3381 | // is alive | |
d3b9f782 | 3382 | wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = NULL); |
0ca07313 JS |
3383 | virtual ~wxRichTextBufferDataObject(); |
3384 | ||
3385 | // after a call to this function, the buffer is owned by the caller and it | |
3386 | // is responsible for deleting it | |
3387 | wxRichTextBuffer* GetRichTextBuffer(); | |
3388 | ||
3389 | // Returns the id for the new data format | |
3390 | static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; } | |
3391 | ||
3392 | // base class pure virtuals | |
3393 | ||
3394 | virtual wxDataFormat GetPreferredFormat(Direction dir) const; | |
3395 | virtual size_t GetDataSize() const; | |
3396 | virtual bool GetDataHere(void *pBuf) const; | |
3397 | virtual bool SetData(size_t len, const void *buf); | |
3398 | ||
3399 | // prevent warnings | |
3400 | ||
3401 | virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); } | |
3402 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); } | |
3403 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); } | |
3404 | ||
3405 | private: | |
3406 | wxDataFormat m_formatRichTextBuffer; // our custom format | |
3407 | wxRichTextBuffer* m_richTextBuffer; // our data | |
3408 | static const wxChar* ms_richTextBufferFormatId; // our format id | |
3409 | }; | |
3410 | ||
3411 | #endif | |
3412 | ||
d2d0adc7 JS |
3413 | /*! |
3414 | * wxRichTextRenderer isolates common drawing functionality | |
3415 | */ | |
3416 | ||
3417 | class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject | |
3418 | { | |
3419 | public: | |
3420 | wxRichTextRenderer() {} | |
3421 | virtual ~wxRichTextRenderer() {} | |
3422 | ||
3423 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
24777478 | 3424 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 JS |
3425 | |
3426 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
24777478 | 3427 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text) = 0; |
d2d0adc7 JS |
3428 | |
3429 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
24777478 | 3430 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 JS |
3431 | |
3432 | /// Enumerate the standard bullet names currently supported | |
3433 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; | |
3434 | }; | |
3435 | ||
3436 | /*! | |
3437 | * wxRichTextStdRenderer: standard renderer | |
3438 | */ | |
3439 | ||
3440 | class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer | |
3441 | { | |
3442 | public: | |
3443 | wxRichTextStdRenderer() {} | |
3444 | ||
3445 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
24777478 | 3446 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 JS |
3447 | |
3448 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
24777478 | 3449 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text); |
d2d0adc7 JS |
3450 | |
3451 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
24777478 | 3452 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 JS |
3453 | |
3454 | /// Enumerate the standard bullet names currently supported | |
3455 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); | |
3456 | }; | |
3457 | ||
5d7836c4 JS |
3458 | /*! |
3459 | * Utilities | |
3460 | * | |
3461 | */ | |
3462 | ||
3463 | inline bool wxRichTextHasStyle(int flags, int style) | |
3464 | { | |
3465 | return ((flags & style) == style); | |
3466 | } | |
3467 | ||
3468 | /// Compare two attribute objects | |
24777478 JS |
3469 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); |
3470 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); | |
5d7836c4 JS |
3471 | |
3472 | /// Compare two attribute objects, but take into account the flags | |
3473 | /// specifying attributes of interest. | |
24777478 | 3474 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); |
5d7836c4 JS |
3475 | |
3476 | /// Apply one style to another | |
24777478 | 3477 | WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); |
59509217 | 3478 | |
aeb6ebe2 | 3479 | // Remove attributes |
24777478 | 3480 | WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style); |
aeb6ebe2 | 3481 | |
42688aea JS |
3482 | /// Combine two bitlists |
3483 | WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB); | |
3484 | ||
3485 | /// Compare two bitlists | |
3486 | WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags); | |
3487 | ||
4f32b3cf | 3488 | /// Split into paragraph and character styles |
24777478 | 3489 | WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxRichTextAttr& style, wxRichTextAttr& parStyle, wxRichTextAttr& charStyle); |
4f32b3cf | 3490 | |
59509217 | 3491 | /// Compare tabs |
d2d0adc7 | 3492 | WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2); |
59509217 | 3493 | |
59509217 | 3494 | /// Convert a decimal to Roman numerals |
d2d0adc7 | 3495 | WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n); |
f1d6804f | 3496 | |
24777478 JS |
3497 | // Collects the attributes that are common to a range of content, building up a note of |
3498 | // which attributes are absent in some objects and which clash in some objects. | |
3499 | WXDLLIMPEXP_RICHTEXT void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAttr& attr, wxTextAttr& clashingAttr, wxTextAttr& absentAttr); | |
3500 | ||
f1d6804f RD |
3501 | WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit(); |
3502 | ||
5d7836c4 JS |
3503 | #endif |
3504 | // wxUSE_RICHTEXT | |
3505 | ||
3506 | #endif | |
3507 | // _WX_RICHTEXTBUFFER_H_ | |
d2d0adc7 | 3508 |