1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextbuffer.h
3 // Purpose: Buffer for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTBUFFER_H_
13 #define _WX_RICHTEXTBUFFER_H_
20 Data is represented by a hierarchy of objects, all derived from
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
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.
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.
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.
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.
63 #include "wx/textctrl.h"
64 #include "wx/bitmap.h"
66 #include "wx/cmdproc.h"
67 #include "wx/txtstrm.h"
68 #include "wx/variant.h"
71 #include "wx/dataobj.h"
75 //#define wxRichTextAttr wxTextAttr
76 #define wxTextAttrEx wxTextAttr
78 // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a
79 // caret reliably without using wxClientDC in case there
80 // are platform-specific problems with the generic caret.
81 #if defined(__WXGTK__) || defined(__WXMAC__)
82 #define wxRICHTEXT_USE_OWN_CARET 1
84 #define wxRICHTEXT_USE_OWN_CARET 0
87 // Switch off for binary compatibility, on for faster drawing
88 // Note: this seems to be buggy (overzealous use of extents) so
90 #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0
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.
96 // Include the wxXmlDocument implementation for output
97 #define wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT 1
99 // Include the faster, direct implementation for output
100 #define wxRICHTEXT_HAVE_DIRECT_OUTPUT 1
106 extern WXDLLIMPEXP_RICHTEXT
const wxChar wxRichTextLineBreakChar
;
109 * File types in wxRichText context.
111 enum wxRichTextFileType
113 wxRICHTEXT_TYPE_ANY
= 0,
114 wxRICHTEXT_TYPE_TEXT
,
116 wxRICHTEXT_TYPE_HTML
,
122 * Forward declarations
125 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl
;
126 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject
;
127 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage
;
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
;
134 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition
;
135 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent
;
136 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer
;
137 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer
;
138 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextXMLHandler
;
139 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraphLayoutBox
;
140 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImageBlock
;
141 class WXDLLIMPEXP_FWD_XML wxXmlNode
;
142 class wxRichTextFloatCollector
;
145 * Flags determining the available space, passed to Layout
148 #define wxRICHTEXT_FIXED_WIDTH 0x01
149 #define wxRICHTEXT_FIXED_HEIGHT 0x02
150 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
151 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
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
158 * Flags to pass to Draw
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
165 #define wxRICHTEXT_DRAW_SELECTED 0x02
166 #define wxRICHTEXT_DRAW_PRINT 0x04
167 #define wxRICHTEXT_DRAW_GUIDELINES 0x08
170 * Flags returned from hit-testing, or passed to hit-test function.
172 enum wxRichTextHitTestFlags
174 // The point was not on this object
175 wxRICHTEXT_HITTEST_NONE
= 0x01,
177 // The point was before the position returned from HitTest
178 wxRICHTEXT_HITTEST_BEFORE
= 0x02,
180 // The point was after the position returned from HitTest
181 wxRICHTEXT_HITTEST_AFTER
= 0x04,
183 // The point was on the position returned from HitTest
184 wxRICHTEXT_HITTEST_ON
= 0x08,
186 // The point was on space outside content
187 wxRICHTEXT_HITTEST_OUTSIDE
= 0x10,
189 // Only do hit-testing at the current level (don't traverse into top-level objects)
190 wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
= 0x20
194 * Flags for GetRangeSize
197 #define wxRICHTEXT_FORMATTED 0x01
198 #define wxRICHTEXT_UNFORMATTED 0x02
199 #define wxRICHTEXT_CACHE_SIZE 0x04
200 #define wxRICHTEXT_HEIGHT_ONLY 0x08
203 * Flags for SetStyle/SetListStyle
206 #define wxRICHTEXT_SETSTYLE_NONE 0x00
208 // Specifies that this operation should be undoable
209 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
211 // Specifies that the style should not be applied if the
212 // combined style at this point is already the style in question.
213 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
215 // Specifies that the style should only be applied to paragraphs,
216 // and not the content. This allows content styling to be
217 // preserved independently from that of e.g. a named paragraph style.
218 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
220 // Specifies that the style should only be applied to characters,
221 // and not the paragraph. This allows content styling to be
222 // preserved independently from that of e.g. a named paragraph style.
223 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
225 // For SetListStyle only: specifies starting from the given number, otherwise
226 // deduces number from existing attributes
227 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
229 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
230 // the current indentation will be used
231 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
233 // Resets the existing style before applying the new style
234 #define wxRICHTEXT_SETSTYLE_RESET 0x40
236 // Removes the given style instead of applying it
237 #define wxRICHTEXT_SETSTYLE_REMOVE 0x80
240 * Flags for object insertion
243 #define wxRICHTEXT_INSERT_NONE 0x00
244 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
245 #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
247 // A special flag telling the buffer to keep the first paragraph style
248 // as-is, when deleting a paragraph marker. In future we might pass a
249 // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
250 #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
253 * Default superscript/subscript font multiplication factor
256 #define wxSCRIPT_MUL_FACTOR 1.5
258 typedef unsigned short wxTextAttrDimensionFlags
;
260 // Miscellaneous text box flags
261 enum wxTextBoxAttrFlags
263 wxTEXT_BOX_ATTR_FLOAT
= 0x00000001,
264 wxTEXT_BOX_ATTR_CLEAR
= 0x00000002,
265 wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
= 0x00000004,
266 wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT
= 0x00000004
269 // Whether a value is present, used in dimension flags
270 enum wxTextAttrValueFlags
272 wxTEXT_ATTR_VALUE_VALID
= 0x1000,
273 wxTEXT_ATTR_VALUE_VALID_MASK
= 0x1000
276 // Units - included in the dimension value
279 wxTEXT_ATTR_UNITS_TENTHS_MM
= 0x0001,
280 wxTEXT_ATTR_UNITS_PIXELS
= 0x0002,
281 wxTEXT_ATTR_UNITS_PERCENTAGE
= 0x0004,
282 wxTEXT_ATTR_UNITS_POINTS
= 0x0008,
284 wxTEXT_ATTR_UNITS_MASK
= 0x000F
287 // Position - included in the dimension flags
288 enum wxTextBoxAttrPosition
290 wxTEXT_BOX_ATTR_POSITION_STATIC
= 0x0000, // Default is static, i.e. as per normal layout
291 wxTEXT_BOX_ATTR_POSITION_RELATIVE
= 0x0010, // Relative to the relevant edge
292 wxTEXT_BOX_ATTR_POSITION_ABSOLUTE
= 0x0020,
294 wxTEXT_BOX_ATTR_POSITION_MASK
= 0x00F0
297 // Dimension, including units and position
298 class WXDLLIMPEXP_RICHTEXT wxTextAttrDimension
301 wxTextAttrDimension() { Reset(); }
302 wxTextAttrDimension(int value
, wxTextAttrUnits units
= wxTEXT_ATTR_UNITS_TENTHS_MM
) { m_value
= value
; m_flags
= units
|wxTEXT_ATTR_VALUE_VALID
; }
304 void Reset() { m_value
= 0; m_flags
= 0; }
306 // Partial equality test
307 bool EqPartial(const wxTextAttrDimension
& dim
) const;
310 bool Apply(const wxTextAttrDimension
& dim
, const wxTextAttrDimension
* compareWith
= NULL
);
312 // Collects the attributes that are common to a range of content, building up a note of
313 // which attributes are absent in some objects and which clash in some objects.
314 void CollectCommonAttributes(const wxTextAttrDimension
& attr
, wxTextAttrDimension
& clashingAttr
, wxTextAttrDimension
& absentAttr
);
316 bool operator==(const wxTextAttrDimension
& dim
) const { return m_value
== dim
.m_value
&& m_flags
== dim
.m_flags
; }
318 int GetValue() const { return m_value
; }
319 float GetValueMM() const { return float(m_value
) / 10.0; }
320 void SetValueMM(float value
) { m_value
= (int) ((value
* 10.0) + 0.5); m_flags
|= wxTEXT_ATTR_VALUE_VALID
; }
321 void SetValue(int value
) { m_value
= value
; m_flags
|= wxTEXT_ATTR_VALUE_VALID
; }
322 void SetValue(int value
, wxTextAttrDimensionFlags flags
) { SetValue(value
); m_flags
= flags
; }
323 void SetValue(int value
, wxTextAttrUnits units
) { m_value
= value
; m_flags
= units
| wxTEXT_ATTR_VALUE_VALID
; }
324 void SetValue(const wxTextAttrDimension
& dim
) { (*this) = dim
; }
326 wxTextAttrUnits
GetUnits() const { return (wxTextAttrUnits
) (m_flags
& wxTEXT_ATTR_UNITS_MASK
); }
327 void SetUnits(wxTextAttrUnits units
) { m_flags
&= ~wxTEXT_ATTR_UNITS_MASK
; m_flags
|= units
; }
329 wxTextBoxAttrPosition
GetPosition() const { return (wxTextBoxAttrPosition
) (m_flags
& wxTEXT_BOX_ATTR_POSITION_MASK
); }
330 void SetPosition(wxTextBoxAttrPosition pos
) { m_flags
&= ~wxTEXT_BOX_ATTR_POSITION_MASK
; m_flags
|= pos
; }
332 bool IsValid() const { return (m_flags
& wxTEXT_ATTR_VALUE_VALID
) != 0; }
333 void SetValid(bool b
) { m_flags
&= ~wxTEXT_ATTR_VALUE_VALID_MASK
; m_flags
|= (b
? wxTEXT_ATTR_VALUE_VALID
: 0); }
335 wxTextAttrDimensionFlags
GetFlags() const { return m_flags
; }
336 void SetFlags(wxTextAttrDimensionFlags flags
) { m_flags
= flags
; }
339 wxTextAttrDimensionFlags m_flags
;
342 // A class for left, right, top and bottom dimensions
343 class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensions
346 wxTextAttrDimensions() {}
348 void Reset() { m_left
.Reset(); m_top
.Reset(); m_right
.Reset(); m_bottom
.Reset(); }
350 bool operator==(const wxTextAttrDimensions
& dims
) const { return m_left
== dims
.m_left
&& m_top
== dims
.m_top
&& m_right
== dims
.m_right
&& m_bottom
== dims
.m_bottom
; }
352 // Partial equality test
353 bool EqPartial(const wxTextAttrDimensions
& dims
) const;
355 // Apply border to 'this', but not if the same as compareWith
356 bool Apply(const wxTextAttrDimensions
& dims
, const wxTextAttrDimensions
* compareWith
= NULL
);
358 // Collects the attributes that are common to a range of content, building up a note of
359 // which attributes are absent in some objects and which clash in some objects.
360 void CollectCommonAttributes(const wxTextAttrDimensions
& attr
, wxTextAttrDimensions
& clashingAttr
, wxTextAttrDimensions
& absentAttr
);
362 // Remove specified attributes from this object
363 bool RemoveStyle(const wxTextAttrDimensions
& attr
);
365 const wxTextAttrDimension
& GetLeft() const { return m_left
; }
366 wxTextAttrDimension
& GetLeft() { return m_left
; }
368 const wxTextAttrDimension
& GetRight() const { return m_right
; }
369 wxTextAttrDimension
& GetRight() { return m_right
; }
371 const wxTextAttrDimension
& GetTop() const { return m_top
; }
372 wxTextAttrDimension
& GetTop() { return m_top
; }
374 const wxTextAttrDimension
& GetBottom() const { return m_bottom
; }
375 wxTextAttrDimension
& GetBottom() { return m_bottom
; }
377 wxTextAttrDimension m_left
;
378 wxTextAttrDimension m_top
;
379 wxTextAttrDimension m_right
;
380 wxTextAttrDimension m_bottom
;
383 // A class for width and height
384 class WXDLLIMPEXP_RICHTEXT wxTextAttrSize
389 void Reset() { m_width
.Reset(); m_height
.Reset(); }
391 bool operator==(const wxTextAttrSize
& size
) const { return m_width
== size
.m_width
&& m_height
== size
.m_height
; }
393 // Partial equality test
394 bool EqPartial(const wxTextAttrSize
& dims
) const;
396 // Apply border to 'this', but not if the same as compareWith
397 bool Apply(const wxTextAttrSize
& dims
, const wxTextAttrSize
* compareWith
= NULL
);
399 // Collects the attributes that are common to a range of content, building up a note of
400 // which attributes are absent in some objects and which clash in some objects.
401 void CollectCommonAttributes(const wxTextAttrSize
& attr
, wxTextAttrSize
& clashingAttr
, wxTextAttrSize
& absentAttr
);
403 // Remove specified attributes from this object
404 bool RemoveStyle(const wxTextAttrSize
& attr
);
408 wxTextAttrDimension
& GetWidth() { return m_width
; }
409 const wxTextAttrDimension
& GetWidth() const { return m_width
; }
411 void SetWidth(int value
, wxTextAttrDimensionFlags flags
) { m_width
.SetValue(value
, flags
); }
412 void SetWidth(int value
, wxTextAttrUnits units
) { m_width
.SetValue(value
, units
); }
413 void SetWidth(const wxTextAttrDimension
& dim
) { m_width
.SetValue(dim
); }
415 wxTextAttrDimension
& GetHeight() { return m_height
; }
416 const wxTextAttrDimension
& GetHeight() const { return m_height
; }
418 void SetHeight(int value
, wxTextAttrDimensionFlags flags
) { m_height
.SetValue(value
, flags
); }
419 void SetHeight(int value
, wxTextAttrUnits units
) { m_height
.SetValue(value
, units
); }
420 void SetHeight(const wxTextAttrDimension
& dim
) { m_height
.SetValue(dim
); }
422 wxTextAttrDimension m_width
;
423 wxTextAttrDimension m_height
;
426 // A class to make it easier to convert dimensions
427 class WXDLLIMPEXP_RICHTEXT wxTextAttrDimensionConverter
430 wxTextAttrDimensionConverter(wxDC
& dc
, double scale
= 1.0, const wxSize
& parentSize
= wxDefaultSize
);
431 wxTextAttrDimensionConverter(int ppi
, double scale
= 1.0, const wxSize
& parentSize
= wxDefaultSize
);
433 int GetPixels(const wxTextAttrDimension
& dim
, int direction
= wxHORIZONTAL
) const;
434 int GetTenthsMM(const wxTextAttrDimension
& dim
) const;
436 int ConvertTenthsMMToPixels(int units
) const;
437 int ConvertPixelsToTenthsMM(int pixels
) const;
445 enum wxTextAttrBorderStyle
447 wxTEXT_BOX_ATTR_BORDER_NONE
= 0,
448 wxTEXT_BOX_ATTR_BORDER_SOLID
= 1,
449 wxTEXT_BOX_ATTR_BORDER_DOTTED
= 2,
450 wxTEXT_BOX_ATTR_BORDER_DASHED
= 3,
451 wxTEXT_BOX_ATTR_BORDER_DOUBLE
= 4,
452 wxTEXT_BOX_ATTR_BORDER_GROOVE
= 5,
453 wxTEXT_BOX_ATTR_BORDER_RIDGE
= 6,
454 wxTEXT_BOX_ATTR_BORDER_INSET
= 7,
455 wxTEXT_BOX_ATTR_BORDER_OUTSET
= 8
458 // Border style presence flags
459 enum wxTextAttrBorderFlags
461 wxTEXT_BOX_ATTR_BORDER_STYLE
= 0x0001,
462 wxTEXT_BOX_ATTR_BORDER_COLOUR
= 0x0002
465 // Border width symbols for qualitative widths
466 enum wxTextAttrBorderWidth
468 wxTEXT_BOX_ATTR_BORDER_THIN
= -1,
469 wxTEXT_BOX_ATTR_BORDER_MEDIUM
= -2,
470 wxTEXT_BOX_ATTR_BORDER_THICK
= -3
474 enum wxTextBoxAttrFloatStyle
476 wxTEXT_BOX_ATTR_FLOAT_NONE
= 0,
477 wxTEXT_BOX_ATTR_FLOAT_LEFT
= 1,
478 wxTEXT_BOX_ATTR_FLOAT_RIGHT
= 2
482 enum wxTextBoxAttrClearStyle
484 wxTEXT_BOX_ATTR_CLEAR_NONE
= 0,
485 wxTEXT_BOX_ATTR_CLEAR_LEFT
= 1,
486 wxTEXT_BOX_ATTR_CLEAR_RIGHT
= 2,
487 wxTEXT_BOX_ATTR_CLEAR_BOTH
= 3
490 // Collapse mode styles. TODO: can they be switched on per side?
491 enum wxTextBoxAttrCollapseMode
493 wxTEXT_BOX_ATTR_COLLAPSE_NONE
= 0,
494 wxTEXT_BOX_ATTR_COLLAPSE_FULL
= 1
497 // Vertical alignment values
498 enum wxTextBoxAttrVerticalAlignment
500 wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE
= 0,
501 wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP
= 1,
502 wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE
= 2,
503 wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM
= 3
507 class WXDLLIMPEXP_RICHTEXT wxTextAttrBorder
510 wxTextAttrBorder() { Reset(); }
512 bool operator==(const wxTextAttrBorder
& border
) const
514 return m_flags
== border
.m_flags
&& m_borderStyle
== border
.m_borderStyle
&&
515 m_borderColour
== border
.m_borderColour
&& m_borderWidth
== border
.m_borderWidth
;
518 void Reset() { m_borderStyle
= 0; m_borderColour
= 0; m_flags
= 0; m_borderWidth
.Reset(); }
520 // Partial equality test
521 bool EqPartial(const wxTextAttrBorder
& border
) const;
523 // Apply border to 'this', but not if the same as compareWith
524 bool Apply(const wxTextAttrBorder
& border
, const wxTextAttrBorder
* compareWith
= NULL
);
526 // Remove specified attributes from this object
527 bool RemoveStyle(const wxTextAttrBorder
& attr
);
529 // Collects the attributes that are common to a range of content, building up a note of
530 // which attributes are absent in some objects and which clash in some objects.
531 void CollectCommonAttributes(const wxTextAttrBorder
& attr
, wxTextAttrBorder
& clashingAttr
, wxTextAttrBorder
& absentAttr
);
533 void SetStyle(int style
) { m_borderStyle
= style
; m_flags
|= wxTEXT_BOX_ATTR_BORDER_STYLE
; }
534 int GetStyle() const { return m_borderStyle
; }
536 void SetColour(unsigned long colour
) { m_borderColour
= colour
; m_flags
|= wxTEXT_BOX_ATTR_BORDER_COLOUR
; }
537 void SetColour(const wxColour
& colour
) { m_borderColour
= colour
.GetRGB(); m_flags
|= wxTEXT_BOX_ATTR_BORDER_COLOUR
; }
538 unsigned long GetColourLong() const { return m_borderColour
; }
539 wxColour
GetColour() const { return wxColour(m_borderColour
); }
541 wxTextAttrDimension
& GetWidth() { return m_borderWidth
; }
542 const wxTextAttrDimension
& GetWidth() const { return m_borderWidth
; }
543 void SetWidth(const wxTextAttrDimension
& width
) { m_borderWidth
= width
; }
544 void SetWidth(int value
, wxTextAttrUnits units
= wxTEXT_ATTR_UNITS_TENTHS_MM
) { SetWidth(wxTextAttrDimension(value
, units
)); }
546 bool HasStyle() const { return (m_flags
& wxTEXT_BOX_ATTR_BORDER_STYLE
) != 0; }
547 bool HasColour() const { return (m_flags
& wxTEXT_BOX_ATTR_BORDER_COLOUR
) != 0; }
548 bool HasWidth() const { return m_borderWidth
.IsValid(); }
550 bool IsValid() const { return HasWidth(); }
551 void MakeValid() { m_borderWidth
.SetValid(true); }
553 int GetFlags() const { return m_flags
; }
554 void SetFlags(int flags
) { m_flags
= flags
; }
555 void AddFlag(int flag
) { m_flags
|= flag
; }
556 void RemoveFlag(int flag
) { m_flags
&= ~flag
; }
559 unsigned long m_borderColour
;
560 wxTextAttrDimension m_borderWidth
;
565 class WXDLLIMPEXP_RICHTEXT wxTextAttrBorders
568 wxTextAttrBorders() { }
570 bool operator==(const wxTextAttrBorders
& borders
) const
572 return m_left
== borders
.m_left
&& m_right
== borders
.m_right
&&
573 m_top
== borders
.m_top
&& m_bottom
== borders
.m_bottom
;
576 // Set style of all borders
577 void SetStyle(int style
);
579 // Set colour of all borders
580 void SetColour(unsigned long colour
);
581 void SetColour(const wxColour
& colour
);
583 // Set width of all borders
584 void SetWidth(const wxTextAttrDimension
& width
);
585 void SetWidth(int value
, wxTextAttrUnits units
= wxTEXT_ATTR_UNITS_TENTHS_MM
) { SetWidth(wxTextAttrDimension(value
, units
)); }
588 void Reset() { m_left
.Reset(); m_right
.Reset(); m_top
.Reset(); m_bottom
.Reset(); }
590 // Partial equality test
591 bool EqPartial(const wxTextAttrBorders
& borders
) const;
593 // Apply border to 'this', but not if the same as compareWith
594 bool Apply(const wxTextAttrBorders
& borders
, const wxTextAttrBorders
* compareWith
= NULL
);
596 // Remove specified attributes from this object
597 bool RemoveStyle(const wxTextAttrBorders
& attr
);
599 // Collects the attributes that are common to a range of content, building up a note of
600 // which attributes are absent in some objects and which clash in some objects.
601 void CollectCommonAttributes(const wxTextAttrBorders
& attr
, wxTextAttrBorders
& clashingAttr
, wxTextAttrBorders
& absentAttr
);
603 bool IsValid() const { return m_left
.IsValid() || m_right
.IsValid() || m_top
.IsValid() || m_bottom
.IsValid(); }
605 const wxTextAttrBorder
& GetLeft() const { return m_left
; }
606 wxTextAttrBorder
& GetLeft() { return m_left
; }
608 const wxTextAttrBorder
& GetRight() const { return m_right
; }
609 wxTextAttrBorder
& GetRight() { return m_right
; }
611 const wxTextAttrBorder
& GetTop() const { return m_top
; }
612 wxTextAttrBorder
& GetTop() { return m_top
; }
614 const wxTextAttrBorder
& GetBottom() const { return m_bottom
; }
615 wxTextAttrBorder
& GetBottom() { return m_bottom
; }
617 wxTextAttrBorder m_left
, m_right
, m_top
, m_bottom
;
621 // ----------------------------------------------------------------------------
622 // wxTextBoxAttr: a structure containing box attributes
623 // ----------------------------------------------------------------------------
625 class WXDLLIMPEXP_RICHTEXT wxTextBoxAttr
629 wxTextBoxAttr() { Init(); }
630 wxTextBoxAttr(const wxTextBoxAttr
& attr
) { Init(); (*this) = attr
; }
632 /// Initialise this object.
633 void Init() { Reset(); }
635 /// Reset this object.
638 // Copy. Unnecessary since we let it do a binary copy
639 //void Copy(const wxTextBoxAttr& attr);
642 //void operator= (const wxTextBoxAttr& attr);
645 bool operator== (const wxTextBoxAttr
& attr
) const;
647 /// Partial equality test, ignoring unset attributes.
648 bool EqPartial(const wxTextBoxAttr
& attr
) const;
650 /// Merges the given attributes. If compareWith
651 /// is non-NULL, then it will be used to mask out those attributes that are the same in style
652 /// and compareWith, for situations where we don't want to explicitly set inherited attributes.
653 bool Apply(const wxTextBoxAttr
& style
, const wxTextBoxAttr
* compareWith
= NULL
);
655 /// Collects the attributes that are common to a range of content, building up a note of
656 /// which attributes are absent in some objects and which clash in some objects.
657 void CollectCommonAttributes(const wxTextBoxAttr
& attr
, wxTextBoxAttr
& clashingAttr
, wxTextBoxAttr
& absentAttr
);
659 /// Removes the specified attributes from this object
660 bool RemoveStyle(const wxTextBoxAttr
& attr
);
663 void SetFlags(int flags
) { m_flags
= flags
; }
665 /// Returns the flags.
666 int GetFlags() const { return m_flags
; }
668 /// Is this flag present?
669 bool HasFlag(wxTextBoxAttrFlags flag
) const { return (m_flags
& flag
) != 0; }
672 void RemoveFlag(wxTextBoxAttrFlags flag
) { m_flags
&= ~flag
; }
675 void AddFlag(wxTextBoxAttrFlags flag
) { m_flags
|= flag
; }
677 /// Is this default? I.e. no attributes set.
678 bool IsDefault() const;
680 /// Get the float mode.
681 wxTextBoxAttrFloatStyle
GetFloatMode() const { return m_floatMode
; }
683 /// Set the float mode.
684 void SetFloatMode(wxTextBoxAttrFloatStyle mode
) { m_floatMode
= mode
; m_flags
|= wxTEXT_BOX_ATTR_FLOAT
; }
686 /// Do we have a float mode?
687 bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT
); }
689 /// Is this object floating?
690 bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE
; }
692 /// Returns the clear mode - whether to wrap text after object. Currently unimplemented.
693 wxTextBoxAttrClearStyle
GetClearMode() const { return m_clearMode
; }
695 /// Set the clear mode. Currently unimplemented.
696 void SetClearMode(wxTextBoxAttrClearStyle mode
) { m_clearMode
= mode
; m_flags
|= wxTEXT_BOX_ATTR_CLEAR
; }
698 /// Do we have a clear mode?
699 bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR
); }
701 /// Returns the collapse mode - whether to collapse borders. Currently unimplemented.
702 wxTextBoxAttrCollapseMode
GetCollapseBorders() const { return m_collapseMode
; }
704 /// Sets the collapse mode - whether to collapse borders. Currently unimplemented.
705 void SetCollapseBorders(wxTextBoxAttrCollapseMode collapse
) { m_collapseMode
= collapse
; m_flags
|= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
; }
707 /// Do we have a collapse borders flag?
708 bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
); }
710 /// Returns the vertical alignment.
711 wxTextBoxAttrVerticalAlignment
GetVerticalAlignment() const { return m_verticalAlignment
; }
713 /// Set the vertical alignment.
714 void SetVerticalAlignment(wxTextBoxAttrVerticalAlignment verticalAlignment
) { m_verticalAlignment
= verticalAlignment
; m_flags
|= wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT
; }
716 /// Do we have a vertical alignment flag?
717 bool HasVerticalAlignment() const { return HasFlag(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT
); }
719 /// Gets the margin values.
720 wxTextAttrDimensions
& GetMargins() { return m_margins
; }
721 const wxTextAttrDimensions
& GetMargins() const { return m_margins
; }
723 /// Gets the left margin.
724 wxTextAttrDimension
& GetLeftMargin() { return m_margins
.m_left
; }
725 const wxTextAttrDimension
& GetLeftMargin() const { return m_margins
.m_left
; }
727 /// Gets the right margin.
728 wxTextAttrDimension
& GetRightMargin() { return m_margins
.m_right
; }
729 const wxTextAttrDimension
& GetRightMargin() const { return m_margins
.m_right
; }
731 /// Gets the top margin.
732 wxTextAttrDimension
& GetTopMargin() { return m_margins
.m_top
; }
733 const wxTextAttrDimension
& GetTopMargin() const { return m_margins
.m_top
; }
735 /// Gets the bottom margin.
736 wxTextAttrDimension
& GetBottomMargin() { return m_margins
.m_bottom
; }
737 const wxTextAttrDimension
& GetBottomMargin() const { return m_margins
.m_bottom
; }
739 /// Returns the position.
740 wxTextAttrDimensions
& GetPosition() { return m_position
; }
741 const wxTextAttrDimensions
& GetPosition() const { return m_position
; }
743 /// Returns the left position.
744 wxTextAttrDimension
& GetLeft() { return m_position
.m_left
; }
745 const wxTextAttrDimension
& GetLeft() const { return m_position
.m_left
; }
747 /// Returns the right position.
748 wxTextAttrDimension
& GetRight() { return m_position
.m_right
; }
749 const wxTextAttrDimension
& GetRight() const { return m_position
.m_right
; }
751 /// Returns the top position.
752 wxTextAttrDimension
& GetTop() { return m_position
.m_top
; }
753 const wxTextAttrDimension
& GetTop() const { return m_position
.m_top
; }
755 /// Returns the bottom position.
756 wxTextAttrDimension
& GetBottom() { return m_position
.m_bottom
; }
757 const wxTextAttrDimension
& GetBottom() const { return m_position
.m_bottom
; }
759 /// Returns the padding values.
760 wxTextAttrDimensions
& GetPadding() { return m_padding
; }
761 const wxTextAttrDimensions
& GetPadding() const { return m_padding
; }
763 /// Returns the left padding value.
764 wxTextAttrDimension
& GetLeftPadding() { return m_padding
.m_left
; }
765 const wxTextAttrDimension
& GetLeftPadding() const { return m_padding
.m_left
; }
767 /// Returns the right padding value.
768 wxTextAttrDimension
& GetRightPadding() { return m_padding
.m_right
; }
769 const wxTextAttrDimension
& GetRightPadding() const { return m_padding
.m_right
; }
771 /// Returns the top padding value.
772 wxTextAttrDimension
& GetTopPadding() { return m_padding
.m_top
; }
773 const wxTextAttrDimension
& GetTopPadding() const { return m_padding
.m_top
; }
775 /// Returns the bottom padding value.
776 wxTextAttrDimension
& GetBottomPadding() { return m_padding
.m_bottom
; }
777 const wxTextAttrDimension
& GetBottomPadding() const { return m_padding
.m_bottom
; }
779 /// Returns the borders.
780 wxTextAttrBorders
& GetBorder() { return m_border
; }
781 const wxTextAttrBorders
& GetBorder() const { return m_border
; }
783 /// Returns the left border.
784 wxTextAttrBorder
& GetLeftBorder() { return m_border
.m_left
; }
785 const wxTextAttrBorder
& GetLeftBorder() const { return m_border
.m_left
; }
787 /// Returns the top border.
788 wxTextAttrBorder
& GetTopBorder() { return m_border
.m_top
; }
789 const wxTextAttrBorder
& GetTopBorder() const { return m_border
.m_top
; }
791 /// Returns the right border.
792 wxTextAttrBorder
& GetRightBorder() { return m_border
.m_right
; }
793 const wxTextAttrBorder
& GetRightBorder() const { return m_border
.m_right
; }
795 /// Returns the bottom border.
796 wxTextAttrBorder
& GetBottomBorder() { return m_border
.m_bottom
; }
797 const wxTextAttrBorder
& GetBottomBorder() const { return m_border
.m_bottom
; }
799 /// Returns the outline.
800 wxTextAttrBorders
& GetOutline() { return m_outline
; }
801 const wxTextAttrBorders
& GetOutline() const { return m_outline
; }
803 /// Returns the left outline.
804 wxTextAttrBorder
& GetLeftOutline() { return m_outline
.m_left
; }
805 const wxTextAttrBorder
& GetLeftOutline() const { return m_outline
.m_left
; }
807 /// Returns the top outline.
808 wxTextAttrBorder
& GetTopOutline() { return m_outline
.m_top
; }
809 const wxTextAttrBorder
& GetTopOutline() const { return m_outline
.m_top
; }
811 /// Returns the right outline.
812 wxTextAttrBorder
& GetRightOutline() { return m_outline
.m_right
; }
813 const wxTextAttrBorder
& GetRightOutline() const { return m_outline
.m_right
; }
815 /// Returns the bottom outline.
816 wxTextAttrBorder
& GetBottomOutline() { return m_outline
.m_bottom
; }
817 const wxTextAttrBorder
& GetBottomOutline() const { return m_outline
.m_bottom
; }
819 /// Returns the object size.
820 wxTextAttrSize
& GetSize() { return m_size
; }
821 const wxTextAttrSize
& GetSize() const { return m_size
; }
823 /// Sets the object size.
824 void SetSize(const wxTextAttrSize
& sz
) { m_size
= sz
; }
826 /// Returns the object width.
827 wxTextAttrDimension
& GetWidth() { return m_size
.m_width
; }
828 const wxTextAttrDimension
& GetWidth() const { return m_size
.m_width
; }
830 /// Returns the object height.
831 wxTextAttrDimension
& GetHeight() { return m_size
.m_height
; }
832 const wxTextAttrDimension
& GetHeight() const { return m_size
.m_height
; }
838 wxTextAttrDimensions m_margins
;
839 wxTextAttrDimensions m_padding
;
840 wxTextAttrDimensions m_position
;
842 wxTextAttrSize m_size
;
844 wxTextAttrBorders m_border
;
845 wxTextAttrBorders m_outline
;
847 wxTextBoxAttrFloatStyle m_floatMode
;
848 wxTextBoxAttrClearStyle m_clearMode
;
849 wxTextBoxAttrCollapseMode m_collapseMode
;
850 wxTextBoxAttrVerticalAlignment m_verticalAlignment
;
853 // ----------------------------------------------------------------------------
854 // wxRichTextAttr: an enhanced attribute
855 // ----------------------------------------------------------------------------
857 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
: public wxTextAttr
860 wxRichTextAttr(const wxTextAttr
& attr
) { wxTextAttr::Copy(attr
); }
861 wxRichTextAttr(const wxRichTextAttr
& attr
): wxTextAttr() { Copy(attr
); }
865 void Copy(const wxRichTextAttr
& attr
);
868 void operator=(const wxRichTextAttr
& attr
) { Copy(attr
); }
869 void operator=(const wxTextAttr
& attr
) { wxTextAttr::Copy(attr
); }
872 bool operator==(const wxRichTextAttr
& attr
) const;
874 // Partial equality test taking comparison object into account
875 bool EqPartial(const wxRichTextAttr
& attr
) const;
877 // Merges the given attributes. If compareWith
878 // is non-NULL, then it will be used to mask out those attributes that are the same in style
879 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
880 bool Apply(const wxRichTextAttr
& style
, const wxRichTextAttr
* compareWith
= NULL
);
882 // Collects the attributes that are common to a range of content, building up a note of
883 // which attributes are absent in some objects and which clash in some objects.
884 void CollectCommonAttributes(const wxRichTextAttr
& attr
, wxRichTextAttr
& clashingAttr
, wxRichTextAttr
& absentAttr
);
886 // Remove specified attributes from this object
887 bool RemoveStyle(const wxRichTextAttr
& attr
);
889 wxTextBoxAttr
& GetTextBoxAttr() { return m_textBoxAttr
; }
890 const wxTextBoxAttr
& GetTextBoxAttr() const { return m_textBoxAttr
; }
891 void SetTextBoxAttr(const wxTextBoxAttr
& attr
) { m_textBoxAttr
= attr
; }
893 wxTextBoxAttr m_textBoxAttr
;
896 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxVariant
, wxRichTextVariantArray
, WXDLLIMPEXP_RICHTEXT
);
898 // ----------------------------------------------------------------------------
899 // wxRichTextProperties - A simple property class using wxVariants
900 // ----------------------------------------------------------------------------
902 class WXDLLIMPEXP_RICHTEXT wxRichTextProperties
: public wxObject
904 DECLARE_DYNAMIC_CLASS(wxRichTextProperties
)
906 wxRichTextProperties() {}
907 wxRichTextProperties(const wxRichTextProperties
& props
): wxObject() { Copy(props
); }
909 void operator=(const wxRichTextProperties
& props
) { Copy(props
); }
910 bool operator==(const wxRichTextProperties
& props
) const;
911 void Copy(const wxRichTextProperties
& props
) { m_properties
= props
.m_properties
; }
912 const wxVariant
& operator[](size_t idx
) const { return m_properties
[idx
]; }
913 wxVariant
& operator[](size_t idx
) { return m_properties
[idx
]; }
914 void Clear() { m_properties
.Clear(); }
916 const wxRichTextVariantArray
& GetProperties() const { return m_properties
; }
917 wxRichTextVariantArray
& GetProperties() { return m_properties
; }
918 void SetProperties(const wxRichTextVariantArray
& props
) { m_properties
= props
; }
920 wxArrayString
GetPropertyNames() const;
922 size_t GetCount() const { return m_properties
.GetCount(); }
924 int HasProperty(const wxString
& name
) const { return Find(name
) != -1; }
926 int Find(const wxString
& name
) const;
927 const wxVariant
& GetProperty(const wxString
& name
) const;
928 wxVariant
* FindOrCreateProperty(const wxString
& name
);
930 wxString
GetPropertyString(const wxString
& name
) const;
931 long GetPropertyLong(const wxString
& name
) const;
932 bool GetPropertyBool(const wxString
& name
) const;
933 double GetPropertyDouble(const wxString
& name
) const;
935 void SetProperty(const wxVariant
& variant
);
936 void SetProperty(const wxString
& name
, const wxVariant
& variant
);
937 void SetProperty(const wxString
& name
, const wxString
& value
);
938 void SetProperty(const wxString
& name
, long value
);
939 void SetProperty(const wxString
& name
, double value
);
940 void SetProperty(const wxString
& name
, bool value
);
943 wxRichTextVariantArray m_properties
;
948 * wxRichTextFontTable
949 * Manages quick access to a pool of fonts for rendering rich text
952 class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable
: public wxObject
955 wxRichTextFontTable();
957 wxRichTextFontTable(const wxRichTextFontTable
& table
);
958 virtual ~wxRichTextFontTable();
960 bool IsOk() const { return m_refData
!= NULL
; }
962 wxFont
FindFont(const wxRichTextAttr
& fontSpec
);
965 void operator= (const wxRichTextFontTable
& table
);
966 bool operator == (const wxRichTextFontTable
& table
) const;
967 bool operator != (const wxRichTextFontTable
& table
) const { return !(*this == table
); }
971 DECLARE_DYNAMIC_CLASS(wxRichTextFontTable
)
975 * wxRichTextRange class declaration
976 * This stores beginning and end positions for a range of data.
977 * TODO: consider renaming wxTextRange and using for all text controls.
980 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
985 wxRichTextRange() { m_start
= 0; m_end
= 0; }
986 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
987 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
988 ~wxRichTextRange() {}
990 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
991 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
992 bool operator !=(const wxRichTextRange
& range
) const { return (m_start
!= range
.m_start
|| m_end
!= range
.m_end
); }
993 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
994 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
996 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
998 void SetStart(long start
) { m_start
= start
; }
999 long GetStart() const { return m_start
; }
1001 void SetEnd(long end
) { m_end
= end
; }
1002 long GetEnd() const { return m_end
; }
1004 /// Returns true if this range is completely outside 'range'
1005 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
1007 /// Returns true if this range is completely within 'range'
1008 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
1010 /// Returns true if the given position is within this range. Allow
1011 /// for the possibility of an empty range - assume the position
1012 /// is within this empty range. NO, I think we should not match with an empty range.
1013 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
1014 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
1016 /// Limit this range to be within 'range'
1017 bool LimitTo(const wxRichTextRange
& range
) ;
1019 /// Gets the length of the range
1020 long GetLength() const { return m_end
- m_start
+ 1; }
1022 /// Swaps the start and end
1023 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
1025 /// Convert to internal form: (n, n) is the range of a single character.
1026 wxRichTextRange
ToInternal() const { return wxRichTextRange(m_start
, m_end
-1); }
1028 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
1029 wxRichTextRange
FromInternal() const { return wxRichTextRange(m_start
, m_end
+1); }
1036 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRichTextRange
, wxRichTextRangeArray
, WXDLLIMPEXP_RICHTEXT
);
1038 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
1039 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
1041 // ----------------------------------------------------------------------------
1042 // wxRichTextSelection: stores selection information
1043 // ----------------------------------------------------------------------------
1045 #define wxRICHTEXT_NO_SELECTION wxRichTextRange(-2, -2)
1047 class WXDLLIMPEXP_RICHTEXT wxRichTextSelection
1050 wxRichTextSelection(const wxRichTextSelection
& sel
) { Copy(sel
); }
1051 wxRichTextSelection(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
* container
) { m_ranges
.Add(range
); m_container
= container
; }
1052 wxRichTextSelection() { Reset(); }
1054 /// Reset the selection
1055 void Reset() { m_ranges
.Clear(); m_container
= NULL
; }
1057 /// Set the selection
1058 void Set(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
* container
)
1059 { m_ranges
.Clear(); m_ranges
.Add(range
); m_container
= container
; }
1062 void Add(const wxRichTextRange
& range
)
1063 { m_ranges
.Add(range
); }
1065 /// Set the selections
1066 void Set(const wxRichTextRangeArray
& ranges
, wxRichTextParagraphLayoutBox
* container
)
1067 { m_ranges
= ranges
; m_container
= container
; }
1070 void Copy(const wxRichTextSelection
& sel
)
1071 { m_ranges
= sel
.m_ranges
; m_container
= sel
.m_container
; }
1074 void operator=(const wxRichTextSelection
& sel
) { Copy(sel
); }
1077 bool operator==(const wxRichTextSelection
& sel
) const;
1080 wxRichTextRange
operator[](size_t i
) const { return GetRange(i
); }
1082 /// Get the selection ranges
1083 wxRichTextRangeArray
& GetRanges() { return m_ranges
; }
1084 const wxRichTextRangeArray
& GetRanges() const { return m_ranges
; }
1086 /// Set the selection ranges
1087 void SetRanges(const wxRichTextRangeArray
& ranges
) { m_ranges
= ranges
; }
1089 /// Get the number of ranges in the selection
1090 size_t GetCount() const { return m_ranges
.GetCount(); }
1092 /// Get the given range
1093 wxRichTextRange
GetRange(size_t i
) const { return m_ranges
[i
]; }
1095 /// Get the first range if there is one, otherwise wxRICHTEXT_NO_SELECTION.
1096 wxRichTextRange
GetRange() const { return (m_ranges
.GetCount() > 0) ? (m_ranges
[0]) : wxRICHTEXT_NO_SELECTION
; }
1098 /// Set a single range.
1099 void SetRange(const wxRichTextRange
& range
) { m_ranges
.Clear(); m_ranges
.Add(range
); }
1101 /// Get the container for which the selection is valid
1102 wxRichTextParagraphLayoutBox
* GetContainer() const { return m_container
; }
1104 /// Set the container for which the selection is valid
1105 void SetContainer(wxRichTextParagraphLayoutBox
* container
) { m_container
= container
; }
1107 /// Is the selection valid?
1108 bool IsValid() const { return m_ranges
.GetCount() > 0 && GetContainer(); }
1110 /// Get the selection appropriate to the specified object, if any; returns an empty array if none
1111 /// at the level of the object's container.
1112 wxRichTextRangeArray
GetSelectionForObject(wxRichTextObject
* obj
) const;
1114 /// Is the given position within the selection?
1115 bool WithinSelection(long pos
, wxRichTextObject
* obj
) const;
1117 /// Is the given position within the selection?
1118 bool WithinSelection(long pos
) const { return WithinSelection(pos
, m_ranges
); }
1120 /// Is the given position within the selection range?
1121 static bool WithinSelection(long pos
, const wxRichTextRangeArray
& ranges
);
1123 /// Is the given range within the selection range?
1124 static bool WithinSelection(const wxRichTextRange
& range
, const wxRichTextRangeArray
& ranges
);
1126 wxRichTextRangeArray m_ranges
;
1127 wxRichTextParagraphLayoutBox
* m_container
;
1131 * wxRichTextObject class declaration
1132 * This is the base for drawable objects.
1135 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
1137 DECLARE_CLASS(wxRichTextObject
)
1141 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
1142 virtual ~wxRichTextObject();
1146 /// Draw the item, within the given range. Some objects may ignore the range (for
1147 /// example paragraphs) while others must obey it (lines, to implement wrapping)
1148 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
) = 0;
1150 /// Lay the item out at the specified position with the given size constraint.
1151 /// Layout must set the cached size.
1152 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
1154 /// Hit-testing: returns a flag indicating hit test details, plus
1155 /// information about position. contextObj is returned to specify what object
1156 /// position is relevant to, since otherwise there's an ambiguity.
1157 /// obj may not a child of contextObj, since we may be referring to the container itself
1158 /// if we have no hit on a child - for example if we click outside an object.
1159 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
, wxRichTextObject
** obj
, wxRichTextObject
** contextObj
, int flags
= 0);
1161 /// Finds the absolute position and row height for the given character position
1162 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
1164 /// Get the best size, i.e. the ideal starting size for this object irrespective
1165 /// of available space. For a short text string, it will be the size that exactly encloses
1166 /// the text. For a longer string, it might use the parent width for example.
1167 virtual wxSize
GetBestSize() const { return m_size
; }
1170 Gets the object size for the given range. Returns false if the range
1171 is invalid for this object.
1174 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const = 0;
1176 /// Do a split, returning an object containing the second part, and setting
1177 /// the first part in 'this'.
1178 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
1180 /// Calculate range. By default, guess that the object is 1 unit long.
1181 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
1184 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
1186 /// Returns true if the object is empty
1187 virtual bool IsEmpty() const { return false; }
1189 /// Whether this object floatable
1190 virtual bool IsFloatable() const { return false; }
1192 /// Whether this object is currently floating
1193 virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); }
1195 /// Whether this object is a place holding one
1196 // virtual bool IsPlaceHolding() const { return false; }
1198 /// The floating direction
1199 virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); }
1201 /// Get any text in this object for the given range
1202 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
1204 /// Returns true if this object can merge itself with the given one.
1205 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
1207 /// Returns true if this object merged itself with the given one.
1208 /// The calling code will then delete the given object.
1209 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
1211 /// Dump to output stream for debugging
1212 virtual void Dump(wxTextOutputStream
& stream
);
1214 /// Can we edit properties via a GUI?
1215 virtual bool CanEditProperties() const { return false; }
1217 /// Edit properties via a GUI
1218 virtual bool EditProperties(wxWindow
* WXUNUSED(parent
), wxRichTextBuffer
* WXUNUSED(buffer
)) { return false; }
1220 /// Return the label to be used for the properties context menu item.
1221 virtual wxString
GetPropertiesMenuLabel() const { return wxEmptyString
; }
1223 /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject
1224 /// is possible. For example, containers supporting text, such as a text box object, can accept the focus,
1225 /// but a table can't (set the focus to individual cells instead).
1226 virtual bool AcceptsFocus() const { return false; }
1229 /// Import this object from XML
1230 virtual bool ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
);
1233 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
1234 /// Export this object directly to the given stream.
1235 virtual bool ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
);
1238 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
1239 /// Export this object to the given parent node, usually creating at least one child node.
1240 virtual bool ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
);
1243 /// Does this object take note of paragraph attributes? Text and image objects don't.
1244 virtual bool UsesParagraphAttributes() const { return true; }
1246 /// What is the XML node name of this object?
1247 virtual wxString
GetXMLNodeName() const { return wxT("unknown"); }
1249 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1250 virtual void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1252 /// Can this object handle the selections of its children? FOr example, a table.
1253 virtual bool HandlesChildSelections() const { return false; }
1255 /// Returns a selection object specifying the selections between start and end character positions.
1256 /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table.
1257 virtual wxRichTextSelection
GetSelection(long WXUNUSED(start
), long WXUNUSED(end
)) const { return wxRichTextSelection(); }
1261 /// Get/set the cached object size as calculated by Layout.
1262 virtual wxSize
GetCachedSize() const { return m_size
; }
1263 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
1265 /// Get/set the maximum object size as calculated by Layout. This allows
1266 /// us to fit an object to its contents or allocate extra space if required.
1267 virtual wxSize
GetMaxSize() const { return m_maxSize
; }
1268 virtual void SetMaxSize(const wxSize
& sz
) { m_maxSize
= sz
; }
1270 /// Get/set the minimum object size as calculated by Layout. This allows
1271 /// us to constrain an object to its absolute minimum size if necessary.
1272 virtual wxSize
GetMinSize() const { return m_minSize
; }
1273 virtual void SetMinSize(const wxSize
& sz
) { m_minSize
= sz
; }
1275 /// Get the 'natural' size for an object. For an image, it would be the
1277 virtual wxTextAttrSize
GetNaturalSize() const { return wxTextAttrSize(); }
1279 /// Get/set the object position
1280 virtual wxPoint
GetPosition() const { return m_pos
; }
1281 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1283 /// Get the absolute object position, by traversing up the child/parent hierarchy
1284 /// TODO: may not be needed, if all object positions are in fact relative to the
1285 /// top of the coordinate space.
1286 virtual wxPoint
GetAbsolutePosition() const;
1288 /// Get the rectangle enclosing the object
1289 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
1292 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1295 const wxRichTextRange
& GetRange() const { return m_range
; }
1296 wxRichTextRange
& GetRange() { return m_range
; }
1298 /// Set the 'own' range, for a top-level object with its own position space
1299 void SetOwnRange(const wxRichTextRange
& range
) { m_ownRange
= range
; }
1301 /// Get own range (valid if top-level)
1302 const wxRichTextRange
& GetOwnRange() const { return m_ownRange
; }
1303 wxRichTextRange
& GetOwnRange() { return m_ownRange
; }
1305 /// Get own range only if a top-level object
1306 wxRichTextRange
GetOwnRangeIfTopLevel() const { return IsTopLevel() ? m_ownRange
: m_range
; }
1308 /// Is this composite?
1309 virtual bool IsComposite() const { return false; }
1311 /// Get/set the parent.
1312 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
1313 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
1315 /// Get/set the top-level container of this object.
1316 /// May return itself if it's a container; use GetParentContainer to return
1317 /// a different container.
1318 virtual wxRichTextParagraphLayoutBox
* GetContainer() const;
1320 /// Get/set the top-level container of this object.
1321 /// Returns a different container than itself, unless there's no parent, in which case it will return NULL.
1322 virtual wxRichTextParagraphLayoutBox
* GetParentContainer() const { return GetParent() ? GetParent()->GetContainer() : GetContainer(); }
1324 /// Set the margin around the object, in pixels
1325 virtual void SetMargins(int margin
);
1326 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
1327 virtual int GetLeftMargin() const;
1328 virtual int GetRightMargin() const;
1329 virtual int GetTopMargin() const;
1330 virtual int GetBottomMargin() const;
1332 /// Calculate the available content space in the given rectangle, given the
1333 /// margins, border and padding specified in the object's attributes.
1334 virtual wxRect
GetAvailableContentArea(wxDC
& dc
, const wxRect
& outerRect
) const;
1336 /// Lays out the object first with a given amount of space, and then if no width was specified in attr,
1337 /// lays out the object again using the minimum size
1338 virtual bool LayoutToBestSize(wxDC
& dc
, wxRichTextBuffer
* buffer
,
1339 const wxRichTextAttr
& parentAttr
, const wxRichTextAttr
& attr
, const wxRect
& availableParentSpace
, int style
);
1341 /// Set/get attributes object
1342 void SetAttributes(const wxRichTextAttr
& attr
) { m_attributes
= attr
; }
1343 const wxRichTextAttr
& GetAttributes() const { return m_attributes
; }
1344 wxRichTextAttr
& GetAttributes() { return m_attributes
; }
1346 /// Set/get properties
1347 wxRichTextProperties
& GetProperties() { return m_properties
; }
1348 const wxRichTextProperties
& GetProperties() const { return m_properties
; }
1349 void SetProperties(const wxRichTextProperties
& props
) { m_properties
= props
; }
1351 /// Set/get stored descent
1352 void SetDescent(int descent
) { m_descent
= descent
; }
1353 int GetDescent() const { return m_descent
; }
1355 /// Gets the containing buffer
1356 wxRichTextBuffer
* GetBuffer() const;
1358 /// Sets the identifying name for this object, as a property.
1359 void SetName(const wxString
& name
) { m_properties
.SetProperty(wxT("name"), name
); }
1361 /// Gets the identifying name for this object.
1362 wxString
GetName() const { return m_properties
.GetPropertyString(wxT("name")); }
1364 /// Is this object top-level, i.e. with its own paragraphs, such as a text box?
1365 virtual bool IsTopLevel() const { return false; }
1367 /// Returns @true if the object will be shown, @false otherwise.
1368 bool IsShown() const { return m_show
; }
1372 /// Call to show or hide this object. This function does not cause the content to be
1373 /// laid out or redrawn.
1374 virtual void Show(bool show
) { m_show
= show
; }
1376 /// Clone the object
1377 virtual wxRichTextObject
* Clone() const { return NULL
; }
1380 void Copy(const wxRichTextObject
& obj
);
1382 /// Reference-counting allows us to use the same object in multiple
1383 /// lists (not yet used)
1384 void Reference() { m_refCount
++; }
1387 /// Move the object recursively, by adding the offset from old to new
1388 virtual void Move(const wxPoint
& pt
);
1390 /// Convert units in tenths of a millimetre to device units
1391 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
1392 static int ConvertTenthsMMToPixels(int ppi
, int units
, double scale
= 1.0);
1394 /// Convert units in pixels to tenths of a millimetre
1395 int ConvertPixelsToTenthsMM(wxDC
& dc
, int pixels
) const;
1396 static int ConvertPixelsToTenthsMM(int ppi
, int pixels
, double scale
= 1.0);
1398 /// Draw the borders and background for the given rectangle and attributes.
1399 /// Width and height are taken to be the outer margin size, not the content.
1400 static bool DrawBoxAttributes(wxDC
& dc
, wxRichTextBuffer
* buffer
, const wxRichTextAttr
& attr
, const wxRect
& boxRect
, int flags
= 0);
1403 static bool DrawBorder(wxDC
& dc
, wxRichTextBuffer
* buffer
, const wxTextAttrBorders
& attr
, const wxRect
& rect
, int flags
= 0);
1405 /// Get the various rectangles of the box model in pixels. You can either specify contentRect (inner)
1406 /// or marginRect (outer), and the other must be the default rectangle (no width or height).
1407 /// Note that the outline doesn't affect the position of the rectangle, it's drawn in whatever space
1409 static bool GetBoxRects(wxDC
& dc
, wxRichTextBuffer
* buffer
, const wxRichTextAttr
& attr
, wxRect
& marginRect
, wxRect
& borderRect
, wxRect
& contentRect
, wxRect
& paddingRect
, wxRect
& outlineRect
);
1411 /// Get the total margin for the object in pixels, taking into account margin, padding and border size
1412 static bool GetTotalMargin(wxDC
& dc
, wxRichTextBuffer
* buffer
, const wxRichTextAttr
& attr
, int& leftMargin
, int& rightMargin
,
1413 int& topMargin
, int& bottomMargin
);
1415 /// Returns the rectangle which the child has available to it given restrictions specified in the
1416 /// child attribute, e.g. 50% width of the parent, 400 pixels, x position 20% of the parent, etc.
1417 static wxRect
AdjustAvailableSpace(wxDC
& dc
, wxRichTextBuffer
* buffer
, const wxRichTextAttr
& parentAttr
, const wxRichTextAttr
& childAttr
, const wxRect
& availableParentSpace
);
1424 int m_descent
; // Descent for this object (if any)
1427 wxRichTextObject
* m_parent
;
1429 /// The range of this object (start position to end position)
1430 wxRichTextRange m_range
;
1432 /// The internal range of this object, if it's a top-level object with its own range space
1433 wxRichTextRange m_ownRange
;
1436 wxRichTextAttr m_attributes
;
1439 wxRichTextProperties m_properties
;
1442 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
1445 * wxRichTextCompositeObject class declaration
1446 * Objects of this class can contain other objects.
1449 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
1451 DECLARE_CLASS(wxRichTextCompositeObject
)
1455 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
1456 virtual ~wxRichTextCompositeObject();
1460 /// Hit-testing: returns a flag indicating hit test details, plus
1461 /// information about position
1462 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
, wxRichTextObject
** obj
, wxRichTextObject
** contextObj
, int flags
= 0);
1464 /// Finds the absolute position and row height for the given character position
1465 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1468 virtual void CalculateRange(long start
, long& end
);
1471 virtual bool DeleteRange(const wxRichTextRange
& range
);
1473 /// Get any text in this object for the given range
1474 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1476 /// Gets the object size for the given range. Returns false if the range
1477 /// is invalid for this object.
1478 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1480 /// Dump to output stream for debugging
1481 virtual void Dump(wxTextOutputStream
& stream
);
1483 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1484 virtual void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1488 /// Get the children
1489 wxRichTextObjectList
& GetChildren() { return m_children
; }
1490 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
1492 /// Get the child count
1493 size_t GetChildCount() const ;
1495 /// Get the nth child
1496 wxRichTextObject
* GetChild(size_t n
) const ;
1498 /// Is this composite?
1499 virtual bool IsComposite() const { return true; }
1501 /// Returns true if the buffer is empty
1502 virtual bool IsEmpty() const { return GetChildCount() == 0; }
1504 /// Get the child object at the given character position
1505 virtual wxRichTextObject
* GetChildAtPosition(long pos
) const;
1510 void Copy(const wxRichTextCompositeObject
& obj
);
1513 void operator= (const wxRichTextCompositeObject
& obj
) { Copy(obj
); }
1515 /// Append a child, returning the position
1516 size_t AppendChild(wxRichTextObject
* child
) ;
1518 /// Insert the child in front of the given object, or at the beginning
1519 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
1521 /// Delete the child
1522 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
1524 /// Delete all children
1525 bool DeleteChildren() ;
1527 /// Recursively merge all pieces that can be merged.
1528 bool Defragment(const wxRichTextRange
& range
= wxRICHTEXT_ALL
);
1530 /// Move the object recursively, by adding the offset from old to new
1531 virtual void Move(const wxPoint
& pt
);
1534 wxRichTextObjectList m_children
;
1538 * wxRichTextParagraphBox class declaration
1539 * This box knows how to lay out paragraphs.
1542 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextCompositeObject
1544 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
1548 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
1549 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
): wxRichTextCompositeObject() { Init(); Copy(obj
); }
1550 ~wxRichTextParagraphLayoutBox();
1554 /// Hit-testing: returns a flag indicating hit test details, plus
1555 /// information about position
1556 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
, wxRichTextObject
** obj
, wxRichTextObject
** contextObj
, int flags
= 0);
1559 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
1561 /// Lay the item out
1562 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1564 /// Gets the object size for the given range. Returns false if the range
1565 /// is invalid for this object.
1566 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1569 virtual bool DeleteRange(const wxRichTextRange
& range
);
1571 /// Get any text in this object for the given range
1572 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1575 /// Import this object from XML
1576 virtual bool ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
);
1579 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
1580 /// Export this object directly to the given stream.
1581 virtual bool ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
);
1584 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
1585 /// Export this object to the given parent node, usually creating at least one child node.
1586 virtual bool ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
);
1589 /// What is the XML node name of this object?
1590 virtual wxString
GetXMLNodeName() const { return wxT("paragraphlayout"); }
1592 /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject
1593 /// is possible. For example, containers supporting text, such as a text box object, can accept the focus,
1594 /// but a table can't (set the focus to individual cells instead).
1595 virtual bool AcceptsFocus() const { return true; }
1599 /// Associate a control with the buffer, for operations that for example require refreshing the window.
1600 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
1602 /// Get the associated control.
1603 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
1605 /// Get/set whether the last paragraph is partial or complete
1606 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
1607 bool GetPartialParagraph() const { return m_partialParagraph
; }
1609 /// Returns the style sheet associated with the overall buffer.
1610 virtual wxRichTextStyleSheet
* GetStyleSheet() const;
1612 /// Is this object top-level, i.e. with its own paragraphs, such as a text box?
1613 virtual bool IsTopLevel() const { return true; }
1617 /// Submit command to insert paragraphs
1618 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
, int flags
= 0);
1620 /// Submit command to insert the given text
1621 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
, int flags
= 0);
1623 /// Submit command to insert the given text
1624 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
, int flags
= 0);
1626 /// Submit command to insert the given image
1627 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
,
1628 wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
, int flags
,
1629 const wxRichTextAttr
& textAttr
);
1631 /// Get the style that is appropriate for a new paragraph at this position.
1632 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1634 wxRichTextAttr
GetStyleForNewParagraph(wxRichTextBuffer
* buffer
, long pos
, bool caretPosition
= false, bool lookUpNewParaStyle
=false) const;
1636 /// Insert an object.
1637 wxRichTextObject
* InsertObjectWithUndo(long pos
, wxRichTextObject
*object
, wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
, int flags
= 0);
1639 /// Submit command to delete this range
1640 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, wxRichTextCtrl
* ctrl
, wxRichTextBuffer
* buffer
);
1642 /// Draw the floats of this buffer
1643 void DrawFloats(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
1645 /// Move an anchored object to another paragraph
1646 void MoveAnchoredObjectToParagraph(wxRichTextParagraph
* from
, wxRichTextParagraph
* to
, wxRichTextObject
* obj
);
1648 /// Initialize the object.
1651 /// Clear all children
1652 virtual void Clear();
1654 /// Clear and initialize with one blank paragraph
1655 virtual void Reset();
1657 /// Convenience function to add a paragraph of text
1658 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
);
1660 /// Convenience function to add an image
1661 virtual wxRichTextRange
AddImage(const wxImage
& image
, wxRichTextAttr
* paraStyle
= NULL
);
1663 /// Adds multiple paragraphs, based on newlines.
1664 virtual wxRichTextRange
AddParagraphs(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
);
1666 /// Get the line at the given position. If caretPosition is true, the position is
1667 /// a caret position, which is normally a smaller number.
1668 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
1670 /// Get the line at the given y pixel position, or the last line.
1671 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
1673 /// Get the paragraph at the given character or caret position
1674 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
1676 /// Get the line size at the given position
1677 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
1679 /// Given a position, get the number of the visible line (potentially many to a paragraph),
1680 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
1681 /// that indicates whether the caret is being shown at the end of the previous line or at the start
1682 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
1684 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
1686 /// Given a line number, get the corresponding wxRichTextLine object.
1687 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
1689 /// Get the leaf object in a paragraph at this position.
1690 /// Given a position, get the corresponding wxRichTextLine object.
1691 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
1693 /// Get the paragraph by number
1694 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
1696 /// Get the paragraph for a given line
1697 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
1699 /// Get the length of the paragraph
1700 virtual int GetParagraphLength(long paragraphNumber
) const;
1702 /// Get the number of paragraphs
1703 virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); }
1705 /// Get the number of visible lines
1706 virtual int GetLineCount() const;
1708 /// Get the text of the paragraph
1709 virtual wxString
GetParagraphText(long paragraphNumber
) const;
1711 /// Convert zero-based line column and paragraph number to a position.
1712 virtual long XYToPosition(long x
, long y
) const;
1714 /// Convert zero-based position to line column and paragraph number
1715 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1717 /// Set text attributes: character and/or paragraph styles.
1718 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1720 /// Set the attributes for the given object only, for example the box attributes for a text box.
1721 virtual void SetStyle(wxRichTextObject
*obj
, const wxRichTextAttr
& textAttr
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1723 /// Get the combined text attributes for this position.
1724 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
1726 /// Get the content (uncombined) attributes for this position.
1727 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
1729 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1730 /// context attributes.
1731 virtual bool DoGetStyle(long position
, wxRichTextAttr
& style
, bool combineStyles
= true);
1733 /// Get the combined style for a range - if any attribute is different within the range,
1734 /// that attribute is not present within the flags
1735 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
);
1737 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1739 bool CollectStyle(wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
& clashingAttr
, wxRichTextAttr
& absentAttr
);
1742 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1743 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1745 /// Clear list for given range
1746 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1748 /// Number/renumber any list elements in the given range.
1749 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1750 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1751 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1753 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1754 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1755 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1756 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1758 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1759 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1760 virtual bool DoNumberList(const wxRichTextRange
& range
, const wxRichTextRange
& promotionRange
, int promoteBy
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1762 /// Fills in the attributes for numbering a paragraph after previousParagraph.
1763 virtual bool FindNextParagraphNumber(wxRichTextParagraph
* previousParagraph
, wxRichTextAttr
& attr
) const;
1765 /// Test if this whole range has character attributes of the specified kind. If any
1766 /// of the attributes are different within the range, the test fails. You
1767 /// can use this to implement, for example, bold button updating. style must have
1768 /// flags indicating which attributes are of interest.
1769 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1771 /// Test if this whole range has paragraph attributes of the specified kind. If any
1772 /// of the attributes are different within the range, the test fails. You
1773 /// can use this to implement, for example, centering button updating. style must have
1774 /// flags indicating which attributes are of interest.
1775 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1778 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1780 /// Insert fragment into this box at the given position. If partialParagraph is true,
1781 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1783 virtual bool InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
);
1785 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1786 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
);
1788 /// Apply the style sheet to the buffer, for example if the styles have changed.
1789 virtual bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1792 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
1795 void operator= (const wxRichTextParagraphLayoutBox
& obj
) { Copy(obj
); }
1797 /// Calculate ranges
1798 virtual void UpdateRanges();
1800 /// Get all the text
1801 virtual wxString
GetText() const;
1803 /// Set default style for new content. Setting it to a default attribute
1804 /// makes new content take on the 'basic' style.
1805 virtual bool SetDefaultStyle(const wxRichTextAttr
& style
);
1807 /// Get default style
1808 virtual const wxRichTextAttr
& GetDefaultStyle() const { return m_defaultAttributes
; }
1810 /// Set basic (overall) style
1811 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { m_attributes
= style
; }
1813 /// Get basic (overall) style
1814 virtual const wxRichTextAttr
& GetBasicStyle() const { return m_attributes
; }
1816 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1817 virtual void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1819 /// Do the (in)validation for this object only
1820 virtual void DoInvalidate(const wxRichTextRange
& invalidRange
);
1822 /// Do the (in)validation both up and down the hierarchy
1823 virtual void InvalidateHierarchy(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1825 /// Gather information about floating objects. If untilObj is non-NULL,
1826 /// will stop getting information if the current object is this, since we
1827 /// will collect the rest later.
1828 virtual bool UpdateFloatingObjects(const wxRect
& availableRect
, wxRichTextObject
* untilObj
= NULL
);
1830 /// Get invalid range, rounding to entire paragraphs if argument is true.
1831 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
1833 /// Does this object need layout?
1834 bool IsDirty() const { return m_invalidRange
!= wxRICHTEXT_NONE
; }
1836 /// Get the wxRichTextFloatCollector of this object
1837 wxRichTextFloatCollector
* GetFloatCollector() { return m_floatCollector
; }
1839 /// Get the number of floating objects at this level
1840 int GetFloatingObjectCount() const;
1842 /// Get a list of floating objects
1843 bool GetFloatingObjects(wxRichTextObjectList
& objects
) const;
1846 wxRichTextCtrl
* m_ctrl
;
1847 wxRichTextAttr m_defaultAttributes
;
1849 /// The invalidated range that will need full layout
1850 wxRichTextRange m_invalidRange
;
1852 // Is the last paragraph partial or complete?
1853 bool m_partialParagraph
;
1855 // The floating layout state
1856 wxRichTextFloatCollector
* m_floatCollector
;
1860 @class wxRichTextBox
1862 wxRichTextBox is a floating or inline text box, containing paragraphs.
1865 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextParagraphLayoutBox
1867 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
1872 Default constructor; optionally pass the parent object.
1875 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
1881 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextParagraphLayoutBox() { Copy(obj
); }
1889 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
1892 Returns the XML node name of this object.
1895 virtual wxString
GetXMLNodeName() const { return wxT("textbox"); }
1897 /// Can we edit properties via a GUI?
1898 virtual bool CanEditProperties() const { return true; }
1900 /// Edit properties via a GUI
1901 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
1903 /// Return the label to be used for the properties context menu item.
1904 virtual wxString
GetPropertiesMenuLabel() const { return _("&Box"); }
1911 Makes a clone of this object.
1913 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
1918 void Copy(const wxRichTextBox
& obj
);
1924 * wxRichTextLine class declaration
1925 * This object represents a line in a paragraph, and stores
1926 * offsets from the start of the paragraph representing the
1927 * start and end positions of the line.
1930 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1935 wxRichTextLine(wxRichTextParagraph
* parent
);
1936 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
1937 virtual ~wxRichTextLine() {}
1944 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1945 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
1947 /// Get the parent paragraph
1948 wxRichTextParagraph
* GetParent() { return m_parent
; }
1951 const wxRichTextRange
& GetRange() const { return m_range
; }
1952 wxRichTextRange
& GetRange() { return m_range
; }
1954 /// Get the absolute range
1955 wxRichTextRange
GetAbsoluteRange() const;
1957 /// Get/set the line size as calculated by Layout.
1958 virtual wxSize
GetSize() const { return m_size
; }
1959 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
1961 /// Get/set the object position relative to the parent
1962 virtual wxPoint
GetPosition() const { return m_pos
; }
1963 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1965 /// Get the absolute object position
1966 virtual wxPoint
GetAbsolutePosition() const;
1968 /// Get the rectangle enclosing the line
1969 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1971 /// Set/get stored descent
1972 void SetDescent(int descent
) { m_descent
= descent
; }
1973 int GetDescent() const { return m_descent
; }
1975 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1976 wxArrayInt
& GetObjectSizes() { return m_objectSizes
; }
1977 const wxArrayInt
& GetObjectSizes() const { return m_objectSizes
; }
1983 void Init(wxRichTextParagraph
* parent
);
1986 void Copy(const wxRichTextLine
& obj
);
1989 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1993 /// The range of the line (start position to end position)
1994 /// This is relative to the parent paragraph.
1995 wxRichTextRange m_range
;
1997 /// Size and position measured relative to top of paragraph
2001 /// Maximum descent for this line (location of text baseline)
2004 // The parent object
2005 wxRichTextParagraph
* m_parent
;
2007 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
2008 wxArrayInt m_objectSizes
;
2012 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
2015 * wxRichTextParagraph class declaration
2016 * This object represents a single paragraph (or in a straight text editor, a line).
2019 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextCompositeObject
2021 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
2025 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* style
= NULL
);
2026 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* paraStyle
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
2027 virtual ~wxRichTextParagraph();
2028 wxRichTextParagraph(const wxRichTextParagraph
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
2033 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
2035 /// Lay the item out
2036 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
2038 /// Gets the object size for the given range. Returns false if the range
2039 /// is invalid for this object.
2040 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
2042 /// Finds the absolute position and row height for the given character position
2043 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
2045 /// Hit-testing: returns a flag indicating hit test details, plus
2046 /// information about position and the object that was found.
2047 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
, wxRichTextObject
** obj
, wxRichTextObject
** contextObj
, int flags
= 0);
2050 virtual void CalculateRange(long start
, long& end
);
2052 /// What is the XML node name of this object?
2053 virtual wxString
GetXMLNodeName() const { return wxT("paragraph"); }
2057 /// Get the cached lines
2058 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
2063 void Copy(const wxRichTextParagraph
& obj
);
2066 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
2068 /// Clear the cached lines
2073 /// Apply paragraph styles such as centering to the wrapped lines
2074 virtual void ApplyParagraphStyle(wxRichTextLine
* line
, const wxRichTextAttr
& attr
, const wxRect
& rect
, wxDC
& dc
);
2076 /// Insert text at the given position
2077 virtual bool InsertText(long pos
, const wxString
& text
);
2079 /// Split an object at this position if necessary, and return
2080 /// the previous object, or NULL if inserting at beginning.
2081 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
2083 /// Move content to a list from this point
2084 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
2086 /// Add content back from list
2087 virtual void MoveFromList(wxList
& list
);
2089 /// Get the plain text searching from the start or end of the range.
2090 /// The resulting string may be shorter than the range given.
2091 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
2093 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
2095 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
, wxArrayInt
* partialExtents
);
2097 /// Find the object at the given position
2098 wxRichTextObject
* FindObjectAtPosition(long position
);
2100 /// Get the bullet text for this paragraph.
2101 wxString
GetBulletText();
2103 /// Allocate or reuse a line object
2104 wxRichTextLine
* AllocateLine(int pos
);
2106 /// Clear remaining unused line objects, if any
2107 bool ClearUnusedLines(int lineCount
);
2109 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
2110 /// retrieve the actual style.
2111 wxRichTextAttr
GetCombinedAttributes(const wxRichTextAttr
& contentStyle
, bool includingBoxAttr
= false) const;
2113 /// Get combined attributes of the base style and paragraph style.
2114 wxRichTextAttr
GetCombinedAttributes(bool includingBoxAttr
= false) const;
2116 /// Get the first position from pos that has a line break character.
2117 long GetFirstLineBreakPosition(long pos
);
2119 /// Create default tabstop array
2120 static void InitDefaultTabs();
2122 /// Clear default tabstop array
2123 static void ClearDefaultTabs();
2125 /// Get default tabstop array
2126 static const wxArrayInt
& GetDefaultTabs() { return sm_defaultTabs
; }
2128 /// Layout the floats object
2129 void LayoutFloat(wxDC
& dc
, const wxRect
& rect
, int style
, wxRichTextFloatCollector
* floatCollector
);
2132 /// The lines that make up the wrapped paragraph
2133 wxRichTextLineList m_cachedLines
;
2135 /// Default tabstops
2136 static wxArrayInt sm_defaultTabs
;
2138 friend class wxRichTextFloatCollector
;
2142 * wxRichTextPlainText class declaration
2143 * This object represents a single piece of text.
2146 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
2148 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
2152 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* style
= NULL
);
2153 wxRichTextPlainText(const wxRichTextPlainText
& obj
): wxRichTextObject() { Copy(obj
); }
2158 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
2160 /// Lay the item out
2161 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
2163 /// Gets the object size for the given range. Returns false if the range
2164 /// is invalid for this object.
2165 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
2167 /// Get any text in this object for the given range
2168 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
2170 /// Do a split, returning an object containing the second part, and setting
2171 /// the first part in 'this'.
2172 virtual wxRichTextObject
* DoSplit(long pos
);
2175 virtual void CalculateRange(long start
, long& end
);
2178 virtual bool DeleteRange(const wxRichTextRange
& range
);
2180 /// Returns true if the object is empty
2181 virtual bool IsEmpty() const { return m_text
.empty(); }
2183 /// Returns true if this object can merge itself with the given one.
2184 virtual bool CanMerge(wxRichTextObject
* object
) const;
2186 /// Returns true if this object merged itself with the given one.
2187 /// The calling code will then delete the given object.
2188 virtual bool Merge(wxRichTextObject
* object
);
2190 /// Dump to output stream for debugging
2191 virtual void Dump(wxTextOutputStream
& stream
);
2193 /// Get the first position from pos that has a line break character.
2194 long GetFirstLineBreakPosition(long pos
);
2196 /// Does this object take note of paragraph attributes? Text and image objects don't.
2197 virtual bool UsesParagraphAttributes() const { return false; }
2200 /// Import this object from XML
2201 virtual bool ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
);
2204 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2205 /// Export this object directly to the given stream.
2206 virtual bool ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
);
2209 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2210 /// Export this object to the given parent node, usually creating at least one child node.
2211 virtual bool ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
);
2214 /// What is the XML node name of this object?
2215 virtual wxString
GetXMLNodeName() const { return wxT("text"); }
2220 const wxString
& GetText() const { return m_text
; }
2223 void SetText(const wxString
& text
) { m_text
= text
; }
2228 void Copy(const wxRichTextPlainText
& obj
);
2231 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
2233 bool DrawTabbedString(wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
2240 * wxRichTextImageBlock stores information about an image, in binary in-memory form
2243 class WXDLLIMPEXP_FWD_BASE wxDataInputStream
;
2244 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream
;
2246 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
2249 wxRichTextImageBlock();
2250 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
2251 virtual ~wxRichTextImageBlock();
2256 // Load the original image into a memory block.
2257 // If the image is not a JPEG, we must convert it into a JPEG
2258 // to conserve space.
2259 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
2260 // load the image a 2nd time.
2261 virtual bool MakeImageBlock(const wxString
& filename
, wxBitmapType imageType
,
2262 wxImage
& image
, bool convertToJPEG
= true);
2264 // Make an image block from the wxImage in the given
2266 virtual bool MakeImageBlock(wxImage
& image
, wxBitmapType imageType
, int quality
= 80);
2268 // Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG)
2269 virtual bool MakeImageBlockDefaultQuality(const wxImage
& image
, wxBitmapType imageType
);
2271 // Makes the image block
2272 virtual bool DoMakeImageBlock(const wxImage
& image
, wxBitmapType imageType
);
2275 bool Write(const wxString
& filename
);
2277 // Write data in hex to a stream
2278 bool WriteHex(wxOutputStream
& stream
);
2280 // Read data in hex from a stream
2281 bool ReadHex(wxInputStream
& stream
, int length
, wxBitmapType imageType
);
2283 // Copy from 'block'
2284 void Copy(const wxRichTextImageBlock
& block
);
2286 // Load a wxImage from the block
2287 bool Load(wxImage
& image
);
2290 void operator=(const wxRichTextImageBlock
& block
);
2294 unsigned char* GetData() const { return m_data
; }
2295 size_t GetDataSize() const { return m_dataSize
; }
2296 wxBitmapType
GetImageType() const { return m_imageType
; }
2298 void SetData(unsigned char* image
) { m_data
= image
; }
2299 void SetDataSize(size_t size
) { m_dataSize
= size
; }
2300 void SetImageType(wxBitmapType imageType
) { m_imageType
= imageType
; }
2302 bool Ok() const { return IsOk(); }
2303 bool IsOk() const { return GetData() != NULL
; }
2305 // Gets the extension for the block's type
2306 wxString
GetExtension() const;
2310 // Allocate and read from stream as a block of memory
2311 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
2312 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
2314 // Write memory block to stream
2315 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
2317 // Write memory block to file
2318 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
2321 // Size in bytes of the image stored.
2322 // This is in the raw, original form such as a JPEG file.
2323 unsigned char* m_data
;
2325 wxBitmapType m_imageType
;
2329 * wxRichTextImage class declaration
2330 * This object represents an image.
2333 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextObject
2335 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
2339 wxRichTextImage(wxRichTextObject
* parent
= NULL
): wxRichTextObject(parent
) { }
2340 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
2341 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
2342 wxRichTextImage(const wxRichTextImage
& obj
): wxRichTextObject(obj
) { Copy(obj
); }
2347 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
2349 /// Lay the item out
2350 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
2352 /// Get the object size for the given range. Returns false if the range
2353 /// is invalid for this object.
2354 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
2356 /// Get the 'natural' size for an object. For an image, it would be the
2358 virtual wxTextAttrSize
GetNaturalSize() const;
2360 /// Returns true if the object is empty. An image is never empty; if the image is broken, that's not the same thing as empty.
2361 virtual bool IsEmpty() const { return false; /* !m_imageBlock.Ok(); */ }
2363 /// Can we edit properties via a GUI?
2364 virtual bool CanEditProperties() const { return true; }
2366 /// Edit properties via a GUI
2367 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
2369 /// Return the label to be used for the properties context menu item.
2370 virtual wxString
GetPropertiesMenuLabel() const { return _("&Picture"); }
2372 /// Does this object take note of paragraph attributes? Text and image objects don't.
2373 virtual bool UsesParagraphAttributes() const { return false; }
2376 /// Import this object from XML
2377 virtual bool ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
);
2380 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2381 /// Export this object directly to the given stream.
2382 virtual bool ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
);
2385 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2386 /// Export this object to the given parent node, usually creating at least one child node.
2387 virtual bool ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
);
2390 // Images can be floatable (optionally).
2391 virtual bool IsFloatable() const { return true; }
2393 /// What is the XML node name of this object?
2394 virtual wxString
GetXMLNodeName() const { return wxT("image"); }
2398 /// Get the image cache (scaled bitmap)
2399 const wxBitmap
& GetImageCache() const { return m_imageCache
; }
2401 /// Set the image cache
2402 void SetImageCache(const wxBitmap
& bitmap
) { m_imageCache
= bitmap
; }
2404 /// Reset the image cache
2405 void ResetImageCache() { m_imageCache
= wxNullBitmap
; }
2407 /// Get the image block containing the raw data
2408 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
2413 void Copy(const wxRichTextImage
& obj
);
2416 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
2418 /// Create a cached image at the required size
2419 virtual bool LoadImageCache(wxDC
& dc
, bool resetCache
= false);
2422 wxRichTextImageBlock m_imageBlock
;
2423 wxBitmap m_imageCache
;
2428 * wxRichTextBuffer class declaration
2429 * This is a kind of box, used to represent the whole buffer
2432 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand
;
2433 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
2435 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
2437 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
2441 wxRichTextBuffer() { Init(); }
2442 wxRichTextBuffer(const wxRichTextBuffer
& obj
): wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
2443 virtual ~wxRichTextBuffer() ;
2447 /// Gets the command processor
2448 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
2450 /// Set style sheet, if any.
2451 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
2452 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
2454 /// Set style sheet and notify of the change
2455 bool SetStyleSheetAndNotify(wxRichTextStyleSheet
* sheet
);
2457 /// Push style sheet to top of stack
2458 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
2460 /// Pop style sheet from top of stack
2461 wxRichTextStyleSheet
* PopStyleSheet();
2463 /// Set/get table storing fonts
2464 wxRichTextFontTable
& GetFontTable() { return m_fontTable
; }
2465 const wxRichTextFontTable
& GetFontTable() const { return m_fontTable
; }
2466 void SetFontTable(const wxRichTextFontTable
& table
) { m_fontTable
= table
; }
2473 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
2474 virtual void ResetAndClearCommands();
2477 virtual bool LoadFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
2480 virtual bool SaveFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
2482 /// Load from a stream
2483 virtual bool LoadFile(wxInputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
2485 /// Save to a stream
2486 virtual bool SaveFile(wxOutputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
2488 /// Set the handler flags, controlling loading and saving
2489 void SetHandlerFlags(int flags
) { m_handlerFlags
= flags
; }
2491 /// Get the handler flags, controlling loading and saving
2492 int GetHandlerFlags() const { return m_handlerFlags
; }
2494 /// Convenience function to add a paragraph of text
2495 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
, paraStyle
); }
2497 /// Begin collapsing undo/redo commands. Note that this may not work properly
2498 /// if combining commands that delete or insert content, changing ranges for
2499 /// subsequent actions.
2500 virtual bool BeginBatchUndo(const wxString
& cmdName
);
2502 /// End collapsing undo/redo commands
2503 virtual bool EndBatchUndo();
2505 /// Collapsing commands?
2506 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
2508 /// Submit immediately, or delay according to whether collapsing is on
2509 virtual bool SubmitAction(wxRichTextAction
* action
);
2511 /// Get collapsed command
2512 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
2514 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
2515 /// differently by each command. If not dealt with by a command implementation, then
2516 /// it will be implemented automatically by not storing the command in the undo history
2517 /// when the action is submitted to the command processor.
2518 virtual bool BeginSuppressUndo();
2520 /// End suppressing undo/redo commands.
2521 virtual bool EndSuppressUndo();
2523 /// Collapsing commands?
2524 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
2526 /// Copy the range to the clipboard
2527 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
2529 /// Paste the clipboard content to the buffer
2530 virtual bool PasteFromClipboard(long position
);
2532 /// Can we paste from the clipboard?
2533 virtual bool CanPasteFromClipboard() const;
2535 /// Begin using a style
2536 virtual bool BeginStyle(const wxRichTextAttr
& style
);
2539 virtual bool EndStyle();
2542 virtual bool EndAllStyles();
2544 /// Clear the style stack
2545 virtual void ClearStyleStack();
2547 /// Get the size of the style stack, for example to check correct nesting
2548 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
2550 /// Begin using bold
2554 bool EndBold() { return EndStyle(); }
2556 /// Begin using italic
2559 /// End using italic
2560 bool EndItalic() { return EndStyle(); }
2562 /// Begin using underline
2563 bool BeginUnderline();
2565 /// End using underline
2566 bool EndUnderline() { return EndStyle(); }
2568 /// Begin using point size
2569 bool BeginFontSize(int pointSize
);
2571 /// End using point size
2572 bool EndFontSize() { return EndStyle(); }
2574 /// Begin using this font
2575 bool BeginFont(const wxFont
& font
);
2577 /// End using a font
2578 bool EndFont() { return EndStyle(); }
2580 /// Begin using this colour
2581 bool BeginTextColour(const wxColour
& colour
);
2583 /// End using a colour
2584 bool EndTextColour() { return EndStyle(); }
2586 /// Begin using alignment
2587 bool BeginAlignment(wxTextAttrAlignment alignment
);
2590 bool EndAlignment() { return EndStyle(); }
2592 /// Begin left indent
2593 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
2596 bool EndLeftIndent() { return EndStyle(); }
2598 /// Begin right indent
2599 bool BeginRightIndent(int rightIndent
);
2601 /// End right indent
2602 bool EndRightIndent() { return EndStyle(); }
2604 /// Begin paragraph spacing
2605 bool BeginParagraphSpacing(int before
, int after
);
2607 /// End paragraph spacing
2608 bool EndParagraphSpacing() { return EndStyle(); }
2610 /// Begin line spacing
2611 bool BeginLineSpacing(int lineSpacing
);
2613 /// End line spacing
2614 bool EndLineSpacing() { return EndStyle(); }
2616 /// Begin numbered bullet
2617 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
2619 /// End numbered bullet
2620 bool EndNumberedBullet() { return EndStyle(); }
2622 /// Begin symbol bullet
2623 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
2625 /// End symbol bullet
2626 bool EndSymbolBullet() { return EndStyle(); }
2628 /// Begin standard bullet
2629 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
2631 /// End standard bullet
2632 bool EndStandardBullet() { return EndStyle(); }
2634 /// Begin named character style
2635 bool BeginCharacterStyle(const wxString
& characterStyle
);
2637 /// End named character style
2638 bool EndCharacterStyle() { return EndStyle(); }
2640 /// Begin named paragraph style
2641 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
2643 /// End named character style
2644 bool EndParagraphStyle() { return EndStyle(); }
2646 /// Begin named list style
2647 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
2649 /// End named character style
2650 bool EndListStyle() { return EndStyle(); }
2653 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
);
2656 bool EndURL() { return EndStyle(); }
2660 /// Add an event handler
2661 bool AddEventHandler(wxEvtHandler
* handler
);
2663 /// Remove an event handler
2664 bool RemoveEventHandler(wxEvtHandler
* handler
, bool deleteHandler
= false);
2666 /// Clear event handlers
2667 void ClearEventHandlers();
2669 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
2670 /// otherwise will stop at the first successful one.
2671 bool SendEvent(wxEvent
& event
, bool sendToAll
= true);
2675 /// Hit-testing: returns a flag indicating hit test details, plus
2676 /// information about position
2677 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
, wxRichTextObject
** obj
, wxRichTextObject
** contextObj
, int flags
= 0);
2680 void Copy(const wxRichTextBuffer
& obj
);
2683 void operator= (const wxRichTextBuffer
& obj
) { Copy(obj
); }
2686 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
2688 /// Submit command to insert paragraphs
2689 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2691 /// Submit command to insert the given text
2692 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2694 /// Submit command to insert a newline
2695 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2697 /// Submit command to insert the given image
2698 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
= 0,
2699 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
2701 /// Submit command to insert an object
2702 wxRichTextObject
* InsertObjectWithUndo(long pos
, wxRichTextObject
*object
, wxRichTextCtrl
* ctrl
, int flags
);
2704 /// Submit command to delete this range
2705 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, wxRichTextCtrl
* ctrl
);
2708 void Modify(bool modify
= true) { m_modified
= modify
; }
2709 bool IsModified() const { return m_modified
; }
2711 /// Dumps contents of buffer for debugging purposes
2712 virtual void Dump();
2713 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
2715 /// Returns the file handlers
2716 static wxList
& GetHandlers() { return sm_handlers
; }
2718 /// Adds a handler to the end
2719 static void AddHandler(wxRichTextFileHandler
*handler
);
2721 /// Inserts a handler at the front
2722 static void InsertHandler(wxRichTextFileHandler
*handler
);
2724 /// Removes a handler
2725 static bool RemoveHandler(const wxString
& name
);
2727 /// Finds a handler by name
2728 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
2730 /// Finds a handler by extension and type
2731 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, wxRichTextFileType imageType
);
2733 /// Finds a handler by filename or, if supplied, type
2734 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
,
2735 wxRichTextFileType imageType
);
2737 /// Finds a handler by type
2738 static wxRichTextFileHandler
*FindHandler(wxRichTextFileType imageType
);
2740 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
2741 /// will be filled with the file type corresponding to each filter. This can be
2742 /// used to determine the type to pass to LoadFile given a selected filter.
2743 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
2745 /// Clean up handlers
2746 static void CleanUpHandlers();
2748 /// Initialise the standard handlers
2749 static void InitStandardHandlers();
2752 static wxRichTextRenderer
* GetRenderer() { return sm_renderer
; }
2754 /// Set renderer, deleting old one
2755 static void SetRenderer(wxRichTextRenderer
* renderer
);
2757 /// Minimum margin between bullet and paragraph in 10ths of a mm
2758 static int GetBulletRightMargin() { return sm_bulletRightMargin
; }
2759 static void SetBulletRightMargin(int margin
) { sm_bulletRightMargin
= margin
; }
2761 /// Factor to multiply by character height to get a reasonable bullet size
2762 static float GetBulletProportion() { return sm_bulletProportion
; }
2763 static void SetBulletProportion(float prop
) { sm_bulletProportion
= prop
; }
2765 /// Scale factor for calculating dimensions
2766 double GetScale() const { return m_scale
; }
2767 void SetScale(double scale
) { m_scale
= scale
; }
2771 /// Command processor
2772 wxCommandProcessor
* m_commandProcessor
;
2774 /// Table storing fonts
2775 wxRichTextFontTable m_fontTable
;
2777 /// Has been modified?
2780 /// Collapsed command stack
2781 int m_batchedCommandDepth
;
2783 /// Name for collapsed command
2784 wxString m_batchedCommandsName
;
2786 /// Current collapsed command accumulating actions
2787 wxRichTextCommand
* m_batchedCommand
;
2789 /// Whether to suppress undo
2792 /// Style sheet, if any
2793 wxRichTextStyleSheet
* m_styleSheet
;
2795 /// List of event handlers that will be notified of events
2796 wxList m_eventHandlers
;
2798 /// Stack of attributes for convenience functions
2799 wxList m_attributeStack
;
2801 /// Flags to be passed to handlers
2805 static wxList sm_handlers
;
2808 static wxRichTextRenderer
* sm_renderer
;
2810 /// Minimum margin between bullet and paragraph in 10ths of a mm
2811 static int sm_bulletRightMargin
;
2813 /// Factor to multiply by character height to get a reasonable bullet size
2814 static float sm_bulletProportion
;
2816 /// Scaling factor in use: needed to calculate correct dimensions when printing
2821 @class wxRichTextCell
2823 wxRichTextCell is the cell in a table.
2826 class WXDLLIMPEXP_RICHTEXT wxRichTextCell
: public wxRichTextBox
2828 DECLARE_DYNAMIC_CLASS(wxRichTextCell
)
2833 Default constructor; optionally pass the parent object.
2836 wxRichTextCell(wxRichTextObject
* parent
= NULL
);
2842 wxRichTextCell(const wxRichTextCell
& obj
): wxRichTextBox() { Copy(obj
); }
2850 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
2853 Returns the XML node name of this object.
2856 virtual wxString
GetXMLNodeName() const { return wxT("cell"); }
2858 /// Can we edit properties via a GUI?
2859 virtual bool CanEditProperties() const { return true; }
2861 /// Edit properties via a GUI
2862 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
2864 /// Return the label to be used for the properties context menu item.
2865 virtual wxString
GetPropertiesMenuLabel() const { return _("&Cell"); }
2872 Makes a clone of this object.
2874 virtual wxRichTextObject
* Clone() const { return new wxRichTextCell(*this); }
2879 void Copy(const wxRichTextCell
& obj
);
2885 @class wxRichTextTable
2887 wxRichTextTable represents a table with arbitrary columns and rows.
2890 WX_DEFINE_ARRAY_PTR(wxRichTextObject
*, wxRichTextObjectPtrArray
);
2891 WX_DECLARE_OBJARRAY(wxRichTextObjectPtrArray
, wxRichTextObjectPtrArrayArray
);
2893 class WXDLLIMPEXP_RICHTEXT wxRichTextTable
: public wxRichTextBox
2895 DECLARE_DYNAMIC_CLASS(wxRichTextTable
)
2901 Default constructor; optionally pass the parent object.
2904 wxRichTextTable(wxRichTextObject
* parent
= NULL
);
2910 wxRichTextTable(const wxRichTextTable
& obj
): wxRichTextBox() { Copy(obj
); }
2914 // Draws the object.
2915 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextSelection
& selection
, const wxRect
& rect
, int descent
, int style
);
2917 // Returns the XML node name of this object.
2918 virtual wxString
GetXMLNodeName() const { return wxT("table"); }
2920 // Lays the object out.
2921 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
2923 // Gets the range size.
2924 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
2926 // Deletes content in the given range.
2927 virtual bool DeleteRange(const wxRichTextRange
& range
);
2929 // Gets any text in this object for the given range.
2930 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
2933 // Import this object from XML
2934 virtual bool ImportFromXML(wxRichTextBuffer
* buffer
, wxXmlNode
* node
, wxRichTextXMLHandler
* handler
, bool* recurse
);
2937 #if wxRICHTEXT_HAVE_DIRECT_OUTPUT
2938 // Export this object directly to the given stream.
2939 virtual bool ExportXML(wxOutputStream
& stream
, int indent
, wxRichTextXMLHandler
* handler
);
2942 #if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
2943 // Export this object to the given parent node, usually creating at least one child node.
2944 virtual bool ExportXML(wxXmlNode
* parent
, wxRichTextXMLHandler
* handler
);
2947 /// Finds the absolute position and row height for the given character position
2948 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
2951 virtual void CalculateRange(long start
, long& end
);
2953 /// Can this object handle the selections of its children? FOr example, a table.
2954 virtual bool HandlesChildSelections() const { return true; }
2956 /// Returns a selection object specifying the selections between start and end character positions.
2957 /// For example, a table would deduce what cells (of range length 1) are selected when dragging across the table.
2958 virtual wxRichTextSelection
GetSelection(long start
, long end
) const;
2960 /// Can we edit properties via a GUI?
2961 virtual bool CanEditProperties() const { return true; }
2963 /// Edit properties via a GUI
2964 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
2966 /// Return the label to be used for the properties context menu item.
2967 virtual wxString
GetPropertiesMenuLabel() const { return _("&Table"); }
2969 /// Returns true if objects of this class can accept the focus, i.e. a call to SetFocusObject
2970 /// is possible. For example, containers supporting text, such as a text box object, can accept the focus,
2971 /// but a table can't (set the focus to individual cells instead).
2972 virtual bool AcceptsFocus() const { return false; }
2976 const wxRichTextObjectPtrArrayArray
& GetCells() const { return m_cells
; }
2977 wxRichTextObjectPtrArrayArray
& GetCells() { return m_cells
; }
2979 int GetRowCount() const { return m_rowCount
; }
2980 int GetColumnCount() const { return m_colCount
; }
2982 /// Get the cell at the given row/column position
2983 virtual wxRichTextCell
* GetCell(int row
, int col
) const;
2985 /// Get the cell at the given character position (in the range of the table).
2986 virtual wxRichTextCell
* GetCell(long pos
) const;
2988 /// Get the row/column for a given character position
2989 virtual bool GetCellRowColumnPosition(long pos
, int& row
, int& col
) const;
2997 virtual void ClearTable();
3000 Creates a table of the given dimensions.
3003 virtual bool CreateTable(int rows
, int cols
);
3006 Sets the attributes for the cells specified by the selection.
3009 virtual bool SetCellStyle(const wxRichTextSelection
& selection
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
3012 Deletes rows from the given row position.
3015 virtual bool DeleteRows(int startRow
, int noRows
= 1);
3018 Deletes columns from the given column position.
3021 virtual bool DeleteColumns(int startCol
, int noCols
= 1);
3024 Adds rows from the given row position.
3027 virtual bool AddRows(int startRow
, int noRows
= 1, const wxRichTextAttr
& attr
= wxRichTextAttr());
3030 Adds columns from the given column position.
3033 virtual bool AddColumns(int startCol
, int noCols
= 1, const wxRichTextAttr
& attr
= wxRichTextAttr());
3035 // Makes a clone of this object.
3036 virtual wxRichTextObject
* Clone() const { return new wxRichTextTable(*this); }
3038 // Copies this object.
3039 void Copy(const wxRichTextTable
& obj
);
3046 // An array of rows, each of which is a wxRichTextObjectPtrArray containing
3047 // the cell objects. The cell objects are also children of this object.
3048 // Problem: if boxes are immediate children of a box, this will cause problems
3049 // with wxRichTextParagraphLayoutBox functions (and functions elsewhere) that
3050 // expect to find just paragraphs. May have to adjust the way we handle the
3051 // hierarchy to accept non-paragraph objects in a a paragraph layout box.
3052 // We'll be overriding much wxRichTextParagraphLayoutBox functionality so this
3053 // may not be such a problem. Perhaps the table should derive from a different
3055 wxRichTextObjectPtrArrayArray m_cells
;
3060 * The command identifiers
3064 enum wxRichTextCommandId
3068 wxRICHTEXT_CHANGE_ATTRIBUTES
,
3069 wxRICHTEXT_CHANGE_STYLE
,
3070 wxRICHTEXT_CHANGE_OBJECT
3074 * A class for specifying an object anywhere in an object hierarchy,
3075 * without using a pointer, necessary since wxRTC commands may delete
3076 * and recreate sub-objects so physical object addresses change. An array
3077 * of positions (one per hierarchy level) is used.
3081 class WXDLLIMPEXP_RICHTEXT wxRichTextObjectAddress
3084 // Creates the address given container and object.
3085 wxRichTextObjectAddress(wxRichTextParagraphLayoutBox
* topLevelContainer
, wxRichTextObject
* obj
) { Create(topLevelContainer
, obj
); }
3086 wxRichTextObjectAddress() { Init(); }
3087 wxRichTextObjectAddress(const wxRichTextObjectAddress
& address
) { Copy(address
); }
3090 void Copy(const wxRichTextObjectAddress
& address
) { m_address
= address
.m_address
; }
3091 void operator=(const wxRichTextObjectAddress
& address
) { Copy(address
); }
3093 wxRichTextObject
* GetObject(wxRichTextParagraphLayoutBox
* topLevelContainer
) const;
3094 bool Create(wxRichTextParagraphLayoutBox
* topLevelContainer
, wxRichTextObject
* obj
);
3096 wxArrayInt
& GetAddress() { return m_address
; }
3097 const wxArrayInt
& GetAddress() const { return m_address
; }
3098 void SetAddress(const wxArrayInt
& address
) { m_address
= address
; }
3102 wxArrayInt m_address
;
3106 * Command classes for undo/redo
3110 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
3111 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
3114 // Ctor for one action
3115 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
3116 wxRichTextParagraphLayoutBox
* container
, wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
3118 // Ctor for multiple actions
3119 wxRichTextCommand(const wxString
& name
);
3121 virtual ~wxRichTextCommand();
3126 void AddAction(wxRichTextAction
* action
);
3127 void ClearActions();
3129 wxList
& GetActions() { return m_actions
; }
3137 * wxRichTextAction class declaration
3138 * There can be more than one action in a command.
3141 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
3144 /// Constructor. 'buffer' is the top-level buffer, while 'container' is the object within
3145 /// which the action is taking place. In the simplest case, they are the same.
3146 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
,
3147 wxRichTextBuffer
* buffer
, wxRichTextParagraphLayoutBox
* container
,
3148 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
3150 virtual ~wxRichTextAction();
3155 /// Update the control appearance
3156 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false,
3157 wxArrayInt
* optimizationLineCharPositions
= NULL
, wxArrayInt
* optimizationLineYPositions
= NULL
, bool isDoCmd
= true);
3159 /// Replace the buffer paragraphs with the given fragment.
3160 void ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
);
3162 /// Get the fragments
3163 wxRichTextParagraphLayoutBox
& GetNewParagraphs() { return m_newParagraphs
; }
3164 wxRichTextParagraphLayoutBox
& GetOldParagraphs() { return m_oldParagraphs
; }
3166 /// Get the attributes
3167 wxRichTextAttr
& GetAttributes() { return m_attributes
; }
3169 /// An object to replace the one at the position
3170 /// defined by the container address and the action's range start position.
3171 wxRichTextObject
* GetObject() const { return m_object
; }
3172 void SetObject(wxRichTextObject
* obj
) { m_object
= obj
; m_objectAddress
.Create(m_buffer
, m_object
); }
3173 void MakeObject(wxRichTextObject
* obj
) { m_objectAddress
.Create(m_buffer
, obj
); }
3175 /// Calculate arrays for refresh optimization
3176 void CalculateRefreshOptimizations(wxArrayInt
& optimizationLineCharPositions
, wxArrayInt
& optimizationLineYPositions
);
3178 /// Set/get the position used for e.g. insertion
3179 void SetPosition(long pos
) { m_position
= pos
; }
3180 long GetPosition() const { return m_position
; }
3182 /// Set/get the range for e.g. deletion
3183 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
3184 const wxRichTextRange
& GetRange() const { return m_range
; }
3186 /// The address (nested position) of the container within the buffer being manipulated
3187 wxRichTextObjectAddress
& GetContainerAddress() { return m_containerAddress
; }
3188 const wxRichTextObjectAddress
& GetContainerAddress() const { return m_containerAddress
; }
3189 void SetContainerAddress(const wxRichTextObjectAddress
& address
) { m_containerAddress
= address
; }
3190 void SetContainerAddress(wxRichTextParagraphLayoutBox
* container
, wxRichTextObject
* obj
) { m_containerAddress
.Create(container
, obj
); }
3192 /// Returns the container that this action refers to, using the container address and top-level buffer.
3193 wxRichTextParagraphLayoutBox
* GetContainer() const;
3195 const wxString
& GetName() const { return m_name
; }
3202 wxRichTextBuffer
* m_buffer
;
3204 // The address (nested position) of the container being manipulated.
3205 // This is necessary because objects are deleted, and we can't
3206 // therefore store actual pointers.
3207 wxRichTextObjectAddress m_containerAddress
;
3210 wxRichTextCtrl
* m_ctrl
;
3212 // Stores the new paragraphs
3213 wxRichTextParagraphLayoutBox m_newParagraphs
;
3215 // Stores the old paragraphs
3216 wxRichTextParagraphLayoutBox m_oldParagraphs
;
3218 // Stores an object to replace the one at the position
3219 // defined by the container address and the action's range start position.
3220 wxRichTextObject
* m_object
;
3222 // Stores the attributes
3223 wxRichTextAttr m_attributes
;
3225 // The address of the object being manipulated (used for changing an individual object or its attributes)
3226 wxRichTextObjectAddress m_objectAddress
;
3228 // Stores the old attributes
3229 // wxRichTextAttr m_oldAttributes;
3231 // The affected range
3232 wxRichTextRange m_range
;
3234 // The insertion point for this command
3237 // Ignore 1st 'Do' operation because we already did it
3240 // The command identifier
3241 wxRichTextCommandId m_cmdId
;
3248 // Include style sheet when loading and saving
3249 #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
3251 // Save images to memory file system in HTML handler
3252 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
3254 // Save images to files in HTML handler
3255 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
3257 // Save images as inline base64 data in HTML handler
3258 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
3260 // Don't write header and footer (or BODY), so we can include the fragment
3261 // in a larger document
3262 #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080
3264 // Convert the more common face names to names that will work on the current platform
3265 // in a larger document
3266 #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100
3269 * wxRichTextFileHandler
3270 * Base class for file handlers
3273 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
3275 DECLARE_CLASS(wxRichTextFileHandler
)
3277 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
3278 : m_name(name
), m_extension(ext
), m_type(type
), m_flags(0), m_visible(true)
3282 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
3283 { return DoLoadFile(buffer
, stream
); }
3284 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
3285 { return DoSaveFile(buffer
, stream
); }
3288 #if wxUSE_FFILE && wxUSE_STREAMS
3289 virtual bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
3290 virtual bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
3291 #endif // wxUSE_STREAMS && wxUSE_STREAMS
3293 /// Can we handle this filename (if using files)? By default, checks the extension.
3294 virtual bool CanHandle(const wxString
& filename
) const;
3296 /// Can we save using this handler?
3297 virtual bool CanSave() const { return false; }
3299 /// Can we load using this handler?
3300 virtual bool CanLoad() const { return false; }
3302 /// Should this handler be visible to the user?
3303 virtual bool IsVisible() const { return m_visible
; }
3304 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
3306 /// The name of the nandler
3307 void SetName(const wxString
& name
) { m_name
= name
; }
3308 wxString
GetName() const { return m_name
; }
3310 /// The default extension to recognise
3311 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
3312 wxString
GetExtension() const { return m_extension
; }
3314 /// The handler type
3315 void SetType(int type
) { m_type
= type
; }
3316 int GetType() const { return m_type
; }
3318 /// Flags controlling how loading and saving is done
3319 void SetFlags(int flags
) { m_flags
= flags
; }
3320 int GetFlags() const { return m_flags
; }
3322 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
3323 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
3324 const wxString
& GetEncoding() const { return m_encoding
; }
3329 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
3330 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
3334 wxString m_encoding
;
3335 wxString m_extension
;
3342 * wxRichTextPlainTextHandler
3343 * Plain text handler
3346 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
3348 DECLARE_CLASS(wxRichTextPlainTextHandler
)
3350 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"),
3351 const wxString
& ext
= wxT("txt"),
3352 wxRichTextFileType type
= wxRICHTEXT_TYPE_TEXT
)
3353 : wxRichTextFileHandler(name
, ext
, type
)
3356 /// Can we save using this handler?
3357 virtual bool CanSave() const { return true; }
3359 /// Can we load using this handler?
3360 virtual bool CanLoad() const { return true; }
3365 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
3366 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
3374 * The data object for a wxRichTextBuffer
3377 class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject
: public wxDataObjectSimple
3380 // ctor doesn't copy the pointer, so it shouldn't go away while this object
3382 wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
= NULL
);
3383 virtual ~wxRichTextBufferDataObject();
3385 // after a call to this function, the buffer is owned by the caller and it
3386 // is responsible for deleting it
3387 wxRichTextBuffer
* GetRichTextBuffer();
3389 // Returns the id for the new data format
3390 static const wxChar
* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId
; }
3392 // base class pure virtuals
3394 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
3395 virtual size_t GetDataSize() const;
3396 virtual bool GetDataHere(void *pBuf
) const;
3397 virtual bool SetData(size_t len
, const void *buf
);
3401 virtual size_t GetDataSize(const wxDataFormat
&) const { return GetDataSize(); }
3402 virtual bool GetDataHere(const wxDataFormat
&, void *buf
) const { return GetDataHere(buf
); }
3403 virtual bool SetData(const wxDataFormat
&, size_t len
, const void *buf
) { return SetData(len
, buf
); }
3406 wxDataFormat m_formatRichTextBuffer
; // our custom format
3407 wxRichTextBuffer
* m_richTextBuffer
; // our data
3408 static const wxChar
* ms_richTextBufferFormatId
; // our format id
3414 * wxRichTextRenderer isolates common drawing functionality
3417 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer
: public wxObject
3420 wxRichTextRenderer() {}
3421 virtual ~wxRichTextRenderer() {}
3423 /// Draw a standard bullet, as specified by the value of GetBulletName
3424 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
) = 0;
3426 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
3427 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
) = 0;
3429 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
3430 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
) = 0;
3432 /// Enumerate the standard bullet names currently supported
3433 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
) = 0;
3437 * wxRichTextStdRenderer: standard renderer
3440 class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer
: public wxRichTextRenderer
3443 wxRichTextStdRenderer() {}
3445 /// Draw a standard bullet, as specified by the value of GetBulletName
3446 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
);
3448 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
3449 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
);
3451 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
3452 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
);
3454 /// Enumerate the standard bullet names currently supported
3455 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
);
3463 inline bool wxRichTextHasStyle(int flags
, int style
)
3465 return ((flags
& style
) == style
);
3468 /// Compare two attribute objects
3469 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
3470 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
3472 /// Compare two attribute objects, but take into account the flags
3473 /// specifying attributes of interest.
3474 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEqPartial(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
3476 /// Apply one style to another
3477 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
= NULL
);
3479 // Remove attributes
3480 WXDLLIMPEXP_RICHTEXT
bool wxRichTextRemoveStyle(wxRichTextAttr
& destStyle
, const wxRichTextAttr
& style
);
3482 /// Combine two bitlists
3483 WXDLLIMPEXP_RICHTEXT
bool wxRichTextCombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
);
3485 /// Compare two bitlists
3486 WXDLLIMPEXP_RICHTEXT
bool wxRichTextBitlistsEqPartial(int valueA
, int valueB
, int flags
);
3488 /// Split into paragraph and character styles
3489 WXDLLIMPEXP_RICHTEXT
bool wxRichTextSplitParaCharStyles(const wxRichTextAttr
& style
, wxRichTextAttr
& parStyle
, wxRichTextAttr
& charStyle
);
3492 WXDLLIMPEXP_RICHTEXT
bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
);
3494 /// Convert a decimal to Roman numerals
3495 WXDLLIMPEXP_RICHTEXT wxString
wxRichTextDecimalToRoman(long n
);
3497 // Collects the attributes that are common to a range of content, building up a note of
3498 // which attributes are absent in some objects and which clash in some objects.
3499 WXDLLIMPEXP_RICHTEXT
void wxTextAttrCollectCommonAttributes(wxTextAttr
& currentStyle
, const wxTextAttr
& attr
, wxTextAttr
& clashingAttr
, wxTextAttr
& absentAttr
);
3501 WXDLLIMPEXP_RICHTEXT
void wxRichTextModuleInit();
3507 // _WX_RICHTEXTBUFFER_H_