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