]>
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 |
5d7836c4 JS |
7 | // Copyright: (c) Julian Smart |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
b01ca8b6 JS |
11 | #ifndef _WX_RICHTEXTBUFFER_H_ |
12 | #define _WX_RICHTEXTBUFFER_H_ | |
13 | ||
5d7836c4 JS |
14 | /* |
15 | ||
16 | Data structures | |
17 | =============== | |
18 | ||
19 | Data is represented by a hierarchy of objects, all derived from | |
20 | wxRichTextObject. | |
21 | ||
22 | The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox. | |
23 | These boxes will allow flexible placement of text boxes on a page, but | |
59509217 JS |
24 | for now there is a single box representing the document, and this box is |
25 | a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph | |
26 | objects, each of which can include text and images. | |
5d7836c4 JS |
27 | |
28 | Each object maintains a range (start and end position) measured | |
29 | from the start of the main parent box. | |
30 | A paragraph object knows its range, and a text fragment knows its range | |
31 | too. So, a character or image in a page has a position relative to the | |
32 | start of the document, and a character in an embedded text box has | |
33 | a position relative to that text box. For now, we will not be dealing with | |
34 | embedded objects but it's something to bear in mind for later. | |
35 | ||
59509217 JS |
36 | Note that internally, a range (5,5) represents a range of one character. |
37 | In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection | |
38 | as (5,6). A paragraph with one character might have an internal range of (0, 1) | |
39 | since the end of the paragraph takes up one position. | |
40 | ||
5d7836c4 JS |
41 | Layout |
42 | ====== | |
43 | ||
44 | When Layout is called on an object, it is given a size which the object | |
45 | must limit itself to, or one or more flexible directions (vertical | |
46 | or horizontal). So for example a centered paragraph is given the page | |
47 | width to play with (minus any margins), but can extend indefinitely | |
48 | in the vertical direction. The implementation of Layout can then | |
49 | cache the calculated size and position within the parent. | |
50 | ||
5d7836c4 JS |
51 | */ |
52 | ||
5d7836c4 JS |
53 | /*! |
54 | * Includes | |
55 | */ | |
56 | ||
b01ca8b6 | 57 | #include "wx/defs.h" |
5d7836c4 JS |
58 | |
59 | #if wxUSE_RICHTEXT | |
60 | ||
b01ca8b6 JS |
61 | #include "wx/list.h" |
62 | #include "wx/textctrl.h" | |
63 | #include "wx/bitmap.h" | |
5d7836c4 JS |
64 | #include "wx/image.h" |
65 | #include "wx/cmdproc.h" | |
66 | #include "wx/txtstrm.h" | |
bec80f4f | 67 | #include "wx/variant.h" |
4c86168d | 68 | #include "wx/position.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 | ||
706465df JS |
102 | /** |
103 | The line break character that can be embedded in content. | |
ff76711f JS |
104 | */ |
105 | ||
106 | extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar; | |
107 | ||
706465df JS |
108 | /** |
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; |
f7667b84 | 128 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextPlainText; |
b5dbe15d VS |
129 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject; |
130 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList; | |
131 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine; | |
132 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph; | |
133 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler; | |
8db2e3ef | 134 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextDrawingHandler; |
7c9fdebe JS |
135 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextField; |
136 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFieldType; | |
b5dbe15d | 137 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet; |
b5dbe15d VS |
138 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition; |
139 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent; | |
140 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer; | |
141 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; | |
bec80f4f | 142 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextXMLHandler; |
603f702b JS |
143 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraphLayoutBox; |
144 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImageBlock; | |
bec80f4f JS |
145 | class WXDLLIMPEXP_FWD_XML wxXmlNode; |
146 | class wxRichTextFloatCollector; | |
706465df JS |
147 | class WXDLLIMPEXP_FWD_BASE wxDataInputStream; |
148 | class WXDLLIMPEXP_FWD_BASE wxDataOutputStream; | |
5d7836c4 | 149 | |
706465df JS |
150 | /** |
151 | Flags determining the available space, passed to Layout. | |
5d7836c4 JS |
152 | */ |
153 | ||
154 | #define wxRICHTEXT_FIXED_WIDTH 0x01 | |
155 | #define wxRICHTEXT_FIXED_HEIGHT 0x02 | |
156 | #define wxRICHTEXT_VARIABLE_WIDTH 0x04 | |
157 | #define wxRICHTEXT_VARIABLE_HEIGHT 0x08 | |
158 | ||
4d551ad5 JS |
159 | // Only lay out the part of the buffer that lies within |
160 | // the rect passed to Layout. | |
161 | #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10 | |
162 | ||
706465df JS |
163 | /** |
164 | Flags to pass to Draw | |
44219ff0 JS |
165 | */ |
166 | ||
167 | // Ignore paragraph cache optimization, e.g. for printing purposes | |
168 | // where one line may be drawn higher (on the next page) compared | |
169 | // with the previous line | |
170 | #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01 | |
603f702b JS |
171 | #define wxRICHTEXT_DRAW_SELECTED 0x02 |
172 | #define wxRICHTEXT_DRAW_PRINT 0x04 | |
173 | #define wxRICHTEXT_DRAW_GUIDELINES 0x08 | |
44219ff0 | 174 | |
706465df JS |
175 | /** |
176 | Flags returned from hit-testing, or passed to hit-test function. | |
5d7836c4 | 177 | */ |
f632e27b FM |
178 | enum wxRichTextHitTestFlags |
179 | { | |
180 | // The point was not on this object | |
181 | wxRICHTEXT_HITTEST_NONE = 0x01, | |
182 | ||
183 | // The point was before the position returned from HitTest | |
184 | wxRICHTEXT_HITTEST_BEFORE = 0x02, | |
185 | ||
186 | // The point was after the position returned from HitTest | |
187 | wxRICHTEXT_HITTEST_AFTER = 0x04, | |
5d7836c4 | 188 | |
f632e27b FM |
189 | // The point was on the position returned from HitTest |
190 | wxRICHTEXT_HITTEST_ON = 0x08, | |
191 | ||
192 | // The point was on space outside content | |
603f702b JS |
193 | wxRICHTEXT_HITTEST_OUTSIDE = 0x10, |
194 | ||
195 | // Only do hit-testing at the current level (don't traverse into top-level objects) | |
343ef639 JS |
196 | wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS = 0x20, |
197 | ||
198 | // Ignore floating objects | |
7c9fdebe JS |
199 | wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS = 0x40, |
200 | ||
201 | // Don't recurse into objects marked as atomic | |
202 | wxRICHTEXT_HITTEST_HONOUR_ATOMIC = 0x80 | |
f632e27b | 203 | }; |
5d7836c4 | 204 | |
706465df JS |
205 | /** |
206 | Flags for GetRangeSize. | |
5d7836c4 JS |
207 | */ |
208 | ||
209 | #define wxRICHTEXT_FORMATTED 0x01 | |
210 | #define wxRICHTEXT_UNFORMATTED 0x02 | |
2f45f554 | 211 | #define wxRICHTEXT_CACHE_SIZE 0x04 |
4f3d5bc0 | 212 | #define wxRICHTEXT_HEIGHT_ONLY 0x08 |
5d7836c4 | 213 | |
706465df JS |
214 | /** |
215 | Flags for SetStyle/SetListStyle. | |
59509217 JS |
216 | */ |
217 | ||
218 | #define wxRICHTEXT_SETSTYLE_NONE 0x00 | |
219 | ||
220 | // Specifies that this operation should be undoable | |
221 | #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01 | |
222 | ||
223 | // Specifies that the style should not be applied if the | |
224 | // combined style at this point is already the style in question. | |
225 | #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02 | |
226 | ||
227 | // Specifies that the style should only be applied to paragraphs, | |
228 | // and not the content. This allows content styling to be | |
229 | // preserved independently from that of e.g. a named paragraph style. | |
230 | #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04 | |
231 | ||
232 | // Specifies that the style should only be applied to characters, | |
233 | // and not the paragraph. This allows content styling to be | |
234 | // preserved independently from that of e.g. a named paragraph style. | |
235 | #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08 | |
236 | ||
38f833b1 JS |
237 | // For SetListStyle only: specifies starting from the given number, otherwise |
238 | // deduces number from existing attributes | |
239 | #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10 | |
240 | ||
241 | // For SetListStyle only: specifies the list level for all paragraphs, otherwise | |
242 | // the current indentation will be used | |
243 | #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20 | |
244 | ||
523d2f14 JS |
245 | // Resets the existing style before applying the new style |
246 | #define wxRICHTEXT_SETSTYLE_RESET 0x40 | |
247 | ||
aeb6ebe2 JS |
248 | // Removes the given style instead of applying it |
249 | #define wxRICHTEXT_SETSTYLE_REMOVE 0x80 | |
250 | ||
590a0f8b JS |
251 | /** |
252 | Flags for SetProperties. | |
253 | */ | |
254 | ||
255 | #define wxRICHTEXT_SETPROPERTIES_NONE 0x00 | |
256 | ||
257 | // Specifies that this operation should be undoable | |
258 | #define wxRICHTEXT_SETPROPERTIES_WITH_UNDO 0x01 | |
259 | ||
260 | // Specifies that the properties should only be applied to paragraphs, | |
261 | // and not the content. | |
262 | #define wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY 0x02 | |
263 | ||
264 | // Specifies that the properties should only be applied to characters, | |
265 | // and not the paragraph. | |
266 | #define wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY 0x04 | |
267 | ||
268 | // Resets the existing properties before applying the new properties. | |
269 | #define wxRICHTEXT_SETPROPERTIES_RESET 0x08 | |
270 | ||
271 | // Removes the given properties instead of applying them. | |
272 | #define wxRICHTEXT_SETPROPERTIES_REMOVE 0x10 | |
273 | ||
706465df JS |
274 | /** |
275 | Flags for object insertion. | |
fe5aa22c JS |
276 | */ |
277 | ||
278 | #define wxRICHTEXT_INSERT_NONE 0x00 | |
279 | #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01 | |
c025e094 | 280 | #define wxRICHTEXT_INSERT_INTERACTIVE 0x02 |
fe5aa22c | 281 | |
6c0ea513 JS |
282 | // A special flag telling the buffer to keep the first paragraph style |
283 | // as-is, when deleting a paragraph marker. In future we might pass a | |
284 | // flag to InsertFragment and DeleteRange to indicate the appropriate mode. | |
32423dd8 | 285 | #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x20000000 |
6c0ea513 | 286 | |
706465df JS |
287 | /** |
288 | Default superscript/subscript font multiplication factor. | |
30bf7630 JS |
289 | */ |
290 | ||
291 | #define wxSCRIPT_MUL_FACTOR 1.5 | |
292 | ||
706465df JS |
293 | /** |
294 | The type for wxTextAttrDimension flags. | |
295 | */ | |
24777478 | 296 | typedef unsigned short wxTextAttrDimensionFlags; |
cdaed652 | 297 | |
706465df JS |
298 | /** |
299 | Miscellaneous text box flags | |
300 | */ | |
24777478 JS |
301 | enum wxTextBoxAttrFlags |
302 | { | |
303 | wxTEXT_BOX_ATTR_FLOAT = 0x00000001, | |
304 | wxTEXT_BOX_ATTR_CLEAR = 0x00000002, | |
603f702b | 305 | wxTEXT_BOX_ATTR_COLLAPSE_BORDERS = 0x00000004, |
2f987d83 JS |
306 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT = 0x00000008, |
307 | wxTEXT_BOX_ATTR_BOX_STYLE_NAME = 0x00000010 | |
24777478 | 308 | }; |
cdaed652 | 309 | |
706465df JS |
310 | /** |
311 | Whether a value is present, used in dimension flags. | |
312 | */ | |
24777478 JS |
313 | enum wxTextAttrValueFlags |
314 | { | |
603f702b JS |
315 | wxTEXT_ATTR_VALUE_VALID = 0x1000, |
316 | wxTEXT_ATTR_VALUE_VALID_MASK = 0x1000 | |
24777478 | 317 | }; |
cdaed652 | 318 | |
706465df JS |
319 | /** |
320 | Units, included in the dimension value. | |
321 | */ | |
24777478 JS |
322 | enum wxTextAttrUnits |
323 | { | |
324 | wxTEXT_ATTR_UNITS_TENTHS_MM = 0x0001, | |
325 | wxTEXT_ATTR_UNITS_PIXELS = 0x0002, | |
326 | wxTEXT_ATTR_UNITS_PERCENTAGE = 0x0004, | |
327 | wxTEXT_ATTR_UNITS_POINTS = 0x0008, | |
328 | ||
329 | wxTEXT_ATTR_UNITS_MASK = 0x000F | |
330 | }; | |
331 | ||
706465df JS |
332 | /** |
333 | Position alternatives, included in the dimension flags. | |
334 | */ | |
24777478 JS |
335 | enum wxTextBoxAttrPosition |
336 | { | |
337 | wxTEXT_BOX_ATTR_POSITION_STATIC = 0x0000, // Default is static, i.e. as per normal layout | |
603f702b | 338 | wxTEXT_BOX_ATTR_POSITION_RELATIVE = 0x0010, // Relative to the relevant edge |
d87098c0 JS |
339 | wxTEXT_BOX_ATTR_POSITION_ABSOLUTE = 0x0020, // Relative to the parent |
340 | wxTEXT_BOX_ATTR_POSITION_FIXED = 0x0040, // Relative to the top-level window | |
24777478 JS |
341 | |
342 | wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0 | |
343 | }; | |
344 | ||
23bdfeee JS |
345 | /** |
346 | @class wxTextAttrDimension | |
347 | ||
348 | A class representing a rich text dimension, including units and position. | |
349 | ||
350 | @library{wxrichtext} | |
351 | @category{richtext} | |
352 | ||
353 | @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimensions | |
354 | */ | |
355 | ||
6ffb5e91 | 356 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimension |
cdaed652 VZ |
357 | { |
358 | public: | |
23bdfeee JS |
359 | /** |
360 | Default constructor. | |
361 | */ | |
24777478 | 362 | wxTextAttrDimension() { Reset(); } |
23bdfeee JS |
363 | /** |
364 | Constructor taking value and units flag. | |
365 | */ | |
603f702b JS |
366 | wxTextAttrDimension(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { m_value = value; m_flags = units|wxTEXT_ATTR_VALUE_VALID; } |
367 | ||
23bdfeee JS |
368 | /** |
369 | Resets the dimension value and flags. | |
370 | */ | |
24777478 JS |
371 | void Reset() { m_value = 0; m_flags = 0; } |
372 | ||
23bdfeee | 373 | /** |
32423dd8 JS |
374 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
375 | have to be present if those attributes of @a dim are present. If @a weakTest is | |
376 | @false, the function will fail if an attribute is present in @a dim but not | |
377 | in this object. | |
23bdfeee | 378 | */ |
32423dd8 | 379 | bool EqPartial(const wxTextAttrDimension& dim, bool weakTest = true) const; |
24777478 | 380 | |
23bdfeee JS |
381 | /** Apply the dimension, but not those identical to @a compareWith if present. |
382 | */ | |
24777478 JS |
383 | bool Apply(const wxTextAttrDimension& dim, const wxTextAttrDimension* compareWith = NULL); |
384 | ||
23bdfeee JS |
385 | /** Collects the attributes that are common to a range of content, building up a note of |
386 | which attributes are absent in some objects and which clash in some objects. | |
387 | */ | |
24777478 JS |
388 | void CollectCommonAttributes(const wxTextAttrDimension& attr, wxTextAttrDimension& clashingAttr, wxTextAttrDimension& absentAttr); |
389 | ||
23bdfeee JS |
390 | /** |
391 | Equality operator. | |
392 | */ | |
24777478 | 393 | bool operator==(const wxTextAttrDimension& dim) const { return m_value == dim.m_value && m_flags == dim.m_flags; } |
603f702b | 394 | |
23bdfeee JS |
395 | /** |
396 | Returns the integer value of the dimension. | |
397 | */ | |
24777478 | 398 | int GetValue() const { return m_value; } |
23bdfeee JS |
399 | |
400 | /** | |
401 | Returns the floating-pointing value of the dimension in mm. | |
402 | ||
403 | */ | |
24777478 | 404 | float GetValueMM() const { return float(m_value) / 10.0; } |
23bdfeee JS |
405 | |
406 | /** | |
407 | Sets the value of the dimension in mm. | |
408 | */ | |
603f702b | 409 | void SetValueMM(float value) { m_value = (int) ((value * 10.0) + 0.5); m_flags |= wxTEXT_ATTR_VALUE_VALID; } |
23bdfeee JS |
410 | |
411 | /** | |
412 | Sets the integer value of the dimension. | |
413 | */ | |
603f702b | 414 | void SetValue(int value) { m_value = value; m_flags |= wxTEXT_ATTR_VALUE_VALID; } |
23bdfeee JS |
415 | |
416 | /** | |
417 | Sets the integer value of the dimension, passing dimension flags. | |
418 | */ | |
603f702b | 419 | void SetValue(int value, wxTextAttrDimensionFlags flags) { SetValue(value); m_flags = flags; } |
23bdfeee JS |
420 | |
421 | /** | |
422 | Sets the integer value and units. | |
423 | */ | |
603f702b | 424 | void SetValue(int value, wxTextAttrUnits units) { m_value = value; m_flags = units | wxTEXT_ATTR_VALUE_VALID; } |
23bdfeee JS |
425 | |
426 | /** | |
427 | Sets the dimension. | |
428 | */ | |
bec80f4f | 429 | void SetValue(const wxTextAttrDimension& dim) { (*this) = dim; } |
603f702b | 430 | |
23bdfeee JS |
431 | /** |
432 | Gets the units of the dimension. | |
433 | */ | |
24777478 | 434 | wxTextAttrUnits GetUnits() const { return (wxTextAttrUnits) (m_flags & wxTEXT_ATTR_UNITS_MASK); } |
23bdfeee JS |
435 | |
436 | /** | |
437 | Sets the units of the dimension. | |
438 | */ | |
24777478 | 439 | void SetUnits(wxTextAttrUnits units) { m_flags &= ~wxTEXT_ATTR_UNITS_MASK; m_flags |= units; } |
603f702b | 440 | |
23bdfeee JS |
441 | /** |
442 | Gets the position flags. | |
443 | */ | |
24777478 | 444 | wxTextBoxAttrPosition GetPosition() const { return (wxTextBoxAttrPosition) (m_flags & wxTEXT_BOX_ATTR_POSITION_MASK); } |
23bdfeee JS |
445 | |
446 | /** | |
447 | Sets the position flags. | |
448 | */ | |
24777478 | 449 | void SetPosition(wxTextBoxAttrPosition pos) { m_flags &= ~wxTEXT_BOX_ATTR_POSITION_MASK; m_flags |= pos; } |
603f702b | 450 | |
23bdfeee JS |
451 | /** |
452 | Returns @true if the dimension is valid. | |
453 | */ | |
603f702b | 454 | bool IsValid() const { return (m_flags & wxTEXT_ATTR_VALUE_VALID) != 0; } |
23bdfeee JS |
455 | |
456 | /** | |
457 | Sets the valid flag. | |
458 | */ | |
603f702b JS |
459 | void SetValid(bool b) { m_flags &= ~wxTEXT_ATTR_VALUE_VALID_MASK; m_flags |= (b ? wxTEXT_ATTR_VALUE_VALID : 0); } |
460 | ||
23bdfeee JS |
461 | /** |
462 | Gets the dimension flags. | |
463 | */ | |
bec80f4f | 464 | wxTextAttrDimensionFlags GetFlags() const { return m_flags; } |
23bdfeee JS |
465 | |
466 | /** | |
467 | Sets the dimension flags. | |
468 | */ | |
bec80f4f | 469 | void SetFlags(wxTextAttrDimensionFlags flags) { m_flags = flags; } |
603f702b | 470 | |
24777478 JS |
471 | int m_value; |
472 | wxTextAttrDimensionFlags m_flags; | |
473 | }; | |
ce00f59b | 474 | |
23bdfeee JS |
475 | /** |
476 | @class wxTextAttrDimensions | |
477 | A class for left, right, top and bottom dimensions. | |
478 | ||
479 | @library{wxrichtext} | |
480 | @category{richtext} | |
481 | ||
482 | @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension | |
483 | */ | |
484 | ||
bec80f4f | 485 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensions |
24777478 JS |
486 | { |
487 | public: | |
23bdfeee JS |
488 | /** |
489 | Default constructor. | |
490 | */ | |
603f702b JS |
491 | wxTextAttrDimensions() {} |
492 | ||
23bdfeee JS |
493 | /** |
494 | Resets the value and flags for all dimensions. | |
495 | */ | |
24777478 | 496 | void Reset() { m_left.Reset(); m_top.Reset(); m_right.Reset(); m_bottom.Reset(); } |
603f702b | 497 | |
23bdfeee JS |
498 | /** |
499 | Equality operator. | |
500 | */ | |
bec80f4f | 501 | 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 | 502 | |
23bdfeee | 503 | /** |
32423dd8 JS |
504 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
505 | have to be present if those attributes of @a dim sare present. If @a weakTest is | |
506 | @false, the function will fail if an attribute is present in @a dims but not | |
507 | in this object. | |
23bdfeee JS |
508 | |
509 | */ | |
32423dd8 | 510 | bool EqPartial(const wxTextAttrDimensions& dims, bool weakTest = true) const; |
24777478 | 511 | |
23bdfeee | 512 | /** |
d87098c0 | 513 | Apply to 'this', but not if the same as @a compareWith. |
23bdfeee JS |
514 | |
515 | */ | |
bec80f4f | 516 | bool Apply(const wxTextAttrDimensions& dims, const wxTextAttrDimensions* compareWith = NULL); |
24777478 | 517 | |
23bdfeee JS |
518 | /** |
519 | Collects the attributes that are common to a range of content, building up a note of | |
520 | which attributes are absent in some objects and which clash in some objects. | |
521 | ||
522 | */ | |
bec80f4f | 523 | void CollectCommonAttributes(const wxTextAttrDimensions& attr, wxTextAttrDimensions& clashingAttr, wxTextAttrDimensions& absentAttr); |
24777478 | 524 | |
23bdfeee JS |
525 | /** |
526 | Remove specified attributes from this object. | |
527 | */ | |
bec80f4f JS |
528 | bool RemoveStyle(const wxTextAttrDimensions& attr); |
529 | ||
23bdfeee JS |
530 | /** |
531 | Gets the left dimension. | |
532 | */ | |
bec80f4f JS |
533 | const wxTextAttrDimension& GetLeft() const { return m_left; } |
534 | wxTextAttrDimension& GetLeft() { return m_left; } | |
535 | ||
23bdfeee JS |
536 | /** |
537 | Gets the right dimension. | |
538 | ||
539 | */ | |
bec80f4f JS |
540 | const wxTextAttrDimension& GetRight() const { return m_right; } |
541 | wxTextAttrDimension& GetRight() { return m_right; } | |
542 | ||
23bdfeee JS |
543 | /** |
544 | Gets the top dimension. | |
545 | ||
546 | */ | |
bec80f4f JS |
547 | const wxTextAttrDimension& GetTop() const { return m_top; } |
548 | wxTextAttrDimension& GetTop() { return m_top; } | |
549 | ||
23bdfeee JS |
550 | /** |
551 | Gets the bottom dimension. | |
552 | ||
553 | */ | |
bec80f4f JS |
554 | const wxTextAttrDimension& GetBottom() const { return m_bottom; } |
555 | wxTextAttrDimension& GetBottom() { return m_bottom; } | |
24777478 | 556 | |
eb3d8a33 JS |
557 | /** |
558 | Are all dimensions valid? | |
559 | ||
560 | */ | |
561 | bool IsValid() const { return m_left.IsValid() && m_top.IsValid() && m_right.IsValid() && m_bottom.IsValid(); } | |
562 | ||
24777478 JS |
563 | wxTextAttrDimension m_left; |
564 | wxTextAttrDimension m_top; | |
565 | wxTextAttrDimension m_right; | |
566 | wxTextAttrDimension m_bottom; | |
567 | }; | |
568 | ||
23bdfeee JS |
569 | /** |
570 | @class wxTextAttrSize | |
571 | A class for representing width and height. | |
572 | ||
573 | @library{wxrichtext} | |
574 | @category{richtext} | |
575 | ||
576 | @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension | |
577 | */ | |
578 | ||
603f702b JS |
579 | class WXDLLIMPEXP_RICHTEXT wxTextAttrSize |
580 | { | |
581 | public: | |
23bdfeee JS |
582 | /** |
583 | Default constructor. | |
584 | */ | |
603f702b JS |
585 | wxTextAttrSize() {} |
586 | ||
23bdfeee JS |
587 | /** |
588 | Resets the width and height dimensions. | |
589 | */ | |
603f702b JS |
590 | void Reset() { m_width.Reset(); m_height.Reset(); } |
591 | ||
23bdfeee JS |
592 | /** |
593 | Equality operator. | |
594 | */ | |
603f702b JS |
595 | bool operator==(const wxTextAttrSize& size) const { return m_width == size.m_width && m_height == size.m_height ; } |
596 | ||
23bdfeee | 597 | /** |
32423dd8 JS |
598 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
599 | have to be present if those attributes of @a size are present. If @a weakTest is | |
600 | @false, the function will fail if an attribute is present in @a size but not | |
601 | in this object. | |
23bdfeee | 602 | */ |
32423dd8 | 603 | bool EqPartial(const wxTextAttrSize& size, bool weakTest = true) const; |
603f702b | 604 | |
23bdfeee | 605 | /** |
d87098c0 | 606 | Apply to this object, but not if the same as @a compareWith. |
23bdfeee | 607 | */ |
603f702b JS |
608 | bool Apply(const wxTextAttrSize& dims, const wxTextAttrSize* compareWith = NULL); |
609 | ||
23bdfeee JS |
610 | /** |
611 | Collects the attributes that are common to a range of content, building up a note of | |
612 | which attributes are absent in some objects and which clash in some objects. | |
613 | */ | |
603f702b JS |
614 | void CollectCommonAttributes(const wxTextAttrSize& attr, wxTextAttrSize& clashingAttr, wxTextAttrSize& absentAttr); |
615 | ||
23bdfeee JS |
616 | /** |
617 | Removes the specified attributes from this object. | |
618 | */ | |
603f702b JS |
619 | bool RemoveStyle(const wxTextAttrSize& attr); |
620 | ||
23bdfeee JS |
621 | /** |
622 | Returns the width. | |
623 | */ | |
603f702b JS |
624 | wxTextAttrDimension& GetWidth() { return m_width; } |
625 | const wxTextAttrDimension& GetWidth() const { return m_width; } | |
626 | ||
23bdfeee JS |
627 | /** |
628 | Sets the width. | |
629 | */ | |
603f702b | 630 | void SetWidth(int value, wxTextAttrDimensionFlags flags) { m_width.SetValue(value, flags); } |
303f0be7 | 631 | |
23bdfeee JS |
632 | /** |
633 | Sets the width. | |
634 | */ | |
603f702b | 635 | void SetWidth(int value, wxTextAttrUnits units) { m_width.SetValue(value, units); } |
303f0be7 | 636 | |
23bdfeee JS |
637 | /** |
638 | Sets the width. | |
639 | */ | |
603f702b JS |
640 | void SetWidth(const wxTextAttrDimension& dim) { m_width.SetValue(dim); } |
641 | ||
23bdfeee JS |
642 | /** |
643 | Gets the height. | |
644 | */ | |
603f702b JS |
645 | wxTextAttrDimension& GetHeight() { return m_height; } |
646 | const wxTextAttrDimension& GetHeight() const { return m_height; } | |
647 | ||
23bdfeee JS |
648 | /** |
649 | Sets the height. | |
650 | */ | |
603f702b | 651 | void SetHeight(int value, wxTextAttrDimensionFlags flags) { m_height.SetValue(value, flags); } |
303f0be7 | 652 | |
23bdfeee JS |
653 | /** |
654 | Sets the height. | |
655 | */ | |
603f702b | 656 | void SetHeight(int value, wxTextAttrUnits units) { m_height.SetValue(value, units); } |
303f0be7 | 657 | |
23bdfeee JS |
658 | /** |
659 | Sets the height. | |
660 | */ | |
603f702b JS |
661 | void SetHeight(const wxTextAttrDimension& dim) { m_height.SetValue(dim); } |
662 | ||
303f0be7 JS |
663 | /** |
664 | Is the size valid? | |
665 | */ | |
666 | bool IsValid() const { return m_width.IsValid() && m_height.IsValid(); } | |
667 | ||
603f702b JS |
668 | wxTextAttrDimension m_width; |
669 | wxTextAttrDimension m_height; | |
670 | }; | |
671 | ||
23bdfeee JS |
672 | /** |
673 | @class wxTextAttrDimensionConverter | |
674 | A class to make it easier to convert dimensions. | |
675 | ||
676 | @library{wxrichtext} | |
677 | @category{richtext} | |
678 | ||
679 | @see wxRichTextAttr, wxRichTextCtrl, wxTextAttrDimension | |
680 | */ | |
681 | ||
bec80f4f JS |
682 | class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensionConverter |
683 | { | |
684 | public: | |
23bdfeee JS |
685 | /** |
686 | Constructor. | |
687 | */ | |
8995db52 | 688 | wxTextAttrDimensionConverter(wxDC& dc, double scale = 1.0, const wxSize& parentSize = wxDefaultSize); |
23bdfeee JS |
689 | /** |
690 | Constructor. | |
691 | */ | |
8995db52 | 692 | wxTextAttrDimensionConverter(int ppi, double scale = 1.0, const wxSize& parentSize = wxDefaultSize); |
603f702b | 693 | |
23bdfeee JS |
694 | /** |
695 | Gets the pixel size for the given dimension. | |
696 | */ | |
bec80f4f | 697 | int GetPixels(const wxTextAttrDimension& dim, int direction = wxHORIZONTAL) const; |
23bdfeee JS |
698 | /** |
699 | Gets the mm size for the given dimension. | |
700 | */ | |
bec80f4f JS |
701 | int GetTenthsMM(const wxTextAttrDimension& dim) const; |
702 | ||
23bdfeee JS |
703 | /** |
704 | Converts tenths of a mm to pixels. | |
705 | */ | |
bec80f4f | 706 | int ConvertTenthsMMToPixels(int units) const; |
23bdfeee JS |
707 | /** |
708 | Converts pixels to tenths of a mm. | |
709 | */ | |
bec80f4f JS |
710 | int ConvertPixelsToTenthsMM(int pixels) const; |
711 | ||
712 | int m_ppi; | |
713 | double m_scale; | |
714 | wxSize m_parentSize; | |
715 | }; | |
716 | ||
706465df JS |
717 | /** |
718 | Border styles, used with wxTextAttrBorder. | |
719 | */ | |
bec80f4f | 720 | enum wxTextAttrBorderStyle |
24777478 JS |
721 | { |
722 | wxTEXT_BOX_ATTR_BORDER_NONE = 0, | |
723 | wxTEXT_BOX_ATTR_BORDER_SOLID = 1, | |
724 | wxTEXT_BOX_ATTR_BORDER_DOTTED = 2, | |
725 | wxTEXT_BOX_ATTR_BORDER_DASHED = 3, | |
726 | wxTEXT_BOX_ATTR_BORDER_DOUBLE = 4, | |
727 | wxTEXT_BOX_ATTR_BORDER_GROOVE = 5, | |
728 | wxTEXT_BOX_ATTR_BORDER_RIDGE = 6, | |
729 | wxTEXT_BOX_ATTR_BORDER_INSET = 7, | |
730 | wxTEXT_BOX_ATTR_BORDER_OUTSET = 8 | |
731 | }; | |
732 | ||
706465df JS |
733 | /** |
734 | Border style presence flags, used with wxTextAttrBorder. | |
735 | */ | |
bec80f4f | 736 | enum wxTextAttrBorderFlags |
24777478 JS |
737 | { |
738 | wxTEXT_BOX_ATTR_BORDER_STYLE = 0x0001, | |
739 | wxTEXT_BOX_ATTR_BORDER_COLOUR = 0x0002 | |
740 | }; | |
741 | ||
706465df JS |
742 | /** |
743 | Border width symbols for qualitative widths, used with wxTextAttrBorder. | |
744 | */ | |
bec80f4f JS |
745 | enum wxTextAttrBorderWidth |
746 | { | |
747 | wxTEXT_BOX_ATTR_BORDER_THIN = -1, | |
748 | wxTEXT_BOX_ATTR_BORDER_MEDIUM = -2, | |
749 | wxTEXT_BOX_ATTR_BORDER_THICK = -3 | |
750 | }; | |
751 | ||
706465df JS |
752 | /** |
753 | Float styles. | |
754 | */ | |
24777478 JS |
755 | enum wxTextBoxAttrFloatStyle |
756 | { | |
757 | wxTEXT_BOX_ATTR_FLOAT_NONE = 0, | |
758 | wxTEXT_BOX_ATTR_FLOAT_LEFT = 1, | |
759 | wxTEXT_BOX_ATTR_FLOAT_RIGHT = 2 | |
760 | }; | |
761 | ||
706465df JS |
762 | /** |
763 | Clear styles. | |
764 | */ | |
24777478 JS |
765 | enum wxTextBoxAttrClearStyle |
766 | { | |
767 | wxTEXT_BOX_ATTR_CLEAR_NONE = 0, | |
768 | wxTEXT_BOX_ATTR_CLEAR_LEFT = 1, | |
769 | wxTEXT_BOX_ATTR_CLEAR_RIGHT = 2, | |
770 | wxTEXT_BOX_ATTR_CLEAR_BOTH = 3 | |
771 | }; | |
772 | ||
706465df JS |
773 | /** |
774 | Collapse mode styles. TODO: can they be switched on per side? | |
775 | */ | |
24777478 JS |
776 | enum wxTextBoxAttrCollapseMode |
777 | { | |
778 | wxTEXT_BOX_ATTR_COLLAPSE_NONE = 0, | |
779 | wxTEXT_BOX_ATTR_COLLAPSE_FULL = 1 | |
780 | }; | |
781 | ||
706465df JS |
782 | /** |
783 | Vertical alignment values. | |
784 | */ | |
603f702b JS |
785 | enum wxTextBoxAttrVerticalAlignment |
786 | { | |
787 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE = 0, | |
788 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP = 1, | |
789 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE = 2, | |
790 | wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM = 3 | |
791 | }; | |
792 | ||
23bdfeee JS |
793 | /** |
794 | @class wxTextAttrBorder | |
795 | A class representing a rich text object border. | |
796 | ||
797 | @library{wxrichtext} | |
798 | @category{richtext} | |
799 | ||
800 | @see wxRichTextAttr, wxRichTextCtrl, wxRichTextAttrBorders | |
801 | */ | |
802 | ||
bec80f4f | 803 | class WXDLLIMPEXP_RICHTEXT wxTextAttrBorder |
24777478 JS |
804 | { |
805 | public: | |
23bdfeee JS |
806 | /** |
807 | Default constructor. | |
808 | */ | |
bec80f4f | 809 | wxTextAttrBorder() { Reset(); } |
603f702b | 810 | |
23bdfeee JS |
811 | /** |
812 | Equality operator. | |
813 | */ | |
bec80f4f | 814 | bool operator==(const wxTextAttrBorder& border) const |
24777478 JS |
815 | { |
816 | return m_flags == border.m_flags && m_borderStyle == border.m_borderStyle && | |
817 | m_borderColour == border.m_borderColour && m_borderWidth == border.m_borderWidth; | |
818 | } | |
819 | ||
23bdfeee JS |
820 | /** |
821 | Resets the border style, colour, width and flags. | |
822 | */ | |
24777478 JS |
823 | void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); } |
824 | ||
23bdfeee | 825 | /** |
32423dd8 JS |
826 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
827 | have to be present if those attributes of @a border are present. If @a weakTest is | |
828 | @false, the function will fail if an attribute is present in @a border but not | |
829 | in this object. | |
23bdfeee | 830 | */ |
32423dd8 | 831 | bool EqPartial(const wxTextAttrBorder& border, bool weakTest = true) const; |
cdaed652 | 832 | |
23bdfeee JS |
833 | /** |
834 | Applies the border to this object, but not if the same as @a compareWith. | |
835 | ||
836 | */ | |
bec80f4f | 837 | bool Apply(const wxTextAttrBorder& border, const wxTextAttrBorder* compareWith = NULL); |
24777478 | 838 | |
23bdfeee JS |
839 | /** |
840 | Removes the specified attributes from this object. | |
841 | */ | |
bec80f4f | 842 | bool RemoveStyle(const wxTextAttrBorder& attr); |
24777478 | 843 | |
23bdfeee JS |
844 | /** |
845 | Collects the attributes that are common to a range of content, building up a note of | |
846 | which attributes are absent in some objects and which clash in some objects. | |
847 | */ | |
bec80f4f | 848 | void CollectCommonAttributes(const wxTextAttrBorder& attr, wxTextAttrBorder& clashingAttr, wxTextAttrBorder& absentAttr); |
24777478 | 849 | |
23bdfeee JS |
850 | /** |
851 | Sets the border style. | |
852 | */ | |
24777478 | 853 | void SetStyle(int style) { m_borderStyle = style; m_flags |= wxTEXT_BOX_ATTR_BORDER_STYLE; } |
23bdfeee JS |
854 | |
855 | /** | |
856 | Gets the border style. | |
857 | ||
858 | */ | |
24777478 JS |
859 | int GetStyle() const { return m_borderStyle; } |
860 | ||
23bdfeee JS |
861 | /** |
862 | Sets the border colour. | |
863 | */ | |
24777478 | 864 | void SetColour(unsigned long colour) { m_borderColour = colour; m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } |
23bdfeee JS |
865 | |
866 | /** | |
867 | Sets the border colour. | |
868 | */ | |
24777478 | 869 | void SetColour(const wxColour& colour) { m_borderColour = colour.GetRGB(); m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } |
23bdfeee JS |
870 | |
871 | /** | |
872 | Gets the colour as a long. | |
873 | */ | |
24777478 | 874 | unsigned long GetColourLong() const { return m_borderColour; } |
23bdfeee JS |
875 | |
876 | /** | |
877 | Gets the colour. | |
878 | */ | |
24777478 JS |
879 | wxColour GetColour() const { return wxColour(m_borderColour); } |
880 | ||
23bdfeee JS |
881 | /** |
882 | Gets the border width. | |
883 | */ | |
24777478 JS |
884 | wxTextAttrDimension& GetWidth() { return m_borderWidth; } |
885 | const wxTextAttrDimension& GetWidth() const { return m_borderWidth; } | |
23bdfeee JS |
886 | |
887 | /** | |
888 | Sets the border width. | |
889 | */ | |
24777478 | 890 | void SetWidth(const wxTextAttrDimension& width) { m_borderWidth = width; } |
23bdfeee JS |
891 | /** |
892 | Sets the border width. | |
893 | */ | |
603f702b | 894 | void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); } |
24777478 | 895 | |
23bdfeee JS |
896 | /** |
897 | True if the border has a valid style. | |
898 | */ | |
bec80f4f | 899 | bool HasStyle() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_STYLE) != 0; } |
23bdfeee JS |
900 | |
901 | /** | |
902 | True if the border has a valid colour. | |
903 | */ | |
bec80f4f | 904 | bool HasColour() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_COLOUR) != 0; } |
23bdfeee JS |
905 | |
906 | /** | |
907 | True if the border has a valid width. | |
908 | */ | |
603f702b JS |
909 | bool HasWidth() const { return m_borderWidth.IsValid(); } |
910 | ||
23bdfeee JS |
911 | /** |
912 | True if the border is valid. | |
913 | */ | |
603f702b | 914 | bool IsValid() const { return HasWidth(); } |
23bdfeee JS |
915 | |
916 | /** | |
917 | Set the valid flag for this border. | |
918 | */ | |
603f702b JS |
919 | void MakeValid() { m_borderWidth.SetValid(true); } |
920 | ||
23bdfeee JS |
921 | /** |
922 | Returns the border flags. | |
923 | */ | |
24777478 | 924 | int GetFlags() const { return m_flags; } |
23bdfeee JS |
925 | |
926 | /** | |
927 | Sets the border flags. | |
928 | */ | |
24777478 | 929 | void SetFlags(int flags) { m_flags = flags; } |
23bdfeee JS |
930 | |
931 | /** | |
932 | Adds a border flag. | |
933 | */ | |
24777478 | 934 | void AddFlag(int flag) { m_flags |= flag; } |
23bdfeee JS |
935 | |
936 | /** | |
937 | Removes a border flag. | |
938 | */ | |
24777478 JS |
939 | void RemoveFlag(int flag) { m_flags &= ~flag; } |
940 | ||
941 | int m_borderStyle; | |
942 | unsigned long m_borderColour; | |
943 | wxTextAttrDimension m_borderWidth; | |
944 | int m_flags; | |
945 | }; | |
946 | ||
23bdfeee JS |
947 | /** |
948 | @class wxTextAttrBorders | |
949 | A class representing a rich text object's borders. | |
950 | ||
951 | @library{wxrichtext} | |
952 | @category{richtext} | |
953 | ||
954 | @see wxRichTextAttr, wxRichTextCtrl, wxRichTextAttrBorder | |
955 | */ | |
956 | ||
bec80f4f | 957 | class WXDLLIMPEXP_RICHTEXT wxTextAttrBorders |
24777478 JS |
958 | { |
959 | public: | |
23bdfeee JS |
960 | /** |
961 | Default constructor. | |
962 | */ | |
bec80f4f | 963 | wxTextAttrBorders() { } |
ce00f59b | 964 | |
23bdfeee JS |
965 | /** |
966 | Equality operator. | |
967 | */ | |
bec80f4f | 968 | bool operator==(const wxTextAttrBorders& borders) const |
24777478 JS |
969 | { |
970 | return m_left == borders.m_left && m_right == borders.m_right && | |
971 | m_top == borders.m_top && m_bottom == borders.m_bottom; | |
972 | } | |
cdaed652 | 973 | |
23bdfeee JS |
974 | /** |
975 | Sets the style of all borders. | |
976 | */ | |
24777478 | 977 | void SetStyle(int style); |
ce00f59b | 978 | |
23bdfeee JS |
979 | /** |
980 | Sets colour of all borders. | |
981 | */ | |
24777478 | 982 | void SetColour(unsigned long colour); |
23bdfeee JS |
983 | |
984 | /** | |
985 | Sets the colour for all borders. | |
986 | */ | |
24777478 | 987 | void SetColour(const wxColour& colour); |
cdaed652 | 988 | |
23bdfeee JS |
989 | /** |
990 | Sets the width of all borders. | |
991 | */ | |
24777478 | 992 | void SetWidth(const wxTextAttrDimension& width); |
23bdfeee JS |
993 | |
994 | /** | |
995 | Sets the width of all borders. | |
996 | */ | |
603f702b JS |
997 | void SetWidth(int value, wxTextAttrUnits units = wxTEXT_ATTR_UNITS_TENTHS_MM) { SetWidth(wxTextAttrDimension(value, units)); } |
998 | ||
23bdfeee JS |
999 | /** |
1000 | Resets all borders. | |
1001 | */ | |
24777478 | 1002 | void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); } |
cdaed652 | 1003 | |
23bdfeee | 1004 | /** |
32423dd8 JS |
1005 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
1006 | have to be present if those attributes of @a borders are present. If @a weakTest is | |
1007 | @false, the function will fail if an attribute is present in @a borders but not | |
1008 | in this object. | |
23bdfeee | 1009 | */ |
32423dd8 | 1010 | bool EqPartial(const wxTextAttrBorders& borders, bool weakTest = true) const; |
cdaed652 | 1011 | |
23bdfeee JS |
1012 | /** |
1013 | Applies border to this object, but not if the same as @a compareWith. | |
1014 | */ | |
bec80f4f | 1015 | bool Apply(const wxTextAttrBorders& borders, const wxTextAttrBorders* compareWith = NULL); |
cdaed652 | 1016 | |
23bdfeee JS |
1017 | /** |
1018 | Removes the specified attributes from this object. | |
1019 | */ | |
bec80f4f | 1020 | bool RemoveStyle(const wxTextAttrBorders& attr); |
cdaed652 | 1021 | |
23bdfeee JS |
1022 | /** |
1023 | Collects the attributes that are common to a range of content, building up a note of | |
1024 | which attributes are absent in some objects and which clash in some objects. | |
1025 | */ | |
bec80f4f | 1026 | void CollectCommonAttributes(const wxTextAttrBorders& attr, wxTextAttrBorders& clashingAttr, wxTextAttrBorders& absentAttr); |
603f702b | 1027 | |
23bdfeee JS |
1028 | /** |
1029 | Returns @true if all borders are valid. | |
1030 | */ | |
603f702b | 1031 | bool IsValid() const { return m_left.IsValid() || m_right.IsValid() || m_top.IsValid() || m_bottom.IsValid(); } |
cdaed652 | 1032 | |
23bdfeee JS |
1033 | /** |
1034 | Returns the left border. | |
1035 | */ | |
bec80f4f JS |
1036 | const wxTextAttrBorder& GetLeft() const { return m_left; } |
1037 | wxTextAttrBorder& GetLeft() { return m_left; } | |
603f702b | 1038 | |
23bdfeee JS |
1039 | /** |
1040 | Returns the right border. | |
1041 | */ | |
bec80f4f JS |
1042 | const wxTextAttrBorder& GetRight() const { return m_right; } |
1043 | wxTextAttrBorder& GetRight() { return m_right; } | |
603f702b | 1044 | |
23bdfeee JS |
1045 | /** |
1046 | Returns the top border. | |
1047 | */ | |
bec80f4f JS |
1048 | const wxTextAttrBorder& GetTop() const { return m_top; } |
1049 | wxTextAttrBorder& GetTop() { return m_top; } | |
603f702b | 1050 | |
23bdfeee JS |
1051 | /** |
1052 | Returns the bottom border. | |
1053 | */ | |
bec80f4f JS |
1054 | const wxTextAttrBorder& GetBottom() const { return m_bottom; } |
1055 | wxTextAttrBorder& GetBottom() { return m_bottom; } | |
603f702b | 1056 | |
bec80f4f | 1057 | wxTextAttrBorder m_left, m_right, m_top, m_bottom; |
cdaed652 | 1058 | |
24777478 JS |
1059 | }; |
1060 | ||
23bdfeee JS |
1061 | /** |
1062 | @class wxTextBoxAttr | |
1063 | A class representing the box attributes of a rich text object. | |
1064 | ||
1065 | @library{wxrichtext} | |
1066 | @category{richtext} | |
1067 | ||
1068 | @see wxRichTextAttr, wxRichTextCtrl | |
1069 | */ | |
24777478 | 1070 | |
6ffb5e91 | 1071 | class WXDLLIMPEXP_RICHTEXT wxTextBoxAttr |
24777478 JS |
1072 | { |
1073 | public: | |
23bdfeee JS |
1074 | /** |
1075 | Default constructor. | |
1076 | */ | |
24777478 | 1077 | wxTextBoxAttr() { Init(); } |
23bdfeee JS |
1078 | |
1079 | /** | |
1080 | Copy constructor. | |
1081 | */ | |
24777478 JS |
1082 | wxTextBoxAttr(const wxTextBoxAttr& attr) { Init(); (*this) = attr; } |
1083 | ||
23bdfeee JS |
1084 | /** |
1085 | Initialises this object. | |
1086 | */ | |
24777478 JS |
1087 | void Init() { Reset(); } |
1088 | ||
23bdfeee JS |
1089 | /** |
1090 | Resets this object. | |
1091 | */ | |
24777478 JS |
1092 | void Reset(); |
1093 | ||
bec80f4f | 1094 | // Copy. Unnecessary since we let it do a binary copy |
24777478 JS |
1095 | //void Copy(const wxTextBoxAttr& attr); |
1096 | ||
1097 | // Assignment | |
1098 | //void operator= (const wxTextBoxAttr& attr); | |
1099 | ||
23bdfeee JS |
1100 | /** |
1101 | Equality test. | |
1102 | */ | |
24777478 JS |
1103 | bool operator== (const wxTextBoxAttr& attr) const; |
1104 | ||
23bdfeee | 1105 | /** |
32423dd8 JS |
1106 | Partial equality test, ignoring unset attributes. If @a weakTest is @true, attributes of this object do not |
1107 | have to be present if those attributes of @a attr are present. If @a weakTest is | |
1108 | @false, the function will fail if an attribute is present in @a attr but not | |
1109 | in this object. | |
23bdfeee JS |
1110 | |
1111 | */ | |
32423dd8 | 1112 | bool EqPartial(const wxTextBoxAttr& attr, bool weakTest = true) const; |
24777478 | 1113 | |
23bdfeee JS |
1114 | /** |
1115 | Merges the given attributes. If @a compareWith is non-NULL, then it will be used | |
1116 | to mask out those attributes that are the same in style and @a compareWith, for | |
1117 | situations where we don't want to explicitly set inherited attributes. | |
1118 | */ | |
24777478 | 1119 | bool Apply(const wxTextBoxAttr& style, const wxTextBoxAttr* compareWith = NULL); |
603f702b | 1120 | |
23bdfeee JS |
1121 | /** |
1122 | Collects the attributes that are common to a range of content, building up a note of | |
1123 | which attributes are absent in some objects and which clash in some objects. | |
1124 | */ | |
24777478 JS |
1125 | void CollectCommonAttributes(const wxTextBoxAttr& attr, wxTextBoxAttr& clashingAttr, wxTextBoxAttr& absentAttr); |
1126 | ||
23bdfeee JS |
1127 | /** |
1128 | Removes the specified attributes from this object. | |
1129 | */ | |
24777478 JS |
1130 | bool RemoveStyle(const wxTextBoxAttr& attr); |
1131 | ||
23bdfeee JS |
1132 | /** |
1133 | Sets the flags. | |
1134 | */ | |
24777478 JS |
1135 | void SetFlags(int flags) { m_flags = flags; } |
1136 | ||
23bdfeee JS |
1137 | /** |
1138 | Returns the flags. | |
1139 | */ | |
24777478 JS |
1140 | int GetFlags() const { return m_flags; } |
1141 | ||
23bdfeee JS |
1142 | /** |
1143 | Is this flag present? | |
1144 | */ | |
24777478 JS |
1145 | bool HasFlag(wxTextBoxAttrFlags flag) const { return (m_flags & flag) != 0; } |
1146 | ||
23bdfeee JS |
1147 | /** |
1148 | Removes this flag. | |
1149 | */ | |
24777478 JS |
1150 | void RemoveFlag(wxTextBoxAttrFlags flag) { m_flags &= ~flag; } |
1151 | ||
23bdfeee JS |
1152 | /** |
1153 | Adds this flag. | |
1154 | */ | |
24777478 JS |
1155 | void AddFlag(wxTextBoxAttrFlags flag) { m_flags |= flag; } |
1156 | ||
23bdfeee JS |
1157 | /** |
1158 | Returns @true if no attributes are set. | |
1159 | */ | |
24777478 JS |
1160 | bool IsDefault() const; |
1161 | ||
23bdfeee JS |
1162 | /** |
1163 | Returns the float mode. | |
1164 | */ | |
603f702b JS |
1165 | wxTextBoxAttrFloatStyle GetFloatMode() const { return m_floatMode; } |
1166 | ||
23bdfeee JS |
1167 | /** |
1168 | Sets the float mode. | |
1169 | */ | |
603f702b JS |
1170 | void SetFloatMode(wxTextBoxAttrFloatStyle mode) { m_floatMode = mode; m_flags |= wxTEXT_BOX_ATTR_FLOAT; } |
1171 | ||
23bdfeee JS |
1172 | /** |
1173 | Returns @true if float mode is active. | |
1174 | */ | |
24777478 | 1175 | bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT); } |
603f702b | 1176 | |
23bdfeee | 1177 | /** |
b3169c12 | 1178 | Returns @true if this object is floating. |
23bdfeee | 1179 | */ |
24777478 JS |
1180 | bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE; } |
1181 | ||
23bdfeee JS |
1182 | /** |
1183 | Returns the clear mode - whether to wrap text after object. Currently unimplemented. | |
1184 | */ | |
603f702b JS |
1185 | wxTextBoxAttrClearStyle GetClearMode() const { return m_clearMode; } |
1186 | ||
23bdfeee JS |
1187 | /** |
1188 | Set the clear mode. Currently unimplemented. | |
1189 | */ | |
603f702b JS |
1190 | void SetClearMode(wxTextBoxAttrClearStyle mode) { m_clearMode = mode; m_flags |= wxTEXT_BOX_ATTR_CLEAR; } |
1191 | ||
23bdfeee JS |
1192 | /** |
1193 | Returns @true if we have a clear flag. | |
1194 | */ | |
24777478 JS |
1195 | bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR); } |
1196 | ||
23bdfeee JS |
1197 | /** |
1198 | Returns the collapse mode - whether to collapse borders. Currently unimplemented. | |
1199 | */ | |
603f702b JS |
1200 | wxTextBoxAttrCollapseMode GetCollapseBorders() const { return m_collapseMode; } |
1201 | ||
23bdfeee JS |
1202 | /** |
1203 | Sets the collapse mode - whether to collapse borders. Currently unimplemented. | |
1204 | */ | |
603f702b JS |
1205 | void SetCollapseBorders(wxTextBoxAttrCollapseMode collapse) { m_collapseMode = collapse; m_flags |= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS; } |
1206 | ||
23bdfeee JS |
1207 | /** |
1208 | Returns @true if the collapse borders flag is present. | |
1209 | */ | |
24777478 | 1210 | bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS); } |
603f702b | 1211 | |
23bdfeee JS |
1212 | /** |
1213 | Returns the vertical alignment. | |
1214 | */ | |
603f702b JS |
1215 | wxTextBoxAttrVerticalAlignment GetVerticalAlignment() const { return m_verticalAlignment; } |
1216 | ||
23bdfeee JS |
1217 | /** |
1218 | Sets the vertical alignment. | |
1219 | */ | |
603f702b JS |
1220 | void SetVerticalAlignment(wxTextBoxAttrVerticalAlignment verticalAlignment) { m_verticalAlignment = verticalAlignment; m_flags |= wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT; } |
1221 | ||
23bdfeee JS |
1222 | /** |
1223 | Returns @true if a vertical alignment flag is present. | |
1224 | */ | |
603f702b JS |
1225 | bool HasVerticalAlignment() const { return HasFlag(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT); } |
1226 | ||
23bdfeee JS |
1227 | /** |
1228 | Returns the margin values. | |
1229 | */ | |
bec80f4f JS |
1230 | wxTextAttrDimensions& GetMargins() { return m_margins; } |
1231 | const wxTextAttrDimensions& GetMargins() const { return m_margins; } | |
1232 | ||
23bdfeee JS |
1233 | /** |
1234 | Returns the left margin. | |
1235 | */ | |
24777478 JS |
1236 | wxTextAttrDimension& GetLeftMargin() { return m_margins.m_left; } |
1237 | const wxTextAttrDimension& GetLeftMargin() const { return m_margins.m_left; } | |
1238 | ||
23bdfeee JS |
1239 | /** |
1240 | Returns the right margin. | |
1241 | */ | |
24777478 JS |
1242 | wxTextAttrDimension& GetRightMargin() { return m_margins.m_right; } |
1243 | const wxTextAttrDimension& GetRightMargin() const { return m_margins.m_right; } | |
1244 | ||
23bdfeee JS |
1245 | /** |
1246 | Returns the top margin. | |
1247 | */ | |
24777478 JS |
1248 | wxTextAttrDimension& GetTopMargin() { return m_margins.m_top; } |
1249 | const wxTextAttrDimension& GetTopMargin() const { return m_margins.m_top; } | |
603f702b | 1250 | |
23bdfeee JS |
1251 | /** |
1252 | Returns the bottom margin. | |
1253 | */ | |
24777478 JS |
1254 | wxTextAttrDimension& GetBottomMargin() { return m_margins.m_bottom; } |
1255 | const wxTextAttrDimension& GetBottomMargin() const { return m_margins.m_bottom; } | |
1256 | ||
23bdfeee JS |
1257 | /** |
1258 | Returns the position. | |
1259 | */ | |
bec80f4f JS |
1260 | wxTextAttrDimensions& GetPosition() { return m_position; } |
1261 | const wxTextAttrDimensions& GetPosition() const { return m_position; } | |
1262 | ||
23bdfeee JS |
1263 | /** |
1264 | Returns the left position. | |
1265 | */ | |
24777478 JS |
1266 | wxTextAttrDimension& GetLeft() { return m_position.m_left; } |
1267 | const wxTextAttrDimension& GetLeft() const { return m_position.m_left; } | |
1268 | ||
23bdfeee JS |
1269 | /** |
1270 | Returns the right position. | |
1271 | */ | |
24777478 JS |
1272 | wxTextAttrDimension& GetRight() { return m_position.m_right; } |
1273 | const wxTextAttrDimension& GetRight() const { return m_position.m_right; } | |
1274 | ||
23bdfeee JS |
1275 | /** |
1276 | Returns the top position. | |
1277 | */ | |
24777478 JS |
1278 | wxTextAttrDimension& GetTop() { return m_position.m_top; } |
1279 | const wxTextAttrDimension& GetTop() const { return m_position.m_top; } | |
603f702b | 1280 | |
23bdfeee JS |
1281 | /** |
1282 | Returns the bottom position. | |
1283 | */ | |
24777478 JS |
1284 | wxTextAttrDimension& GetBottom() { return m_position.m_bottom; } |
1285 | const wxTextAttrDimension& GetBottom() const { return m_position.m_bottom; } | |
1286 | ||
23bdfeee JS |
1287 | /** |
1288 | Returns the padding values. | |
1289 | */ | |
bec80f4f JS |
1290 | wxTextAttrDimensions& GetPadding() { return m_padding; } |
1291 | const wxTextAttrDimensions& GetPadding() const { return m_padding; } | |
1292 | ||
23bdfeee JS |
1293 | /** |
1294 | Returns the left padding value. | |
1295 | */ | |
24777478 JS |
1296 | wxTextAttrDimension& GetLeftPadding() { return m_padding.m_left; } |
1297 | const wxTextAttrDimension& GetLeftPadding() const { return m_padding.m_left; } | |
603f702b | 1298 | |
23bdfeee JS |
1299 | /** |
1300 | Returns the right padding value. | |
1301 | */ | |
24777478 JS |
1302 | wxTextAttrDimension& GetRightPadding() { return m_padding.m_right; } |
1303 | const wxTextAttrDimension& GetRightPadding() const { return m_padding.m_right; } | |
603f702b | 1304 | |
23bdfeee JS |
1305 | /** |
1306 | Returns the top padding value. | |
1307 | */ | |
24777478 JS |
1308 | wxTextAttrDimension& GetTopPadding() { return m_padding.m_top; } |
1309 | const wxTextAttrDimension& GetTopPadding() const { return m_padding.m_top; } | |
1310 | ||
23bdfeee JS |
1311 | /** |
1312 | Returns the bottom padding value. | |
1313 | */ | |
24777478 JS |
1314 | wxTextAttrDimension& GetBottomPadding() { return m_padding.m_bottom; } |
1315 | const wxTextAttrDimension& GetBottomPadding() const { return m_padding.m_bottom; } | |
24777478 | 1316 | |
23bdfeee JS |
1317 | /** |
1318 | Returns the borders. | |
1319 | */ | |
bec80f4f JS |
1320 | wxTextAttrBorders& GetBorder() { return m_border; } |
1321 | const wxTextAttrBorders& GetBorder() const { return m_border; } | |
24777478 | 1322 | |
23bdfeee JS |
1323 | /** |
1324 | Returns the left border. | |
1325 | */ | |
bec80f4f JS |
1326 | wxTextAttrBorder& GetLeftBorder() { return m_border.m_left; } |
1327 | const wxTextAttrBorder& GetLeftBorder() const { return m_border.m_left; } | |
24777478 | 1328 | |
23bdfeee JS |
1329 | /** |
1330 | Returns the top border. | |
1331 | */ | |
bec80f4f JS |
1332 | wxTextAttrBorder& GetTopBorder() { return m_border.m_top; } |
1333 | const wxTextAttrBorder& GetTopBorder() const { return m_border.m_top; } | |
24777478 | 1334 | |
23bdfeee JS |
1335 | /** |
1336 | Returns the right border. | |
1337 | */ | |
bec80f4f JS |
1338 | wxTextAttrBorder& GetRightBorder() { return m_border.m_right; } |
1339 | const wxTextAttrBorder& GetRightBorder() const { return m_border.m_right; } | |
24777478 | 1340 | |
23bdfeee JS |
1341 | /** |
1342 | Returns the bottom border. | |
1343 | */ | |
bec80f4f JS |
1344 | wxTextAttrBorder& GetBottomBorder() { return m_border.m_bottom; } |
1345 | const wxTextAttrBorder& GetBottomBorder() const { return m_border.m_bottom; } | |
24777478 | 1346 | |
23bdfeee JS |
1347 | /** |
1348 | Returns the outline. | |
1349 | */ | |
bec80f4f JS |
1350 | wxTextAttrBorders& GetOutline() { return m_outline; } |
1351 | const wxTextAttrBorders& GetOutline() const { return m_outline; } | |
24777478 | 1352 | |
23bdfeee JS |
1353 | /** |
1354 | Returns the left outline. | |
1355 | */ | |
bec80f4f JS |
1356 | wxTextAttrBorder& GetLeftOutline() { return m_outline.m_left; } |
1357 | const wxTextAttrBorder& GetLeftOutline() const { return m_outline.m_left; } | |
24777478 | 1358 | |
23bdfeee JS |
1359 | /** |
1360 | Returns the top outline. | |
1361 | */ | |
bec80f4f JS |
1362 | wxTextAttrBorder& GetTopOutline() { return m_outline.m_top; } |
1363 | const wxTextAttrBorder& GetTopOutline() const { return m_outline.m_top; } | |
24777478 | 1364 | |
23bdfeee JS |
1365 | /** |
1366 | Returns the right outline. | |
1367 | */ | |
bec80f4f JS |
1368 | wxTextAttrBorder& GetRightOutline() { return m_outline.m_right; } |
1369 | const wxTextAttrBorder& GetRightOutline() const { return m_outline.m_right; } | |
24777478 | 1370 | |
23bdfeee JS |
1371 | /** |
1372 | Returns the bottom outline. | |
1373 | */ | |
bec80f4f JS |
1374 | wxTextAttrBorder& GetBottomOutline() { return m_outline.m_bottom; } |
1375 | const wxTextAttrBorder& GetBottomOutline() const { return m_outline.m_bottom; } | |
24777478 | 1376 | |
23bdfeee JS |
1377 | /** |
1378 | Returns the object size. | |
1379 | */ | |
603f702b JS |
1380 | wxTextAttrSize& GetSize() { return m_size; } |
1381 | const wxTextAttrSize& GetSize() const { return m_size; } | |
24777478 | 1382 | |
303f0be7 JS |
1383 | /** |
1384 | Returns the object minimum size. | |
1385 | */ | |
1386 | ||
1387 | wxTextAttrSize& GetMinSize() { return m_minSize; } | |
1388 | const wxTextAttrSize& GetMinSize() const { return m_minSize; } | |
1389 | ||
1390 | /** | |
1391 | Returns the object maximum size. | |
1392 | */ | |
1393 | ||
1394 | wxTextAttrSize& GetMaxSize() { return m_maxSize; } | |
1395 | const wxTextAttrSize& GetMaxSize() const { return m_maxSize; } | |
1396 | ||
23bdfeee JS |
1397 | /** |
1398 | Sets the object size. | |
1399 | */ | |
603f702b | 1400 | void SetSize(const wxTextAttrSize& sz) { m_size = sz; } |
24777478 | 1401 | |
303f0be7 JS |
1402 | /** |
1403 | Sets the object minimum size. | |
1404 | */ | |
1405 | void SetMinSize(const wxTextAttrSize& sz) { m_minSize = sz; } | |
1406 | ||
1407 | /** | |
1408 | Sets the object maximum size. | |
1409 | */ | |
1410 | void SetMaxSize(const wxTextAttrSize& sz) { m_maxSize = sz; } | |
1411 | ||
23bdfeee JS |
1412 | /** |
1413 | Returns the object width. | |
1414 | */ | |
603f702b JS |
1415 | wxTextAttrDimension& GetWidth() { return m_size.m_width; } |
1416 | const wxTextAttrDimension& GetWidth() const { return m_size.m_width; } | |
1417 | ||
23bdfeee JS |
1418 | /** |
1419 | Returns the object height. | |
1420 | */ | |
603f702b JS |
1421 | wxTextAttrDimension& GetHeight() { return m_size.m_height; } |
1422 | const wxTextAttrDimension& GetHeight() const { return m_size.m_height; } | |
24777478 | 1423 | |
2f987d83 JS |
1424 | /** |
1425 | Returns the box style name. | |
1426 | */ | |
1427 | const wxString& GetBoxStyleName() const { return m_boxStyleName; } | |
1428 | ||
1429 | /** | |
1430 | Sets the box style name. | |
1431 | */ | |
1432 | void SetBoxStyleName(const wxString& name) { m_boxStyleName = name; AddFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); } | |
1433 | ||
1434 | /** | |
1435 | Returns @true if the box style name is present. | |
1436 | */ | |
1437 | bool HasBoxStyleName() const { return HasFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); } | |
1438 | ||
24777478 JS |
1439 | public: |
1440 | ||
603f702b | 1441 | int m_flags; |
24777478 | 1442 | |
603f702b JS |
1443 | wxTextAttrDimensions m_margins; |
1444 | wxTextAttrDimensions m_padding; | |
1445 | wxTextAttrDimensions m_position; | |
24777478 | 1446 | |
603f702b | 1447 | wxTextAttrSize m_size; |
303f0be7 JS |
1448 | wxTextAttrSize m_minSize; |
1449 | wxTextAttrSize m_maxSize; | |
24777478 | 1450 | |
603f702b JS |
1451 | wxTextAttrBorders m_border; |
1452 | wxTextAttrBorders m_outline; | |
1453 | ||
1454 | wxTextBoxAttrFloatStyle m_floatMode; | |
1455 | wxTextBoxAttrClearStyle m_clearMode; | |
1456 | wxTextBoxAttrCollapseMode m_collapseMode; | |
1457 | wxTextBoxAttrVerticalAlignment m_verticalAlignment; | |
2f987d83 | 1458 | wxString m_boxStyleName; |
24777478 JS |
1459 | }; |
1460 | ||
23bdfeee JS |
1461 | /** |
1462 | @class wxRichTextAttr | |
1463 | A class representing enhanced attributes for rich text objects. | |
1464 | This adds a wxTextBoxAttr member to the basic wxTextAttr class. | |
1465 | ||
1466 | @library{wxrichtext} | |
1467 | @category{richtext} | |
1468 | ||
1469 | @see wxRichTextAttr, wxTextBoxAttr, wxRichTextCtrl | |
1470 | */ | |
24777478 JS |
1471 | |
1472 | class WXDLLIMPEXP_RICHTEXT wxRichTextAttr: public wxTextAttr | |
1473 | { | |
1474 | public: | |
23bdfeee JS |
1475 | /** |
1476 | Constructor taking a wxTextAttr. | |
1477 | */ | |
24777478 | 1478 | wxRichTextAttr(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } |
23bdfeee JS |
1479 | |
1480 | /** | |
1481 | Copy constructor. | |
1482 | */ | |
603f702b | 1483 | wxRichTextAttr(const wxRichTextAttr& attr): wxTextAttr() { Copy(attr); } |
23bdfeee JS |
1484 | |
1485 | /** | |
1486 | Default constructor. | |
1487 | */ | |
24777478 | 1488 | wxRichTextAttr() {} |
603f702b | 1489 | |
23bdfeee JS |
1490 | /** |
1491 | Copy function. | |
1492 | */ | |
24777478 | 1493 | void Copy(const wxRichTextAttr& attr); |
603f702b | 1494 | |
23bdfeee JS |
1495 | /** |
1496 | Assignment operator. | |
1497 | */ | |
24777478 | 1498 | void operator=(const wxRichTextAttr& attr) { Copy(attr); } |
23bdfeee JS |
1499 | |
1500 | /** | |
1501 | Assignment operator. | |
1502 | */ | |
24777478 | 1503 | void operator=(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } |
603f702b | 1504 | |
23bdfeee JS |
1505 | /** |
1506 | Equality test. | |
1507 | */ | |
24777478 JS |
1508 | bool operator==(const wxRichTextAttr& attr) const; |
1509 | ||
23bdfeee | 1510 | /** |
32423dd8 JS |
1511 | Partial equality test. If @a weakTest is @true, attributes of this object do not |
1512 | have to be present if those attributes of @a attr are present. If @a weakTest is | |
1513 | @false, the function will fail if an attribute is present in @a attr but not | |
1514 | in this object. | |
23bdfeee | 1515 | */ |
32423dd8 | 1516 | bool EqPartial(const wxRichTextAttr& attr, bool weakTest = true) const; |
24777478 | 1517 | |
23bdfeee JS |
1518 | /** |
1519 | Merges the given attributes. If @a compareWith | |
1520 | is non-NULL, then it will be used to mask out those attributes that are the same in style | |
1521 | and @a compareWith, for situations where we don't want to explicitly set inherited attributes. | |
1522 | */ | |
24777478 JS |
1523 | bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL); |
1524 | ||
23bdfeee JS |
1525 | /** |
1526 | Collects the attributes that are common to a range of content, building up a note of | |
1527 | which attributes are absent in some objects and which clash in some objects. | |
1528 | */ | |
24777478 JS |
1529 | void CollectCommonAttributes(const wxRichTextAttr& attr, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); |
1530 | ||
23bdfeee JS |
1531 | /** |
1532 | Removes the specified attributes from this object. | |
1533 | */ | |
24777478 JS |
1534 | bool RemoveStyle(const wxRichTextAttr& attr); |
1535 | ||
23bdfeee JS |
1536 | /** |
1537 | Returns the text box attributes. | |
1538 | */ | |
24777478 JS |
1539 | wxTextBoxAttr& GetTextBoxAttr() { return m_textBoxAttr; } |
1540 | const wxTextBoxAttr& GetTextBoxAttr() const { return m_textBoxAttr; } | |
23bdfeee JS |
1541 | |
1542 | /** | |
1543 | Set the text box attributes. | |
1544 | */ | |
24777478 | 1545 | void SetTextBoxAttr(const wxTextBoxAttr& attr) { m_textBoxAttr = attr; } |
603f702b | 1546 | |
f7667b84 JS |
1547 | /** |
1548 | Returns @true if no attributes are set. | |
1549 | */ | |
1550 | bool IsDefault() const { return (GetFlags() == 0) && m_textBoxAttr.IsDefault(); } | |
1551 | ||
24777478 | 1552 | wxTextBoxAttr m_textBoxAttr; |
cdaed652 VZ |
1553 | }; |
1554 | ||
f7667b84 JS |
1555 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextAttr, wxRichTextAttrArray, WXDLLIMPEXP_RICHTEXT); |
1556 | ||
bec80f4f JS |
1557 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxVariant, wxRichTextVariantArray, WXDLLIMPEXP_RICHTEXT); |
1558 | ||
343ef639 JS |
1559 | /** |
1560 | @class wxRichTextProperties | |
1561 | A simple property class using wxVariants. This is used to give each rich text object the | |
1562 | ability to store custom properties that can be used by the application. | |
1563 | ||
1564 | @library{wxrichtext} | |
1565 | @category{richtext} | |
1566 | ||
1567 | @see wxRichTextBuffer, wxRichTextObject, wxRichTextCtrl | |
1568 | */ | |
bec80f4f JS |
1569 | |
1570 | class WXDLLIMPEXP_RICHTEXT wxRichTextProperties: public wxObject | |
1571 | { | |
1572 | DECLARE_DYNAMIC_CLASS(wxRichTextProperties) | |
1573 | public: | |
343ef639 JS |
1574 | |
1575 | /** | |
1576 | Default constructor. | |
1577 | */ | |
bec80f4f | 1578 | wxRichTextProperties() {} |
343ef639 JS |
1579 | |
1580 | /** | |
1581 | Copy constructor. | |
1582 | */ | |
603f702b | 1583 | wxRichTextProperties(const wxRichTextProperties& props): wxObject() { Copy(props); } |
bec80f4f | 1584 | |
343ef639 JS |
1585 | /** |
1586 | Assignment operator. | |
1587 | */ | |
bec80f4f | 1588 | void operator=(const wxRichTextProperties& props) { Copy(props); } |
343ef639 JS |
1589 | |
1590 | /** | |
1591 | Equality operator. | |
1592 | */ | |
bec80f4f | 1593 | bool operator==(const wxRichTextProperties& props) const; |
343ef639 JS |
1594 | |
1595 | /** | |
1596 | Copies from @a props. | |
1597 | */ | |
bec80f4f | 1598 | void Copy(const wxRichTextProperties& props) { m_properties = props.m_properties; } |
343ef639 JS |
1599 | |
1600 | /** | |
1601 | Returns the variant at the given index. | |
1602 | */ | |
bec80f4f | 1603 | const wxVariant& operator[](size_t idx) const { return m_properties[idx]; } |
343ef639 JS |
1604 | |
1605 | /** | |
1606 | Returns the variant at the given index. | |
1607 | */ | |
bec80f4f | 1608 | wxVariant& operator[](size_t idx) { return m_properties[idx]; } |
343ef639 JS |
1609 | |
1610 | /** | |
1611 | Clears the properties. | |
1612 | */ | |
bec80f4f JS |
1613 | void Clear() { m_properties.Clear(); } |
1614 | ||
343ef639 JS |
1615 | /** |
1616 | Returns the array of variants implementing the properties. | |
1617 | */ | |
bec80f4f | 1618 | const wxRichTextVariantArray& GetProperties() const { return m_properties; } |
343ef639 JS |
1619 | |
1620 | /** | |
1621 | Returns the array of variants implementing the properties. | |
1622 | */ | |
bec80f4f | 1623 | wxRichTextVariantArray& GetProperties() { return m_properties; } |
343ef639 JS |
1624 | |
1625 | /** | |
1626 | Sets the array of variants. | |
1627 | */ | |
bec80f4f JS |
1628 | void SetProperties(const wxRichTextVariantArray& props) { m_properties = props; } |
1629 | ||
343ef639 JS |
1630 | /** |
1631 | Returns all the property names. | |
1632 | */ | |
bec80f4f JS |
1633 | wxArrayString GetPropertyNames() const; |
1634 | ||
343ef639 JS |
1635 | /** |
1636 | Returns a count of the properties. | |
1637 | */ | |
bec80f4f JS |
1638 | size_t GetCount() const { return m_properties.GetCount(); } |
1639 | ||
343ef639 JS |
1640 | /** |
1641 | Returns @true if the given property is found. | |
1642 | */ | |
1643 | bool HasProperty(const wxString& name) const { return Find(name) != -1; } | |
bec80f4f | 1644 | |
343ef639 JS |
1645 | /** |
1646 | Finds the given property. | |
1647 | */ | |
bec80f4f | 1648 | int Find(const wxString& name) const; |
343ef639 | 1649 | |
590a0f8b JS |
1650 | /** |
1651 | Removes the given property. | |
1652 | */ | |
1653 | bool Remove(const wxString& name); | |
1654 | ||
343ef639 JS |
1655 | /** |
1656 | Gets the property variant by name. | |
1657 | */ | |
bec80f4f | 1658 | const wxVariant& GetProperty(const wxString& name) const; |
343ef639 JS |
1659 | |
1660 | /** | |
1661 | Finds or creates a property with the given name, returning a pointer to the variant. | |
1662 | */ | |
bec80f4f JS |
1663 | wxVariant* FindOrCreateProperty(const wxString& name); |
1664 | ||
343ef639 JS |
1665 | /** |
1666 | Gets the value of the named property as a string. | |
1667 | */ | |
bec80f4f | 1668 | wxString GetPropertyString(const wxString& name) const; |
343ef639 JS |
1669 | |
1670 | /** | |
1671 | Gets the value of the named property as a long integer. | |
1672 | */ | |
bec80f4f | 1673 | long GetPropertyLong(const wxString& name) const; |
343ef639 JS |
1674 | |
1675 | /** | |
1676 | Gets the value of the named property as a boolean. | |
1677 | */ | |
bec80f4f | 1678 | bool GetPropertyBool(const wxString& name) const; |
343ef639 JS |
1679 | |
1680 | /** | |
1681 | Gets the value of the named property as a double. | |
1682 | */ | |
bec80f4f JS |
1683 | double GetPropertyDouble(const wxString& name) const; |
1684 | ||
343ef639 JS |
1685 | /** |
1686 | Sets the property by passing a variant which contains a name and value. | |
1687 | */ | |
bec80f4f | 1688 | void SetProperty(const wxVariant& variant); |
343ef639 JS |
1689 | |
1690 | /** | |
1691 | Sets a property by name and variant. | |
1692 | */ | |
bec80f4f | 1693 | void SetProperty(const wxString& name, const wxVariant& variant); |
343ef639 JS |
1694 | |
1695 | /** | |
1696 | Sets a property by name and string value. | |
1697 | */ | |
bec80f4f | 1698 | void SetProperty(const wxString& name, const wxString& value); |
343ef639 JS |
1699 | |
1700 | /** | |
1701 | Sets property by name and long integer value. | |
1702 | */ | |
bec80f4f | 1703 | void SetProperty(const wxString& name, long value); |
343ef639 JS |
1704 | |
1705 | /** | |
1706 | Sets property by name and double value. | |
1707 | */ | |
bec80f4f | 1708 | void SetProperty(const wxString& name, double value); |
343ef639 JS |
1709 | |
1710 | /** | |
1711 | Sets property by name and boolean value. | |
1712 | */ | |
bec80f4f JS |
1713 | void SetProperty(const wxString& name, bool value); |
1714 | ||
590a0f8b JS |
1715 | /** |
1716 | Removes the given properties from these properties. | |
1717 | */ | |
1718 | void RemoveProperties(const wxRichTextProperties& properties); | |
1719 | ||
1720 | /** | |
1721 | Merges the given properties with these properties. | |
1722 | */ | |
1723 | void MergeProperties(const wxRichTextProperties& properties); | |
1724 | ||
bec80f4f JS |
1725 | protected: |
1726 | wxRichTextVariantArray m_properties; | |
1727 | }; | |
1728 | ||
1729 | ||
343ef639 JS |
1730 | /** |
1731 | @class wxRichTextFontTable | |
1732 | Manages quick access to a pool of fonts for rendering rich text. | |
1733 | ||
1734 | @library{wxrichtext} | |
1735 | @category{richtext} | |
1736 | ||
1737 | @see wxRichTextBuffer, wxRichTextCtrl | |
1738 | */ | |
5d7836c4 | 1739 | |
44cc96a8 JS |
1740 | class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable: public wxObject |
1741 | { | |
1742 | public: | |
343ef639 JS |
1743 | /** |
1744 | Default constructor. | |
1745 | */ | |
44cc96a8 | 1746 | wxRichTextFontTable(); |
42688aea | 1747 | |
343ef639 JS |
1748 | /** |
1749 | Copy constructor. | |
1750 | */ | |
44cc96a8 JS |
1751 | wxRichTextFontTable(const wxRichTextFontTable& table); |
1752 | virtual ~wxRichTextFontTable(); | |
5d7836c4 | 1753 | |
343ef639 JS |
1754 | /** |
1755 | Returns @true if the font table is valid. | |
1756 | */ | |
44cc96a8 | 1757 | bool IsOk() const { return m_refData != NULL; } |
5d7836c4 | 1758 | |
343ef639 JS |
1759 | /** |
1760 | Finds a font for the given attribute object. | |
1761 | */ | |
24777478 | 1762 | wxFont FindFont(const wxRichTextAttr& fontSpec); |
343ef639 JS |
1763 | |
1764 | /** | |
1765 | Clears the font table. | |
1766 | */ | |
44cc96a8 | 1767 | void Clear(); |
d2d0adc7 | 1768 | |
343ef639 JS |
1769 | /** |
1770 | Assignment operator. | |
1771 | */ | |
44cc96a8 | 1772 | void operator= (const wxRichTextFontTable& table); |
343ef639 JS |
1773 | |
1774 | /** | |
1775 | Equality operator. | |
1776 | */ | |
44cc96a8 | 1777 | bool operator == (const wxRichTextFontTable& table) const; |
343ef639 JS |
1778 | |
1779 | /** | |
1780 | Inequality operator. | |
1781 | */ | |
44cc96a8 | 1782 | bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); } |
d2d0adc7 | 1783 | |
32423dd8 JS |
1784 | /** |
1785 | Set the font scale factor. | |
1786 | */ | |
1787 | void SetFontScale(double fontScale); | |
1788 | ||
44cc96a8 | 1789 | protected: |
d2d0adc7 | 1790 | |
32423dd8 JS |
1791 | double m_fontScale; |
1792 | ||
44cc96a8 JS |
1793 | DECLARE_DYNAMIC_CLASS(wxRichTextFontTable) |
1794 | }; | |
d2d0adc7 | 1795 | |
343ef639 JS |
1796 | /** |
1797 | @class wxRichTextRange | |
1798 | ||
1799 | This stores beginning and end positions for a range of data. | |
1800 | ||
1801 | @library{wxrichtext} | |
1802 | @category{richtext} | |
1803 | ||
1804 | @see wxRichTextBuffer, wxRichTextCtrl | |
1805 | */ | |
5d7836c4 | 1806 | |
3b2cb431 | 1807 | class WXDLLIMPEXP_RICHTEXT wxRichTextRange |
5d7836c4 JS |
1808 | { |
1809 | public: | |
1810 | // Constructors | |
1811 | ||
343ef639 JS |
1812 | /** |
1813 | Default constructor. | |
1814 | */ | |
5d7836c4 | 1815 | wxRichTextRange() { m_start = 0; m_end = 0; } |
343ef639 JS |
1816 | |
1817 | /** | |
1818 | Constructor taking start and end positions. | |
1819 | */ | |
5d7836c4 | 1820 | wxRichTextRange(long start, long end) { m_start = start; m_end = end; } |
343ef639 JS |
1821 | |
1822 | /** | |
1823 | Copy constructor. | |
1824 | */ | |
5d7836c4 JS |
1825 | wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } |
1826 | ~wxRichTextRange() {} | |
1827 | ||
343ef639 | 1828 | /** |
706465df | 1829 | Assigns @a range to this range. |
343ef639 | 1830 | */ |
5d7836c4 | 1831 | void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } |
343ef639 JS |
1832 | |
1833 | /** | |
706465df | 1834 | Equality operator. Returns @true if @a range is the same as this range. |
343ef639 | 1835 | */ |
38113684 | 1836 | bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); } |
343ef639 JS |
1837 | |
1838 | /** | |
1839 | Inequality operator. | |
1840 | */ | |
e0983733 | 1841 | bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start || m_end != range.m_end); } |
343ef639 JS |
1842 | |
1843 | /** | |
1844 | Subtracts a range from this range. | |
1845 | */ | |
5d7836c4 | 1846 | wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); } |
343ef639 JS |
1847 | |
1848 | /** | |
1849 | Adds a range to this range. | |
1850 | */ | |
5d7836c4 JS |
1851 | wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); } |
1852 | ||
343ef639 JS |
1853 | /** |
1854 | Sets the range start and end positions. | |
1855 | */ | |
5d7836c4 JS |
1856 | void SetRange(long start, long end) { m_start = start; m_end = end; } |
1857 | ||
343ef639 JS |
1858 | /** |
1859 | Sets the start position. | |
1860 | */ | |
5d7836c4 | 1861 | void SetStart(long start) { m_start = start; } |
343ef639 JS |
1862 | |
1863 | /** | |
1864 | Returns the start position. | |
1865 | */ | |
5d7836c4 JS |
1866 | long GetStart() const { return m_start; } |
1867 | ||
343ef639 JS |
1868 | /** |
1869 | Sets the end position. | |
1870 | */ | |
5d7836c4 | 1871 | void SetEnd(long end) { m_end = end; } |
343ef639 JS |
1872 | |
1873 | /** | |
1874 | Gets the end position. | |
1875 | */ | |
5d7836c4 JS |
1876 | long GetEnd() const { return m_end; } |
1877 | ||
343ef639 JS |
1878 | /** |
1879 | Returns true if this range is completely outside @a range. | |
1880 | */ | |
5d7836c4 JS |
1881 | bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; } |
1882 | ||
343ef639 JS |
1883 | /** |
1884 | Returns true if this range is completely within @a range. | |
1885 | */ | |
5d7836c4 JS |
1886 | bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; } |
1887 | ||
343ef639 | 1888 | /** |
706465df | 1889 | Returns true if @a pos was within the range. Does not match if the range is empty. |
343ef639 | 1890 | */ |
5d7836c4 JS |
1891 | bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; } |
1892 | ||
343ef639 JS |
1893 | /** |
1894 | Limit this range to be within @a range. | |
1895 | */ | |
5d7836c4 JS |
1896 | bool LimitTo(const wxRichTextRange& range) ; |
1897 | ||
343ef639 JS |
1898 | /** |
1899 | Gets the length of the range. | |
1900 | */ | |
5d7836c4 JS |
1901 | long GetLength() const { return m_end - m_start + 1; } |
1902 | ||
343ef639 JS |
1903 | /** |
1904 | Swaps the start and end. | |
1905 | */ | |
5d7836c4 JS |
1906 | void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; } |
1907 | ||
343ef639 | 1908 | /** |
706465df JS |
1909 | Converts the API-standard range, whose end is one past the last character in |
1910 | the range, to the internal form, which uses the first and last character | |
1911 | positions of the range. In other words, one is subtracted from the end position. | |
1912 | (n, n) is the range of a single character. | |
343ef639 | 1913 | */ |
96c9f0f6 JS |
1914 | wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); } |
1915 | ||
343ef639 | 1916 | /** |
706465df JS |
1917 | Converts the internal range, which uses the first and last character positions |
1918 | of the range, to the API-standard range, whose end is one past the last | |
1919 | character in the range. In other words, one is added to the end position. | |
1920 | (n, n+1) is the range of a single character. | |
343ef639 | 1921 | */ |
96c9f0f6 JS |
1922 | wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); } |
1923 | ||
5d7836c4 JS |
1924 | protected: |
1925 | long m_start; | |
1926 | long m_end; | |
1927 | }; | |
1928 | ||
603f702b JS |
1929 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextRange, wxRichTextRangeArray, WXDLLIMPEXP_RICHTEXT); |
1930 | ||
1e967276 JS |
1931 | #define wxRICHTEXT_ALL wxRichTextRange(-2, -2) |
1932 | #define wxRICHTEXT_NONE wxRichTextRange(-1, -1) | |
1933 | ||
603f702b JS |
1934 | #define wxRICHTEXT_NO_SELECTION wxRichTextRange(-2, -2) |
1935 | ||
343ef639 JS |
1936 | /** |
1937 | @class wxRichTextSelection | |
1938 | ||
1939 | Stores selection information. The selection does not have to be contiguous, though currently non-contiguous | |
1940 | selections are only supported for a range of table cells (a geometric block of cells can consist | |
1941 | of a set of non-contiguous positions). | |
1942 | ||
1943 | The selection consists of an array of ranges, and the container that is the context for the selection. It | |
1944 | follows that a single selection object can only represent ranges with the same parent container. | |
1945 | ||
1946 | @library{wxrichtext} | |
1947 | @category{richtext} | |
1948 | ||
1949 | @see wxRichTextBuffer, wxRichTextCtrl | |
1950 | */ | |
1951 | ||
603f702b JS |
1952 | class WXDLLIMPEXP_RICHTEXT wxRichTextSelection |
1953 | { | |
1954 | public: | |
343ef639 JS |
1955 | /** |
1956 | Copy constructor. | |
1957 | */ | |
603f702b | 1958 | wxRichTextSelection(const wxRichTextSelection& sel) { Copy(sel); } |
343ef639 JS |
1959 | |
1960 | /** | |
1961 | Creates a selection from a range and a container. | |
1962 | */ | |
603f702b | 1963 | wxRichTextSelection(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container) { m_ranges.Add(range); m_container = container; } |
343ef639 JS |
1964 | |
1965 | /** | |
1966 | Default constructor. | |
1967 | */ | |
603f702b JS |
1968 | wxRichTextSelection() { Reset(); } |
1969 | ||
343ef639 JS |
1970 | /** |
1971 | Resets the selection. | |
1972 | */ | |
603f702b JS |
1973 | void Reset() { m_ranges.Clear(); m_container = NULL; } |
1974 | ||
343ef639 JS |
1975 | /** |
1976 | Sets the selection. | |
1977 | */ | |
1978 | ||
603f702b JS |
1979 | void Set(const wxRichTextRange& range, wxRichTextParagraphLayoutBox* container) |
1980 | { m_ranges.Clear(); m_ranges.Add(range); m_container = container; } | |
1981 | ||
343ef639 | 1982 | /** |
706465df | 1983 | Adds a range to the selection. |
343ef639 | 1984 | */ |
603f702b JS |
1985 | void Add(const wxRichTextRange& range) |
1986 | { m_ranges.Add(range); } | |
1987 | ||
343ef639 JS |
1988 | /** |
1989 | Sets the selections from an array of ranges and a container object. | |
1990 | */ | |
603f702b JS |
1991 | void Set(const wxRichTextRangeArray& ranges, wxRichTextParagraphLayoutBox* container) |
1992 | { m_ranges = ranges; m_container = container; } | |
1993 | ||
343ef639 JS |
1994 | /** |
1995 | Copies from @a sel. | |
1996 | */ | |
603f702b JS |
1997 | void Copy(const wxRichTextSelection& sel) |
1998 | { m_ranges = sel.m_ranges; m_container = sel.m_container; } | |
1999 | ||
343ef639 JS |
2000 | /** |
2001 | Assignment operator. | |
2002 | */ | |
603f702b JS |
2003 | void operator=(const wxRichTextSelection& sel) { Copy(sel); } |
2004 | ||
343ef639 JS |
2005 | /** |
2006 | Equality operator. | |
2007 | */ | |
603f702b JS |
2008 | bool operator==(const wxRichTextSelection& sel) const; |
2009 | ||
343ef639 JS |
2010 | /** |
2011 | Index operator. | |
2012 | */ | |
603f702b JS |
2013 | wxRichTextRange operator[](size_t i) const { return GetRange(i); } |
2014 | ||
343ef639 JS |
2015 | /** |
2016 | Returns the selection ranges. | |
2017 | */ | |
603f702b | 2018 | wxRichTextRangeArray& GetRanges() { return m_ranges; } |
343ef639 JS |
2019 | |
2020 | /** | |
2021 | Returns the selection ranges. | |
2022 | */ | |
603f702b JS |
2023 | const wxRichTextRangeArray& GetRanges() const { return m_ranges; } |
2024 | ||
343ef639 JS |
2025 | /** |
2026 | Sets the selection ranges. | |
2027 | */ | |
603f702b JS |
2028 | void SetRanges(const wxRichTextRangeArray& ranges) { m_ranges = ranges; } |
2029 | ||
343ef639 JS |
2030 | /** |
2031 | Returns the number of ranges in the selection. | |
2032 | */ | |
603f702b JS |
2033 | size_t GetCount() const { return m_ranges.GetCount(); } |
2034 | ||
343ef639 JS |
2035 | /** |
2036 | Returns the range at the given index. | |
2037 | ||
2038 | */ | |
603f702b JS |
2039 | wxRichTextRange GetRange(size_t i) const { return m_ranges[i]; } |
2040 | ||
343ef639 JS |
2041 | /** |
2042 | Returns the first range if there is one, otherwise wxRICHTEXT_NO_SELECTION. | |
2043 | */ | |
603f702b JS |
2044 | wxRichTextRange GetRange() const { return (m_ranges.GetCount() > 0) ? (m_ranges[0]) : wxRICHTEXT_NO_SELECTION; } |
2045 | ||
343ef639 JS |
2046 | /** |
2047 | Sets a single range. | |
2048 | */ | |
603f702b JS |
2049 | void SetRange(const wxRichTextRange& range) { m_ranges.Clear(); m_ranges.Add(range); } |
2050 | ||
343ef639 JS |
2051 | /** |
2052 | Returns the container for which the selection is valid. | |
2053 | */ | |
603f702b JS |
2054 | wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; } |
2055 | ||
343ef639 JS |
2056 | /** |
2057 | Sets the container for which the selection is valid. | |
2058 | */ | |
603f702b JS |
2059 | void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; } |
2060 | ||
343ef639 JS |
2061 | /** |
2062 | Returns @true if the selection is valid. | |
2063 | */ | |
603f702b JS |
2064 | bool IsValid() const { return m_ranges.GetCount() > 0 && GetContainer(); } |
2065 | ||
343ef639 JS |
2066 | /** |
2067 | Returns the selection appropriate to the specified object, if any; returns an empty array if none | |
2068 | at the level of the object's container. | |
2069 | */ | |
603f702b JS |
2070 | wxRichTextRangeArray GetSelectionForObject(wxRichTextObject* obj) const; |
2071 | ||
343ef639 JS |
2072 | /** |
2073 | Returns @true if the given position is within the selection. | |
2074 | */ | |
603f702b JS |
2075 | bool WithinSelection(long pos, wxRichTextObject* obj) const; |
2076 | ||
343ef639 JS |
2077 | /** |
2078 | Returns @true if the given position is within the selection. | |
2079 | ||
2080 | */ | |
603f702b JS |
2081 | bool WithinSelection(long pos) const { return WithinSelection(pos, m_ranges); } |
2082 | ||
343ef639 JS |
2083 | /** |
2084 | Returns @true if the given position is within the selection range. | |
2085 | */ | |
603f702b JS |
2086 | static bool WithinSelection(long pos, const wxRichTextRangeArray& ranges); |
2087 | ||
343ef639 JS |
2088 | /** |
2089 | Returns @true if the given range is within the selection range. | |
2090 | */ | |
603f702b JS |
2091 | static bool WithinSelection(const wxRichTextRange& range, const wxRichTextRangeArray& ranges); |
2092 | ||
2093 | wxRichTextRangeArray m_ranges; | |
2094 | wxRichTextParagraphLayoutBox* m_container; | |
2095 | }; | |
2096 | ||
8db2e3ef JS |
2097 | /** |
2098 | @class wxRichTextDrawingContext | |
2099 | ||
2100 | A class for passing information to drawing and measuring functions. | |
2101 | ||
2102 | @library{wxrichtext} | |
2103 | @category{richtext} | |
2104 | ||
2105 | @see wxRichTextBuffer, wxRichTextCtrl | |
2106 | */ | |
2107 | ||
2108 | class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingContext: public wxObject | |
2109 | { | |
2110 | DECLARE_CLASS(wxRichTextDrawingContext) | |
2111 | public: | |
2112 | ||
2113 | /** | |
2114 | Pass the buffer to the context so the context can retrieve information | |
2115 | such as virtual attributes. | |
2116 | */ | |
f7667b84 | 2117 | wxRichTextDrawingContext(wxRichTextBuffer* buffer); |
8db2e3ef | 2118 | |
f7667b84 | 2119 | void Init() { m_buffer = NULL; m_enableVirtualAttributes = true; } |
8db2e3ef JS |
2120 | |
2121 | /** | |
2122 | Does this object have virtual attributes? | |
2123 | Virtual attributes can be provided for visual cues without | |
2124 | affecting the actual styling. | |
2125 | */ | |
2126 | bool HasVirtualAttributes(wxRichTextObject* obj) const; | |
2127 | ||
2128 | /** | |
2129 | Returns the virtual attributes for this object. | |
2130 | Virtual attributes can be provided for visual cues without | |
2131 | affecting the actual styling. | |
2132 | */ | |
2133 | wxRichTextAttr GetVirtualAttributes(wxRichTextObject* obj) const; | |
2134 | ||
2135 | /** | |
2136 | Applies any virtual attributes relevant to this object. | |
2137 | */ | |
2138 | bool ApplyVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const; | |
2139 | ||
f7667b84 JS |
2140 | /** |
2141 | Gets the count for mixed virtual attributes for individual positions within the object. | |
2142 | For example, individual characters within a text object may require special highlighting. | |
2143 | */ | |
2144 | int GetVirtualSubobjectAttributesCount(wxRichTextObject* obj) const; | |
2145 | ||
2146 | /** | |
2147 | Gets the mixed virtual attributes for individual positions within the object. | |
2148 | For example, individual characters within a text object may require special highlighting. | |
2149 | The function is passed the count returned by GetVirtualSubobjectAttributesCount. | |
2150 | */ | |
2151 | int GetVirtualSubobjectAttributes(wxRichTextObject* obj, wxArrayInt& positions, wxRichTextAttrArray& attributes) const; | |
2152 | ||
2153 | /** | |
2154 | Do we have virtual text for this object? Virtual text allows an application | |
2155 | to replace characters in an object for editing and display purposes, for example | |
2156 | for highlighting special characters. | |
2157 | */ | |
2158 | bool HasVirtualText(const wxRichTextPlainText* obj) const; | |
2159 | ||
2160 | /** | |
2161 | Gets the virtual text for this object. | |
2162 | */ | |
2163 | bool GetVirtualText(const wxRichTextPlainText* obj, wxString& text) const; | |
2164 | ||
2165 | /** | |
2166 | Enables virtual attribute processing. | |
2167 | */ | |
2168 | ||
2169 | void EnableVirtualAttributes(bool b) { m_enableVirtualAttributes = b; } | |
2170 | ||
2171 | /** | |
2172 | Returns @true if virtual attribute processing is enabled. | |
2173 | */ | |
2174 | ||
2175 | bool GetVirtualAttributesEnabled() const { return m_enableVirtualAttributes; } | |
2176 | ||
8db2e3ef | 2177 | wxRichTextBuffer* m_buffer; |
f7667b84 | 2178 | bool m_enableVirtualAttributes; |
8db2e3ef JS |
2179 | }; |
2180 | ||
706465df JS |
2181 | /** |
2182 | @class wxRichTextObject | |
2183 | ||
2184 | This is the base for drawable rich text objects. | |
2185 | ||
2186 | @library{wxrichtext} | |
2187 | @category{richtext} | |
2188 | ||
2189 | @see wxRichTextBuffer, wxRichTextCtrl | |
2190 | */ | |
5d7836c4 | 2191 | |
3b2cb431 | 2192 | class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject |
5d7836c4 JS |
2193 | { |
2194 | DECLARE_CLASS(wxRichTextObject) | |
2195 | public: | |
706465df JS |
2196 | /** |
2197 | Constructor, taking an optional parent pointer. | |
2198 | */ | |
5d7836c4 | 2199 | wxRichTextObject(wxRichTextObject* parent = NULL); |
706465df | 2200 | |
d3c7fc99 | 2201 | virtual ~wxRichTextObject(); |
5d7836c4 | 2202 | |
d13b34d3 | 2203 | // Overridables |
5d7836c4 | 2204 | |
706465df JS |
2205 | /** |
2206 | Draw the item, within the given range. Some objects may ignore the range (for | |
2207 | example paragraphs) while others must obey it (lines, to implement wrapping) | |
2208 | */ | |
8db2e3ef | 2209 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0; |
5d7836c4 | 2210 | |
706465df JS |
2211 | /** |
2212 | Lay the item out at the specified position with the given size constraint. | |
bb7bbd12 JS |
2213 | Layout must set the cached size. @rect is the available space for the object, |
2214 | and @a parentRect is the container that is used to determine a relative size | |
2215 | or position (for example if a text box must be 50% of the parent text box). | |
706465df | 2216 | */ |
8db2e3ef | 2217 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style) = 0; |
5d7836c4 | 2218 | |
706465df JS |
2219 | /** |
2220 | Hit-testing: returns a flag indicating hit test details, plus | |
7afd2b58 | 2221 | information about position. @a contextObj is returned to specify what object |
706465df | 2222 | position is relevant to, since otherwise there's an ambiguity. |
7afd2b58 | 2223 | @ obj might not be a child of @a contextObj, since we may be referring to the container itself |
706465df | 2224 | if we have no hit on a child - for example if we click outside an object. |
7afd2b58 JS |
2225 | |
2226 | The function puts the position in @a textPosition if one is found. | |
2227 | @a pt is in logical units (a zero y position is at the beginning of the buffer). | |
2228 | ||
71185527 JS |
2229 | Pass wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS if you only want to consider objects |
2230 | directly under the object you are calling HitTest on. Otherwise, it will recurse | |
2231 | and potentially find a nested object. | |
2232 | ||
7afd2b58 | 2233 | @return One of the ::wxRichTextHitTestFlags values. |
706465df | 2234 | */ |
7afd2b58 | 2235 | |
8db2e3ef | 2236 | virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
5d7836c4 | 2237 | |
706465df JS |
2238 | /** |
2239 | Finds the absolute position and row height for the given character position. | |
2240 | */ | |
8db2e3ef | 2241 | virtual bool FindPosition(wxDC& WXUNUSED(dc), wxRichTextDrawingContext& WXUNUSED(context), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; } |
5d7836c4 | 2242 | |
706465df JS |
2243 | /** |
2244 | Returns the best size, i.e. the ideal starting size for this object irrespective | |
2245 | of available space. For a short text string, it will be the size that exactly encloses | |
2246 | the text. For a longer string, it might use the parent width for example. | |
2247 | */ | |
5d7836c4 JS |
2248 | virtual wxSize GetBestSize() const { return m_size; } |
2249 | ||
603f702b | 2250 | /** |
706465df | 2251 | Returns the object size for the given range. Returns @false if the range |
603f702b JS |
2252 | is invalid for this object. |
2253 | */ | |
2254 | ||
914a4e23 | 2255 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const = 0; |
5d7836c4 | 2256 | |
706465df JS |
2257 | /** |
2258 | Do a split from @a pos, returning an object containing the second part, and setting | |
2259 | the first part in 'this'. | |
2260 | */ | |
5d7836c4 JS |
2261 | virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; } |
2262 | ||
706465df JS |
2263 | /** |
2264 | Calculates the range of the object. By default, guess that the object is 1 unit long. | |
2265 | */ | |
5d7836c4 JS |
2266 | virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); } |
2267 | ||
706465df JS |
2268 | /** |
2269 | Deletes the given range. | |
2270 | */ | |
5d7836c4 JS |
2271 | virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; } |
2272 | ||
706465df JS |
2273 | /** |
2274 | Returns @true if the object is empty. | |
2275 | */ | |
5d7836c4 JS |
2276 | virtual bool IsEmpty() const { return false; } |
2277 | ||
706465df JS |
2278 | /** |
2279 | Returns @true if this class of object is floatable. | |
2280 | */ | |
cdaed652 VZ |
2281 | virtual bool IsFloatable() const { return false; } |
2282 | ||
706465df JS |
2283 | /** |
2284 | Returns @true if this object is currently floating. | |
2285 | */ | |
bec80f4f | 2286 | virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); } |
cdaed652 | 2287 | |
706465df JS |
2288 | /** |
2289 | Returns the floating direction. | |
2290 | */ | |
bec80f4f | 2291 | virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); } |
cdaed652 | 2292 | |
706465df JS |
2293 | /** |
2294 | Returns any text in this object for the given range. | |
2295 | */ | |
5d7836c4 JS |
2296 | virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; } |
2297 | ||
706465df JS |
2298 | /** |
2299 | Returns @true if this object can merge itself with the given one. | |
2300 | */ | |
f7667b84 | 2301 | virtual bool CanMerge(wxRichTextObject* WXUNUSED(object), wxRichTextDrawingContext& WXUNUSED(context)) const { return false; } |
5d7836c4 | 2302 | |
706465df JS |
2303 | /** |
2304 | Returns @true if this object merged itself with the given one. | |
2305 | The calling code will then delete the given object. | |
2306 | */ | |
f7667b84 JS |
2307 | virtual bool Merge(wxRichTextObject* WXUNUSED(object), wxRichTextDrawingContext& WXUNUSED(context)) { return false; } |
2308 | ||
2309 | /** | |
2310 | JACS | |
2311 | Returns @true if this object can potentially be split, by virtue of having | |
2312 | different virtual attributes for individual sub-objects. | |
2313 | */ | |
2314 | virtual bool CanSplit(wxRichTextDrawingContext& WXUNUSED(context)) const { return false; } | |
2315 | ||
2316 | /** | |
2317 | Returns the final object in the split objects if this object was split due to differences between sub-object virtual attributes. | |
2318 | Returns itself if it was not split. | |
2319 | */ | |
2320 | virtual wxRichTextObject* Split(wxRichTextDrawingContext& WXUNUSED(context)) { return this; } | |
5d7836c4 | 2321 | |
706465df JS |
2322 | /** |
2323 | Dump object data to the given output stream for debugging. | |
2324 | */ | |
5d7836c4 | 2325 | virtual void Dump(wxTextOutputStream& stream); |
ce00f59b | 2326 | |
706465df JS |
2327 | /** |
2328 | Returns @true if we can edit the object's properties via a GUI. | |
2329 | */ | |
cdaed652 VZ |
2330 | virtual bool CanEditProperties() const { return false; } |
2331 | ||
706465df JS |
2332 | /** |
2333 | Edits the object's properties via a GUI. | |
2334 | */ | |
cdaed652 | 2335 | virtual bool EditProperties(wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; } |
5d7836c4 | 2336 | |
706465df JS |
2337 | /** |
2338 | Returns the label to be used for the properties context menu item. | |
2339 | */ | |
603f702b JS |
2340 | virtual wxString GetPropertiesMenuLabel() const { return wxEmptyString; } |
2341 | ||
706465df JS |
2342 | /** |
2343 | Returns @true if objects of this class can accept the focus, i.e. a call to SetFocusObject | |
2344 | is possible. For example, containers supporting text, such as a text box object, can accept the focus, | |
2345 | but a table can't (set the focus to individual cells instead). | |
2346 | */ | |
603f702b JS |
2347 | virtual bool AcceptsFocus() const { return false; } |
2348 | ||
bec80f4f | 2349 | #if wxUSE_XML |
706465df JS |
2350 | /** |
2351 | Imports this object from XML. | |
2352 | */ | |
603f702b | 2353 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
2354 | #endif |
2355 | ||
2356 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
706465df JS |
2357 | /** |
2358 | Exports this object directly to the given stream, bypassing the creation of a wxXmlNode hierarchy. | |
2359 | This method is considerably faster than creating a tree first. However, both versions of ExportXML must be | |
2360 | implemented so that if the tree method is made efficient in the future, we can deprecate the | |
2361 | more verbose direct output method. Compiled only if wxRICHTEXT_HAVE_DIRECT_OUTPUT is defined (on by default). | |
2362 | */ | |
bec80f4f JS |
2363 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); |
2364 | #endif | |
2365 | ||
2366 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
706465df JS |
2367 | /** |
2368 | Exports this object to the given parent node, usually creating at least one child node. | |
2369 | This method is less efficient than the direct-to-stream method but is retained to allow for | |
2370 | switching to this method if we make it more efficient. Compiled only if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT is defined | |
2371 | (on by default). | |
2372 | */ | |
bec80f4f JS |
2373 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); |
2374 | #endif | |
2375 | ||
706465df JS |
2376 | /** |
2377 | Returns @true if this object takes note of paragraph attributes (text and image objects don't). | |
2378 | */ | |
bec80f4f | 2379 | virtual bool UsesParagraphAttributes() const { return true; } |
603f702b | 2380 | |
706465df JS |
2381 | /** |
2382 | Returns the XML node name of this object. This must be overridden for wxXmlNode-base XML export to work. | |
2383 | */ | |
bec80f4f JS |
2384 | virtual wxString GetXMLNodeName() const { return wxT("unknown"); } |
2385 | ||
706465df JS |
2386 | /** |
2387 | Invalidates the object at the given range. With no argument, invalidates the whole object. | |
2388 | */ | |
603f702b JS |
2389 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
2390 | ||
706465df JS |
2391 | /** |
2392 | Returns @true if this object can handle the selections of its children, fOr example a table. | |
2393 | Required for composite selection handling to work. | |
2394 | */ | |
603f702b JS |
2395 | virtual bool HandlesChildSelections() const { return false; } |
2396 | ||
706465df JS |
2397 | /** |
2398 | Returns a selection object specifying the selections between start and end character positions. | |
2399 | For example, a table would deduce what cells (of range length 1) are selected when dragging across the table. | |
2400 | */ | |
603f702b JS |
2401 | virtual wxRichTextSelection GetSelection(long WXUNUSED(start), long WXUNUSED(end)) const { return wxRichTextSelection(); } |
2402 | ||
5d7836c4 JS |
2403 | // Accessors |
2404 | ||
706465df JS |
2405 | /** |
2406 | Gets the cached object size as calculated by Layout. | |
2407 | */ | |
5d7836c4 | 2408 | virtual wxSize GetCachedSize() const { return m_size; } |
706465df JS |
2409 | |
2410 | /** | |
2411 | Sets the cached object size as calculated by Layout. | |
2412 | */ | |
5d7836c4 JS |
2413 | virtual void SetCachedSize(const wxSize& sz) { m_size = sz; } |
2414 | ||
706465df JS |
2415 | /** |
2416 | Gets the maximum object size as calculated by Layout. This allows | |
2417 | us to fit an object to its contents or allocate extra space if required. | |
2418 | */ | |
603f702b | 2419 | virtual wxSize GetMaxSize() const { return m_maxSize; } |
706465df JS |
2420 | |
2421 | /** | |
2422 | Sets the maximum object size as calculated by Layout. This allows | |
2423 | us to fit an object to its contents or allocate extra space if required. | |
2424 | */ | |
603f702b JS |
2425 | virtual void SetMaxSize(const wxSize& sz) { m_maxSize = sz; } |
2426 | ||
706465df JS |
2427 | /** |
2428 | Gets the minimum object size as calculated by Layout. This allows | |
2429 | us to constrain an object to its absolute minimum size if necessary. | |
2430 | */ | |
603f702b | 2431 | virtual wxSize GetMinSize() const { return m_minSize; } |
706465df JS |
2432 | |
2433 | /** | |
2434 | Sets the minimum object size as calculated by Layout. This allows | |
2435 | us to constrain an object to its absolute minimum size if necessary. | |
2436 | */ | |
603f702b JS |
2437 | virtual void SetMinSize(const wxSize& sz) { m_minSize = sz; } |
2438 | ||
706465df JS |
2439 | /** |
2440 | Gets the 'natural' size for an object. For an image, it would be the | |
2441 | image size. | |
2442 | */ | |
603f702b JS |
2443 | virtual wxTextAttrSize GetNaturalSize() const { return wxTextAttrSize(); } |
2444 | ||
706465df JS |
2445 | /** |
2446 | Returns the object position in pixels. | |
2447 | */ | |
5d7836c4 | 2448 | virtual wxPoint GetPosition() const { return m_pos; } |
706465df JS |
2449 | |
2450 | /** | |
2451 | Sets the object position in pixels. | |
2452 | */ | |
5d7836c4 JS |
2453 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } |
2454 | ||
706465df JS |
2455 | /** |
2456 | Returns the absolute object position, by traversing up the child/parent hierarchy. | |
2457 | TODO: may not be needed, if all object positions are in fact relative to the | |
2458 | top of the coordinate space. | |
2459 | */ | |
603f702b JS |
2460 | virtual wxPoint GetAbsolutePosition() const; |
2461 | ||
706465df JS |
2462 | /** |
2463 | Returns the rectangle enclosing the object. | |
2464 | */ | |
5d7836c4 JS |
2465 | virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); } |
2466 | ||
706465df JS |
2467 | /** |
2468 | Sets the object's range within its container. | |
2469 | */ | |
5d7836c4 JS |
2470 | void SetRange(const wxRichTextRange& range) { m_range = range; } |
2471 | ||
706465df JS |
2472 | /** |
2473 | Returns the object's range. | |
2474 | */ | |
5d7836c4 | 2475 | const wxRichTextRange& GetRange() const { return m_range; } |
706465df JS |
2476 | |
2477 | /** | |
2478 | Returns the object's range. | |
2479 | */ | |
5d7836c4 JS |
2480 | wxRichTextRange& GetRange() { return m_range; } |
2481 | ||
706465df JS |
2482 | /** |
2483 | Set the object's own range, for a top-level object with its own position space. | |
2484 | */ | |
603f702b JS |
2485 | void SetOwnRange(const wxRichTextRange& range) { m_ownRange = range; } |
2486 | ||
706465df JS |
2487 | /** |
2488 | Returns the object's own range (valid if top-level). | |
2489 | */ | |
603f702b | 2490 | const wxRichTextRange& GetOwnRange() const { return m_ownRange; } |
706465df JS |
2491 | |
2492 | /** | |
2493 | Returns the object's own range (valid if top-level). | |
2494 | */ | |
603f702b JS |
2495 | wxRichTextRange& GetOwnRange() { return m_ownRange; } |
2496 | ||
706465df JS |
2497 | /** |
2498 | Returns the object's own range only if a top-level object. | |
2499 | */ | |
603f702b | 2500 | wxRichTextRange GetOwnRangeIfTopLevel() const { return IsTopLevel() ? m_ownRange : m_range; } |
5d7836c4 | 2501 | |
706465df | 2502 | /** |
7c9fdebe | 2503 | Returns @true if this object is composite. |
706465df | 2504 | */ |
5d7836c4 JS |
2505 | virtual bool IsComposite() const { return false; } |
2506 | ||
7c9fdebe JS |
2507 | /** |
2508 | Returns @true if no user editing can be done inside the object. This returns @true for simple objects, | |
2509 | @false for most composite objects, but @true for fields, which if composite, should not be user-edited. | |
2510 | */ | |
2511 | virtual bool IsAtomic() const { return true; } | |
2512 | ||
706465df JS |
2513 | /** |
2514 | Returns a pointer to the parent object. | |
2515 | */ | |
5d7836c4 | 2516 | virtual wxRichTextObject* GetParent() const { return m_parent; } |
706465df JS |
2517 | |
2518 | /** | |
2519 | Sets the pointer to the parent object. | |
2520 | */ | |
5d7836c4 JS |
2521 | virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; } |
2522 | ||
706465df JS |
2523 | /** |
2524 | Returns the top-level container of this object. | |
2525 | May return itself if it's a container; use GetParentContainer to return | |
2526 | a different container. | |
2527 | */ | |
603f702b JS |
2528 | virtual wxRichTextParagraphLayoutBox* GetContainer() const; |
2529 | ||
706465df JS |
2530 | /** |
2531 | Returns the top-level container of this object. | |
2532 | Returns a different container than itself, unless there's no parent, in which case it will return NULL. | |
2533 | */ | |
603f702b JS |
2534 | virtual wxRichTextParagraphLayoutBox* GetParentContainer() const { return GetParent() ? GetParent()->GetContainer() : GetContainer(); } |
2535 | ||
706465df JS |
2536 | /** |
2537 | Set the margin around the object, in pixels. | |
2538 | */ | |
5d7836c4 | 2539 | virtual void SetMargins(int margin); |
706465df JS |
2540 | |
2541 | /** | |
2542 | Set the margin around the object, in pixels. | |
2543 | */ | |
5d7836c4 | 2544 | virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin); |
706465df JS |
2545 | |
2546 | /** | |
2547 | Returns the left margin of the object, in pixels. | |
2548 | */ | |
603f702b | 2549 | virtual int GetLeftMargin() const; |
706465df JS |
2550 | |
2551 | /** | |
2552 | Returns the right margin of the object, in pixels. | |
2553 | */ | |
603f702b | 2554 | virtual int GetRightMargin() const; |
706465df JS |
2555 | |
2556 | /** | |
2557 | Returns the top margin of the object, in pixels. | |
2558 | */ | |
603f702b | 2559 | virtual int GetTopMargin() const; |
706465df JS |
2560 | |
2561 | /** | |
2562 | Returns the bottom margin of the object, in pixels. | |
2563 | */ | |
603f702b JS |
2564 | virtual int GetBottomMargin() const; |
2565 | ||
706465df JS |
2566 | /** |
2567 | Calculates the available content space in the given rectangle, given the | |
2568 | margins, border and padding specified in the object's attributes. | |
2569 | */ | |
8db2e3ef | 2570 | virtual wxRect GetAvailableContentArea(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& outerRect) const; |
603f702b | 2571 | |
706465df JS |
2572 | /** |
2573 | Lays out the object first with a given amount of space, and then if no width was specified in attr, | |
bb7bbd12 JS |
2574 | lays out the object again using the minimum size. @a availableParentSpace is the maximum space |
2575 | for the object, whereas @a availableContainerSpace is the container with which relative positions and | |
2576 | sizes should be computed. For example, a text box whose space has already been constrained | |
2577 | in a previous layout pass to @a availableParentSpace, but should have a width of 50% of @a availableContainerSpace. | |
2578 | (If these two rects were the same, a 2nd pass could see the object getting too small.) | |
706465df | 2579 | */ |
8db2e3ef | 2580 | virtual bool LayoutToBestSize(wxDC& dc, wxRichTextDrawingContext& context, wxRichTextBuffer* buffer, |
bb7bbd12 JS |
2581 | const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr, |
2582 | const wxRect& availableParentSpace, const wxRect& availableContainerSpace, int style); | |
5d7836c4 | 2583 | |
706465df JS |
2584 | /** |
2585 | Sets the object's attributes. | |
2586 | */ | |
24777478 | 2587 | void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; } |
706465df JS |
2588 | |
2589 | /** | |
2590 | Returns the object's attributes. | |
2591 | */ | |
24777478 | 2592 | const wxRichTextAttr& GetAttributes() const { return m_attributes; } |
706465df JS |
2593 | |
2594 | /** | |
2595 | Returns the object's attributes. | |
2596 | */ | |
24777478 | 2597 | wxRichTextAttr& GetAttributes() { return m_attributes; } |
603f702b | 2598 | |
706465df | 2599 | /** |
7c9fdebe | 2600 | Returns the object's properties. |
706465df | 2601 | */ |
bec80f4f | 2602 | wxRichTextProperties& GetProperties() { return m_properties; } |
706465df JS |
2603 | |
2604 | /** | |
2605 | Returns the object's properties. | |
2606 | */ | |
bec80f4f | 2607 | const wxRichTextProperties& GetProperties() const { return m_properties; } |
706465df JS |
2608 | |
2609 | /** | |
7c9fdebe | 2610 | Sets the object's properties. |
706465df | 2611 | */ |
bec80f4f | 2612 | void SetProperties(const wxRichTextProperties& props) { m_properties = props; } |
5d7836c4 | 2613 | |
706465df JS |
2614 | /** |
2615 | Sets the stored descent value. | |
2616 | */ | |
5d7836c4 | 2617 | void SetDescent(int descent) { m_descent = descent; } |
706465df JS |
2618 | |
2619 | /** | |
2620 | Returns the stored descent value. | |
2621 | */ | |
5d7836c4 JS |
2622 | int GetDescent() const { return m_descent; } |
2623 | ||
706465df JS |
2624 | /** |
2625 | Returns the containing buffer. | |
2626 | */ | |
44219ff0 JS |
2627 | wxRichTextBuffer* GetBuffer() const; |
2628 | ||
706465df JS |
2629 | /** |
2630 | Sets the identifying name for this object as a property using the "name" key. | |
2631 | */ | |
603f702b JS |
2632 | void SetName(const wxString& name) { m_properties.SetProperty(wxT("name"), name); } |
2633 | ||
706465df JS |
2634 | /** |
2635 | Returns the identifying name for this object from the properties, using the "name" key. | |
2636 | */ | |
603f702b JS |
2637 | wxString GetName() const { return m_properties.GetPropertyString(wxT("name")); } |
2638 | ||
706465df JS |
2639 | /** |
2640 | Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box. | |
2641 | */ | |
603f702b JS |
2642 | virtual bool IsTopLevel() const { return false; } |
2643 | ||
706465df JS |
2644 | /** |
2645 | Returns @true if the object will be shown, @false otherwise. | |
2646 | */ | |
603f702b JS |
2647 | bool IsShown() const { return m_show; } |
2648 | ||
5d7836c4 JS |
2649 | // Operations |
2650 | ||
706465df JS |
2651 | /** |
2652 | Call to show or hide this object. This function does not cause the content to be | |
2653 | laid out or redrawn. | |
2654 | */ | |
603f702b JS |
2655 | virtual void Show(bool show) { m_show = show; } |
2656 | ||
706465df JS |
2657 | /** |
2658 | Clones the object. | |
2659 | */ | |
5d7836c4 JS |
2660 | virtual wxRichTextObject* Clone() const { return NULL; } |
2661 | ||
706465df JS |
2662 | /** |
2663 | Copies the object. | |
2664 | */ | |
5d7836c4 JS |
2665 | void Copy(const wxRichTextObject& obj); |
2666 | ||
706465df JS |
2667 | /** |
2668 | Reference-counting allows us to use the same object in multiple | |
2669 | lists (not yet used). | |
2670 | */ | |
2671 | ||
5d7836c4 | 2672 | void Reference() { m_refCount ++; } |
706465df JS |
2673 | |
2674 | /** | |
2675 | Reference-counting allows us to use the same object in multiple | |
2676 | lists (not yet used). | |
2677 | */ | |
5d7836c4 JS |
2678 | void Dereference(); |
2679 | ||
706465df JS |
2680 | /** |
2681 | Moves the object recursively, by adding the offset from old to new. | |
2682 | */ | |
603f702b JS |
2683 | virtual void Move(const wxPoint& pt); |
2684 | ||
706465df JS |
2685 | /** |
2686 | Converts units in tenths of a millimetre to device units. | |
2687 | */ | |
cdaed652 | 2688 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; |
706465df JS |
2689 | |
2690 | /** | |
2691 | Converts units in tenths of a millimetre to device units. | |
2692 | */ | |
bec80f4f | 2693 | static int ConvertTenthsMMToPixels(int ppi, int units, double scale = 1.0); |
5d7836c4 | 2694 | |
706465df JS |
2695 | /** |
2696 | Convert units in pixels to tenths of a millimetre. | |
2697 | */ | |
24777478 | 2698 | int ConvertPixelsToTenthsMM(wxDC& dc, int pixels) const; |
706465df JS |
2699 | |
2700 | /** | |
2701 | Convert units in pixels to tenths of a millimetre. | |
2702 | */ | |
bec80f4f | 2703 | static int ConvertPixelsToTenthsMM(int ppi, int pixels, double scale = 1.0); |
603f702b | 2704 | |
706465df JS |
2705 | /** |
2706 | Draws the borders and background for the given rectangle and attributes. | |
2707 | @a boxRect is taken to be the outer margin box, not the box around the content. | |
2708 | */ | |
603f702b | 2709 | static bool DrawBoxAttributes(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, const wxRect& boxRect, int flags = 0); |
bec80f4f | 2710 | |
706465df JS |
2711 | /** |
2712 | Draws a border. | |
2713 | */ | |
603f702b | 2714 | static bool DrawBorder(wxDC& dc, wxRichTextBuffer* buffer, const wxTextAttrBorders& attr, const wxRect& rect, int flags = 0); |
bec80f4f | 2715 | |
706465df JS |
2716 | /** |
2717 | Returns the various rectangles of the box model in pixels. You can either specify @a contentRect (inner) | |
2718 | or @a marginRect (outer), and the other must be the default rectangle (no width or height). | |
2719 | Note that the outline doesn't affect the position of the rectangle, it's drawn in whatever space | |
2720 | is available. | |
2721 | */ | |
603f702b JS |
2722 | static bool GetBoxRects(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, wxRect& marginRect, wxRect& borderRect, wxRect& contentRect, wxRect& paddingRect, wxRect& outlineRect); |
2723 | ||
706465df JS |
2724 | /** |
2725 | Returns the total margin for the object in pixels, taking into account margin, padding and border size. | |
2726 | */ | |
603f702b JS |
2727 | static bool GetTotalMargin(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& attr, int& leftMargin, int& rightMargin, |
2728 | int& topMargin, int& bottomMargin); | |
2729 | ||
706465df JS |
2730 | /** |
2731 | Returns the rectangle which the child has available to it given restrictions specified in the | |
2732 | child attribute, e.g. 50% width of the parent, 400 pixels, x position 20% of the parent, etc. | |
bb7bbd12 JS |
2733 | availableContainerSpace might be a parent that the cell has to compute its width relative to. |
2734 | E.g. a cell that's 50% of its parent. | |
706465df | 2735 | */ |
bb7bbd12 JS |
2736 | static wxRect AdjustAvailableSpace(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& parentAttr, const wxRichTextAttr& childAttr, |
2737 | const wxRect& availableParentSpace, const wxRect& availableContainerSpace); | |
24777478 | 2738 | |
5d7836c4 JS |
2739 | protected: |
2740 | wxSize m_size; | |
603f702b JS |
2741 | wxSize m_maxSize; |
2742 | wxSize m_minSize; | |
5d7836c4 JS |
2743 | wxPoint m_pos; |
2744 | int m_descent; // Descent for this object (if any) | |
5d7836c4 | 2745 | int m_refCount; |
603f702b | 2746 | bool m_show; |
5d7836c4 JS |
2747 | wxRichTextObject* m_parent; |
2748 | ||
706465df | 2749 | // The range of this object (start position to end position) |
5d7836c4 JS |
2750 | wxRichTextRange m_range; |
2751 | ||
706465df | 2752 | // The internal range of this object, if it's a top-level object with its own range space |
603f702b | 2753 | wxRichTextRange m_ownRange; |
5d7836c4 | 2754 | |
706465df | 2755 | // Attributes |
24777478 | 2756 | wxRichTextAttr m_attributes; |
603f702b | 2757 | |
706465df | 2758 | // Properties |
bec80f4f | 2759 | wxRichTextProperties m_properties; |
5d7836c4 JS |
2760 | }; |
2761 | ||
3b2cb431 | 2762 | WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 | 2763 | |
706465df JS |
2764 | /** |
2765 | @class wxRichTextCompositeObject | |
2766 | ||
2767 | Objects of this class can contain other objects. | |
2768 | ||
2769 | @library{wxrichtext} | |
2770 | @category{richtext} | |
2771 | ||
2772 | @see wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl | |
2773 | */ | |
5d7836c4 | 2774 | |
3b2cb431 | 2775 | class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject |
5d7836c4 JS |
2776 | { |
2777 | DECLARE_CLASS(wxRichTextCompositeObject) | |
2778 | public: | |
2779 | // Constructors | |
2780 | ||
2781 | wxRichTextCompositeObject(wxRichTextObject* parent = NULL); | |
d3c7fc99 | 2782 | virtual ~wxRichTextCompositeObject(); |
5d7836c4 | 2783 | |
d13b34d3 | 2784 | // Overridables |
5d7836c4 | 2785 | |
8db2e3ef | 2786 | virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
5d7836c4 | 2787 | |
8db2e3ef | 2788 | virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); |
5d7836c4 | 2789 | |
5d7836c4 JS |
2790 | virtual void CalculateRange(long start, long& end); |
2791 | ||
5d7836c4 JS |
2792 | virtual bool DeleteRange(const wxRichTextRange& range); |
2793 | ||
5d7836c4 JS |
2794 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; |
2795 | ||
914a4e23 | 2796 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
603f702b | 2797 | |
5d7836c4 JS |
2798 | virtual void Dump(wxTextOutputStream& stream); |
2799 | ||
603f702b JS |
2800 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
2801 | ||
5d7836c4 JS |
2802 | // Accessors |
2803 | ||
b3169c12 JS |
2804 | /** |
2805 | Returns the children. | |
2806 | */ | |
5d7836c4 | 2807 | wxRichTextObjectList& GetChildren() { return m_children; } |
b3169c12 JS |
2808 | /** |
2809 | Returns the children. | |
2810 | */ | |
5d7836c4 JS |
2811 | const wxRichTextObjectList& GetChildren() const { return m_children; } |
2812 | ||
b3169c12 JS |
2813 | /** |
2814 | Returns the number of children. | |
2815 | */ | |
5d7836c4 JS |
2816 | size_t GetChildCount() const ; |
2817 | ||
b3169c12 JS |
2818 | /** |
2819 | Returns the nth child. | |
2820 | */ | |
5d7836c4 JS |
2821 | wxRichTextObject* GetChild(size_t n) const ; |
2822 | ||
b3169c12 JS |
2823 | /** |
2824 | Returns @true if this object is composite. | |
2825 | */ | |
5d7836c4 JS |
2826 | virtual bool IsComposite() const { return true; } |
2827 | ||
7c9fdebe JS |
2828 | /** |
2829 | Returns @true if no user editing can be done inside the object. This returns @true for simple objects, | |
2830 | @false for most composite objects, but @true for fields, which if composite, should not be user-edited. | |
2831 | */ | |
2832 | virtual bool IsAtomic() const { return false; } | |
2833 | ||
b3169c12 JS |
2834 | /** |
2835 | Returns true if the buffer is empty. | |
2836 | */ | |
5d7836c4 JS |
2837 | virtual bool IsEmpty() const { return GetChildCount() == 0; } |
2838 | ||
b3169c12 JS |
2839 | /** |
2840 | Returns the child object at the given character position. | |
2841 | */ | |
603f702b JS |
2842 | virtual wxRichTextObject* GetChildAtPosition(long pos) const; |
2843 | ||
5d7836c4 JS |
2844 | // Operations |
2845 | ||
5d7836c4 JS |
2846 | void Copy(const wxRichTextCompositeObject& obj); |
2847 | ||
0ca07313 JS |
2848 | void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); } |
2849 | ||
b3169c12 JS |
2850 | /** |
2851 | Appends a child, returning the position. | |
2852 | */ | |
5d7836c4 JS |
2853 | size_t AppendChild(wxRichTextObject* child) ; |
2854 | ||
b3169c12 JS |
2855 | /** |
2856 | Inserts the child in front of the given object, or at the beginning. | |
2857 | */ | |
5d7836c4 JS |
2858 | bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ; |
2859 | ||
b3169c12 JS |
2860 | /** |
2861 | Removes and optionally deletes the specified child. | |
2862 | */ | |
5d7836c4 JS |
2863 | bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ; |
2864 | ||
b3169c12 JS |
2865 | /** |
2866 | Deletes all the children. | |
2867 | */ | |
5d7836c4 JS |
2868 | bool DeleteChildren() ; |
2869 | ||
b3169c12 JS |
2870 | /** |
2871 | Recursively merges all pieces that can be merged. | |
2872 | */ | |
f7667b84 | 2873 | bool Defragment(wxRichTextDrawingContext& context, const wxRichTextRange& range = wxRICHTEXT_ALL); |
5d7836c4 | 2874 | |
b3169c12 JS |
2875 | /** |
2876 | Moves the object recursively, by adding the offset from old to new. | |
2877 | */ | |
603f702b JS |
2878 | virtual void Move(const wxPoint& pt); |
2879 | ||
5d7836c4 JS |
2880 | protected: |
2881 | wxRichTextObjectList m_children; | |
2882 | }; | |
2883 | ||
706465df JS |
2884 | /** |
2885 | @class wxRichTextParagraphBox | |
2886 | ||
2887 | This class knows how to lay out paragraphs. | |
2888 | ||
2889 | @library{wxrichtext} | |
2890 | @category{richtext} | |
2891 | ||
2892 | @see wxRichTextCompositeObject, wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl | |
2893 | */ | |
5d7836c4 | 2894 | |
bec80f4f | 2895 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextCompositeObject |
5d7836c4 JS |
2896 | { |
2897 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox) | |
2898 | public: | |
2899 | // Constructors | |
2900 | ||
2901 | wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL); | |
bec80f4f | 2902 | wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextCompositeObject() { Init(); Copy(obj); } |
cdaed652 | 2903 | ~wxRichTextParagraphLayoutBox(); |
5d7836c4 | 2904 | |
d13b34d3 | 2905 | // Overridables |
5d7836c4 | 2906 | |
8db2e3ef | 2907 | virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
cdaed652 | 2908 | |
8db2e3ef | 2909 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 | 2910 | |
8db2e3ef | 2911 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); |
5d7836c4 | 2912 | |
914a4e23 | 2913 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
5d7836c4 | 2914 | |
5d7836c4 JS |
2915 | virtual bool DeleteRange(const wxRichTextRange& range); |
2916 | ||
5d7836c4 JS |
2917 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; |
2918 | ||
bec80f4f | 2919 | #if wxUSE_XML |
603f702b | 2920 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
2921 | #endif |
2922 | ||
2923 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
bec80f4f JS |
2924 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); |
2925 | #endif | |
2926 | ||
2927 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
bec80f4f JS |
2928 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); |
2929 | #endif | |
2930 | ||
bec80f4f JS |
2931 | virtual wxString GetXMLNodeName() const { return wxT("paragraphlayout"); } |
2932 | ||
603f702b JS |
2933 | virtual bool AcceptsFocus() const { return true; } |
2934 | ||
5d7836c4 JS |
2935 | // Accessors |
2936 | ||
b3169c12 JS |
2937 | /** |
2938 | Associates a control with the buffer, for operations that for example require refreshing the window. | |
2939 | */ | |
5d7836c4 JS |
2940 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; } |
2941 | ||
b3169c12 JS |
2942 | /** |
2943 | Returns the associated control. | |
2944 | */ | |
5d7836c4 JS |
2945 | wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; } |
2946 | ||
b3169c12 JS |
2947 | /** |
2948 | Sets a flag indicating whether the last paragraph is partial or complete. | |
2949 | */ | |
0ca07313 | 2950 | void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; } |
b3169c12 JS |
2951 | |
2952 | /** | |
2953 | Returns a flag indicating whether the last paragraph is partial or complete. | |
2954 | */ | |
0ca07313 JS |
2955 | bool GetPartialParagraph() const { return m_partialParagraph; } |
2956 | ||
b3169c12 JS |
2957 | /** |
2958 | Returns the style sheet associated with the overall buffer. | |
2959 | */ | |
603f702b JS |
2960 | virtual wxRichTextStyleSheet* GetStyleSheet() const; |
2961 | ||
603f702b | 2962 | virtual bool IsTopLevel() const { return true; } |
38f833b1 | 2963 | |
5d7836c4 | 2964 | // Operations |
603f702b | 2965 | |
b3169c12 JS |
2966 | /** |
2967 | Submits a command to insert paragraphs. | |
2968 | */ | |
4e63bfb9 | 2969 | bool InsertParagraphsWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); |
603f702b | 2970 | |
b3169c12 JS |
2971 | /** |
2972 | Submits a command to insert the given text. | |
2973 | */ | |
4e63bfb9 | 2974 | bool InsertTextWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); |
603f702b | 2975 | |
b3169c12 JS |
2976 | /** |
2977 | Submits a command to insert the given text. | |
2978 | */ | |
4e63bfb9 | 2979 | bool InsertNewlineWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextCtrl* ctrl, int flags = 0); |
603f702b | 2980 | |
b3169c12 JS |
2981 | /** |
2982 | Submits a command to insert the given image. | |
2983 | */ | |
4e63bfb9 JS |
2984 | bool InsertImageWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextImageBlock& imageBlock, |
2985 | wxRichTextCtrl* ctrl, int flags, const wxRichTextAttr& textAttr); | |
603f702b | 2986 | |
7c9fdebe JS |
2987 | /** |
2988 | Submits a command to insert the given field. Field data can be included in properties. | |
2989 | ||
2990 | @see wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard | |
2991 | */ | |
2992 | wxRichTextField* InsertFieldWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& fieldType, | |
2993 | const wxRichTextProperties& properties, | |
2994 | wxRichTextCtrl* ctrl, int flags, | |
2995 | const wxRichTextAttr& textAttr); | |
2996 | ||
b3169c12 JS |
2997 | /** |
2998 | Returns the style that is appropriate for a new paragraph at this position. | |
2999 | If the previous paragraph has a paragraph style name, looks up the next-paragraph | |
3000 | style. | |
3001 | */ | |
603f702b JS |
3002 | wxRichTextAttr GetStyleForNewParagraph(wxRichTextBuffer* buffer, long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const; |
3003 | ||
b3169c12 JS |
3004 | /** |
3005 | Inserts an object. | |
3006 | */ | |
4e63bfb9 | 3007 | wxRichTextObject* InsertObjectWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags = 0); |
603f702b | 3008 | |
b3169c12 JS |
3009 | /** |
3010 | Submits a command to delete this range. | |
3011 | */ | |
603f702b JS |
3012 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer); |
3013 | ||
b3169c12 JS |
3014 | /** |
3015 | Draws the floating objects in this buffer. | |
3016 | */ | |
8db2e3ef | 3017 | void DrawFloats(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
cdaed652 | 3018 | |
b3169c12 JS |
3019 | /** |
3020 | Moves an anchored object to another paragraph. | |
3021 | */ | |
bec80f4f | 3022 | void MoveAnchoredObjectToParagraph(wxRichTextParagraph* from, wxRichTextParagraph* to, wxRichTextObject* obj); |
5d7836c4 | 3023 | |
b3169c12 JS |
3024 | /** |
3025 | Initializes the object. | |
3026 | */ | |
5d7836c4 JS |
3027 | void Init(); |
3028 | ||
b3169c12 JS |
3029 | /** |
3030 | Clears all the children. | |
3031 | */ | |
5d7836c4 JS |
3032 | virtual void Clear(); |
3033 | ||
b3169c12 JS |
3034 | /** |
3035 | Clears and initializes with one blank paragraph. | |
3036 | */ | |
5d7836c4 JS |
3037 | virtual void Reset(); |
3038 | ||
b3169c12 JS |
3039 | /** |
3040 | Convenience function to add a paragraph of text. | |
3041 | */ | |
24777478 | 3042 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 | 3043 | |
b3169c12 JS |
3044 | /** |
3045 | Convenience function to add an image. | |
3046 | */ | |
24777478 | 3047 | virtual wxRichTextRange AddImage(const wxImage& image, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 | 3048 | |
b3169c12 JS |
3049 | /** |
3050 | Adds multiple paragraphs, based on newlines. | |
3051 | */ | |
24777478 | 3052 | virtual wxRichTextRange AddParagraphs(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 | 3053 | |
b3169c12 JS |
3054 | /** |
3055 | Returns the line at the given position. If @a caretPosition is true, the position is | |
3056 | a caret position, which is normally a smaller number. | |
3057 | */ | |
5d7836c4 JS |
3058 | virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const; |
3059 | ||
b3169c12 JS |
3060 | /** |
3061 | Returns the line at the given y pixel position, or the last line. | |
3062 | */ | |
5d7836c4 JS |
3063 | virtual wxRichTextLine* GetLineAtYPosition(int y) const; |
3064 | ||
b3169c12 JS |
3065 | /** |
3066 | Returns the paragraph at the given character or caret position. | |
3067 | */ | |
5d7836c4 JS |
3068 | virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const; |
3069 | ||
b3169c12 JS |
3070 | /** |
3071 | Returns the line size at the given position. | |
3072 | */ | |
5d7836c4 JS |
3073 | virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const; |
3074 | ||
b3169c12 JS |
3075 | /** |
3076 | Given a position, returns the number of the visible line (potentially many to a paragraph), | |
3077 | starting from zero at the start of the buffer. We also have to pass a bool (@a startOfLine) | |
3078 | that indicates whether the caret is being shown at the end of the previous line or at the start | |
3079 | of the next, since the caret can be shown at two visible positions for the same underlying | |
3080 | position. | |
3081 | */ | |
5d7836c4 JS |
3082 | virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const; |
3083 | ||
b3169c12 JS |
3084 | /** |
3085 | Given a line number, returns the corresponding wxRichTextLine object. | |
3086 | */ | |
5d7836c4 JS |
3087 | virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const; |
3088 | ||
b3169c12 JS |
3089 | /** |
3090 | Returns the leaf object in a paragraph at this position. | |
3091 | */ | |
5d7836c4 JS |
3092 | virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; |
3093 | ||
b3169c12 JS |
3094 | /** |
3095 | Returns the paragraph by number. | |
3096 | */ | |
7fe8059f | 3097 | virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; |
5d7836c4 | 3098 | |
b3169c12 JS |
3099 | /** |
3100 | Returns the paragraph for a given line. | |
3101 | */ | |
7fe8059f | 3102 | virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; |
5d7836c4 | 3103 | |
b3169c12 JS |
3104 | /** |
3105 | Returns the length of the paragraph. | |
3106 | */ | |
5d7836c4 JS |
3107 | virtual int GetParagraphLength(long paragraphNumber) const; |
3108 | ||
b3169c12 JS |
3109 | /** |
3110 | Returns the number of paragraphs. | |
3111 | */ | |
42632bce | 3112 | virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); } |
5d7836c4 | 3113 | |
b3169c12 JS |
3114 | /** |
3115 | Returns the number of visible lines. | |
3116 | */ | |
5d7836c4 JS |
3117 | virtual int GetLineCount() const; |
3118 | ||
b3169c12 JS |
3119 | /** |
3120 | Returns the text of the paragraph. | |
3121 | */ | |
5d7836c4 JS |
3122 | virtual wxString GetParagraphText(long paragraphNumber) const; |
3123 | ||
b3169c12 JS |
3124 | /** |
3125 | Converts zero-based line column and paragraph number to a position. | |
3126 | */ | |
5d7836c4 JS |
3127 | virtual long XYToPosition(long x, long y) const; |
3128 | ||
b3169c12 JS |
3129 | /** |
3130 | Converts a zero-based position to line column and paragraph number. | |
3131 | */ | |
5d7836c4 JS |
3132 | virtual bool PositionToXY(long pos, long* x, long* y) const; |
3133 | ||
b3169c12 | 3134 | /** |
7afd2b58 JS |
3135 | Sets the attributes for the given range. Pass flags to determine how the |
3136 | attributes are set. | |
3137 | ||
3138 | The end point of range is specified as the last character position of the span | |
3139 | of text. So, for example, to set the style for a character at position 5, | |
3140 | use the range (5,5). | |
3141 | This differs from the wxRichTextCtrl API, where you would specify (5,6). | |
3142 | ||
3143 | @a flags may contain a bit list of the following values: | |
3144 | - wxRICHTEXT_SETSTYLE_NONE: no style flag. | |
3145 | - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be | |
3146 | undoable. | |
3147 | - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied | |
3148 | if the combined style at this point is already the style in question. | |
3149 | - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be | |
3150 | applied to paragraphs, and not the content. | |
3151 | This allows content styling to be preserved independently from that | |
3152 | of e.g. a named paragraph style. | |
3153 | - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be | |
3154 | applied to characters, and not the paragraph. | |
3155 | This allows content styling to be preserved independently from that | |
3156 | of e.g. a named paragraph style. | |
3157 | - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying | |
3158 | the new style. | |
3159 | - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. | |
3160 | Only the style flags are used in this operation. | |
b3169c12 | 3161 | */ |
24777478 | 3162 | virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
5d7836c4 | 3163 | |
b3169c12 JS |
3164 | /** |
3165 | Sets the attributes for the given object only, for example the box attributes for a text box. | |
3166 | */ | |
603f702b | 3167 | virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
cdaed652 | 3168 | |
b3169c12 JS |
3169 | /** |
3170 | Returns the combined text attributes for this position. | |
7afd2b58 JS |
3171 | |
3172 | This function gets the @e uncombined style - that is, the attributes associated | |
3173 | with the paragraph or character content, and not necessarily the combined | |
3174 | attributes you see on the screen. To get the combined attributes, use GetStyle(). | |
3175 | If you specify (any) paragraph attribute in @e style's flags, this function | |
3176 | will fetch the paragraph attributes. | |
3177 | Otherwise, it will return the character attributes. | |
b3169c12 | 3178 | */ |
24777478 | 3179 | virtual bool GetStyle(long position, wxRichTextAttr& style); |
5d7836c4 | 3180 | |
b3169c12 JS |
3181 | /** |
3182 | Returns the content (uncombined) attributes for this position. | |
3183 | */ | |
24777478 | 3184 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); |
fe5aa22c | 3185 | |
b3169c12 JS |
3186 | /** |
3187 | Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and | |
3188 | context attributes. | |
3189 | */ | |
24777478 | 3190 | virtual bool DoGetStyle(long position, wxRichTextAttr& style, bool combineStyles = true); |
fe5aa22c | 3191 | |
b3169c12 | 3192 | /** |
7afd2b58 JS |
3193 | This function gets a style representing the common, combined attributes in the |
3194 | given range. | |
3195 | Attributes which have different values within the specified range will not be | |
3196 | included the style flags. | |
3197 | ||
3198 | The function is used to get the attributes to display in the formatting dialog: | |
3199 | the user can edit the attributes common to the selection, and optionally specify the | |
3200 | values of further attributes to be applied uniformly. | |
3201 | ||
3202 | To apply the edited attributes, you can use SetStyle() specifying | |
3203 | the wxRICHTEXT_SETSTYLE_OPTIMIZE flag, which will only apply attributes that | |
3204 | are different from the @e combined attributes within the range. | |
3205 | So, the user edits the effective, displayed attributes for the range, | |
3206 | but his choice won't be applied unnecessarily to content. As an example, | |
3207 | say the style for a paragraph specifies bold, but the paragraph text doesn't | |
3208 | specify a weight. | |
3209 | The combined style is bold, and this is what the user will see on-screen and | |
3210 | in the formatting dialog. The user now specifies red text, in addition to bold. | |
3211 | When applying with SetStyle(), the content font weight attributes won't be | |
3212 | changed to bold because this is already specified by the paragraph. | |
3213 | However the text colour attributes @e will be changed to show red. | |
b3169c12 | 3214 | */ |
24777478 | 3215 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); |
59509217 | 3216 | |
b3169c12 JS |
3217 | /** |
3218 | Combines @a style with @a currentStyle for the purpose of summarising the attributes of a range of | |
3219 | content. | |
3220 | */ | |
24777478 | 3221 | bool CollectStyle(wxRichTextAttr& currentStyle, const wxRichTextAttr& style, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); |
59509217 | 3222 | |
7afd2b58 | 3223 | //@{ |
b3169c12 | 3224 | /** |
7afd2b58 JS |
3225 | Sets the list attributes for the given range, passing flags to determine how |
3226 | the attributes are set. | |
3227 | Either the style definition or the name of the style definition (in the current | |
3228 | sheet) can be passed. | |
b3169c12 | 3229 | |
7afd2b58 JS |
3230 | @a flags is a bit list of the following: |
3231 | - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable. | |
3232 | - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from | |
3233 | @a startFrom, otherwise existing attributes are used. | |
3234 | - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used | |
3235 | as the level for all paragraphs, otherwise the current indentation will be used. | |
3236 | ||
3237 | @see NumberList(), PromoteList(), ClearListStyle(). | |
b3169c12 | 3238 | */ |
7afd2b58 | 3239 | virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
38f833b1 | 3240 | virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
7afd2b58 | 3241 | //@} |
38f833b1 | 3242 | |
b3169c12 | 3243 | /** |
7afd2b58 JS |
3244 | Clears the list style from the given range, clearing list-related attributes |
3245 | and applying any named paragraph style associated with each paragraph. | |
3246 | ||
3247 | @a flags is a bit list of the following: | |
3248 | - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable. | |
3249 | ||
3250 | @see SetListStyle(), PromoteList(), NumberList() | |
b3169c12 | 3251 | */ |
38f833b1 JS |
3252 | virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
3253 | ||
7afd2b58 | 3254 | //@{ |
b3169c12 | 3255 | /** |
7afd2b58 JS |
3256 | Numbers the paragraphs in the given range. |
3257 | ||
3258 | Pass flags to determine how the attributes are set. | |
3259 | Either the style definition or the name of the style definition (in the current | |
3260 | sheet) can be passed. | |
3261 | ||
3262 | @a flags is a bit list of the following: | |
3263 | - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable. | |
3264 | - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from | |
3265 | @a startFrom, otherwise existing attributes are used. | |
3266 | - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used | |
3267 | as the level for all paragraphs, otherwise the current indentation will be used. | |
3268 | ||
b3169c12 | 3269 | @a def can be NULL to indicate that the existing list style should be used. |
b3169c12 | 3270 | |
7afd2b58 | 3271 | @see SetListStyle(), PromoteList(), ClearListStyle() |
b3169c12 | 3272 | */ |
7afd2b58 | 3273 | virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
38f833b1 | 3274 | virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
7afd2b58 | 3275 | //@} |
38f833b1 | 3276 | |
7afd2b58 | 3277 | //@{ |
b3169c12 | 3278 | /** |
7afd2b58 JS |
3279 | Promotes the list items within the given range. |
3280 | A positive @a promoteBy produces a smaller indent, and a negative number | |
3281 | produces a larger indent. Pass flags to determine how the attributes are set. | |
3282 | Either the style definition or the name of the style definition (in the current | |
3283 | sheet) can be passed. | |
b3169c12 | 3284 | |
7afd2b58 JS |
3285 | @a flags is a bit list of the following: |
3286 | - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable. | |
3287 | - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from | |
3288 | @a startFrom, otherwise existing attributes are used. | |
3289 | - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used | |
3290 | as the level for all paragraphs, otherwise the current indentation will be used. | |
3291 | ||
3292 | @see SetListStyle(), SetListStyle(), ClearListStyle() | |
b3169c12 | 3293 | */ |
7afd2b58 | 3294 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
38f833b1 | 3295 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
7afd2b58 | 3296 | //@} |
38f833b1 | 3297 | |
b3169c12 JS |
3298 | /** |
3299 | Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously | |
3300 | @a def can be NULL/empty to indicate that the existing list style should be used. | |
3301 | */ | |
38f833b1 JS |
3302 | 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); |
3303 | ||
b3169c12 JS |
3304 | /** |
3305 | Fills in the attributes for numbering a paragraph after previousParagraph. | |
3306 | */ | |
24777478 | 3307 | virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const; |
d2d0adc7 | 3308 | |
590a0f8b JS |
3309 | /** |
3310 | Sets the properties for the given range, passing flags to determine how the | |
3311 | attributes are set. You can merge properties or replace them. | |
3312 | ||
3313 | The end point of range is specified as the last character position of the span | |
3314 | of text, plus one. So, for example, to set the properties for a character at | |
3315 | position 5, use the range (5,6). | |
3316 | ||
3317 | @a flags may contain a bit list of the following values: | |
3318 | - wxRICHTEXT_SETPROPERTIES_NONE: no flag. | |
3319 | - wxRICHTEXT_SETPROPERTIES_WITH_UNDO: specifies that this operation should be | |
3320 | undoable. | |
3321 | - wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY: specifies that the properties should only be | |
3322 | applied to paragraphs, and not the content. | |
3323 | - wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY: specifies that the properties should only be | |
3324 | applied to characters, and not the paragraph. | |
3325 | - wxRICHTEXT_SETPROPERTIES_RESET: resets (clears) the existing properties before applying | |
3326 | the new properties. | |
3327 | - wxRICHTEXT_SETPROPERTIES_REMOVE: removes the specified properties. | |
3328 | */ | |
3329 | virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO); | |
3330 | ||
b3169c12 JS |
3331 | /** |
3332 | Test if this whole range has character attributes of the specified kind. If any | |
3333 | of the attributes are different within the range, the test fails. You | |
3334 | can use this to implement, for example, bold button updating. style must have | |
3335 | flags indicating which attributes are of interest. | |
3336 | */ | |
24777478 | 3337 | virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 | 3338 | |
b3169c12 JS |
3339 | /** |
3340 | Test if this whole range has paragraph attributes of the specified kind. If any | |
3341 | of the attributes are different within the range, the test fails. You | |
3342 | can use this to implement, for example, centering button updating. style must have | |
3343 | flags indicating which attributes are of interest. | |
3344 | */ | |
24777478 | 3345 | virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 | 3346 | |
5d7836c4 JS |
3347 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); } |
3348 | ||
cc2aecde JS |
3349 | /** |
3350 | Prepares the content just before insertion (or after buffer reset). | |
3351 | Currently is only called if undo mode is on. | |
3352 | */ | |
3353 | virtual void PrepareContent(wxRichTextParagraphLayoutBox& container); | |
3354 | ||
b3169c12 JS |
3355 | /** |
3356 | Insert fragment into this box at the given position. If partialParagraph is true, | |
3357 | it is assumed that the last (or only) paragraph is just a piece of data with no paragraph | |
3358 | marker. | |
3359 | */ | |
0ca07313 | 3360 | virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 | 3361 | |
b3169c12 JS |
3362 | /** |
3363 | Make a copy of the fragment corresponding to the given range, putting it in @a fragment. | |
3364 | */ | |
0ca07313 | 3365 | virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 | 3366 | |
b3169c12 JS |
3367 | /** |
3368 | Apply the style sheet to the buffer, for example if the styles have changed. | |
3369 | */ | |
fe5aa22c JS |
3370 | virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet); |
3371 | ||
5d7836c4 JS |
3372 | void Copy(const wxRichTextParagraphLayoutBox& obj); |
3373 | ||
0ca07313 JS |
3374 | void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); } |
3375 | ||
b3169c12 JS |
3376 | /** |
3377 | Calculate ranges. | |
3378 | */ | |
603f702b | 3379 | virtual void UpdateRanges(); |
5d7836c4 | 3380 | |
b3169c12 JS |
3381 | /** |
3382 | Get all the text. | |
3383 | */ | |
5d7836c4 JS |
3384 | virtual wxString GetText() const; |
3385 | ||
b3169c12 | 3386 | /** |
7afd2b58 JS |
3387 | Sets the default style, affecting the style currently being applied |
3388 | (for example, setting the default style to bold will cause subsequently | |
3389 | inserted text to be bold). | |
3390 | ||
3391 | This is not cumulative - setting the default style will replace the previous | |
3392 | default style. | |
3393 | ||
3394 | Setting it to a default attribute object makes new content take on the 'basic' style. | |
b3169c12 | 3395 | */ |
24777478 | 3396 | virtual bool SetDefaultStyle(const wxRichTextAttr& style); |
5d7836c4 | 3397 | |
b3169c12 | 3398 | /** |
7afd2b58 JS |
3399 | Returns the current default style, affecting the style currently being applied |
3400 | (for example, setting the default style to bold will cause subsequently | |
3401 | inserted text to be bold). | |
b3169c12 | 3402 | */ |
24777478 | 3403 | virtual const wxRichTextAttr& GetDefaultStyle() const { return m_defaultAttributes; } |
5d7836c4 | 3404 | |
b3169c12 | 3405 | /** |
7afd2b58 JS |
3406 | Sets the basic (overall) style. This is the style of the whole |
3407 | buffer before further styles are applied, unlike the default style, which | |
3408 | only affects the style currently being applied (for example, setting the default | |
3409 | style to bold will cause subsequently inserted text to be bold). | |
b3169c12 | 3410 | */ |
24777478 | 3411 | virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; } |
5d7836c4 | 3412 | |
b3169c12 JS |
3413 | /** |
3414 | Returns the basic (overall) style. | |
7afd2b58 JS |
3415 | |
3416 | This is the style of the whole buffer before further styles are applied, | |
3417 | unlike the default style, which only affects the style currently being | |
3418 | applied (for example, setting the default style to bold will cause | |
3419 | subsequently inserted text to be bold). | |
b3169c12 | 3420 | */ |
24777478 | 3421 | virtual const wxRichTextAttr& GetBasicStyle() const { return m_attributes; } |
5d7836c4 | 3422 | |
b3169c12 JS |
3423 | /** |
3424 | Invalidates the buffer. With no argument, invalidates whole buffer. | |
3425 | */ | |
603f702b JS |
3426 | virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
3427 | ||
b3169c12 JS |
3428 | /** |
3429 | Do the (in)validation for this object only. | |
3430 | */ | |
603f702b JS |
3431 | virtual void DoInvalidate(const wxRichTextRange& invalidRange); |
3432 | ||
b3169c12 JS |
3433 | /** |
3434 | Do the (in)validation both up and down the hierarchy. | |
3435 | */ | |
603f702b | 3436 | virtual void InvalidateHierarchy(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
ce00f59b | 3437 | |
b3169c12 JS |
3438 | /** |
3439 | Gather information about floating objects. If untilObj is non-NULL, | |
3440 | will stop getting information if the current object is this, since we | |
3441 | will collect the rest later. | |
3442 | */ | |
603f702b | 3443 | virtual bool UpdateFloatingObjects(const wxRect& availableRect, wxRichTextObject* untilObj = NULL); |
38113684 | 3444 | |
b3169c12 JS |
3445 | /** |
3446 | Get invalid range, rounding to entire paragraphs if argument is true. | |
3447 | */ | |
38113684 JS |
3448 | wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const; |
3449 | ||
b3169c12 JS |
3450 | /** |
3451 | Returns @true if this object needs layout. | |
3452 | */ | |
603f702b JS |
3453 | bool IsDirty() const { return m_invalidRange != wxRICHTEXT_NONE; } |
3454 | ||
b3169c12 JS |
3455 | /** |
3456 | Returns the wxRichTextFloatCollector of this object. | |
3457 | */ | |
cdaed652 VZ |
3458 | wxRichTextFloatCollector* GetFloatCollector() { return m_floatCollector; } |
3459 | ||
b3169c12 JS |
3460 | /** |
3461 | Returns the number of floating objects at this level. | |
3462 | */ | |
603f702b JS |
3463 | int GetFloatingObjectCount() const; |
3464 | ||
b3169c12 JS |
3465 | /** |
3466 | Returns a list of floating objects. | |
3467 | */ | |
603f702b JS |
3468 | bool GetFloatingObjects(wxRichTextObjectList& objects) const; |
3469 | ||
5d7836c4 JS |
3470 | protected: |
3471 | wxRichTextCtrl* m_ctrl; | |
24777478 | 3472 | wxRichTextAttr m_defaultAttributes; |
38113684 | 3473 | |
b3169c12 | 3474 | // The invalidated range that will need full layout |
0ca07313 | 3475 | wxRichTextRange m_invalidRange; |
5d7836c4 JS |
3476 | |
3477 | // Is the last paragraph partial or complete? | |
0ca07313 | 3478 | bool m_partialParagraph; |
cdaed652 VZ |
3479 | |
3480 | // The floating layout state | |
3481 | wxRichTextFloatCollector* m_floatCollector; | |
5d7836c4 JS |
3482 | }; |
3483 | ||
603f702b JS |
3484 | /** |
3485 | @class wxRichTextBox | |
3486 | ||
706465df JS |
3487 | This class implements a floating or inline text box, containing paragraphs. |
3488 | ||
3489 | @library{wxrichtext} | |
3490 | @category{richtext} | |
3491 | ||
3492 | @see wxRichTextParagraphLayoutBox, wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl | |
3493 | */ | |
bec80f4f | 3494 | |
603f702b | 3495 | class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextParagraphLayoutBox |
bec80f4f JS |
3496 | { |
3497 | DECLARE_DYNAMIC_CLASS(wxRichTextBox) | |
3498 | public: | |
3499 | // Constructors | |
3500 | ||
603f702b JS |
3501 | /** |
3502 | Default constructor; optionally pass the parent object. | |
3503 | */ | |
3504 | ||
bec80f4f | 3505 | wxRichTextBox(wxRichTextObject* parent = NULL); |
603f702b JS |
3506 | |
3507 | /** | |
3508 | Copy constructor. | |
3509 | */ | |
3510 | ||
3511 | wxRichTextBox(const wxRichTextBox& obj): wxRichTextParagraphLayoutBox() { Copy(obj); } | |
bec80f4f | 3512 | |
d13b34d3 | 3513 | // Overridables |
bec80f4f | 3514 | |
8db2e3ef | 3515 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
bec80f4f | 3516 | |
603f702b JS |
3517 | virtual wxString GetXMLNodeName() const { return wxT("textbox"); } |
3518 | ||
603f702b JS |
3519 | virtual bool CanEditProperties() const { return true; } |
3520 | ||
603f702b JS |
3521 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); |
3522 | ||
603f702b | 3523 | virtual wxString GetPropertiesMenuLabel() const { return _("&Box"); } |
5ad9ae3a | 3524 | |
bec80f4f JS |
3525 | // Accessors |
3526 | ||
3527 | // Operations | |
3528 | ||
bec80f4f JS |
3529 | virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); } |
3530 | ||
bec80f4f JS |
3531 | void Copy(const wxRichTextBox& obj); |
3532 | ||
3533 | protected: | |
3534 | }; | |
3535 | ||
7c9fdebe JS |
3536 | /** |
3537 | @class wxRichTextField | |
3538 | ||
3539 | This class implements the general concept of a field, an object that represents | |
3540 | additional functionality such as a footnote, a bookmark, a page number, a table | |
3541 | of contents, and so on. Extra information (such as a bookmark name) can be stored | |
3542 | in the object properties. | |
3543 | ||
3544 | Drawing, layout, and property editing is delegated to classes derived | |
3545 | from wxRichTextFieldType, such as instances of wxRichTextFieldTypeStandard; this makes | |
3546 | the use of fields an efficient method of introducing extra functionality, since | |
3547 | most of the information required to draw a field (such as a bitmap) is kept centrally | |
3548 | in a single field type definition. | |
3549 | ||
3550 | The FieldType property, accessed by SetFieldType/GetFieldType, is used to retrieve | |
3551 | the field type definition. So be careful not to overwrite this property. | |
3552 | ||
3553 | wxRichTextField is derived from wxRichTextParagraphLayoutBox, which means that it | |
3554 | can contain its own read-only content, refreshed when the application calls the UpdateField | |
3555 | function. Whether a field is treated as a composite or a single graphic is determined | |
3556 | by the field type definition. If using wxRichTextFieldTypeStandard, passing the display | |
3557 | type wxRICHTEXT_FIELD_STYLE_COMPOSITE to the field type definition causes the field | |
3558 | to behave like a composite; the other display styles display a simple graphic. | |
3559 | When implementing a composite field, you will still need to derive from wxRichTextFieldTypeStandard | |
3560 | or wxRichTextFieldType, if only to implement UpdateField to refresh the field content | |
3561 | appropriately. wxRichTextFieldTypeStandard is only one possible implementation, but | |
3562 | covers common needs especially for simple, static fields using text or a bitmap. | |
3563 | ||
3564 | Register field types on application initialisation with the static function | |
3174a8a9 RD |
3565 | wxRichTextBuffer::AddFieldType. They will be deleted automatically on |
3566 | application exit. | |
7c9fdebe JS |
3567 | |
3568 | An application can write a field to a control with wxRichTextCtrl::WriteField, | |
3569 | taking a field type, the properties for the field, and optional attributes. | |
3570 | ||
3571 | @library{wxrichtext} | |
3572 | @category{richtext} | |
3573 | ||
3574 | @see wxRichTextFieldTypeStandard, wxRichTextFieldType, wxRichTextParagraphLayoutBox, wxRichTextProperties, wxRichTextCtrl | |
3575 | */ | |
3576 | ||
3577 | class WXDLLIMPEXP_RICHTEXT wxRichTextField: public wxRichTextParagraphLayoutBox | |
3578 | { | |
3579 | DECLARE_DYNAMIC_CLASS(wxRichTextField) | |
3580 | public: | |
3581 | // Constructors | |
3582 | ||
3583 | /** | |
3584 | Default constructor; optionally pass the parent object. | |
3585 | */ | |
3586 | ||
3587 | wxRichTextField(const wxString& fieldType = wxEmptyString, wxRichTextObject* parent = NULL); | |
3588 | ||
3589 | /** | |
3590 | Copy constructor. | |
3591 | */ | |
3592 | ||
3593 | wxRichTextField(const wxRichTextField& obj): wxRichTextParagraphLayoutBox() { Copy(obj); } | |
3594 | ||
3595 | // Overridables | |
3596 | ||
3597 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); | |
3598 | ||
3599 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); | |
3600 | ||
914a4e23 | 3601 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
7c9fdebe JS |
3602 | |
3603 | virtual wxString GetXMLNodeName() const { return wxT("field"); } | |
3604 | ||
3605 | virtual bool CanEditProperties() const; | |
3606 | ||
3607 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
3608 | ||
3609 | virtual wxString GetPropertiesMenuLabel() const; | |
3610 | ||
3611 | virtual bool AcceptsFocus() const { return false; } | |
3612 | ||
3613 | virtual void CalculateRange(long start, long& end); | |
3614 | ||
3615 | /** | |
3616 | If a field has children, we don't want the user to be able to edit it. | |
3617 | */ | |
3618 | virtual bool IsAtomic() const { return true; } | |
3619 | ||
3620 | virtual bool IsEmpty() const { return false; } | |
3621 | ||
3622 | virtual bool IsTopLevel() const; | |
3623 | ||
3624 | // Accessors | |
3625 | ||
3626 | void SetFieldType(const wxString& fieldType) { GetProperties().SetProperty(wxT("FieldType"), fieldType); } | |
3627 | wxString GetFieldType() const { return GetProperties().GetPropertyString(wxT("FieldType")); } | |
3628 | ||
3629 | // Operations | |
3630 | ||
3631 | /** | |
3632 | Update the field; delegated to the associated field type. This would typically expand the field to its value, | |
3633 | if this is a dynamically changing and/or composite field. | |
3634 | */ | |
32423dd8 | 3635 | virtual bool UpdateField(wxRichTextBuffer* buffer); |
7c9fdebe JS |
3636 | |
3637 | virtual wxRichTextObject* Clone() const { return new wxRichTextField(*this); } | |
3638 | ||
3639 | void Copy(const wxRichTextField& obj); | |
3640 | ||
3641 | protected: | |
3642 | }; | |
3643 | ||
3644 | /** | |
3645 | @class wxRichTextFieldType | |
3646 | ||
3647 | The base class for custom field types. Each type definition handles one | |
3648 | field type. Override functions to provide drawing, layout, updating and | |
3649 | property editing functionality for a field. | |
3650 | ||
3651 | Register field types on application initialisation with the static function | |
3174a8a9 RD |
3652 | wxRichTextBuffer::AddFieldType. They will be deleted automatically on |
3653 | application exit. | |
7c9fdebe JS |
3654 | |
3655 | @library{wxrichtext} | |
3656 | @category{richtext} | |
3657 | ||
3658 | @see wxRichTextFieldTypeStandard, wxRichTextField, wxRichTextCtrl | |
3659 | */ | |
3660 | ||
3661 | class WXDLLIMPEXP_RICHTEXT wxRichTextFieldType: public wxObject | |
3662 | { | |
3663 | DECLARE_CLASS(wxRichTextFieldType) | |
3664 | public: | |
3665 | /** | |
3666 | Creates a field type definition. | |
3667 | */ | |
3668 | wxRichTextFieldType(const wxString& name = wxEmptyString) | |
3669 | : m_name(name) | |
3670 | { } | |
3671 | ||
3672 | /** | |
3673 | Copy constructor. | |
3674 | */ | |
2643e2e4 VZ |
3675 | wxRichTextFieldType(const wxRichTextFieldType& fieldType) |
3676 | : wxObject(fieldType) | |
3677 | { Copy(fieldType); } | |
7c9fdebe JS |
3678 | |
3679 | void Copy(const wxRichTextFieldType& fieldType) { m_name = fieldType.m_name; } | |
3680 | ||
3681 | /** | |
3682 | Draw the item, within the given range. Some objects may ignore the range (for | |
3683 | example paragraphs) while others must obey it (lines, to implement wrapping) | |
3684 | */ | |
3685 | virtual bool Draw(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0; | |
3686 | ||
3687 | /** | |
3688 | Lay the item out at the specified position with the given size constraint. | |
3689 | Layout must set the cached size. @rect is the available space for the object, | |
3690 | and @a parentRect is the container that is used to determine a relative size | |
3691 | or position (for example if a text box must be 50% of the parent text box). | |
3692 | */ | |
3693 | virtual bool Layout(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style) = 0; | |
3694 | ||
3695 | /** | |
3696 | Returns the object size for the given range. Returns @false if the range | |
3697 | is invalid for this object. | |
3698 | */ | |
914a4e23 | 3699 | virtual bool GetRangeSize(wxRichTextField* obj, const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const = 0; |
7c9fdebe JS |
3700 | |
3701 | /** | |
3702 | Returns @true if we can edit the object's properties via a GUI. | |
3703 | */ | |
3704 | virtual bool CanEditProperties(wxRichTextField* WXUNUSED(obj)) const { return false; } | |
3705 | ||
3706 | /** | |
3707 | Edits the object's properties via a GUI. | |
3708 | */ | |
3709 | virtual bool EditProperties(wxRichTextField* WXUNUSED(obj), wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; } | |
3710 | ||
3711 | /** | |
3712 | Returns the label to be used for the properties context menu item. | |
3713 | */ | |
3714 | virtual wxString GetPropertiesMenuLabel(wxRichTextField* WXUNUSED(obj)) const { return wxEmptyString; } | |
3715 | ||
3716 | /** | |
3717 | Update the field. This would typically expand the field to its value, | |
3718 | if this is a dynamically changing and/or composite field. | |
3719 | */ | |
32423dd8 | 3720 | virtual bool UpdateField(wxRichTextBuffer* WXUNUSED(buffer), wxRichTextField* WXUNUSED(obj)) { return false; } |
7c9fdebe JS |
3721 | |
3722 | /** | |
3723 | Returns @true if this object is top-level, i.e. contains its own paragraphs, such as a text box. | |
3724 | */ | |
3725 | virtual bool IsTopLevel(wxRichTextField* WXUNUSED(obj)) const { return true; } | |
3726 | ||
3727 | /** | |
3728 | Sets the field type name. There should be a unique name per field type object. | |
3729 | */ | |
3730 | void SetName(const wxString& name) { m_name = name; } | |
3731 | ||
3732 | /** | |
3733 | Returns the field type name. There should be a unique name per field type object. | |
3734 | */ | |
3735 | wxString GetName() const { return m_name; } | |
3736 | ||
3737 | protected: | |
3738 | ||
3739 | wxString m_name; | |
3740 | }; | |
3741 | ||
3742 | WX_DECLARE_STRING_HASH_MAP(wxRichTextFieldType*, wxRichTextFieldTypeHashMap); | |
3743 | ||
3744 | /** | |
3745 | @class wxRichTextFieldTypeStandard | |
3746 | ||
3747 | A field type that can handle fields with text or bitmap labels, with a small range | |
3748 | of styles for implementing rectangular fields and fields that can be used for start | |
3749 | and end tags. | |
3750 | ||
3751 | The border, text and background colours can be customised; the default is | |
3752 | white text on a black background. | |
3753 | ||
3754 | The following display styles can be used. | |
3755 | ||
3756 | @beginStyleTable | |
3757 | @style{wxRICHTEXT_FIELD_STYLE_COMPOSITE} | |
3758 | Creates a composite field; you will probably need to derive a new class to implement UpdateField. | |
3759 | @style{wxRICHTEXT_FIELD_STYLE_RECTANGLE} | |
3760 | Shows a rounded rectangle background. | |
3761 | @style{wxRICHTEXT_FIELD_STYLE_NO_BORDER} | |
3762 | Suppresses the background and border; mostly used with a bitmap label. | |
3763 | @style{wxRICHTEXT_FIELD_STYLE_START_TAG} | |
3764 | Shows a start tag background, with the pointy end facing right. | |
3765 | @style{wxRICHTEXT_FIELD_STYLE_END_TAG} | |
3766 | Shows an end tag background, with the pointy end facing left. | |
3767 | @endStyleTable | |
3768 | ||
3769 | @library{wxrichtext} | |
3770 | @category{richtext} | |
3771 | ||
3772 | @see wxRichTextFieldType, wxRichTextField, wxRichTextBuffer, wxRichTextCtrl | |
3773 | */ | |
3774 | ||
3775 | class WXDLLIMPEXP_RICHTEXT wxRichTextFieldTypeStandard: public wxRichTextFieldType | |
3776 | { | |
3777 | DECLARE_CLASS(wxRichTextFieldTypeStandard) | |
3778 | public: | |
3779 | ||
3780 | // Display style types | |
3781 | enum { wxRICHTEXT_FIELD_STYLE_COMPOSITE = 0x01, | |
3782 | wxRICHTEXT_FIELD_STYLE_RECTANGLE = 0x02, | |
3783 | wxRICHTEXT_FIELD_STYLE_NO_BORDER = 0x04, | |
3784 | wxRICHTEXT_FIELD_STYLE_START_TAG = 0x08, | |
3785 | wxRICHTEXT_FIELD_STYLE_END_TAG = 0x10 | |
3786 | }; | |
3787 | ||
3788 | /** | |
3789 | Constructor, creating a field type definition with a text label. | |
3790 | ||
3791 | @param parent | |
3792 | The name of the type definition. This must be unique, and is the type | |
3793 | name used when adding a field to a control. | |
3794 | @param label | |
3795 | The text label to be shown on the field. | |
3796 | @param displayStyle | |
3797 | The display style: one of wxRICHTEXT_FIELD_STYLE_RECTANGLE, | |
3798 | wxRICHTEXT_FIELD_STYLE_NO_BORDER, wxRICHTEXT_FIELD_STYLE_START_TAG, | |
3799 | wxRICHTEXT_FIELD_STYLE_END_TAG. | |
3800 | ||
3801 | */ | |
3802 | wxRichTextFieldTypeStandard(const wxString& name, const wxString& label, int displayStyle = wxRICHTEXT_FIELD_STYLE_RECTANGLE); | |
3803 | ||
3804 | /** | |
3805 | Constructor, creating a field type definition with a bitmap label. | |
3806 | ||
3807 | @param parent | |
3808 | The name of the type definition. This must be unique, and is the type | |
3809 | name used when adding a field to a control. | |
3810 | @param label | |
3811 | The bitmap label to be shown on the field. | |
3812 | @param displayStyle | |
3813 | The display style: one of wxRICHTEXT_FIELD_STYLE_RECTANGLE, | |
3814 | wxRICHTEXT_FIELD_STYLE_NO_BORDER, wxRICHTEXT_FIELD_STYLE_START_TAG, | |
3815 | wxRICHTEXT_FIELD_STYLE_END_TAG. | |
3816 | ||
3817 | */ | |
3818 | wxRichTextFieldTypeStandard(const wxString& name, const wxBitmap& bitmap, int displayStyle = wxRICHTEXT_FIELD_STYLE_NO_BORDER); | |
3819 | ||
3820 | /** | |
3821 | The default constructor. | |
3822 | ||
3823 | */ | |
3824 | wxRichTextFieldTypeStandard() { Init(); } | |
3825 | ||
3826 | /** | |
3827 | The copy constructor. | |
3828 | ||
3829 | */ | |
2643e2e4 VZ |
3830 | wxRichTextFieldTypeStandard(const wxRichTextFieldTypeStandard& field) |
3831 | : wxRichTextFieldType(field) | |
3832 | { Copy(field); } | |
7c9fdebe JS |
3833 | |
3834 | /** | |
3835 | Initialises the object. | |
3836 | */ | |
3837 | void Init(); | |
3838 | ||
3839 | /** | |
3840 | Copies the object. | |
3841 | */ | |
3842 | void Copy(const wxRichTextFieldTypeStandard& field); | |
3843 | ||
3844 | /** | |
3845 | The assignment operator. | |
3846 | */ | |
3847 | void operator=(const wxRichTextFieldTypeStandard& field) { Copy(field); } | |
3848 | ||
3849 | /** | |
3850 | Draw the item, within the given range. Some objects may ignore the range (for | |
3851 | example paragraphs) while others must obey it (lines, to implement wrapping) | |
3852 | */ | |
3853 | virtual bool Draw(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); | |
3854 | ||
3855 | /** | |
3856 | Lay the item out at the specified position with the given size constraint. | |
3857 | Layout must set the cached size. @rect is the available space for the object, | |
3858 | and @a parentRect is the container that is used to determine a relative size | |
3859 | or position (for example if a text box must be 50% of the parent text box). | |
3860 | */ | |
3861 | virtual bool Layout(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); | |
3862 | ||
3863 | /** | |
3864 | Returns the object size for the given range. Returns @false if the range | |
3865 | is invalid for this object. | |
3866 | */ | |
914a4e23 | 3867 | virtual bool GetRangeSize(wxRichTextField* obj, const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
7c9fdebe JS |
3868 | |
3869 | /** | |
3870 | Get the size of the field, given the label, font size, and so on. | |
3871 | */ | |
3872 | wxSize GetSize(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, int style) const; | |
3873 | ||
3874 | /** | |
3875 | Returns @true if the display type is wxRICHTEXT_FIELD_STYLE_COMPOSITE, @false otherwise. | |
3876 | */ | |
3877 | virtual bool IsTopLevel(wxRichTextField* WXUNUSED(obj)) const { return (GetDisplayStyle() & wxRICHTEXT_FIELD_STYLE_COMPOSITE) != 0; } | |
3878 | ||
3879 | /** | |
3880 | Sets the text label for fields of this type. | |
3881 | */ | |
3882 | void SetLabel(const wxString& label) { m_label = label; } | |
3883 | ||
3884 | /** | |
3885 | Returns the text label for fields of this type. | |
3886 | */ | |
3887 | const wxString& GetLabel() const { return m_label; } | |
3888 | ||
3889 | /** | |
3890 | Sets the bitmap label for fields of this type. | |
3891 | */ | |
3892 | void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } | |
3893 | ||
3894 | /** | |
3895 | Gets the bitmap label for fields of this type. | |
3896 | */ | |
3897 | const wxBitmap& GetBitmap() const { return m_bitmap; } | |
3898 | ||
3899 | /** | |
3900 | Gets the display style for fields of this type. | |
3901 | */ | |
3902 | int GetDisplayStyle() const { return m_displayStyle; } | |
3903 | ||
3904 | /** | |
3905 | Sets the display style for fields of this type. | |
3906 | */ | |
3907 | void SetDisplayStyle(int displayStyle) { m_displayStyle = displayStyle; } | |
3908 | ||
3909 | /** | |
3910 | Gets the font used for drawing the text label. | |
3911 | */ | |
3912 | const wxFont& GetFont() const { return m_font; } | |
3913 | ||
3914 | /** | |
3915 | Sets the font used for drawing the text label. | |
3916 | */ | |
3917 | void SetFont(const wxFont& font) { m_font = font; } | |
3918 | ||
3919 | /** | |
3920 | Gets the colour used for drawing the text label. | |
3921 | */ | |
3922 | const wxColour& GetTextColour() const { return m_textColour; } | |
3923 | ||
3924 | /** | |
3925 | Sets the colour used for drawing the text label. | |
3926 | */ | |
3927 | void SetTextColour(const wxColour& colour) { m_textColour = colour; } | |
3928 | ||
3929 | /** | |
3930 | Gets the colour used for drawing the field border. | |
3931 | */ | |
3932 | const wxColour& GetBorderColour() const { return m_borderColour; } | |
3933 | ||
3934 | /** | |
3935 | Sets the colour used for drawing the field border. | |
3936 | */ | |
3937 | void SetBorderColour(const wxColour& colour) { m_borderColour = colour; } | |
3938 | ||
3939 | /** | |
3940 | Gets the colour used for drawing the field background. | |
3941 | */ | |
3942 | const wxColour& GetBackgroundColour() const { return m_backgroundColour; } | |
3943 | ||
3944 | /** | |
3945 | Sets the colour used for drawing the field background. | |
3946 | */ | |
3947 | void SetBackgroundColour(const wxColour& colour) { m_backgroundColour = colour; } | |
3948 | ||
3949 | /** | |
3950 | Sets the vertical padding (the distance between the border and the text). | |
3951 | */ | |
3952 | void SetVerticalPadding(int padding) { m_verticalPadding = padding; } | |
3953 | ||
3954 | /** | |
3955 | Gets the vertical padding (the distance between the border and the text). | |
3956 | */ | |
3957 | int GetVerticalPadding() const { return m_verticalPadding; } | |
3958 | ||
3959 | /** | |
3960 | Sets the horizontal padding (the distance between the border and the text). | |
3961 | */ | |
3962 | void SetHorizontalPadding(int padding) { m_horizontalPadding = padding; } | |
3963 | ||
3964 | /** | |
3965 | Sets the horizontal padding (the distance between the border and the text). | |
3966 | */ | |
3967 | int GetHorizontalPadding() const { return m_horizontalPadding; } | |
3968 | ||
3969 | /** | |
3970 | Sets the horizontal margin surrounding the field object. | |
3971 | */ | |
3972 | void SetHorizontalMargin(int margin) { m_horizontalMargin = margin; } | |
3973 | ||
3974 | /** | |
3975 | Gets the horizontal margin surrounding the field object. | |
3976 | */ | |
3977 | int GetHorizontalMargin() const { return m_horizontalMargin; } | |
3978 | ||
3979 | /** | |
3980 | Sets the vertical margin surrounding the field object. | |
3981 | */ | |
3982 | void SetVerticalMargin(int margin) { m_verticalMargin = margin; } | |
3983 | ||
3984 | /** | |
3985 | Gets the vertical margin surrounding the field object. | |
3986 | */ | |
3987 | int GetVerticalMargin() const { return m_verticalMargin; } | |
3988 | ||
3989 | protected: | |
3990 | ||
3991 | wxString m_label; | |
3992 | int m_displayStyle; | |
3993 | wxFont m_font; | |
3994 | wxColour m_textColour; | |
3995 | wxColour m_borderColour; | |
3996 | wxColour m_backgroundColour; | |
3997 | int m_verticalPadding; | |
3998 | int m_horizontalPadding; | |
3999 | int m_horizontalMargin; | |
4000 | int m_verticalMargin; | |
4001 | wxBitmap m_bitmap; | |
4002 | }; | |
4003 | ||
706465df JS |
4004 | /** |
4005 | @class wxRichTextLine | |
4006 | ||
4007 | This object represents a line in a paragraph, and stores | |
4008 | offsets from the start of the paragraph representing the | |
4009 | start and end positions of the line. | |
4010 | ||
4011 | @library{wxrichtext} | |
4012 | @category{richtext} | |
4013 | ||
4014 | @see wxRichTextBuffer, wxRichTextCtrl | |
4015 | */ | |
5d7836c4 | 4016 | |
3b2cb431 | 4017 | class WXDLLIMPEXP_RICHTEXT wxRichTextLine |
5d7836c4 JS |
4018 | { |
4019 | public: | |
4020 | // Constructors | |
4021 | ||
4022 | wxRichTextLine(wxRichTextParagraph* parent); | |
1e967276 | 4023 | wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); } |
5d7836c4 JS |
4024 | virtual ~wxRichTextLine() {} |
4025 | ||
d13b34d3 | 4026 | // Overridables |
5d7836c4 JS |
4027 | |
4028 | // Accessors | |
4029 | ||
b3169c12 JS |
4030 | /** |
4031 | Sets the range associated with this line. | |
4032 | */ | |
5d7836c4 | 4033 | void SetRange(const wxRichTextRange& range) { m_range = range; } |
b3169c12 JS |
4034 | /** |
4035 | Sets the range associated with this line. | |
4036 | */ | |
5d7836c4 JS |
4037 | void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); } |
4038 | ||
b3169c12 JS |
4039 | /** |
4040 | Returns the parent paragraph. | |
4041 | */ | |
5d7836c4 JS |
4042 | wxRichTextParagraph* GetParent() { return m_parent; } |
4043 | ||
b3169c12 JS |
4044 | /** |
4045 | Returns the range. | |
4046 | */ | |
5d7836c4 | 4047 | const wxRichTextRange& GetRange() const { return m_range; } |
b3169c12 JS |
4048 | /** |
4049 | Returns the range. | |
4050 | */ | |
5d7836c4 JS |
4051 | wxRichTextRange& GetRange() { return m_range; } |
4052 | ||
b3169c12 JS |
4053 | /** |
4054 | Returns the absolute range. | |
4055 | */ | |
1e967276 JS |
4056 | wxRichTextRange GetAbsoluteRange() const; |
4057 | ||
b3169c12 JS |
4058 | /** |
4059 | Returns the line size as calculated by Layout. | |
4060 | */ | |
5d7836c4 | 4061 | virtual wxSize GetSize() const { return m_size; } |
b3169c12 JS |
4062 | |
4063 | /** | |
4064 | Sets the line size as calculated by Layout. | |
4065 | */ | |
5d7836c4 JS |
4066 | virtual void SetSize(const wxSize& sz) { m_size = sz; } |
4067 | ||
b3169c12 JS |
4068 | /** |
4069 | Returns the object position relative to the parent. | |
4070 | */ | |
5d7836c4 | 4071 | virtual wxPoint GetPosition() const { return m_pos; } |
b3169c12 JS |
4072 | |
4073 | /** | |
4074 | Sets the object position relative to the parent. | |
4075 | */ | |
5d7836c4 JS |
4076 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } |
4077 | ||
b3169c12 JS |
4078 | /** |
4079 | Returns the absolute object position. | |
4080 | */ | |
5d7836c4 JS |
4081 | virtual wxPoint GetAbsolutePosition() const; |
4082 | ||
b3169c12 JS |
4083 | /** |
4084 | Returns the rectangle enclosing the line. | |
4085 | */ | |
5d7836c4 JS |
4086 | virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); } |
4087 | ||
b3169c12 JS |
4088 | /** |
4089 | Sets the stored descent. | |
4090 | */ | |
5d7836c4 | 4091 | void SetDescent(int descent) { m_descent = descent; } |
b3169c12 JS |
4092 | |
4093 | /** | |
4094 | Returns the stored descent. | |
4095 | */ | |
5d7836c4 JS |
4096 | int GetDescent() const { return m_descent; } |
4097 | ||
2f45f554 JS |
4098 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING |
4099 | wxArrayInt& GetObjectSizes() { return m_objectSizes; } | |
4100 | const wxArrayInt& GetObjectSizes() const { return m_objectSizes; } | |
4101 | #endif | |
4102 | ||
5d7836c4 JS |
4103 | // Operations |
4104 | ||
b3169c12 JS |
4105 | /** |
4106 | Initialises the object. | |
4107 | */ | |
1e967276 | 4108 | void Init(wxRichTextParagraph* parent); |
5d7836c4 | 4109 | |
b3169c12 JS |
4110 | /** |
4111 | Copies from @a obj. | |
4112 | */ | |
5d7836c4 JS |
4113 | void Copy(const wxRichTextLine& obj); |
4114 | ||
5d7836c4 JS |
4115 | virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); } |
4116 | ||
4117 | protected: | |
4118 | ||
b3169c12 JS |
4119 | // The range of the line (start position to end position) |
4120 | // This is relative to the parent paragraph. | |
5d7836c4 JS |
4121 | wxRichTextRange m_range; |
4122 | ||
b3169c12 | 4123 | // Size and position measured relative to top of paragraph |
5d7836c4 JS |
4124 | wxPoint m_pos; |
4125 | wxSize m_size; | |
4126 | ||
b3169c12 | 4127 | // Maximum descent for this line (location of text baseline) |
5d7836c4 JS |
4128 | int m_descent; |
4129 | ||
4130 | // The parent object | |
4131 | wxRichTextParagraph* m_parent; | |
2f45f554 JS |
4132 | |
4133 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING | |
4134 | wxArrayInt m_objectSizes; | |
4135 | #endif | |
5d7836c4 JS |
4136 | }; |
4137 | ||
3b2cb431 | 4138 | WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 | 4139 | |
706465df JS |
4140 | /** |
4141 | @class wxRichTextParagraph | |
4142 | ||
4143 | This object represents a single paragraph containing various objects such as text content, images, and further paragraph layout objects. | |
4144 | ||
4145 | @library{wxrichtext} | |
4146 | @category{richtext} | |
4147 | ||
4148 | @see wxRichTextBuffer, wxRichTextCtrl | |
4149 | */ | |
5d7836c4 | 4150 | |
603f702b | 4151 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextCompositeObject |
5d7836c4 JS |
4152 | { |
4153 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraph) | |
4154 | public: | |
4155 | // Constructors | |
4156 | ||
b3169c12 JS |
4157 | /** |
4158 | Constructor taking a parent and style. | |
4159 | */ | |
24777478 | 4160 | wxRichTextParagraph(wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
b3169c12 JS |
4161 | /** |
4162 | Constructor taking a text string, a parent and paragraph and character attributes. | |
4163 | */ | |
24777478 | 4164 | wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxRichTextAttr* paraStyle = NULL, wxRichTextAttr* charStyle = NULL); |
d3c7fc99 | 4165 | virtual ~wxRichTextParagraph(); |
603f702b | 4166 | wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextCompositeObject() { Copy(obj); } |
5d7836c4 | 4167 | |
d13b34d3 | 4168 | // Overridables |
5d7836c4 | 4169 | |
8db2e3ef | 4170 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 | 4171 | |
8db2e3ef | 4172 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); |
5d7836c4 | 4173 | |
914a4e23 | 4174 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
5d7836c4 | 4175 | |
8db2e3ef | 4176 | virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); |
5d7836c4 | 4177 | |
8db2e3ef | 4178 | virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
5d7836c4 | 4179 | |
5d7836c4 JS |
4180 | virtual void CalculateRange(long start, long& end); |
4181 | ||
bec80f4f JS |
4182 | virtual wxString GetXMLNodeName() const { return wxT("paragraph"); } |
4183 | ||
5d7836c4 JS |
4184 | // Accessors |
4185 | ||
b3169c12 JS |
4186 | /** |
4187 | Returns the cached lines. | |
4188 | */ | |
5d7836c4 JS |
4189 | wxRichTextLineList& GetLines() { return m_cachedLines; } |
4190 | ||
4191 | // Operations | |
4192 | ||
b3169c12 JS |
4193 | /** |
4194 | Copies the object. | |
4195 | */ | |
5d7836c4 JS |
4196 | void Copy(const wxRichTextParagraph& obj); |
4197 | ||
5d7836c4 JS |
4198 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); } |
4199 | ||
b3169c12 JS |
4200 | /** |
4201 | Clears the cached lines. | |
4202 | */ | |
5d7836c4 JS |
4203 | void ClearLines(); |
4204 | ||
4205 | // Implementation | |
4206 | ||
b3169c12 JS |
4207 | /** |
4208 | Applies paragraph styles such as centering to the wrapped lines. | |
4209 | */ | |
603f702b | 4210 | virtual void ApplyParagraphStyle(wxRichTextLine* line, const wxRichTextAttr& attr, const wxRect& rect, wxDC& dc); |
5d7836c4 | 4211 | |
b3169c12 JS |
4212 | /** |
4213 | Inserts text at the given position. | |
4214 | */ | |
5d7836c4 JS |
4215 | virtual bool InsertText(long pos, const wxString& text); |
4216 | ||
b3169c12 JS |
4217 | /** |
4218 | Splits an object at this position if necessary, and returns | |
4219 | the previous object, or NULL if inserting at the beginning. | |
4220 | */ | |
5d7836c4 JS |
4221 | virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL); |
4222 | ||
b3169c12 JS |
4223 | /** |
4224 | Moves content to a list from this point. | |
4225 | */ | |
5d7836c4 JS |
4226 | virtual void MoveToList(wxRichTextObject* obj, wxList& list); |
4227 | ||
b3169c12 JS |
4228 | /** |
4229 | Adds content back from a list. | |
4230 | */ | |
5d7836c4 JS |
4231 | virtual void MoveFromList(wxList& list); |
4232 | ||
b3169c12 JS |
4233 | /** |
4234 | Returns the plain text searching from the start or end of the range. | |
4235 | The resulting string may be shorter than the range given. | |
4236 | */ | |
5d7836c4 JS |
4237 | bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true); |
4238 | ||
b3169c12 JS |
4239 | /** |
4240 | Finds a suitable wrap position. @a wrapPosition is the last position in the line to the left | |
4241 | of the split. | |
4242 | */ | |
8db2e3ef | 4243 | bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, wxRichTextDrawingContext& context, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); |
5d7836c4 | 4244 | |
b3169c12 JS |
4245 | /** |
4246 | Finds the object at the given position. | |
4247 | */ | |
5d7836c4 JS |
4248 | wxRichTextObject* FindObjectAtPosition(long position); |
4249 | ||
b3169c12 JS |
4250 | /** |
4251 | Returns the bullet text for this paragraph. | |
4252 | */ | |
5d7836c4 JS |
4253 | wxString GetBulletText(); |
4254 | ||
b3169c12 JS |
4255 | /** |
4256 | Allocates or reuses a line object. | |
4257 | */ | |
1e967276 JS |
4258 | wxRichTextLine* AllocateLine(int pos); |
4259 | ||
b3169c12 JS |
4260 | /** |
4261 | Clears remaining unused line objects, if any. | |
4262 | */ | |
1e967276 JS |
4263 | bool ClearUnusedLines(int lineCount); |
4264 | ||
b3169c12 JS |
4265 | /** |
4266 | Returns combined attributes of the base style, paragraph style and character style. We use this to dynamically | |
4267 | retrieve the actual style. | |
4268 | */ | |
603f702b | 4269 | wxRichTextAttr GetCombinedAttributes(const wxRichTextAttr& contentStyle, bool includingBoxAttr = false) const; |
fe5aa22c | 4270 | |
b3169c12 JS |
4271 | /** |
4272 | Returns the combined attributes of the base style and paragraph style. | |
4273 | */ | |
603f702b | 4274 | wxRichTextAttr GetCombinedAttributes(bool includingBoxAttr = false) const; |
fe5aa22c | 4275 | |
b3169c12 JS |
4276 | /** |
4277 | Returns the first position from pos that has a line break character. | |
4278 | */ | |
ff76711f JS |
4279 | long GetFirstLineBreakPosition(long pos); |
4280 | ||
b3169c12 JS |
4281 | /** |
4282 | Creates a default tabstop array. | |
4283 | */ | |
cfa3b256 JS |
4284 | static void InitDefaultTabs(); |
4285 | ||
b3169c12 JS |
4286 | /** |
4287 | Clears the default tabstop array. | |
4288 | */ | |
cfa3b256 JS |
4289 | static void ClearDefaultTabs(); |
4290 | ||
b3169c12 JS |
4291 | /** |
4292 | Returns the default tabstop array. | |
4293 | */ | |
cfa3b256 JS |
4294 | static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; } |
4295 | ||
b3169c12 JS |
4296 | /** |
4297 | Lays out the floating objects. | |
4298 | */ | |
c4168888 | 4299 | void LayoutFloat(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style, wxRichTextFloatCollector* floatCollector); |
cdaed652 | 4300 | |
5d7836c4 | 4301 | protected: |
b3169c12 JS |
4302 | |
4303 | // The lines that make up the wrapped paragraph | |
5d7836c4 | 4304 | wxRichTextLineList m_cachedLines; |
cfa3b256 | 4305 | |
b3169c12 | 4306 | // Default tabstops |
cfa3b256 | 4307 | static wxArrayInt sm_defaultTabs; |
cdaed652 VZ |
4308 | |
4309 | friend class wxRichTextFloatCollector; | |
5d7836c4 JS |
4310 | }; |
4311 | ||
706465df JS |
4312 | /** |
4313 | @class wxRichTextPlainText | |
4314 | ||
4315 | This object represents a single piece of text. | |
4316 | ||
4317 | @library{wxrichtext} | |
4318 | @category{richtext} | |
4319 | ||
4320 | @see wxRichTextBuffer, wxRichTextCtrl | |
4321 | */ | |
5d7836c4 | 4322 | |
3b2cb431 | 4323 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject |
5d7836c4 JS |
4324 | { |
4325 | DECLARE_DYNAMIC_CLASS(wxRichTextPlainText) | |
4326 | public: | |
4327 | // Constructors | |
4328 | ||
7afd2b58 JS |
4329 | /** |
4330 | Constructor. | |
4331 | */ | |
24777478 | 4332 | wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
7afd2b58 JS |
4333 | |
4334 | /** | |
4335 | Copy constructor. | |
4336 | */ | |
0ca07313 | 4337 | wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); } |
5d7836c4 | 4338 | |
d13b34d3 | 4339 | // Overridables |
5d7836c4 | 4340 | |
8db2e3ef | 4341 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 | 4342 | |
8db2e3ef | 4343 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); |
5d7836c4 | 4344 | |
914a4e23 | 4345 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
5d7836c4 | 4346 | |
5d7836c4 JS |
4347 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; |
4348 | ||
5d7836c4 JS |
4349 | virtual wxRichTextObject* DoSplit(long pos); |
4350 | ||
5d7836c4 JS |
4351 | virtual void CalculateRange(long start, long& end); |
4352 | ||
5d7836c4 JS |
4353 | virtual bool DeleteRange(const wxRichTextRange& range); |
4354 | ||
7fe8059f | 4355 | virtual bool IsEmpty() const { return m_text.empty(); } |
5d7836c4 | 4356 | |
f7667b84 | 4357 | virtual bool CanMerge(wxRichTextObject* object, wxRichTextDrawingContext& context) const; |
5d7836c4 | 4358 | |
f7667b84 | 4359 | virtual bool Merge(wxRichTextObject* object, wxRichTextDrawingContext& context); |
5d7836c4 | 4360 | |
5d7836c4 JS |
4361 | virtual void Dump(wxTextOutputStream& stream); |
4362 | ||
f7667b84 JS |
4363 | virtual bool CanSplit(wxRichTextDrawingContext& context) const; |
4364 | ||
4365 | virtual wxRichTextObject* Split(wxRichTextDrawingContext& context); | |
4366 | ||
7afd2b58 JS |
4367 | /** |
4368 | Get the first position from pos that has a line break character. | |
4369 | */ | |
ff76711f JS |
4370 | long GetFirstLineBreakPosition(long pos); |
4371 | ||
bec80f4f JS |
4372 | /// Does this object take note of paragraph attributes? Text and image objects don't. |
4373 | virtual bool UsesParagraphAttributes() const { return false; } | |
4374 | ||
4375 | #if wxUSE_XML | |
603f702b | 4376 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
4377 | #endif |
4378 | ||
4379 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
bec80f4f JS |
4380 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); |
4381 | #endif | |
4382 | ||
4383 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
bec80f4f JS |
4384 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); |
4385 | #endif | |
4386 | ||
bec80f4f JS |
4387 | virtual wxString GetXMLNodeName() const { return wxT("text"); } |
4388 | ||
5d7836c4 JS |
4389 | // Accessors |
4390 | ||
7afd2b58 JS |
4391 | /** |
4392 | Returns the text. | |
4393 | */ | |
5d7836c4 JS |
4394 | const wxString& GetText() const { return m_text; } |
4395 | ||
7afd2b58 JS |
4396 | /** |
4397 | Sets the text. | |
4398 | */ | |
5d7836c4 JS |
4399 | void SetText(const wxString& text) { m_text = text; } |
4400 | ||
4401 | // Operations | |
4402 | ||
7afd2b58 | 4403 | // Copies the text object, |
5d7836c4 JS |
4404 | void Copy(const wxRichTextPlainText& obj); |
4405 | ||
7afd2b58 | 4406 | // Clones the text object. |
5d7836c4 | 4407 | virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); } |
7afd2b58 | 4408 | |
7f0d9d71 | 4409 | private: |
24777478 | 4410 | bool DrawTabbedString(wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected); |
5d7836c4 JS |
4411 | |
4412 | protected: | |
4413 | wxString m_text; | |
4414 | }; | |
4415 | ||
706465df JS |
4416 | /** |
4417 | @class wxRichTextImageBlock | |
5d7836c4 | 4418 | |
706465df JS |
4419 | This class stores information about an image, in binary in-memory form. |
4420 | ||
4421 | @library{wxrichtext} | |
4422 | @category{richtext} | |
4423 | ||
4424 | @see wxRichTextBuffer, wxRichTextCtrl | |
4425 | */ | |
5d7836c4 | 4426 | |
3b2cb431 | 4427 | class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject |
5d7836c4 JS |
4428 | { |
4429 | public: | |
7afd2b58 JS |
4430 | /** |
4431 | Constructor. | |
4432 | */ | |
5d7836c4 | 4433 | wxRichTextImageBlock(); |
7afd2b58 JS |
4434 | |
4435 | /** | |
4436 | Copy constructor. | |
4437 | */ | |
5d7836c4 | 4438 | wxRichTextImageBlock(const wxRichTextImageBlock& block); |
d3c7fc99 | 4439 | virtual ~wxRichTextImageBlock(); |
5d7836c4 | 4440 | |
7afd2b58 JS |
4441 | /** |
4442 | Initialises the block. | |
4443 | */ | |
5d7836c4 | 4444 | void Init(); |
7afd2b58 JS |
4445 | |
4446 | /** | |
4447 | Clears the block. | |
4448 | */ | |
4449 | ||
5d7836c4 JS |
4450 | void Clear(); |
4451 | ||
7afd2b58 JS |
4452 | /** |
4453 | Load the original image into a memory block. | |
4454 | If the image is not a JPEG, we must convert it into a JPEG | |
4455 | to conserve space. | |
4456 | If it's not a JPEG we can make use of @a image, already scaled, so we don't have to | |
4457 | load the image a second time. | |
4458 | */ | |
d75a69e8 FM |
4459 | virtual bool MakeImageBlock(const wxString& filename, wxBitmapType imageType, |
4460 | wxImage& image, bool convertToJPEG = true); | |
5d7836c4 | 4461 | |
7afd2b58 JS |
4462 | /** |
4463 | Make an image block from the wxImage in the given | |
4464 | format. | |
4465 | */ | |
d75a69e8 | 4466 | virtual bool MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality = 80); |
ce00f59b | 4467 | |
7afd2b58 JS |
4468 | /** |
4469 | Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG) | |
4470 | */ | |
cdaed652 VZ |
4471 | virtual bool MakeImageBlockDefaultQuality(const wxImage& image, wxBitmapType imageType); |
4472 | ||
7afd2b58 JS |
4473 | /** |
4474 | Makes the image block. | |
4475 | */ | |
cdaed652 | 4476 | virtual bool DoMakeImageBlock(const wxImage& image, wxBitmapType imageType); |
5d7836c4 | 4477 | |
7afd2b58 JS |
4478 | /** |
4479 | Writes the block to a file. | |
4480 | */ | |
5d7836c4 JS |
4481 | bool Write(const wxString& filename); |
4482 | ||
7afd2b58 JS |
4483 | /** |
4484 | Writes the data in hex to a stream. | |
4485 | */ | |
5d7836c4 JS |
4486 | bool WriteHex(wxOutputStream& stream); |
4487 | ||
7afd2b58 JS |
4488 | /** |
4489 | Reads the data in hex from a stream. | |
4490 | */ | |
d75a69e8 | 4491 | bool ReadHex(wxInputStream& stream, int length, wxBitmapType imageType); |
5d7836c4 | 4492 | |
7afd2b58 JS |
4493 | /** |
4494 | Copy from @a block. | |
4495 | */ | |
5d7836c4 JS |
4496 | void Copy(const wxRichTextImageBlock& block); |
4497 | ||
4498 | // Load a wxImage from the block | |
7afd2b58 JS |
4499 | /** |
4500 | */ | |
5d7836c4 JS |
4501 | bool Load(wxImage& image); |
4502 | ||
7afd2b58 JS |
4503 | // Operators |
4504 | ||
4505 | /** | |
4506 | Assignment operation. | |
4507 | */ | |
5d7836c4 JS |
4508 | void operator=(const wxRichTextImageBlock& block); |
4509 | ||
7afd2b58 | 4510 | // Accessors |
5d7836c4 | 4511 | |
7afd2b58 JS |
4512 | /** |
4513 | Returns the raw data. | |
4514 | */ | |
5d7836c4 | 4515 | unsigned char* GetData() const { return m_data; } |
7afd2b58 JS |
4516 | |
4517 | /** | |
4518 | Returns the data size in bytes. | |
4519 | */ | |
5d7836c4 | 4520 | size_t GetDataSize() const { return m_dataSize; } |
7afd2b58 JS |
4521 | |
4522 | /** | |
4523 | Returns the image type. | |
4524 | */ | |
d75a69e8 | 4525 | wxBitmapType GetImageType() const { return m_imageType; } |
5d7836c4 | 4526 | |
7afd2b58 JS |
4527 | /** |
4528 | */ | |
5d7836c4 | 4529 | void SetData(unsigned char* image) { m_data = image; } |
7afd2b58 JS |
4530 | |
4531 | /** | |
4532 | Sets the data size. | |
4533 | */ | |
5d7836c4 | 4534 | void SetDataSize(size_t size) { m_dataSize = size; } |
7afd2b58 JS |
4535 | |
4536 | /** | |
4537 | Sets the image type. | |
4538 | */ | |
d75a69e8 | 4539 | void SetImageType(wxBitmapType imageType) { m_imageType = imageType; } |
5d7836c4 | 4540 | |
7afd2b58 JS |
4541 | /** |
4542 | Returns @true if the data is non-NULL. | |
4543 | */ | |
b7cacb43 | 4544 | bool IsOk() const { return GetData() != NULL; } |
7afd2b58 | 4545 | bool Ok() const { return IsOk(); } |
5d7836c4 | 4546 | |
7afd2b58 JS |
4547 | /** |
4548 | Gets the extension for the block's type. | |
4549 | */ | |
d2d0adc7 JS |
4550 | wxString GetExtension() const; |
4551 | ||
5d7836c4 JS |
4552 | /// Implementation |
4553 | ||
7afd2b58 JS |
4554 | /** |
4555 | Allocates and reads from a stream as a block of memory. | |
4556 | */ | |
5d7836c4 | 4557 | static unsigned char* ReadBlock(wxInputStream& stream, size_t size); |
7afd2b58 JS |
4558 | |
4559 | /** | |
4560 | Allocates and reads from a file as a block of memory. | |
4561 | */ | |
5d7836c4 JS |
4562 | static unsigned char* ReadBlock(const wxString& filename, size_t size); |
4563 | ||
7afd2b58 JS |
4564 | /** |
4565 | Writes a memory block to stream. | |
4566 | */ | |
5d7836c4 JS |
4567 | static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size); |
4568 | ||
7afd2b58 JS |
4569 | /** |
4570 | Writes a memory block to a file. | |
4571 | */ | |
5d7836c4 JS |
4572 | static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size); |
4573 | ||
4574 | protected: | |
4575 | // Size in bytes of the image stored. | |
4576 | // This is in the raw, original form such as a JPEG file. | |
4577 | unsigned char* m_data; | |
4578 | size_t m_dataSize; | |
d75a69e8 | 4579 | wxBitmapType m_imageType; |
5d7836c4 JS |
4580 | }; |
4581 | ||
706465df JS |
4582 | /** |
4583 | @class wxRichTextImage | |
4584 | ||
4585 | This class implements a graphic object. | |
4586 | ||
4587 | @library{wxrichtext} | |
4588 | @category{richtext} | |
4589 | ||
4590 | @see wxRichTextBuffer, wxRichTextCtrl, wxRichTextImageBlock | |
4591 | */ | |
5d7836c4 | 4592 | |
bec80f4f | 4593 | class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject |
5d7836c4 JS |
4594 | { |
4595 | DECLARE_DYNAMIC_CLASS(wxRichTextImage) | |
4596 | public: | |
4597 | // Constructors | |
4598 | ||
7afd2b58 JS |
4599 | /** |
4600 | Default constructor. | |
4601 | */ | |
23698b12 | 4602 | wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { Init(); } |
7afd2b58 JS |
4603 | |
4604 | /** | |
4605 | Creates a wxRichTextImage from a wxImage. | |
4606 | */ | |
24777478 | 4607 | wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); |
7afd2b58 JS |
4608 | |
4609 | /** | |
4610 | Creates a wxRichTextImage from an image block. | |
4611 | */ | |
24777478 | 4612 | wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); |
7afd2b58 JS |
4613 | |
4614 | /** | |
4615 | Copy constructor. | |
4616 | */ | |
bec80f4f | 4617 | wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject(obj) { Copy(obj); } |
5d7836c4 | 4618 | |
914a4e23 JS |
4619 | /** |
4620 | Destructor. | |
4621 | */ | |
4622 | ~wxRichTextImage(); | |
4623 | ||
23698b12 JS |
4624 | /** |
4625 | Initialisation. | |
4626 | */ | |
4627 | void Init(); | |
4628 | ||
d13b34d3 | 4629 | // Overridables |
5d7836c4 | 4630 | |
8db2e3ef | 4631 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
5d7836c4 | 4632 | |
8db2e3ef | 4633 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); |
5d7836c4 | 4634 | |
914a4e23 | 4635 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
5d7836c4 | 4636 | |
7afd2b58 JS |
4637 | /** |
4638 | Returns the 'natural' size for this object - the image size. | |
4639 | */ | |
603f702b JS |
4640 | virtual wxTextAttrSize GetNaturalSize() const; |
4641 | ||
a1b806b9 | 4642 | virtual bool IsEmpty() const { return false; /* !m_imageBlock.IsOk(); */ } |
cdaed652 | 4643 | |
cdaed652 VZ |
4644 | virtual bool CanEditProperties() const { return true; } |
4645 | ||
cdaed652 | 4646 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); |
5d7836c4 | 4647 | |
603f702b JS |
4648 | virtual wxString GetPropertiesMenuLabel() const { return _("&Picture"); } |
4649 | ||
bec80f4f JS |
4650 | virtual bool UsesParagraphAttributes() const { return false; } |
4651 | ||
4652 | #if wxUSE_XML | |
603f702b | 4653 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
bec80f4f JS |
4654 | #endif |
4655 | ||
4656 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
bec80f4f JS |
4657 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); |
4658 | #endif | |
4659 | ||
4660 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
bec80f4f JS |
4661 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); |
4662 | #endif | |
4663 | ||
4664 | // Images can be floatable (optionally). | |
4665 | virtual bool IsFloatable() const { return true; } | |
4666 | ||
bec80f4f JS |
4667 | virtual wxString GetXMLNodeName() const { return wxT("image"); } |
4668 | ||
5d7836c4 JS |
4669 | // Accessors |
4670 | ||
7afd2b58 JS |
4671 | /** |
4672 | Returns the image cache (a scaled bitmap). | |
4673 | */ | |
cdaed652 | 4674 | const wxBitmap& GetImageCache() const { return m_imageCache; } |
5d7836c4 | 4675 | |
7afd2b58 JS |
4676 | /** |
4677 | Sets the image cache. | |
4678 | */ | |
23698b12 | 4679 | void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; m_originalImageSize = wxSize(bitmap.GetWidth(), bitmap.GetHeight()); } |
cdaed652 | 4680 | |
7afd2b58 JS |
4681 | /** |
4682 | Resets the image cache. | |
4683 | */ | |
23698b12 | 4684 | void ResetImageCache() { m_imageCache = wxNullBitmap; m_originalImageSize = wxSize(-1, -1); } |
5d7836c4 | 4685 | |
7afd2b58 JS |
4686 | /** |
4687 | Returns the image block containing the raw data. | |
4688 | */ | |
5d7836c4 JS |
4689 | wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; } |
4690 | ||
4691 | // Operations | |
4692 | ||
7afd2b58 JS |
4693 | /** |
4694 | Copies the image object. | |
4695 | */ | |
5d7836c4 JS |
4696 | void Copy(const wxRichTextImage& obj); |
4697 | ||
7afd2b58 JS |
4698 | /** |
4699 | Clones the image object. | |
4700 | */ | |
5d7836c4 JS |
4701 | virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); } |
4702 | ||
7afd2b58 JS |
4703 | /** |
4704 | Creates a cached image at the required size. | |
4705 | */ | |
914a4e23 | 4706 | virtual bool LoadImageCache(wxDC& dc, bool resetCache = false, const wxSize& parentSize = wxDefaultSize); |
5d7836c4 | 4707 | |
23698b12 JS |
4708 | /** |
4709 | Gets the original image size. | |
4710 | */ | |
4711 | wxSize GetOriginalImageSize() const { return m_originalImageSize; } | |
4712 | ||
4713 | /** | |
4714 | Sets the original image size. | |
4715 | */ | |
4716 | void SetOriginalImageSize(const wxSize& sz) { m_originalImageSize = sz; } | |
4717 | ||
5d7836c4 | 4718 | protected: |
5d7836c4 | 4719 | wxRichTextImageBlock m_imageBlock; |
cdaed652 | 4720 | wxBitmap m_imageCache; |
23698b12 | 4721 | wxSize m_originalImageSize; |
5d7836c4 JS |
4722 | }; |
4723 | ||
b5dbe15d VS |
4724 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand; |
4725 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; | |
5d7836c4 | 4726 | |
706465df JS |
4727 | /** |
4728 | @class wxRichTextBuffer | |
4729 | ||
4730 | This is a kind of paragraph layout box, used to represent the whole buffer. | |
4731 | ||
4732 | @library{wxrichtext} | |
4733 | @category{richtext} | |
4734 | ||
4735 | @see wxRichTextParagraphLayoutBox, wxRichTextCtrl | |
4736 | */ | |
4737 | ||
3b2cb431 | 4738 | class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox |
5d7836c4 JS |
4739 | { |
4740 | DECLARE_DYNAMIC_CLASS(wxRichTextBuffer) | |
4741 | public: | |
4742 | // Constructors | |
4743 | ||
7afd2b58 JS |
4744 | /** |
4745 | Default constructor. | |
4746 | */ | |
5d7836c4 | 4747 | wxRichTextBuffer() { Init(); } |
7afd2b58 JS |
4748 | |
4749 | /** | |
4750 | Copy constructor. | |
4751 | */ | |
0ca07313 | 4752 | wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); } |
7afd2b58 | 4753 | |
d3c7fc99 | 4754 | virtual ~wxRichTextBuffer() ; |
5d7836c4 JS |
4755 | |
4756 | // Accessors | |
4757 | ||
7afd2b58 JS |
4758 | /** |
4759 | Returns the command processor. | |
4760 | A text buffer always creates its own command processor when it is initialized. | |
4761 | */ | |
5d7836c4 JS |
4762 | wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; } |
4763 | ||
7afd2b58 JS |
4764 | /** |
4765 | Sets style sheet, if any. This will allow the application to use named character and paragraph | |
4766 | styles found in the style sheet. | |
4767 | ||
4768 | Neither the buffer nor the control owns the style sheet so must be deleted by the application. | |
4769 | */ | |
5d7836c4 | 4770 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } |
7afd2b58 JS |
4771 | |
4772 | /** | |
4773 | Returns the style sheet. | |
4774 | */ | |
38f833b1 JS |
4775 | virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } |
4776 | ||
7afd2b58 JS |
4777 | /** |
4778 | Sets the style sheet and sends a notification of the change. | |
4779 | */ | |
d2d0adc7 JS |
4780 | bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet); |
4781 | ||
7afd2b58 JS |
4782 | /** |
4783 | Pushes the style sheet to the top of the style sheet stack. | |
4784 | */ | |
38f833b1 JS |
4785 | bool PushStyleSheet(wxRichTextStyleSheet* styleSheet); |
4786 | ||
7afd2b58 JS |
4787 | /** |
4788 | Pops the style sheet from the top of the style sheet stack. | |
4789 | */ | |
38f833b1 | 4790 | wxRichTextStyleSheet* PopStyleSheet(); |
5d7836c4 | 4791 | |
7afd2b58 JS |
4792 | /** |
4793 | Returns the table storing fonts, for quick access and font reuse. | |
4794 | */ | |
44cc96a8 | 4795 | wxRichTextFontTable& GetFontTable() { return m_fontTable; } |
7afd2b58 JS |
4796 | |
4797 | /** | |
4798 | Returns the table storing fonts, for quick access and font reuse. | |
4799 | */ | |
44cc96a8 | 4800 | const wxRichTextFontTable& GetFontTable() const { return m_fontTable; } |
7afd2b58 JS |
4801 | |
4802 | /** | |
4803 | Sets table storing fonts, for quick access and font reuse. | |
4804 | */ | |
44cc96a8 JS |
4805 | void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; } |
4806 | ||
32423dd8 JS |
4807 | /** |
4808 | Sets the scale factor for displaying fonts, for example for more comfortable | |
4809 | editing. | |
4810 | */ | |
4811 | void SetFontScale(double fontScale); | |
4812 | ||
4813 | /** | |
4814 | Returns the scale factor for displaying fonts, for example for more comfortable | |
4815 | editing. | |
4816 | */ | |
4817 | double GetFontScale() const { return m_fontScale; } | |
4818 | ||
4819 | /** | |
4820 | Sets the scale factor for displaying certain dimensions such as indentation and | |
4821 | inter-paragraph spacing. This can be useful when editing in a small control | |
4822 | where you still want legible text, but a minimum of wasted white space. | |
4823 | */ | |
4824 | void SetDimensionScale(double dimScale); | |
4825 | ||
4826 | /** | |
4827 | Returns the scale factor for displaying certain dimensions such as indentation | |
4828 | and inter-paragraph spacing. | |
4829 | */ | |
4830 | double GetDimensionScale() const { return m_dimensionScale; } | |
4831 | ||
5d7836c4 JS |
4832 | // Operations |
4833 | ||
7afd2b58 JS |
4834 | /** |
4835 | Initialisation. | |
4836 | */ | |
5d7836c4 JS |
4837 | void Init(); |
4838 | ||
7afd2b58 JS |
4839 | /** |
4840 | Clears the buffer, adds an empty paragraph, and clears the command processor. | |
4841 | */ | |
85d8909b | 4842 | virtual void ResetAndClearCommands(); |
5d7836c4 | 4843 | |
7e81e3a7 | 4844 | #if wxUSE_FFILE && wxUSE_STREAMS |
7afd2b58 JS |
4845 | //@{ |
4846 | /** | |
7e81e3a7 | 4847 | Loads content from a file. |
7afd2b58 JS |
4848 | Not all handlers will implement file loading. |
4849 | */ | |
d75a69e8 | 4850 | virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
7afd2b58 | 4851 | //@} |
5d7836c4 | 4852 | |
7afd2b58 JS |
4853 | //@{ |
4854 | /** | |
7e81e3a7 | 4855 | Saves content to a file. |
7afd2b58 JS |
4856 | Not all handlers will implement file saving. |
4857 | */ | |
4858 | virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); | |
7e81e3a7 VZ |
4859 | //@} |
4860 | #endif // wxUSE_FFILE | |
4861 | ||
4862 | #if wxUSE_STREAMS | |
4863 | //@{ | |
4864 | /** | |
4865 | Loads content from a stream. | |
4866 | Not all handlers will implement loading from a stream. | |
4867 | */ | |
4868 | virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); | |
4869 | //@} | |
4870 | ||
4871 | //@{ | |
4872 | /** | |
4873 | Saves content to a stream. | |
4874 | Not all handlers will implement saving to a stream. | |
4875 | */ | |
d75a69e8 | 4876 | virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
7afd2b58 | 4877 | //@} |
7e81e3a7 | 4878 | #endif // wxUSE_STREAMS |
5d7836c4 | 4879 | |
7afd2b58 JS |
4880 | /** |
4881 | Sets the handler flags, controlling loading and saving. | |
4882 | */ | |
d2d0adc7 JS |
4883 | void SetHandlerFlags(int flags) { m_handlerFlags = flags; } |
4884 | ||
7afd2b58 JS |
4885 | /** |
4886 | Gets the handler flags, controlling loading and saving. | |
4887 | */ | |
d2d0adc7 JS |
4888 | int GetHandlerFlags() const { return m_handlerFlags; } |
4889 | ||
7afd2b58 JS |
4890 | /** |
4891 | Convenience function to add a paragraph of text. | |
4892 | */ | |
24777478 | 4893 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); } |
5d7836c4 | 4894 | |
7afd2b58 JS |
4895 | /** |
4896 | Begin collapsing undo/redo commands. Note that this may not work properly | |
4897 | if combining commands that delete or insert content, changing ranges for | |
4898 | subsequent actions. | |
4899 | ||
4900 | @a cmdName should be the name of the combined command that will appear | |
4901 | next to Undo and Redo in the edit menu. | |
4902 | */ | |
5d7836c4 JS |
4903 | virtual bool BeginBatchUndo(const wxString& cmdName); |
4904 | ||
7afd2b58 JS |
4905 | /** |
4906 | End collapsing undo/redo commands. | |
4907 | */ | |
5d7836c4 JS |
4908 | virtual bool EndBatchUndo(); |
4909 | ||
7afd2b58 JS |
4910 | /** |
4911 | Returns @true if we are collapsing commands. | |
4912 | */ | |
5d7836c4 JS |
4913 | virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; } |
4914 | ||
7afd2b58 JS |
4915 | /** |
4916 | Submit the action immediately, or delay according to whether collapsing is on. | |
4917 | */ | |
5d7836c4 JS |
4918 | virtual bool SubmitAction(wxRichTextAction* action); |
4919 | ||
7afd2b58 JS |
4920 | /** |
4921 | Returns the collapsed command. | |
4922 | */ | |
5d7836c4 JS |
4923 | virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; } |
4924 | ||
7afd2b58 JS |
4925 | /** |
4926 | Begin suppressing undo/redo commands. The way undo is suppressed may be implemented | |
4927 | differently by each command. If not dealt with by a command implementation, then | |
4928 | it will be implemented automatically by not storing the command in the undo history | |
4929 | when the action is submitted to the command processor. | |
4930 | */ | |
5d7836c4 JS |
4931 | virtual bool BeginSuppressUndo(); |
4932 | ||
7afd2b58 JS |
4933 | /** |
4934 | End suppressing undo/redo commands. | |
4935 | */ | |
5d7836c4 JS |
4936 | virtual bool EndSuppressUndo(); |
4937 | ||
7afd2b58 JS |
4938 | /** |
4939 | Are we suppressing undo?? | |
4940 | */ | |
5d7836c4 JS |
4941 | virtual bool SuppressingUndo() const { return m_suppressUndo > 0; } |
4942 | ||
7afd2b58 JS |
4943 | /** |
4944 | Copy the range to the clipboard. | |
4945 | */ | |
5d7836c4 JS |
4946 | virtual bool CopyToClipboard(const wxRichTextRange& range); |
4947 | ||
7afd2b58 JS |
4948 | /** |
4949 | Paste the clipboard content to the buffer. | |
4950 | */ | |
5d7836c4 JS |
4951 | virtual bool PasteFromClipboard(long position); |
4952 | ||
7afd2b58 JS |
4953 | /** |
4954 | Returns @true if we can paste from the clipboard. | |
4955 | */ | |
5d7836c4 JS |
4956 | virtual bool CanPasteFromClipboard() const; |
4957 | ||
7afd2b58 JS |
4958 | /** |
4959 | Begin using a style. | |
4960 | */ | |
24777478 | 4961 | virtual bool BeginStyle(const wxRichTextAttr& style); |
5d7836c4 | 4962 | |
7afd2b58 JS |
4963 | /** |
4964 | End the style. | |
4965 | */ | |
5d7836c4 JS |
4966 | virtual bool EndStyle(); |
4967 | ||
7afd2b58 JS |
4968 | /** |
4969 | End all styles. | |
4970 | */ | |
5d7836c4 JS |
4971 | virtual bool EndAllStyles(); |
4972 | ||
7afd2b58 JS |
4973 | /** |
4974 | Clears the style stack. | |
4975 | */ | |
5d7836c4 JS |
4976 | virtual void ClearStyleStack(); |
4977 | ||
7afd2b58 JS |
4978 | /** |
4979 | Returns the size of the style stack, for example to check correct nesting. | |
4980 | */ | |
3b38e2a0 | 4981 | virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); } |
5d7836c4 | 4982 | |
7afd2b58 JS |
4983 | /** |
4984 | Begins using bold. | |
4985 | */ | |
5d7836c4 JS |
4986 | bool BeginBold(); |
4987 | ||
7afd2b58 JS |
4988 | /** |
4989 | Ends using bold. | |
4990 | */ | |
5d7836c4 JS |
4991 | bool EndBold() { return EndStyle(); } |
4992 | ||
7afd2b58 JS |
4993 | /** |
4994 | Begins using italic. | |
4995 | */ | |
5d7836c4 JS |
4996 | bool BeginItalic(); |
4997 | ||
7afd2b58 JS |
4998 | /** |
4999 | Ends using italic. | |
5000 | */ | |
5d7836c4 JS |
5001 | bool EndItalic() { return EndStyle(); } |
5002 | ||
7afd2b58 JS |
5003 | /** |
5004 | Begins using underline. | |
5005 | */ | |
5d7836c4 JS |
5006 | bool BeginUnderline(); |
5007 | ||
7afd2b58 JS |
5008 | /** |
5009 | Ends using underline. | |
5010 | */ | |
5d7836c4 JS |
5011 | bool EndUnderline() { return EndStyle(); } |
5012 | ||
7afd2b58 JS |
5013 | /** |
5014 | Begins using point size. | |
5015 | */ | |
5d7836c4 JS |
5016 | bool BeginFontSize(int pointSize); |
5017 | ||
7afd2b58 JS |
5018 | /** |
5019 | Ends using point size. | |
5020 | */ | |
5d7836c4 JS |
5021 | bool EndFontSize() { return EndStyle(); } |
5022 | ||
7afd2b58 JS |
5023 | /** |
5024 | Begins using this font. | |
5025 | */ | |
5d7836c4 JS |
5026 | bool BeginFont(const wxFont& font); |
5027 | ||
7afd2b58 JS |
5028 | /** |
5029 | Ends using a font. | |
5030 | */ | |
5d7836c4 JS |
5031 | bool EndFont() { return EndStyle(); } |
5032 | ||
7afd2b58 JS |
5033 | /** |
5034 | Begins using this colour. | |
5035 | */ | |
5d7836c4 JS |
5036 | bool BeginTextColour(const wxColour& colour); |
5037 | ||
7afd2b58 JS |
5038 | /** |
5039 | Ends using a colour. | |
5040 | */ | |
5d7836c4 JS |
5041 | bool EndTextColour() { return EndStyle(); } |
5042 | ||
7afd2b58 JS |
5043 | /** |
5044 | Begins using alignment. | |
5045 | */ | |
5d7836c4 JS |
5046 | bool BeginAlignment(wxTextAttrAlignment alignment); |
5047 | ||
7afd2b58 JS |
5048 | /** |
5049 | Ends alignment. | |
5050 | */ | |
5d7836c4 JS |
5051 | bool EndAlignment() { return EndStyle(); } |
5052 | ||
7afd2b58 JS |
5053 | /** |
5054 | Begins using @a leftIndent for the left indent, and optionally @a leftSubIndent for | |
5055 | the sub-indent. Both are expressed in tenths of a millimetre. | |
5056 | ||
5057 | The sub-indent is an offset from the left of the paragraph, and is used for all | |
5058 | but the first line in a paragraph. A positive value will cause the first line to appear | |
5059 | to the left of the subsequent lines, and a negative value will cause the first line to be | |
5060 | indented relative to the subsequent lines. | |
5061 | */ | |
5d7836c4 JS |
5062 | bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0); |
5063 | ||
7afd2b58 JS |
5064 | /** |
5065 | Ends left indent. | |
5066 | */ | |
5d7836c4 JS |
5067 | bool EndLeftIndent() { return EndStyle(); } |
5068 | ||
7afd2b58 JS |
5069 | /** |
5070 | Begins a right indent, specified in tenths of a millimetre. | |
5071 | */ | |
5d7836c4 JS |
5072 | bool BeginRightIndent(int rightIndent); |
5073 | ||
7afd2b58 JS |
5074 | /** |
5075 | Ends right indent. | |
5076 | */ | |
5d7836c4 JS |
5077 | bool EndRightIndent() { return EndStyle(); } |
5078 | ||
7afd2b58 JS |
5079 | /** |
5080 | Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing | |
5081 | in tenths of a millimetre. | |
5082 | */ | |
5d7836c4 JS |
5083 | bool BeginParagraphSpacing(int before, int after); |
5084 | ||
7afd2b58 JS |
5085 | /** |
5086 | Ends paragraph spacing. | |
5087 | */ | |
5d7836c4 JS |
5088 | bool EndParagraphSpacing() { return EndStyle(); } |
5089 | ||
7afd2b58 JS |
5090 | /** |
5091 | Begins line spacing using the specified value. @e spacing is a multiple, where | |
5092 | 10 means single-spacing, 15 means 1.5 spacing, and 20 means double spacing. | |
5093 | ||
5094 | The ::wxTextAttrLineSpacing enumeration values are defined for convenience. | |
5095 | */ | |
5d7836c4 JS |
5096 | bool BeginLineSpacing(int lineSpacing); |
5097 | ||
7afd2b58 JS |
5098 | /** |
5099 | Ends line spacing. | |
5100 | */ | |
5d7836c4 JS |
5101 | bool EndLineSpacing() { return EndStyle(); } |
5102 | ||
7afd2b58 JS |
5103 | /** |
5104 | Begins numbered bullet. | |
5105 | ||
5106 | This call will be needed for each item in the list, and the | |
5107 | application should take care of incrementing the numbering. | |
5108 | ||
5109 | @a bulletNumber is a number, usually starting with 1. | |
5110 | @a leftIndent and @a leftSubIndent are values in tenths of a millimetre. | |
5111 | @a bulletStyle is a bitlist of the following values: | |
5112 | ||
5113 | wxRichTextBuffer uses indentation to render a bulleted item. | |
5114 | The left indent is the distance between the margin and the bullet. | |
5115 | The content of the paragraph, including the first line, starts | |
5116 | at leftMargin + leftSubIndent. | |
5117 | So the distance between the left edge of the bullet and the | |
5118 | left of the actual paragraph is leftSubIndent. | |
5119 | */ | |
5d7836c4 JS |
5120 | bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD); |
5121 | ||
7afd2b58 JS |
5122 | /** |
5123 | Ends numbered bullet. | |
5124 | */ | |
5d7836c4 JS |
5125 | bool EndNumberedBullet() { return EndStyle(); } |
5126 | ||
7afd2b58 JS |
5127 | /** |
5128 | Begins applying a symbol bullet, using a character from the current font. | |
5129 | ||
5130 | See BeginNumberedBullet() for an explanation of how indentation is used | |
5131 | to render the bulleted paragraph. | |
5132 | */ | |
d2d0adc7 | 5133 | bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL); |
5d7836c4 | 5134 | |
7afd2b58 JS |
5135 | /** |
5136 | Ends symbol bullet. | |
5137 | */ | |
5d7836c4 JS |
5138 | bool EndSymbolBullet() { return EndStyle(); } |
5139 | ||
7afd2b58 JS |
5140 | /** |
5141 | Begins applying a standard bullet, using one of the standard bullet names | |
5142 | (currently @c standard/circle or @c standard/square. | |
5143 | ||
5144 | See BeginNumberedBullet() for an explanation of how indentation is used to | |
5145 | render the bulleted paragraph. | |
5146 | */ | |
f089713f JS |
5147 | bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD); |
5148 | ||
7afd2b58 JS |
5149 | /** |
5150 | Ends standard bullet. | |
5151 | */ | |
f089713f JS |
5152 | bool EndStandardBullet() { return EndStyle(); } |
5153 | ||
7afd2b58 JS |
5154 | /** |
5155 | Begins named character style. | |
5156 | */ | |
5d7836c4 JS |
5157 | bool BeginCharacterStyle(const wxString& characterStyle); |
5158 | ||
7afd2b58 JS |
5159 | /** |
5160 | Ends named character style. | |
5161 | */ | |
5d7836c4 JS |
5162 | bool EndCharacterStyle() { return EndStyle(); } |
5163 | ||
7afd2b58 JS |
5164 | /** |
5165 | Begins named paragraph style. | |
5166 | */ | |
5d7836c4 JS |
5167 | bool BeginParagraphStyle(const wxString& paragraphStyle); |
5168 | ||
7afd2b58 JS |
5169 | /** |
5170 | Ends named character style. | |
5171 | */ | |
5d7836c4 | 5172 | bool EndParagraphStyle() { return EndStyle(); } |
f089713f | 5173 | |
7afd2b58 JS |
5174 | /** |
5175 | Begins named list style. | |
5176 | ||
5177 | Optionally, you can also pass a level and a number. | |
5178 | */ | |
f089713f JS |
5179 | bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1); |
5180 | ||
7afd2b58 JS |
5181 | /** |
5182 | Ends named character style. | |
5183 | */ | |
f089713f | 5184 | bool EndListStyle() { return EndStyle(); } |
5d7836c4 | 5185 | |
7afd2b58 JS |
5186 | /** |
5187 | Begins applying wxTEXT_ATTR_URL to the content. | |
5188 | ||
5189 | Pass a URL and optionally, a character style to apply, since it is common | |
5190 | to mark a URL with a familiar style such as blue text with underlining. | |
5191 | */ | |
d2d0adc7 JS |
5192 | bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString); |
5193 | ||
7afd2b58 JS |
5194 | /** |
5195 | Ends URL. | |
5196 | */ | |
d2d0adc7 JS |
5197 | bool EndURL() { return EndStyle(); } |
5198 | ||
5199 | // Event handling | |
5200 | ||
7afd2b58 JS |
5201 | /** |
5202 | Adds an event handler. | |
5203 | ||
5204 | A buffer associated with a control has the control as the only event handler, | |
5205 | but the application is free to add more if further notification is required. | |
5206 | All handlers are notified of an event originating from the buffer, such as | |
5207 | the replacement of a style sheet during loading. | |
5208 | ||
5209 | The buffer never deletes any of the event handlers, unless RemoveEventHandler() | |
5210 | is called with @true as the second argument. | |
5211 | */ | |
d2d0adc7 JS |
5212 | bool AddEventHandler(wxEvtHandler* handler); |
5213 | ||
7afd2b58 JS |
5214 | /** |
5215 | Removes an event handler from the buffer's list of handlers, deleting the | |
5216 | object if @a deleteHandler is @true. | |
5217 | */ | |
d2d0adc7 JS |
5218 | bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false); |
5219 | ||
7afd2b58 JS |
5220 | /** |
5221 | Clear event handlers. | |
5222 | */ | |
d2d0adc7 JS |
5223 | void ClearEventHandlers(); |
5224 | ||
7afd2b58 JS |
5225 | /** |
5226 | Send event to event handlers. If sendToAll is true, will send to all event handlers, | |
5227 | otherwise will stop at the first successful one. | |
5228 | */ | |
d2d0adc7 JS |
5229 | bool SendEvent(wxEvent& event, bool sendToAll = true); |
5230 | ||
5d7836c4 JS |
5231 | // Implementation |
5232 | ||
8db2e3ef | 5233 | virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); |
603f702b | 5234 | |
7afd2b58 JS |
5235 | /** |
5236 | Copies the buffer. | |
5237 | */ | |
0ca07313 | 5238 | void Copy(const wxRichTextBuffer& obj); |
5d7836c4 | 5239 | |
7afd2b58 JS |
5240 | /** |
5241 | Assignment operator. | |
5242 | */ | |
bec80f4f JS |
5243 | void operator= (const wxRichTextBuffer& obj) { Copy(obj); } |
5244 | ||
7afd2b58 JS |
5245 | /** |
5246 | Clones the buffer. | |
5247 | */ | |
5d7836c4 JS |
5248 | virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); } |
5249 | ||
7afd2b58 JS |
5250 | /** |
5251 | Submits a command to insert paragraphs. | |
5252 | */ | |
0ca07313 JS |
5253 | bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); |
5254 | ||
7afd2b58 JS |
5255 | /** |
5256 | Submits a command to insert the given text. | |
5257 | */ | |
fe5aa22c | 5258 | bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 | 5259 | |
7afd2b58 JS |
5260 | /** |
5261 | Submits a command to insert a newline. | |
5262 | */ | |
fe5aa22c | 5263 | bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 | 5264 | |
7afd2b58 JS |
5265 | /** |
5266 | Submits a command to insert the given image. | |
5267 | */ | |
24777478 JS |
5268 | bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0, |
5269 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
cdaed652 | 5270 | |
7afd2b58 JS |
5271 | /** |
5272 | Submits a command to insert an object. | |
5273 | */ | |
603f702b | 5274 | wxRichTextObject* InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags); |
5d7836c4 | 5275 | |
7afd2b58 JS |
5276 | /** |
5277 | Submits a command to delete this range. | |
5278 | */ | |
12cc29c5 | 5279 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl); |
5d7836c4 | 5280 | |
7afd2b58 JS |
5281 | /** |
5282 | Mark modified. | |
5283 | */ | |
5d7836c4 | 5284 | void Modify(bool modify = true) { m_modified = modify; } |
7afd2b58 JS |
5285 | |
5286 | /** | |
5287 | Returns @true if the buffer was modified. | |
5288 | */ | |
5d7836c4 JS |
5289 | bool IsModified() const { return m_modified; } |
5290 | ||
7afd2b58 JS |
5291 | //@{ |
5292 | /** | |
5293 | Dumps contents of buffer for debugging purposes. | |
5294 | */ | |
5d7836c4 JS |
5295 | virtual void Dump(); |
5296 | virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); } | |
7afd2b58 | 5297 | //@} |
5d7836c4 | 5298 | |
7afd2b58 JS |
5299 | /** |
5300 | Returns the file handlers. | |
5301 | */ | |
5d7836c4 JS |
5302 | static wxList& GetHandlers() { return sm_handlers; } |
5303 | ||
7afd2b58 JS |
5304 | /** |
5305 | Adds a file handler to the end. | |
5306 | */ | |
5d7836c4 JS |
5307 | static void AddHandler(wxRichTextFileHandler *handler); |
5308 | ||
7afd2b58 JS |
5309 | /** |
5310 | Inserts a file handler at the front. | |
5311 | */ | |
5d7836c4 JS |
5312 | static void InsertHandler(wxRichTextFileHandler *handler); |
5313 | ||
7afd2b58 JS |
5314 | /** |
5315 | Removes a file handler. | |
5316 | */ | |
5d7836c4 JS |
5317 | static bool RemoveHandler(const wxString& name); |
5318 | ||
7afd2b58 JS |
5319 | /** |
5320 | Finds a file handler by name. | |
5321 | */ | |
5d7836c4 JS |
5322 | static wxRichTextFileHandler *FindHandler(const wxString& name); |
5323 | ||
7afd2b58 JS |
5324 | /** |
5325 | Finds a file handler by extension and type. | |
5326 | */ | |
d75a69e8 | 5327 | static wxRichTextFileHandler *FindHandler(const wxString& extension, wxRichTextFileType imageType); |
5d7836c4 | 5328 | |
7afd2b58 JS |
5329 | /** |
5330 | Finds a handler by filename or, if supplied, type. | |
5331 | */ | |
d75a69e8 FM |
5332 | static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, |
5333 | wxRichTextFileType imageType); | |
5d7836c4 | 5334 | |
7afd2b58 JS |
5335 | /** |
5336 | Finds a handler by type. | |
5337 | */ | |
d75a69e8 | 5338 | static wxRichTextFileHandler *FindHandler(wxRichTextFileType imageType); |
5d7836c4 | 5339 | |
7afd2b58 JS |
5340 | /** |
5341 | Gets a wildcard incorporating all visible handlers. If @a types is present, | |
5342 | it will be filled with the file type corresponding to each filter. This can be | |
5343 | used to determine the type to pass to LoadFile given a selected filter. | |
5344 | */ | |
1e967276 | 5345 | static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL); |
5d7836c4 | 5346 | |
7afd2b58 JS |
5347 | /** |
5348 | Clean up file handlers. | |
5349 | */ | |
5d7836c4 JS |
5350 | static void CleanUpHandlers(); |
5351 | ||
7afd2b58 JS |
5352 | /** |
5353 | Initialise the standard file handlers. | |
5354 | Currently, only the plain text loading/saving handler is initialised by default. | |
5355 | */ | |
5d7836c4 JS |
5356 | static void InitStandardHandlers(); |
5357 | ||
8db2e3ef JS |
5358 | /** |
5359 | Returns the drawing handlers. | |
5360 | */ | |
5361 | static wxList& GetDrawingHandlers() { return sm_drawingHandlers; } | |
5362 | ||
5363 | /** | |
5364 | Adds a drawing handler to the end. | |
5365 | */ | |
5366 | static void AddDrawingHandler(wxRichTextDrawingHandler *handler); | |
5367 | ||
5368 | /** | |
5369 | Inserts a drawing handler at the front. | |
5370 | */ | |
5371 | static void InsertDrawingHandler(wxRichTextDrawingHandler *handler); | |
5372 | ||
5373 | /** | |
5374 | Removes a drawing handler. | |
5375 | */ | |
5376 | static bool RemoveDrawingHandler(const wxString& name); | |
5377 | ||
5378 | /** | |
5379 | Finds a drawing handler by name. | |
5380 | */ | |
5381 | static wxRichTextDrawingHandler *FindDrawingHandler(const wxString& name); | |
5382 | ||
5383 | /** | |
5384 | Clean up drawing handlers. | |
5385 | */ | |
5386 | static void CleanUpDrawingHandlers(); | |
5387 | ||
7c9fdebe JS |
5388 | /** |
5389 | Returns the field types. | |
5390 | */ | |
5391 | static wxRichTextFieldTypeHashMap& GetFieldTypes() { return sm_fieldTypes; } | |
5392 | ||
5393 | /** | |
5394 | Adds a field type. | |
5395 | ||
5396 | @see RemoveFieldType(), FindFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard | |
5397 | ||
5398 | */ | |
5399 | static void AddFieldType(wxRichTextFieldType *fieldType); | |
5400 | ||
5401 | /** | |
5402 | Removes a field type by name. | |
5403 | ||
5404 | @see AddFieldType(), FindFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard | |
5405 | */ | |
5406 | static bool RemoveFieldType(const wxString& name); | |
5407 | ||
5408 | /** | |
5409 | Finds a field type by name. | |
5410 | ||
5411 | @see RemoveFieldType(), AddFieldType(), wxRichTextField, wxRichTextFieldType, wxRichTextFieldTypeStandard | |
5412 | */ | |
5413 | static wxRichTextFieldType *FindFieldType(const wxString& name); | |
5414 | ||
5415 | /** | |
5416 | Cleans up field types. | |
5417 | */ | |
5418 | static void CleanUpFieldTypes(); | |
5419 | ||
7afd2b58 JS |
5420 | /** |
5421 | Returns the renderer object. | |
5422 | */ | |
d2d0adc7 JS |
5423 | static wxRichTextRenderer* GetRenderer() { return sm_renderer; } |
5424 | ||
7afd2b58 JS |
5425 | /** |
5426 | Sets @a renderer as the object to be used to render certain aspects of the | |
5427 | content, such as bullets. | |
5428 | ||
5429 | You can override default rendering by deriving a new class from | |
5430 | wxRichTextRenderer or wxRichTextStdRenderer, overriding one or more | |
5431 | virtual functions, and setting an instance of the class using this function. | |
5432 | */ | |
d2d0adc7 JS |
5433 | static void SetRenderer(wxRichTextRenderer* renderer); |
5434 | ||
7afd2b58 JS |
5435 | /** |
5436 | Returns the minimum margin between bullet and paragraph in 10ths of a mm. | |
5437 | */ | |
d2d0adc7 | 5438 | static int GetBulletRightMargin() { return sm_bulletRightMargin; } |
7afd2b58 JS |
5439 | |
5440 | /** | |
5441 | Sets the minimum margin between bullet and paragraph in 10ths of a mm. | |
5442 | */ | |
d2d0adc7 JS |
5443 | static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; } |
5444 | ||
7afd2b58 JS |
5445 | /** |
5446 | Returns the factor to multiply by character height to get a reasonable bullet size. | |
5447 | */ | |
d2d0adc7 | 5448 | static float GetBulletProportion() { return sm_bulletProportion; } |
7afd2b58 JS |
5449 | |
5450 | /** | |
5451 | Sets the factor to multiply by character height to get a reasonable bullet size. | |
5452 | */ | |
d2d0adc7 | 5453 | static void SetBulletProportion(float prop) { sm_bulletProportion = prop; } |
44219ff0 | 5454 | |
7afd2b58 JS |
5455 | /** |
5456 | Returns the scale factor for calculating dimensions. | |
5457 | */ | |
44219ff0 | 5458 | double GetScale() const { return m_scale; } |
7afd2b58 JS |
5459 | |
5460 | /** | |
5461 | Sets the scale factor for calculating dimensions. | |
5462 | */ | |
44219ff0 JS |
5463 | void SetScale(double scale) { m_scale = scale; } |
5464 | ||
e12b91a3 JS |
5465 | /** |
5466 | Sets the floating layout mode. Pass @false to speed up editing by not performing | |
5467 | floating layout. This setting affects all buffers. | |
5468 | ||
5469 | */ | |
5470 | static void SetFloatingLayoutMode(bool mode) { sm_floatingLayoutMode = mode; } | |
5471 | ||
5472 | /** | |
5473 | Returns the floating layout mode. The default is @true, where objects | |
5474 | are laid out according to their floating status. | |
5475 | */ | |
5476 | static bool GetFloatingLayoutMode() { return sm_floatingLayoutMode; } | |
5477 | ||
5d7836c4 JS |
5478 | protected: |
5479 | ||
5480 | /// Command processor | |
5481 | wxCommandProcessor* m_commandProcessor; | |
5482 | ||
44cc96a8 JS |
5483 | /// Table storing fonts |
5484 | wxRichTextFontTable m_fontTable; | |
5485 | ||
5d7836c4 JS |
5486 | /// Has been modified? |
5487 | bool m_modified; | |
5488 | ||
5489 | /// Collapsed command stack | |
5490 | int m_batchedCommandDepth; | |
5491 | ||
5492 | /// Name for collapsed command | |
5493 | wxString m_batchedCommandsName; | |
5494 | ||
5495 | /// Current collapsed command accumulating actions | |
5496 | wxRichTextCommand* m_batchedCommand; | |
5497 | ||
5498 | /// Whether to suppress undo | |
5499 | int m_suppressUndo; | |
5500 | ||
5501 | /// Style sheet, if any | |
5502 | wxRichTextStyleSheet* m_styleSheet; | |
5503 | ||
d2d0adc7 JS |
5504 | /// List of event handlers that will be notified of events |
5505 | wxList m_eventHandlers; | |
5506 | ||
5d7836c4 JS |
5507 | /// Stack of attributes for convenience functions |
5508 | wxList m_attributeStack; | |
5509 | ||
d2d0adc7 JS |
5510 | /// Flags to be passed to handlers |
5511 | int m_handlerFlags; | |
5512 | ||
5d7836c4 JS |
5513 | /// File handlers |
5514 | static wxList sm_handlers; | |
d2d0adc7 | 5515 | |
8db2e3ef JS |
5516 | /// Drawing handlers |
5517 | static wxList sm_drawingHandlers; | |
5518 | ||
7c9fdebe JS |
5519 | /// Field types |
5520 | static wxRichTextFieldTypeHashMap sm_fieldTypes; | |
5521 | ||
d2d0adc7 JS |
5522 | /// Renderer |
5523 | static wxRichTextRenderer* sm_renderer; | |
5524 | ||
5525 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
5526 | static int sm_bulletRightMargin; | |
5527 | ||
5528 | /// Factor to multiply by character height to get a reasonable bullet size | |
5529 | static float sm_bulletProportion; | |
e12b91a3 JS |
5530 | |
5531 | /// Floating layout mode, @true by default | |
5532 | static bool sm_floatingLayoutMode; | |
44219ff0 JS |
5533 | |
5534 | /// Scaling factor in use: needed to calculate correct dimensions when printing | |
5535 | double m_scale; | |
32423dd8 JS |
5536 | |
5537 | /// Font scale for adjusting the text size when editing | |
5538 | double m_fontScale; | |
5539 | ||
5540 | /// Dimension scale for reducing redundant whitespace when editing | |
5541 | double m_dimensionScale; | |
5d7836c4 JS |
5542 | }; |
5543 | ||
603f702b JS |
5544 | /** |
5545 | @class wxRichTextCell | |
5546 | ||
5547 | wxRichTextCell is the cell in a table. | |
5548 | */ | |
5549 | ||
5550 | class WXDLLIMPEXP_RICHTEXT wxRichTextCell: public wxRichTextBox | |
5551 | { | |
5552 | DECLARE_DYNAMIC_CLASS(wxRichTextCell) | |
5553 | public: | |
5554 | // Constructors | |
5555 | ||
5556 | /** | |
5557 | Default constructor; optionally pass the parent object. | |
5558 | */ | |
5559 | ||
5560 | wxRichTextCell(wxRichTextObject* parent = NULL); | |
5561 | ||
5562 | /** | |
5563 | Copy constructor. | |
5564 | */ | |
5565 | ||
5566 | wxRichTextCell(const wxRichTextCell& obj): wxRichTextBox() { Copy(obj); } | |
5567 | ||
d13b34d3 | 5568 | // Overridables |
603f702b | 5569 | |
8db2e3ef | 5570 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
603f702b | 5571 | |
603f702b JS |
5572 | virtual wxString GetXMLNodeName() const { return wxT("cell"); } |
5573 | ||
603f702b JS |
5574 | virtual bool CanEditProperties() const { return true; } |
5575 | ||
603f702b JS |
5576 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); |
5577 | ||
603f702b JS |
5578 | virtual wxString GetPropertiesMenuLabel() const { return _("&Cell"); } |
5579 | ||
5580 | // Accessors | |
5581 | ||
8a28cd66 JS |
5582 | int GetColspan() const; |
5583 | ||
5584 | void SetColspan(long span) { GetProperties().SetProperty(wxT("colspan"), span); } | |
5585 | ||
5586 | int GetRowspan() const; | |
5587 | ||
5588 | void SetRowspan(long span) { GetProperties().SetProperty(wxT("rowspan"), span); } | |
5589 | ||
603f702b JS |
5590 | // Operations |
5591 | ||
603f702b JS |
5592 | virtual wxRichTextObject* Clone() const { return new wxRichTextCell(*this); } |
5593 | ||
603f702b JS |
5594 | void Copy(const wxRichTextCell& obj); |
5595 | ||
5596 | protected: | |
5597 | }; | |
5598 | ||
5599 | /** | |
5600 | @class wxRichTextTable | |
5601 | ||
5602 | wxRichTextTable represents a table with arbitrary columns and rows. | |
5603 | */ | |
5604 | ||
5605 | WX_DEFINE_ARRAY_PTR(wxRichTextObject*, wxRichTextObjectPtrArray); | |
48afbebb | 5606 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextObjectPtrArray, wxRichTextObjectPtrArrayArray, WXDLLIMPEXP_RICHTEXT); |
603f702b JS |
5607 | |
5608 | class WXDLLIMPEXP_RICHTEXT wxRichTextTable: public wxRichTextBox | |
5609 | { | |
5610 | DECLARE_DYNAMIC_CLASS(wxRichTextTable) | |
5611 | public: | |
5612 | ||
5613 | // Constructors | |
5614 | ||
5615 | /** | |
5616 | Default constructor; optionally pass the parent object. | |
5617 | */ | |
5618 | ||
5619 | wxRichTextTable(wxRichTextObject* parent = NULL); | |
5620 | ||
5621 | /** | |
5622 | Copy constructor. | |
5623 | */ | |
5624 | ||
5625 | wxRichTextTable(const wxRichTextTable& obj): wxRichTextBox() { Copy(obj); } | |
5626 | ||
d13b34d3 | 5627 | // Overridables |
603f702b | 5628 | |
8db2e3ef | 5629 | virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); |
603f702b | 5630 | |
603f702b JS |
5631 | virtual wxString GetXMLNodeName() const { return wxT("table"); } |
5632 | ||
8db2e3ef | 5633 | virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style); |
603f702b | 5634 | |
914a4e23 | 5635 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const; |
603f702b | 5636 | |
603f702b JS |
5637 | virtual bool DeleteRange(const wxRichTextRange& range); |
5638 | ||
603f702b JS |
5639 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; |
5640 | ||
5641 | #if wxUSE_XML | |
603f702b JS |
5642 | virtual bool ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse); |
5643 | #endif | |
5644 | ||
5645 | #if wxRICHTEXT_HAVE_DIRECT_OUTPUT | |
603f702b JS |
5646 | virtual bool ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler); |
5647 | #endif | |
5648 | ||
5649 | #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT | |
603f702b JS |
5650 | virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); |
5651 | #endif | |
5652 | ||
8db2e3ef | 5653 | virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); |
603f702b | 5654 | |
603f702b JS |
5655 | virtual void CalculateRange(long start, long& end); |
5656 | ||
b3169c12 | 5657 | // Can this object handle the selections of its children? FOr example, a table. |
603f702b JS |
5658 | virtual bool HandlesChildSelections() const { return true; } |
5659 | ||
5660 | /// Returns a selection object specifying the selections between start and end character positions. | |
5661 | /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table. | |
5662 | virtual wxRichTextSelection GetSelection(long start, long end) const; | |
5663 | ||
603f702b JS |
5664 | virtual bool CanEditProperties() const { return true; } |
5665 | ||
603f702b JS |
5666 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); |
5667 | ||
603f702b JS |
5668 | virtual wxString GetPropertiesMenuLabel() const { return _("&Table"); } |
5669 | ||
b3169c12 JS |
5670 | // Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject |
5671 | // is possible. For example, containers supporting text, such as a text box object, can accept the focus, | |
5672 | // but a table can't (set the focus to individual cells instead). | |
603f702b JS |
5673 | virtual bool AcceptsFocus() const { return false; } |
5674 | ||
5675 | // Accessors | |
5676 | ||
7afd2b58 JS |
5677 | /** |
5678 | Returns the cells array. | |
5679 | */ | |
603f702b | 5680 | const wxRichTextObjectPtrArrayArray& GetCells() const { return m_cells; } |
7afd2b58 JS |
5681 | |
5682 | /** | |
5683 | Returns the cells array. | |
5684 | */ | |
603f702b JS |
5685 | wxRichTextObjectPtrArrayArray& GetCells() { return m_cells; } |
5686 | ||
7afd2b58 JS |
5687 | /** |
5688 | Returns the row count. | |
5689 | */ | |
603f702b | 5690 | int GetRowCount() const { return m_rowCount; } |
7afd2b58 JS |
5691 | |
5692 | /** | |
5693 | Returns the column count. | |
5694 | */ | |
603f702b JS |
5695 | int GetColumnCount() const { return m_colCount; } |
5696 | ||
7afd2b58 JS |
5697 | /** |
5698 | Returns the cell at the given row/column position. | |
5699 | */ | |
603f702b JS |
5700 | virtual wxRichTextCell* GetCell(int row, int col) const; |
5701 | ||
7afd2b58 JS |
5702 | /** |
5703 | Returns the cell at the given character position (in the range of the table). | |
5704 | */ | |
603f702b JS |
5705 | virtual wxRichTextCell* GetCell(long pos) const; |
5706 | ||
7afd2b58 JS |
5707 | /** |
5708 | Returns the row/column for a given character position. | |
5709 | */ | |
603f702b JS |
5710 | virtual bool GetCellRowColumnPosition(long pos, int& row, int& col) const; |
5711 | ||
4c86168d JS |
5712 | /** |
5713 | Returns the coordinates of the cell with keyboard focus, or (-1,-1) if none. | |
5714 | */ | |
5715 | virtual wxPosition GetFocusedCell() const; | |
5716 | ||
603f702b JS |
5717 | // Operations |
5718 | ||
5719 | /** | |
5720 | Clears the table. | |
5721 | */ | |
5722 | ||
5723 | virtual void ClearTable(); | |
5724 | ||
5725 | /** | |
5726 | Creates a table of the given dimensions. | |
5727 | */ | |
5728 | ||
5729 | virtual bool CreateTable(int rows, int cols); | |
5730 | ||
5731 | /** | |
5732 | Sets the attributes for the cells specified by the selection. | |
5733 | */ | |
5734 | ||
5735 | virtual bool SetCellStyle(const wxRichTextSelection& selection, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
5736 | ||
5737 | /** | |
5738 | Deletes rows from the given row position. | |
5739 | */ | |
5740 | ||
5741 | virtual bool DeleteRows(int startRow, int noRows = 1); | |
5742 | ||
5743 | /** | |
5744 | Deletes columns from the given column position. | |
5745 | */ | |
5746 | ||
5747 | virtual bool DeleteColumns(int startCol, int noCols = 1); | |
5748 | ||
5749 | /** | |
5750 | Adds rows from the given row position. | |
5751 | */ | |
5752 | ||
5753 | virtual bool AddRows(int startRow, int noRows = 1, const wxRichTextAttr& attr = wxRichTextAttr()); | |
5754 | ||
5755 | /** | |
5756 | Adds columns from the given column position. | |
5757 | */ | |
5758 | ||
5759 | virtual bool AddColumns(int startCol, int noCols = 1, const wxRichTextAttr& attr = wxRichTextAttr()); | |
5760 | ||
5761 | // Makes a clone of this object. | |
5762 | virtual wxRichTextObject* Clone() const { return new wxRichTextTable(*this); } | |
5763 | ||
5764 | // Copies this object. | |
5765 | void Copy(const wxRichTextTable& obj); | |
5766 | ||
5767 | protected: | |
5768 | ||
5769 | int m_rowCount; | |
5770 | int m_colCount; | |
5771 | ||
5772 | // An array of rows, each of which is a wxRichTextObjectPtrArray containing | |
5773 | // the cell objects. The cell objects are also children of this object. | |
5774 | // Problem: if boxes are immediate children of a box, this will cause problems | |
5775 | // with wxRichTextParagraphLayoutBox functions (and functions elsewhere) that | |
5776 | // expect to find just paragraphs. May have to adjust the way we handle the | |
d13b34d3 | 5777 | // hierarchy to accept non-paragraph objects in a paragraph layout box. |
603f702b JS |
5778 | // We'll be overriding much wxRichTextParagraphLayoutBox functionality so this |
5779 | // may not be such a problem. Perhaps the table should derive from a different | |
5780 | // class? | |
5781 | wxRichTextObjectPtrArrayArray m_cells; | |
5782 | }; | |
5783 | ||
5784 | ||
7afd2b58 JS |
5785 | /** |
5786 | The command identifiers for Do/Undo. | |
5787 | */ | |
5d7836c4 JS |
5788 | |
5789 | enum wxRichTextCommandId | |
5790 | { | |
5791 | wxRICHTEXT_INSERT, | |
5792 | wxRICHTEXT_DELETE, | |
603f702b JS |
5793 | wxRICHTEXT_CHANGE_ATTRIBUTES, |
5794 | wxRICHTEXT_CHANGE_STYLE, | |
590a0f8b | 5795 | wxRICHTEXT_CHANGE_PROPERTIES, |
603f702b JS |
5796 | wxRICHTEXT_CHANGE_OBJECT |
5797 | }; | |
5798 | ||
706465df JS |
5799 | /** |
5800 | @class wxRichTextObjectAddress | |
5801 | ||
5802 | A class for specifying an object anywhere in an object hierarchy, | |
5803 | without using a pointer, necessary since wxRTC commands may delete | |
5804 | and recreate sub-objects so physical object addresses change. An array | |
5805 | of positions (one per hierarchy level) is used. | |
5806 | ||
5807 | @library{wxrichtext} | |
5808 | @category{richtext} | |
5809 | ||
5810 | @see wxRichTextCommand | |
5811 | */ | |
603f702b JS |
5812 | |
5813 | class WXDLLIMPEXP_RICHTEXT wxRichTextObjectAddress | |
5814 | { | |
5815 | public: | |
7afd2b58 JS |
5816 | /** |
5817 | Creates the address given a container and an object. | |
5818 | */ | |
603f702b | 5819 | wxRichTextObjectAddress(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj) { Create(topLevelContainer, obj); } |
7afd2b58 JS |
5820 | /** |
5821 | */ | |
603f702b | 5822 | wxRichTextObjectAddress() { Init(); } |
7afd2b58 JS |
5823 | /** |
5824 | */ | |
603f702b JS |
5825 | wxRichTextObjectAddress(const wxRichTextObjectAddress& address) { Copy(address); } |
5826 | ||
5827 | void Init() {} | |
7afd2b58 JS |
5828 | |
5829 | /** | |
5830 | Copies the address. | |
5831 | */ | |
603f702b | 5832 | void Copy(const wxRichTextObjectAddress& address) { m_address = address.m_address; } |
7afd2b58 JS |
5833 | |
5834 | /** | |
5835 | Assignment operator. | |
5836 | */ | |
603f702b JS |
5837 | void operator=(const wxRichTextObjectAddress& address) { Copy(address); } |
5838 | ||
7afd2b58 JS |
5839 | /** |
5840 | Returns the object specified by the address, given a top level container. | |
5841 | */ | |
603f702b | 5842 | wxRichTextObject* GetObject(wxRichTextParagraphLayoutBox* topLevelContainer) const; |
7afd2b58 JS |
5843 | |
5844 | /** | |
5845 | Creates the address given a container and an object. | |
5846 | */ | |
603f702b JS |
5847 | bool Create(wxRichTextParagraphLayoutBox* topLevelContainer, wxRichTextObject* obj); |
5848 | ||
7afd2b58 JS |
5849 | /** |
5850 | Returns the array of integers representing the object address. | |
5851 | */ | |
603f702b | 5852 | wxArrayInt& GetAddress() { return m_address; } |
7afd2b58 JS |
5853 | |
5854 | /** | |
5855 | Returns the array of integers representing the object address. | |
5856 | */ | |
603f702b | 5857 | const wxArrayInt& GetAddress() const { return m_address; } |
7afd2b58 JS |
5858 | |
5859 | /** | |
5860 | Sets the address from an array of integers. | |
5861 | */ | |
603f702b JS |
5862 | void SetAddress(const wxArrayInt& address) { m_address = address; } |
5863 | ||
5864 | protected: | |
5865 | ||
5866 | wxArrayInt m_address; | |
5d7836c4 JS |
5867 | }; |
5868 | ||
b5dbe15d | 5869 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; |
706465df JS |
5870 | |
5871 | /** | |
5872 | @class wxRichTextCommand | |
5873 | ||
5874 | Implements a command on the undo/redo stack. A wxRichTextCommand object contains one or more wxRichTextAction | |
5875 | objects, allowing aggregation of a number of operations into one command. | |
5876 | ||
5877 | @library{wxrichtext} | |
5878 | @category{richtext} | |
5879 | ||
5880 | @see wxRichTextAction | |
5881 | */ | |
5882 | ||
3b2cb431 | 5883 | class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand |
5d7836c4 JS |
5884 | { |
5885 | public: | |
7afd2b58 JS |
5886 | /** |
5887 | Constructor for one action. | |
5888 | */ | |
5d7836c4 | 5889 | wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, |
603f702b | 5890 | wxRichTextParagraphLayoutBox* container, wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 | 5891 | |
7afd2b58 JS |
5892 | /** |
5893 | Constructor for multiple actions. | |
5894 | */ | |
5d7836c4 JS |
5895 | wxRichTextCommand(const wxString& name); |
5896 | ||
d3c7fc99 | 5897 | virtual ~wxRichTextCommand(); |
5d7836c4 | 5898 | |
7afd2b58 JS |
5899 | /** |
5900 | Performs the command. | |
5901 | */ | |
5d7836c4 | 5902 | bool Do(); |
7afd2b58 JS |
5903 | |
5904 | /** | |
5905 | Undoes the command. | |
5906 | */ | |
5d7836c4 JS |
5907 | bool Undo(); |
5908 | ||
7afd2b58 JS |
5909 | /** |
5910 | Adds an action to the action list. | |
5911 | */ | |
5d7836c4 | 5912 | void AddAction(wxRichTextAction* action); |
7afd2b58 JS |
5913 | |
5914 | /** | |
5915 | Clears the action list. | |
5916 | */ | |
5d7836c4 JS |
5917 | void ClearActions(); |
5918 | ||
7afd2b58 JS |
5919 | /** |
5920 | Returns the action list. | |
5921 | */ | |
5d7836c4 JS |
5922 | wxList& GetActions() { return m_actions; } |
5923 | ||
5924 | protected: | |
5925 | ||
5926 | wxList m_actions; | |
5927 | }; | |
5928 | ||
706465df JS |
5929 | /** |
5930 | @class wxRichTextAction | |
5931 | ||
5932 | Implements a part of a command. | |
5933 | ||
5934 | @library{wxrichtext} | |
5935 | @category{richtext} | |
5936 | ||
5937 | @see wxRichTextCommand | |
5938 | */ | |
5d7836c4 | 5939 | |
3b2cb431 | 5940 | class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject |
5d7836c4 JS |
5941 | { |
5942 | public: | |
7afd2b58 JS |
5943 | /** |
5944 | Constructor. @a buffer is the top-level buffer, while @a container is the object within | |
5945 | which the action is taking place. In the simplest case, they are the same. | |
5946 | */ | |
603f702b JS |
5947 | wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, |
5948 | wxRichTextBuffer* buffer, wxRichTextParagraphLayoutBox* container, | |
7fe8059f | 5949 | wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 | 5950 | |
d3c7fc99 | 5951 | virtual ~wxRichTextAction(); |
5d7836c4 | 5952 | |
7afd2b58 JS |
5953 | /** |
5954 | Performs the action. | |
5955 | */ | |
5d7836c4 | 5956 | bool Do(); |
7afd2b58 JS |
5957 | |
5958 | /** | |
5959 | Undoes the action. | |
5960 | */ | |
5d7836c4 JS |
5961 | bool Undo(); |
5962 | ||
7afd2b58 JS |
5963 | /** |
5964 | Updates the control appearance, optimizing if possible given information from the call to Layout. | |
5965 | */ | |
ea160b2e | 5966 | void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false, |
7051fa41 | 5967 | wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL, bool isDoCmd = true); |
5d7836c4 | 5968 | |
7afd2b58 JS |
5969 | /** |
5970 | Replaces the buffer paragraphs with the given fragment. | |
5971 | */ | |
0ca07313 | 5972 | void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 | 5973 | |
7afd2b58 JS |
5974 | /** |
5975 | Returns the new fragments. | |
5976 | */ | |
0ca07313 | 5977 | wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; } |
7afd2b58 JS |
5978 | |
5979 | /** | |
5980 | Returns the old fragments. | |
5981 | */ | |
0ca07313 | 5982 | wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; } |
5d7836c4 | 5983 | |
7afd2b58 JS |
5984 | /** |
5985 | Returns the attributes, for single-object commands. | |
5986 | */ | |
603f702b JS |
5987 | wxRichTextAttr& GetAttributes() { return m_attributes; } |
5988 | ||
7afd2b58 JS |
5989 | /** |
5990 | Returns the object to replace the one at the position defined by the container address | |
5991 | and the action's range start position. | |
5992 | */ | |
603f702b | 5993 | wxRichTextObject* GetObject() const { return m_object; } |
7afd2b58 | 5994 | |
31be8400 JS |
5995 | /** |
5996 | Stores the object to replace the one at the position defined by the container address | |
5997 | without making an address for it (cf SetObject() and MakeObject()). | |
5998 | */ | |
5999 | void StoreObject(wxRichTextObject* obj) { m_object = obj; } | |
6000 | ||
7afd2b58 JS |
6001 | /** |
6002 | Sets the object to replace the one at the position defined by the container address | |
6003 | and the action's range start position. | |
6004 | */ | |
603f702b | 6005 | void SetObject(wxRichTextObject* obj) { m_object = obj; m_objectAddress.Create(m_buffer, m_object); } |
7afd2b58 JS |
6006 | |
6007 | /** | |
6008 | Makes an address from the given object. | |
6009 | */ | |
603f702b JS |
6010 | void MakeObject(wxRichTextObject* obj) { m_objectAddress.Create(m_buffer, obj); } |
6011 | ||
7afd2b58 JS |
6012 | /** |
6013 | Calculate arrays for refresh optimization. | |
6014 | */ | |
7051fa41 JS |
6015 | void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions); |
6016 | ||
7afd2b58 JS |
6017 | /** |
6018 | Sets the position used for e.g. insertion. | |
6019 | */ | |
5d7836c4 | 6020 | void SetPosition(long pos) { m_position = pos; } |
7afd2b58 JS |
6021 | |
6022 | /** | |
6023 | Returns the position used for e.g. insertion. | |
6024 | */ | |
5d7836c4 JS |
6025 | long GetPosition() const { return m_position; } |
6026 | ||
7afd2b58 JS |
6027 | /** |
6028 | Sets the range for e.g. deletion. | |
6029 | */ | |
5d7836c4 | 6030 | void SetRange(const wxRichTextRange& range) { m_range = range; } |
7afd2b58 JS |
6031 | |
6032 | /** | |
6033 | Returns the range for e.g. deletion. | |
6034 | */ | |
5d7836c4 JS |
6035 | const wxRichTextRange& GetRange() const { return m_range; } |
6036 | ||
7afd2b58 JS |
6037 | /** |
6038 | Returns the address (nested position) of the container within the buffer being manipulated. | |
6039 | */ | |
603f702b | 6040 | wxRichTextObjectAddress& GetContainerAddress() { return m_containerAddress; } |
7afd2b58 JS |
6041 | |
6042 | /** | |
6043 | Returns the address (nested position) of the container within the buffer being manipulated. | |
6044 | */ | |
603f702b | 6045 | const wxRichTextObjectAddress& GetContainerAddress() const { return m_containerAddress; } |
7afd2b58 JS |
6046 | |
6047 | /** | |
6048 | Sets the address (nested position) of the container within the buffer being manipulated. | |
6049 | */ | |
603f702b | 6050 | void SetContainerAddress(const wxRichTextObjectAddress& address) { m_containerAddress = address; } |
7afd2b58 JS |
6051 | |
6052 | /** | |
6053 | Sets the address (nested position) of the container within the buffer being manipulated. | |
6054 | */ | |
603f702b JS |
6055 | void SetContainerAddress(wxRichTextParagraphLayoutBox* container, wxRichTextObject* obj) { m_containerAddress.Create(container, obj); } |
6056 | ||
7afd2b58 JS |
6057 | /** |
6058 | Returns the container that this action refers to, using the container address and top-level buffer. | |
6059 | */ | |
603f702b | 6060 | wxRichTextParagraphLayoutBox* GetContainer() const; |
7afd2b58 JS |
6061 | |
6062 | /** | |
6063 | Returns the action name. | |
6064 | */ | |
5d7836c4 JS |
6065 | const wxString& GetName() const { return m_name; } |
6066 | ||
6067 | protected: | |
6068 | // Action name | |
6069 | wxString m_name; | |
6070 | ||
6071 | // Buffer | |
6072 | wxRichTextBuffer* m_buffer; | |
6073 | ||
603f702b JS |
6074 | // The address (nested position) of the container being manipulated. |
6075 | // This is necessary because objects are deleted, and we can't | |
6076 | // therefore store actual pointers. | |
6077 | wxRichTextObjectAddress m_containerAddress; | |
6078 | ||
5d7836c4 JS |
6079 | // Control |
6080 | wxRichTextCtrl* m_ctrl; | |
6081 | ||
6082 | // Stores the new paragraphs | |
0ca07313 | 6083 | wxRichTextParagraphLayoutBox m_newParagraphs; |
5d7836c4 JS |
6084 | |
6085 | // Stores the old paragraphs | |
0ca07313 | 6086 | wxRichTextParagraphLayoutBox m_oldParagraphs; |
5d7836c4 | 6087 | |
603f702b JS |
6088 | // Stores an object to replace the one at the position |
6089 | // defined by the container address and the action's range start position. | |
6090 | wxRichTextObject* m_object; | |
6091 | ||
6092 | // Stores the attributes | |
6093 | wxRichTextAttr m_attributes; | |
6094 | ||
6095 | // The address of the object being manipulated (used for changing an individual object or its attributes) | |
6096 | wxRichTextObjectAddress m_objectAddress; | |
6097 | ||
6098 | // Stores the old attributes | |
6099 | // wxRichTextAttr m_oldAttributes; | |
6100 | ||
5d7836c4 JS |
6101 | // The affected range |
6102 | wxRichTextRange m_range; | |
6103 | ||
6104 | // The insertion point for this command | |
6105 | long m_position; | |
6106 | ||
6107 | // Ignore 1st 'Do' operation because we already did it | |
6108 | bool m_ignoreThis; | |
6109 | ||
6110 | // The command identifier | |
6111 | wxRichTextCommandId m_cmdId; | |
6112 | }; | |
6113 | ||
d2d0adc7 JS |
6114 | /*! |
6115 | * Handler flags | |
6116 | */ | |
6117 | ||
6118 | // Include style sheet when loading and saving | |
6119 | #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001 | |
6120 | ||
6121 | // Save images to memory file system in HTML handler | |
6122 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010 | |
6123 | ||
6124 | // Save images to files in HTML handler | |
6125 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020 | |
6126 | ||
6127 | // Save images as inline base64 data in HTML handler | |
6128 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040 | |
6129 | ||
b774c698 JS |
6130 | // Don't write header and footer (or BODY), so we can include the fragment |
6131 | // in a larger document | |
6132 | #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080 | |
6133 | ||
a2beab22 JS |
6134 | // Convert the more common face names to names that will work on the current platform |
6135 | // in a larger document | |
6136 | #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100 | |
6137 | ||
706465df JS |
6138 | /** |
6139 | @class wxRichTextFileHandler | |
6140 | ||
6141 | The base class for file handlers. | |
6142 | ||
6143 | @library{wxrichtext} | |
6144 | @category{richtext} | |
6145 | ||
6146 | @see wxRichTextBuffer, wxRichTextCtrl | |
6147 | */ | |
5d7836c4 | 6148 | |
3b2cb431 | 6149 | class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject |
5d7836c4 JS |
6150 | { |
6151 | DECLARE_CLASS(wxRichTextFileHandler) | |
6152 | public: | |
7afd2b58 JS |
6153 | /** |
6154 | Creates a file handler object. | |
6155 | */ | |
5d7836c4 | 6156 | wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0) |
d8dd214c | 6157 | : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true) |
5d7836c4 JS |
6158 | { } |
6159 | ||
6160 | #if wxUSE_STREAMS | |
7afd2b58 JS |
6161 | /** |
6162 | Loads the buffer from a stream. | |
6163 | Not all handlers will implement file loading. | |
6164 | */ | |
7fe8059f WS |
6165 | bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) |
6166 | { return DoLoadFile(buffer, stream); } | |
7afd2b58 JS |
6167 | |
6168 | /** | |
6169 | Saves the buffer to a stream. | |
6170 | Not all handlers will implement file saving. | |
6171 | */ | |
7fe8059f WS |
6172 | bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) |
6173 | { return DoSaveFile(buffer, stream); } | |
5d7836c4 JS |
6174 | #endif |
6175 | ||
a9b9495b | 6176 | #if wxUSE_FFILE && wxUSE_STREAMS |
7afd2b58 JS |
6177 | /** |
6178 | Loads the buffer from a file. | |
6179 | */ | |
fe8b0361 | 6180 | virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); |
7afd2b58 JS |
6181 | |
6182 | /** | |
6183 | Saves the buffer to a file. | |
6184 | */ | |
fe8b0361 | 6185 | virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); |
a9b9495b | 6186 | #endif // wxUSE_STREAMS && wxUSE_STREAMS |
5d7836c4 | 6187 | |
7afd2b58 JS |
6188 | /** |
6189 | Returns @true if we handle this filename (if using files). By default, checks the extension. | |
6190 | */ | |
5d7836c4 JS |
6191 | virtual bool CanHandle(const wxString& filename) const; |
6192 | ||
7afd2b58 JS |
6193 | /** |
6194 | Returns @true if we can save using this handler. | |
6195 | */ | |
5d7836c4 JS |
6196 | virtual bool CanSave() const { return false; } |
6197 | ||
7afd2b58 JS |
6198 | /** |
6199 | Returns @true if we can load using this handler. | |
6200 | */ | |
5d7836c4 JS |
6201 | virtual bool CanLoad() const { return false; } |
6202 | ||
7afd2b58 JS |
6203 | /** |
6204 | Returns @true if this handler should be visible to the user. | |
6205 | */ | |
5d7836c4 | 6206 | virtual bool IsVisible() const { return m_visible; } |
7afd2b58 JS |
6207 | |
6208 | /** | |
6209 | Sets whether the handler should be visible to the user (via the application's | |
6210 | load and save dialogs). | |
6211 | */ | |
5d7836c4 JS |
6212 | virtual void SetVisible(bool visible) { m_visible = visible; } |
6213 | ||
7afd2b58 | 6214 | /** |
7c9fdebe | 6215 | Sets the name of the handler. |
7afd2b58 | 6216 | */ |
5d7836c4 | 6217 | void SetName(const wxString& name) { m_name = name; } |
7afd2b58 JS |
6218 | |
6219 | /** | |
7c9fdebe | 6220 | Returns the name of the handler. |
7afd2b58 | 6221 | */ |
5d7836c4 JS |
6222 | wxString GetName() const { return m_name; } |
6223 | ||
7afd2b58 JS |
6224 | /** |
6225 | Sets the default extension to recognise. | |
6226 | */ | |
5d7836c4 | 6227 | void SetExtension(const wxString& ext) { m_extension = ext; } |
7afd2b58 JS |
6228 | |
6229 | /** | |
6230 | Returns the default extension to recognise. | |
6231 | */ | |
5d7836c4 JS |
6232 | wxString GetExtension() const { return m_extension; } |
6233 | ||
7afd2b58 JS |
6234 | /** |
6235 | Sets the handler type. | |
6236 | */ | |
5d7836c4 | 6237 | void SetType(int type) { m_type = type; } |
7afd2b58 JS |
6238 | |
6239 | /** | |
6240 | Returns the handler type. | |
6241 | */ | |
5d7836c4 JS |
6242 | int GetType() const { return m_type; } |
6243 | ||
7afd2b58 JS |
6244 | /** |
6245 | Sets flags that change the behaviour of loading or saving. | |
6246 | See the documentation for each handler class to see what flags are relevant | |
6247 | for each handler. | |
6248 | ||
6249 | You call this function directly if you are using a file handler explicitly | |
6250 | (without going through the text control or buffer LoadFile/SaveFile API). | |
6251 | Or, you can call the control or buffer's SetHandlerFlags function to set | |
6252 | the flags that will be used for subsequent load and save operations. | |
6253 | */ | |
d2d0adc7 | 6254 | void SetFlags(int flags) { m_flags = flags; } |
7afd2b58 JS |
6255 | |
6256 | /** | |
6257 | Returns flags controlling how loading and saving is done. | |
6258 | */ | |
d2d0adc7 JS |
6259 | int GetFlags() const { return m_flags; } |
6260 | ||
7afd2b58 JS |
6261 | /** |
6262 | Sets the encoding to use when saving a file. If empty, a suitable encoding is chosen. | |
6263 | */ | |
b71e9aa4 | 6264 | void SetEncoding(const wxString& encoding) { m_encoding = encoding; } |
7afd2b58 JS |
6265 | |
6266 | /** | |
6267 | Returns the encoding to use when saving a file. If empty, a suitable encoding is chosen. | |
6268 | */ | |
b71e9aa4 JS |
6269 | const wxString& GetEncoding() const { return m_encoding; } |
6270 | ||
5d7836c4 JS |
6271 | protected: |
6272 | ||
7fe8059f | 6273 | #if wxUSE_STREAMS |
7afd2b58 JS |
6274 | /** |
6275 | Override to load content from @a stream into @a buffer. | |
6276 | */ | |
7fe8059f | 6277 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0; |
7afd2b58 JS |
6278 | |
6279 | /** | |
6280 | Override to save content to @a stream from @a buffer. | |
6281 | */ | |
7fe8059f WS |
6282 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0; |
6283 | #endif | |
6284 | ||
5d7836c4 | 6285 | wxString m_name; |
b71e9aa4 | 6286 | wxString m_encoding; |
5d7836c4 JS |
6287 | wxString m_extension; |
6288 | int m_type; | |
d2d0adc7 | 6289 | int m_flags; |
5d7836c4 JS |
6290 | bool m_visible; |
6291 | }; | |
6292 | ||
706465df JS |
6293 | /** |
6294 | @class wxRichTextPlainTextHandler | |
6295 | ||
6296 | Implements saving a buffer to plain text. | |
6297 | ||
6298 | @library{wxrichtext} | |
6299 | @category{richtext} | |
6300 | ||
6301 | @see wxRichTextFileHandler, wxRichTextBuffer, wxRichTextCtrl | |
6302 | */ | |
5d7836c4 | 6303 | |
3b2cb431 | 6304 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler |
5d7836c4 JS |
6305 | { |
6306 | DECLARE_CLASS(wxRichTextPlainTextHandler) | |
6307 | public: | |
d75a69e8 FM |
6308 | wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), |
6309 | const wxString& ext = wxT("txt"), | |
6310 | wxRichTextFileType type = wxRICHTEXT_TYPE_TEXT) | |
5d7836c4 JS |
6311 | : wxRichTextFileHandler(name, ext, type) |
6312 | { } | |
6313 | ||
7afd2b58 | 6314 | // Can we save using this handler? |
5d7836c4 JS |
6315 | virtual bool CanSave() const { return true; } |
6316 | ||
7afd2b58 | 6317 | // Can we load using this handler? |
5d7836c4 JS |
6318 | virtual bool CanLoad() const { return true; } |
6319 | ||
6320 | protected: | |
6321 | ||
7fe8059f WS |
6322 | #if wxUSE_STREAMS |
6323 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
6324 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
6325 | #endif | |
6326 | ||
5d7836c4 JS |
6327 | }; |
6328 | ||
8db2e3ef JS |
6329 | /** |
6330 | @class wxRichTextDrawingHandler | |
6331 | ||
6332 | The base class for custom drawing handlers. | |
7c9fdebe | 6333 | Currently, drawing handlers can provide virtual attributes. |
8db2e3ef JS |
6334 | |
6335 | @library{wxrichtext} | |
6336 | @category{richtext} | |
6337 | ||
6338 | @see wxRichTextBuffer, wxRichTextCtrl | |
6339 | */ | |
6340 | ||
6341 | class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingHandler: public wxObject | |
6342 | { | |
6343 | DECLARE_CLASS(wxRichTextDrawingHandler) | |
6344 | public: | |
6345 | /** | |
6346 | Creates a drawing handler object. | |
6347 | */ | |
6348 | wxRichTextDrawingHandler(const wxString& name = wxEmptyString) | |
6349 | : m_name(name) | |
6350 | { } | |
6351 | ||
6352 | /** | |
6353 | Returns @true if this object has virtual attributes that we can provide. | |
6354 | */ | |
6355 | virtual bool HasVirtualAttributes(wxRichTextObject* obj) const = 0; | |
6356 | ||
6357 | /** | |
6358 | Provides virtual attributes that we can provide. | |
6359 | */ | |
6360 | virtual bool GetVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const = 0; | |
6361 | ||
f7667b84 JS |
6362 | /** |
6363 | Gets the count for mixed virtual attributes for individual positions within the object. | |
6364 | For example, individual characters within a text object may require special highlighting. | |
6365 | */ | |
6366 | virtual int GetVirtualSubobjectAttributesCount(wxRichTextObject* obj) const = 0; | |
6367 | ||
6368 | /** | |
6369 | Gets the mixed virtual attributes for individual positions within the object. | |
6370 | For example, individual characters within a text object may require special highlighting. | |
6371 | Returns the number of virtual attributes found. | |
6372 | */ | |
6373 | virtual int GetVirtualSubobjectAttributes(wxRichTextObject* obj, wxArrayInt& positions, wxRichTextAttrArray& attributes) const = 0; | |
6374 | ||
6375 | /** | |
6376 | Do we have virtual text for this object? Virtual text allows an application | |
6377 | to replace characters in an object for editing and display purposes, for example | |
6378 | for highlighting special characters. | |
6379 | */ | |
6380 | virtual bool HasVirtualText(const wxRichTextPlainText* obj) const = 0; | |
6381 | ||
6382 | /** | |
6383 | Gets the virtual text for this object. | |
6384 | */ | |
6385 | virtual bool GetVirtualText(const wxRichTextPlainText* obj, wxString& text) const = 0; | |
6386 | ||
8db2e3ef | 6387 | /** |
7c9fdebe | 6388 | Sets the name of the handler. |
8db2e3ef JS |
6389 | */ |
6390 | void SetName(const wxString& name) { m_name = name; } | |
6391 | ||
6392 | /** | |
7c9fdebe | 6393 | Returns the name of the handler. |
8db2e3ef JS |
6394 | */ |
6395 | wxString GetName() const { return m_name; } | |
6396 | ||
6397 | protected: | |
6398 | ||
6399 | wxString m_name; | |
6400 | }; | |
6401 | ||
0ca07313 JS |
6402 | #if wxUSE_DATAOBJ |
6403 | ||
706465df JS |
6404 | /** |
6405 | @class wxRichTextBufferDataObject | |
6406 | ||
6407 | Implements a rich text data object for clipboard transfer. | |
6408 | ||
6409 | @library{wxrichtext} | |
6410 | @category{richtext} | |
6411 | ||
6412 | @see wxDataObjectSimple, wxRichTextBuffer, wxRichTextCtrl | |
6413 | */ | |
0ca07313 | 6414 | |
d2d0adc7 | 6415 | class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple |
0ca07313 JS |
6416 | { |
6417 | public: | |
7afd2b58 JS |
6418 | /** |
6419 | The constructor doesn't copy the pointer, so it shouldn't go away while this object | |
6420 | is alive. | |
6421 | */ | |
d3b9f782 | 6422 | wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = NULL); |
0ca07313 JS |
6423 | virtual ~wxRichTextBufferDataObject(); |
6424 | ||
7afd2b58 JS |
6425 | /** |
6426 | After a call to this function, the buffer is owned by the caller and it | |
6427 | is responsible for deleting it. | |
6428 | */ | |
0ca07313 JS |
6429 | wxRichTextBuffer* GetRichTextBuffer(); |
6430 | ||
7afd2b58 JS |
6431 | /** |
6432 | Returns the id for the new data format. | |
6433 | */ | |
0ca07313 JS |
6434 | static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; } |
6435 | ||
6436 | // base class pure virtuals | |
6437 | ||
6438 | virtual wxDataFormat GetPreferredFormat(Direction dir) const; | |
6439 | virtual size_t GetDataSize() const; | |
6440 | virtual bool GetDataHere(void *pBuf) const; | |
6441 | virtual bool SetData(size_t len, const void *buf); | |
6442 | ||
6443 | // prevent warnings | |
6444 | ||
6445 | virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); } | |
6446 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); } | |
6447 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); } | |
6448 | ||
6449 | private: | |
6450 | wxDataFormat m_formatRichTextBuffer; // our custom format | |
6451 | wxRichTextBuffer* m_richTextBuffer; // our data | |
6452 | static const wxChar* ms_richTextBufferFormatId; // our format id | |
6453 | }; | |
6454 | ||
6455 | #endif | |
6456 | ||
706465df JS |
6457 | /** |
6458 | @class wxRichTextRenderer | |
6459 | ||
6460 | This class isolates some common drawing functionality. | |
6461 | ||
6462 | @library{wxrichtext} | |
6463 | @category{richtext} | |
6464 | ||
6465 | @see wxRichTextBuffer, wxRichTextCtrl | |
6466 | */ | |
d2d0adc7 JS |
6467 | |
6468 | class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject | |
6469 | { | |
6470 | public: | |
7afd2b58 JS |
6471 | /** |
6472 | Constructor. | |
6473 | */ | |
d2d0adc7 JS |
6474 | wxRichTextRenderer() {} |
6475 | virtual ~wxRichTextRenderer() {} | |
6476 | ||
7afd2b58 JS |
6477 | /** |
6478 | Draws a standard bullet, as specified by the value of GetBulletName. This function should be overridden. | |
6479 | */ | |
24777478 | 6480 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 | 6481 | |
7afd2b58 JS |
6482 | /** |
6483 | Draws a bullet that can be described by text, such as numbered or symbol bullets. This function should be overridden. | |
6484 | */ | |
24777478 | 6485 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text) = 0; |
d2d0adc7 | 6486 | |
7afd2b58 JS |
6487 | /** |
6488 | Draws a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName. This function should be overridden. | |
6489 | */ | |
24777478 | 6490 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 | 6491 | |
7afd2b58 JS |
6492 | /** |
6493 | Enumerate the standard bullet names currently supported. This function should be overridden. | |
6494 | */ | |
d2d0adc7 JS |
6495 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; |
6496 | }; | |
6497 | ||
706465df JS |
6498 | /** |
6499 | @class wxRichTextStdRenderer | |
6500 | ||
6501 | The standard renderer for drawing bullets. | |
6502 | ||
6503 | @library{wxrichtext} | |
6504 | @category{richtext} | |
6505 | ||
6506 | @see wxRichTextRenderer, wxRichTextBuffer, wxRichTextCtrl | |
6507 | */ | |
d2d0adc7 JS |
6508 | |
6509 | class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer | |
6510 | { | |
6511 | public: | |
7afd2b58 JS |
6512 | /** |
6513 | Constructor. | |
6514 | */ | |
d2d0adc7 JS |
6515 | wxRichTextStdRenderer() {} |
6516 | ||
7afd2b58 | 6517 | // Draw a standard bullet, as specified by the value of GetBulletName |
24777478 | 6518 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 | 6519 | |
7afd2b58 | 6520 | // Draw a bullet that can be described by text, such as numbered or symbol bullets |
24777478 | 6521 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text); |
d2d0adc7 | 6522 | |
7afd2b58 | 6523 | // Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName |
24777478 | 6524 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 | 6525 | |
7afd2b58 | 6526 | // Enumerate the standard bullet names currently supported |
d2d0adc7 JS |
6527 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); |
6528 | }; | |
6529 | ||
5d7836c4 JS |
6530 | /*! |
6531 | * Utilities | |
6532 | * | |
6533 | */ | |
6534 | ||
6535 | inline bool wxRichTextHasStyle(int flags, int style) | |
6536 | { | |
6537 | return ((flags & style) == style); | |
6538 | } | |
6539 | ||
6540 | /// Compare two attribute objects | |
24777478 JS |
6541 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); |
6542 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); | |
5d7836c4 | 6543 | |
5d7836c4 | 6544 | /// Apply one style to another |
24777478 | 6545 | WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); |
59509217 | 6546 | |
aeb6ebe2 | 6547 | // Remove attributes |
24777478 | 6548 | WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style); |
aeb6ebe2 | 6549 | |
42688aea JS |
6550 | /// Combine two bitlists |
6551 | WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB); | |
6552 | ||
6553 | /// Compare two bitlists | |
6554 | WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags); | |
6555 | ||
4f32b3cf | 6556 | /// Split into paragraph and character styles |
24777478 | 6557 | WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxRichTextAttr& style, wxRichTextAttr& parStyle, wxRichTextAttr& charStyle); |
4f32b3cf | 6558 | |
59509217 | 6559 | /// Compare tabs |
d2d0adc7 | 6560 | WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2); |
59509217 | 6561 | |
59509217 | 6562 | /// Convert a decimal to Roman numerals |
d2d0adc7 | 6563 | WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n); |
f1d6804f | 6564 | |
24777478 JS |
6565 | // Collects the attributes that are common to a range of content, building up a note of |
6566 | // which attributes are absent in some objects and which clash in some objects. | |
6567 | WXDLLIMPEXP_RICHTEXT void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAttr& attr, wxTextAttr& clashingAttr, wxTextAttr& absentAttr); | |
6568 | ||
f1d6804f RD |
6569 | WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit(); |
6570 | ||
5d7836c4 JS |
6571 | #endif |
6572 | // wxUSE_RICHTEXT | |
6573 | ||
6574 | #endif | |
6575 | // _WX_RICHTEXTBUFFER_H_ | |
d2d0adc7 | 6576 |