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