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"
70 #include "wx/dataobj.h"
74 //#define wxRichTextAttr wxTextAttr
75 #define wxTextAttrEx wxTextAttr
77 // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a
78 // caret reliably without using wxClientDC in case there
79 // are platform-specific problems with the generic caret.
80 #if defined(__WXGTK__) || defined(__WXMAC__)
81 #define wxRICHTEXT_USE_OWN_CARET 1
83 #define wxRICHTEXT_USE_OWN_CARET 0
86 // Switch off for binary compatibility, on for faster drawing
87 // Note: this seems to be buggy (overzealous use of extents) so
89 #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0
95 extern WXDLLIMPEXP_RICHTEXT
const wxChar wxRichTextLineBreakChar
;
98 * File types in wxRichText context.
100 enum wxRichTextFileType
102 wxRICHTEXT_TYPE_ANY
= 0,
103 wxRICHTEXT_TYPE_TEXT
,
105 wxRICHTEXT_TYPE_HTML
,
111 * Forward declarations
114 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl
;
115 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject
;
116 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage
;
117 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject
;
118 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList
;
119 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine
;
120 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph
;
121 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler
;
122 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet
;
123 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition
;
124 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent
;
125 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer
;
126 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer
;
127 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAnchoredObject
;
128 class wxRichTextFloatCollector
;
131 * Flags determining the available space, passed to Layout
134 #define wxRICHTEXT_FIXED_WIDTH 0x01
135 #define wxRICHTEXT_FIXED_HEIGHT 0x02
136 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
137 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
139 // Only lay out the part of the buffer that lies within
140 // the rect passed to Layout.
141 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
144 * Flags to pass to Draw
147 // Ignore paragraph cache optimization, e.g. for printing purposes
148 // where one line may be drawn higher (on the next page) compared
149 // with the previous line
150 #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
153 * Flags returned from hit-testing
155 enum wxRichTextHitTestFlags
157 // The point was not on this object
158 wxRICHTEXT_HITTEST_NONE
= 0x01,
160 // The point was before the position returned from HitTest
161 wxRICHTEXT_HITTEST_BEFORE
= 0x02,
163 // The point was after the position returned from HitTest
164 wxRICHTEXT_HITTEST_AFTER
= 0x04,
166 // The point was on the position returned from HitTest
167 wxRICHTEXT_HITTEST_ON
= 0x08,
169 // The point was on space outside content
170 wxRICHTEXT_HITTEST_OUTSIDE
= 0x10
174 * Flags for GetRangeSize
177 #define wxRICHTEXT_FORMATTED 0x01
178 #define wxRICHTEXT_UNFORMATTED 0x02
179 #define wxRICHTEXT_CACHE_SIZE 0x04
180 #define wxRICHTEXT_HEIGHT_ONLY 0x08
183 * Flags for SetStyle/SetListStyle
186 #define wxRICHTEXT_SETSTYLE_NONE 0x00
188 // Specifies that this operation should be undoable
189 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
191 // Specifies that the style should not be applied if the
192 // combined style at this point is already the style in question.
193 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
195 // Specifies that the style should only be applied to paragraphs,
196 // and not the content. This allows content styling to be
197 // preserved independently from that of e.g. a named paragraph style.
198 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
200 // Specifies that the style should only be applied to characters,
201 // and not the paragraph. This allows content styling to be
202 // preserved independently from that of e.g. a named paragraph style.
203 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
205 // For SetListStyle only: specifies starting from the given number, otherwise
206 // deduces number from existing attributes
207 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
209 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
210 // the current indentation will be used
211 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
213 // Resets the existing style before applying the new style
214 #define wxRICHTEXT_SETSTYLE_RESET 0x40
216 // Removes the given style instead of applying it
217 #define wxRICHTEXT_SETSTYLE_REMOVE 0x80
220 * Flags for text insertion
223 #define wxRICHTEXT_INSERT_NONE 0x00
224 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
225 #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
227 // A special flag telling the buffer to keep the first paragraph style
228 // as-is, when deleting a paragraph marker. In future we might pass a
229 // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
230 #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
233 * Default superscript/subscript font multiplication factor
236 #define wxSCRIPT_MUL_FACTOR 1.5
238 typedef unsigned short wxTextAttrDimensionFlags
;
240 // Miscelaneous text box flags
241 enum wxTextBoxAttrFlags
243 wxTEXT_BOX_ATTR_FLOAT
= 0x00000001,
244 wxTEXT_BOX_ATTR_CLEAR
= 0x00000002,
245 wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
= 0x00000004
248 // Whether a value is present, used in dimension flags
249 enum wxTextAttrValueFlags
251 wxTEXT_ATTR_VALUE_PRESENT
= 0x1000,
252 wxTEXT_ATTR_VALUE_PRESENT_MASK
= 0x1000
255 // Units - included in the dimension value
258 wxTEXT_ATTR_UNITS_TENTHS_MM
= 0x0001,
259 wxTEXT_ATTR_UNITS_PIXELS
= 0x0002,
260 wxTEXT_ATTR_UNITS_PERCENTAGE
= 0x0004,
261 wxTEXT_ATTR_UNITS_POINTS
= 0x0008,
263 wxTEXT_ATTR_UNITS_MASK
= 0x000F
266 // Position - included in the dimension flags
267 enum wxTextBoxAttrPosition
269 wxTEXT_BOX_ATTR_POSITION_STATIC
= 0x0000, // Default is static, i.e. as per normal layout
270 wxTEXT_BOX_ATTR_POSITION_RELATIVE
= 0x0010,
271 wxTEXT_BOX_ATTR_POSITION_ABSOLUTE
= 0x0020,
273 wxTEXT_BOX_ATTR_POSITION_MASK
= 0x00F0
276 // Dimension, including units and position
277 class WXDLLIMPEXP_CORE wxTextAttrDimension
280 wxTextAttrDimension() { Reset(); }
281 wxTextAttrDimension(int value
, wxTextAttrDimensionFlags flags
= wxTEXT_ATTR_VALUE_PRESENT
|wxTEXT_ATTR_UNITS_TENTHS_MM
) { m_value
= value
; m_flags
= flags
; }
283 void Reset() { m_value
= 0; m_flags
= 0; }
285 // Partial equality test
286 bool EqPartial(const wxTextAttrDimension
& dim
) const;
289 bool Apply(const wxTextAttrDimension
& dim
, const wxTextAttrDimension
* compareWith
= NULL
);
291 // Collects the attributes that are common to a range of content, building up a note of
292 // which attributes are absent in some objects and which clash in some objects.
293 void CollectCommonAttributes(const wxTextAttrDimension
& attr
, wxTextAttrDimension
& clashingAttr
, wxTextAttrDimension
& absentAttr
);
295 bool operator==(const wxTextAttrDimension
& dim
) const { return m_value
== dim
.m_value
&& m_flags
== dim
.m_flags
; }
297 int GetValue() const { return m_value
; }
298 float GetValueMM() const { return float(m_value
) / 10.0; }
299 void SetValueMM(float value
) { m_value
= (int) ((value
* 10.0) + 0.5); m_flags
|= wxTEXT_ATTR_VALUE_PRESENT
; }
300 void SetValue(int value
) { m_value
= value
; m_flags
|= wxTEXT_ATTR_VALUE_PRESENT
; }
301 void SetValue(int value
, wxTextAttrDimensionFlags flags
) { m_value
= value
; m_flags
= flags
; }
303 wxTextAttrUnits
GetUnits() const { return (wxTextAttrUnits
) (m_flags
& wxTEXT_ATTR_UNITS_MASK
); }
304 void SetUnits(wxTextAttrUnits units
) { m_flags
&= ~wxTEXT_ATTR_UNITS_MASK
; m_flags
|= units
; }
306 wxTextBoxAttrPosition
GetPosition() const { return (wxTextBoxAttrPosition
) (m_flags
& wxTEXT_BOX_ATTR_POSITION_MASK
); }
307 void SetPosition(wxTextBoxAttrPosition pos
) { m_flags
&= ~wxTEXT_BOX_ATTR_POSITION_MASK
; m_flags
|= pos
; }
309 bool IsPresent() const { return (m_flags
& wxTEXT_ATTR_VALUE_PRESENT
) != 0; }
310 void SetPresent(bool b
) { m_flags
&= ~wxTEXT_ATTR_VALUE_PRESENT_MASK
; m_flags
|= (b
? wxTEXT_ATTR_VALUE_PRESENT
: 0); }
313 wxTextAttrDimensionFlags m_flags
;
316 class WXDLLIMPEXP_CORE wxTextBoxAttrDimensions
319 void Reset() { m_left
.Reset(); m_top
.Reset(); m_right
.Reset(); m_bottom
.Reset(); }
321 bool operator==(const wxTextBoxAttrDimensions
& dims
) const { return m_left
== dims
.m_left
&& m_top
== dims
.m_top
&& m_right
== dims
.m_right
&& m_bottom
== dims
.m_bottom
; }
323 // Partial equality test
324 bool EqPartial(const wxTextBoxAttrDimensions
& dims
) const;
326 // Apply border to 'this', but not if the same as compareWith
327 bool Apply(const wxTextBoxAttrDimensions
& dims
, const wxTextBoxAttrDimensions
* compareWith
= NULL
);
329 // Collects the attributes that are common to a range of content, building up a note of
330 // which attributes are absent in some objects and which clash in some objects.
331 void CollectCommonAttributes(const wxTextBoxAttrDimensions
& attr
, wxTextBoxAttrDimensions
& clashingAttr
, wxTextBoxAttrDimensions
& absentAttr
);
333 // Remove specified attributes from this object
334 bool RemoveStyle(const wxTextBoxAttrDimensions
& attr
);
336 wxTextAttrDimension m_left
;
337 wxTextAttrDimension m_top
;
338 wxTextAttrDimension m_right
;
339 wxTextAttrDimension m_bottom
;
343 enum wxTextBoxAttrBorderStyle
345 wxTEXT_BOX_ATTR_BORDER_NONE
= 0,
346 wxTEXT_BOX_ATTR_BORDER_SOLID
= 1,
347 wxTEXT_BOX_ATTR_BORDER_DOTTED
= 2,
348 wxTEXT_BOX_ATTR_BORDER_DASHED
= 3,
349 wxTEXT_BOX_ATTR_BORDER_DOUBLE
= 4,
350 wxTEXT_BOX_ATTR_BORDER_GROOVE
= 5,
351 wxTEXT_BOX_ATTR_BORDER_RIDGE
= 6,
352 wxTEXT_BOX_ATTR_BORDER_INSET
= 7,
353 wxTEXT_BOX_ATTR_BORDER_OUTSET
= 8
356 // Border style presence flags
357 enum wxTextBoxAttrBorderFlags
359 wxTEXT_BOX_ATTR_BORDER_STYLE
= 0x0001,
360 wxTEXT_BOX_ATTR_BORDER_COLOUR
= 0x0002
364 enum wxTextBoxAttrFloatStyle
366 wxTEXT_BOX_ATTR_FLOAT_NONE
= 0,
367 wxTEXT_BOX_ATTR_FLOAT_LEFT
= 1,
368 wxTEXT_BOX_ATTR_FLOAT_RIGHT
= 2
372 enum wxTextBoxAttrClearStyle
374 wxTEXT_BOX_ATTR_CLEAR_NONE
= 0,
375 wxTEXT_BOX_ATTR_CLEAR_LEFT
= 1,
376 wxTEXT_BOX_ATTR_CLEAR_RIGHT
= 2,
377 wxTEXT_BOX_ATTR_CLEAR_BOTH
= 3
380 // Collapse mode styles. TODO: can they be switched on per side?
381 enum wxTextBoxAttrCollapseMode
383 wxTEXT_BOX_ATTR_COLLAPSE_NONE
= 0,
384 wxTEXT_BOX_ATTR_COLLAPSE_FULL
= 1
388 class WXDLLIMPEXP_CORE wxTextBoxAttrBorder
391 wxTextBoxAttrBorder() { Reset(); }
393 bool operator==(const wxTextBoxAttrBorder
& border
) const
395 return m_flags
== border
.m_flags
&& m_borderStyle
== border
.m_borderStyle
&&
396 m_borderColour
== border
.m_borderColour
&& m_borderWidth
== border
.m_borderWidth
;
399 void Reset() { m_borderStyle
= 0; m_borderColour
= 0; m_flags
= 0; m_borderWidth
.Reset(); }
401 // Partial equality test
402 bool EqPartial(const wxTextBoxAttrBorder
& border
) const;
404 // Apply border to 'this', but not if the same as compareWith
405 bool Apply(const wxTextBoxAttrBorder
& border
, const wxTextBoxAttrBorder
* compareWith
= NULL
);
407 // Remove specified attributes from this object
408 bool RemoveStyle(const wxTextBoxAttrBorder
& attr
);
410 // Collects the attributes that are common to a range of content, building up a note of
411 // which attributes are absent in some objects and which clash in some objects.
412 void CollectCommonAttributes(const wxTextBoxAttrBorder
& attr
, wxTextBoxAttrBorder
& clashingAttr
, wxTextBoxAttrBorder
& absentAttr
);
414 void SetStyle(int style
) { m_borderStyle
= style
; m_flags
|= wxTEXT_BOX_ATTR_BORDER_STYLE
; }
415 int GetStyle() const { return m_borderStyle
; }
417 void SetColour(unsigned long colour
) { m_borderColour
= colour
; m_flags
|= wxTEXT_BOX_ATTR_BORDER_COLOUR
; }
418 void SetColour(const wxColour
& colour
) { m_borderColour
= colour
.GetRGB(); m_flags
|= wxTEXT_BOX_ATTR_BORDER_COLOUR
; }
419 unsigned long GetColourLong() const { return m_borderColour
; }
420 wxColour
GetColour() const { return wxColour(m_borderColour
); }
422 wxTextAttrDimension
& GetWidth() { return m_borderWidth
; }
423 const wxTextAttrDimension
& GetWidth() const { return m_borderWidth
; }
424 void SetWidth(const wxTextAttrDimension
& width
) { m_borderWidth
= width
; }
426 bool HasStyle() const { return (m_flags
& wxTEXT_BOX_ATTR_BORDER_STYLE
) == 0; }
427 bool HasColour() const { return (m_flags
& wxTEXT_BOX_ATTR_BORDER_COLOUR
) == 0; }
428 bool HasWidth() const { return m_borderWidth
.IsPresent(); }
430 int GetFlags() const { return m_flags
; }
431 void SetFlags(int flags
) { m_flags
= flags
; }
432 void AddFlag(int flag
) { m_flags
|= flag
; }
433 void RemoveFlag(int flag
) { m_flags
&= ~flag
; }
436 unsigned long m_borderColour
;
437 wxTextAttrDimension m_borderWidth
;
442 class WXDLLIMPEXP_CORE wxTextBoxAttrBorders
445 wxTextBoxAttrBorders() { }
447 bool operator==(const wxTextBoxAttrBorders
& borders
) const
449 return m_left
== borders
.m_left
&& m_right
== borders
.m_right
&&
450 m_top
== borders
.m_top
&& m_bottom
== borders
.m_bottom
;
453 // Set style of all borders
454 void SetStyle(int style
);
456 // Set colour of all borders
457 void SetColour(unsigned long colour
);
458 void SetColour(const wxColour
& colour
);
460 // Set width of all borders
461 void SetWidth(const wxTextAttrDimension
& width
);
464 void Reset() { m_left
.Reset(); m_right
.Reset(); m_top
.Reset(); m_bottom
.Reset(); }
466 // Partial equality test
467 bool EqPartial(const wxTextBoxAttrBorders
& borders
) const;
469 // Apply border to 'this', but not if the same as compareWith
470 bool Apply(const wxTextBoxAttrBorders
& borders
, const wxTextBoxAttrBorders
* compareWith
= NULL
);
472 // Remove specified attributes from this object
473 bool RemoveStyle(const wxTextBoxAttrBorders
& attr
);
475 // Collects the attributes that are common to a range of content, building up a note of
476 // which attributes are absent in some objects and which clash in some objects.
477 void CollectCommonAttributes(const wxTextBoxAttrBorders
& attr
, wxTextBoxAttrBorders
& clashingAttr
, wxTextBoxAttrBorders
& absentAttr
);
479 wxTextBoxAttrBorder m_left
, m_right
, m_top
, m_bottom
;
483 // ----------------------------------------------------------------------------
484 // wxTextBoxAttr: a structure containing box attributes
485 // ----------------------------------------------------------------------------
487 class WXDLLIMPEXP_CORE wxTextBoxAttr
491 wxTextBoxAttr() { Init(); }
492 wxTextBoxAttr(const wxTextBoxAttr
& attr
) { Init(); (*this) = attr
; }
494 // Initialise this object.
495 void Init() { Reset(); }
497 // Reset this object.
500 // Copy. Unecessary since we let it do a binary copy
501 //void Copy(const wxTextBoxAttr& attr);
504 //void operator= (const wxTextBoxAttr& attr);
507 bool operator== (const wxTextBoxAttr
& attr
) const;
509 // Partial equality test
510 bool EqPartial(const wxTextBoxAttr
& attr
) const;
512 // Merges the given attributes. If compareWith
513 // is non-NULL, then it will be used to mask out those attributes that are the same in style
514 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
515 bool Apply(const wxTextBoxAttr
& style
, const wxTextBoxAttr
* compareWith
= NULL
);
517 // Collects the attributes that are common to a range of content, building up a note of
518 // which attributes are absent in some objects and which clash in some objects.
519 void CollectCommonAttributes(const wxTextBoxAttr
& attr
, wxTextBoxAttr
& clashingAttr
, wxTextBoxAttr
& absentAttr
);
521 // Remove specified attributes from this object
522 bool RemoveStyle(const wxTextBoxAttr
& attr
);
525 void SetFlags(int flags
) { m_flags
= flags
; }
528 int GetFlags() const { return m_flags
; }
530 // Is this flag present?
531 bool HasFlag(wxTextBoxAttrFlags flag
) const { return (m_flags
& flag
) != 0; }
534 void RemoveFlag(wxTextBoxAttrFlags flag
) { m_flags
&= ~flag
; }
537 void AddFlag(wxTextBoxAttrFlags flag
) { m_flags
|= flag
; }
539 // Is this default? I.e. no flags set
540 bool IsDefault() const;
543 short int GetFloatMode() const { return m_floatMode
; }
544 void SetFloatMode(short int mode
) { m_floatMode
= mode
; m_flags
|= wxTEXT_BOX_ATTR_FLOAT
; }
545 bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT
); }
546 bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE
; }
548 // Whether to wrap text after object
549 short int GetClearMode() const { return m_clearMode
; }
550 void SetClearMode(short int mode
) { m_clearMode
= mode
; m_flags
|= wxTEXT_BOX_ATTR_CLEAR
; }
551 bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR
); }
553 // Whether to collapse borders
554 int GetCollapseBorders() const { return m_collapseMode
; }
555 void SetCollapseBorders(int collapse
) { m_collapseMode
= collapse
; m_flags
|= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
; }
556 bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS
); }
560 wxTextAttrDimension
& GetLeftMargin() { return m_margins
.m_left
; }
561 const wxTextAttrDimension
& GetLeftMargin() const { return m_margins
.m_left
; }
563 wxTextAttrDimension
& GetRightMargin() { return m_margins
.m_right
; }
564 const wxTextAttrDimension
& GetRightMargin() const { return m_margins
.m_right
; }
566 wxTextAttrDimension
& GetTopMargin() { return m_margins
.m_top
; }
567 const wxTextAttrDimension
& GetTopMargin() const { return m_margins
.m_top
; }
569 wxTextAttrDimension
& GetBottomMargin() { return m_margins
.m_bottom
; }
570 const wxTextAttrDimension
& GetBottomMargin() const { return m_margins
.m_bottom
; }
574 wxTextAttrDimension
& GetLeft() { return m_position
.m_left
; }
575 const wxTextAttrDimension
& GetLeft() const { return m_position
.m_left
; }
577 wxTextAttrDimension
& GetRight() { return m_position
.m_right
; }
578 const wxTextAttrDimension
& GetRight() const { return m_position
.m_right
; }
580 wxTextAttrDimension
& GetTop() { return m_position
.m_top
; }
581 const wxTextAttrDimension
& GetTop() const { return m_position
.m_top
; }
583 wxTextAttrDimension
& GetBottom() { return m_position
.m_bottom
; }
584 const wxTextAttrDimension
& GetBottom() const { return m_position
.m_bottom
; }
588 wxTextAttrDimension
& GetLeftPadding() { return m_padding
.m_left
; }
589 const wxTextAttrDimension
& GetLeftPadding() const { return m_padding
.m_left
; }
591 wxTextAttrDimension
& GetRightPadding() { return m_padding
.m_right
; }
592 const wxTextAttrDimension
& GetRightPadding() const { return m_padding
.m_right
; }
594 wxTextAttrDimension
& GetTopPadding() { return m_padding
.m_top
; }
595 const wxTextAttrDimension
& GetTopPadding() const { return m_padding
.m_top
; }
597 wxTextAttrDimension
& GetBottomPadding() { return m_padding
.m_bottom
; }
598 const wxTextAttrDimension
& GetBottomPadding() const { return m_padding
.m_bottom
; }
602 wxTextBoxAttrBorders
& GetBorder() { return m_border
; }
603 const wxTextBoxAttrBorders
& GetBorder() const { return m_border
; }
605 wxTextBoxAttrBorder
& GetLeftBorder() { return m_border
.m_left
; }
606 const wxTextBoxAttrBorder
& GetLeftBorder() const { return m_border
.m_left
; }
608 wxTextBoxAttrBorder
& GetTopBorder() { return m_border
.m_top
; }
609 const wxTextBoxAttrBorder
& GetTopBorder() const { return m_border
.m_top
; }
611 wxTextBoxAttrBorder
& GetRightBorder() { return m_border
.m_right
; }
612 const wxTextBoxAttrBorder
& GetRightBorder() const { return m_border
.m_right
; }
614 wxTextBoxAttrBorder
& GetBottomBorder() { return m_border
.m_bottom
; }
615 const wxTextBoxAttrBorder
& GetBottomBorder() const { return m_border
.m_bottom
; }
619 wxTextBoxAttrBorders
& GetOutline() { return m_outline
; }
620 const wxTextBoxAttrBorders
& GetOutline() const { return m_outline
; }
622 wxTextBoxAttrBorder
& GetLeftOutline() { return m_outline
.m_left
; }
623 const wxTextBoxAttrBorder
& GetLeftOutline() const { return m_outline
.m_left
; }
625 wxTextBoxAttrBorder
& GetTopOutline() { return m_outline
.m_top
; }
626 const wxTextBoxAttrBorder
& GetTopOutline() const { return m_outline
.m_top
; }
628 wxTextBoxAttrBorder
& GetRightOutline() { return m_outline
.m_right
; }
629 const wxTextBoxAttrBorder
& GetRightOutline() const { return m_outline
.m_right
; }
631 wxTextBoxAttrBorder
& GetBottomOutline() { return m_outline
.m_bottom
; }
632 const wxTextBoxAttrBorder
& GetBottomOutline() const { return m_outline
.m_bottom
; }
637 wxTextAttrDimension
& GetWidth() { return m_width
; }
638 const wxTextAttrDimension
& GetWidth() const { return m_width
; }
640 wxTextAttrDimension
& GetHeight() { return m_height
; }
641 const wxTextAttrDimension
& GetHeight() const { return m_height
; }
647 wxTextBoxAttrDimensions m_margins
;
648 wxTextBoxAttrDimensions m_padding
;
649 wxTextBoxAttrDimensions m_position
;
651 wxTextAttrDimension m_width
;
652 wxTextAttrDimension m_height
;
654 wxTextBoxAttrBorders m_border
;
655 wxTextBoxAttrBorders m_outline
;
657 short int m_floatMode
;
658 short int m_clearMode
;
659 short int m_collapseMode
;
662 // ----------------------------------------------------------------------------
663 // wxRichTextAttr: an enhanced attribute
664 // ----------------------------------------------------------------------------
666 class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
: public wxTextAttr
669 wxRichTextAttr(const wxTextAttr
& attr
) { wxTextAttr::Copy(attr
); }
670 wxRichTextAttr(const wxRichTextAttr
& attr
) { Copy(attr
); }
674 void Copy(const wxRichTextAttr
& attr
);
677 void operator=(const wxRichTextAttr
& attr
) { Copy(attr
); }
678 void operator=(const wxTextAttr
& attr
) { wxTextAttr::Copy(attr
); }
681 bool operator==(const wxRichTextAttr
& attr
) const;
683 // Partial equality test taking comparison object into account
684 bool EqPartial(const wxRichTextAttr
& attr
) const;
686 // Merges the given attributes. If compareWith
687 // is non-NULL, then it will be used to mask out those attributes that are the same in style
688 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
689 bool Apply(const wxRichTextAttr
& style
, const wxRichTextAttr
* compareWith
= NULL
);
691 // Collects the attributes that are common to a range of content, building up a note of
692 // which attributes are absent in some objects and which clash in some objects.
693 void CollectCommonAttributes(const wxRichTextAttr
& attr
, wxRichTextAttr
& clashingAttr
, wxRichTextAttr
& absentAttr
);
695 // Remove specified attributes from this object
696 bool RemoveStyle(const wxRichTextAttr
& attr
);
698 wxTextBoxAttr
& GetTextBoxAttr() { return m_textBoxAttr
; }
699 const wxTextBoxAttr
& GetTextBoxAttr() const { return m_textBoxAttr
; }
700 void SetTextBoxAttr(const wxTextBoxAttr
& attr
) { m_textBoxAttr
= attr
; }
702 wxTextBoxAttr m_textBoxAttr
;
706 * wxRichTextFontTable
707 * Manages quick access to a pool of fonts for rendering rich text
710 class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable
: public wxObject
713 wxRichTextFontTable();
715 wxRichTextFontTable(const wxRichTextFontTable
& table
);
716 virtual ~wxRichTextFontTable();
718 bool IsOk() const { return m_refData
!= NULL
; }
720 wxFont
FindFont(const wxRichTextAttr
& fontSpec
);
723 void operator= (const wxRichTextFontTable
& table
);
724 bool operator == (const wxRichTextFontTable
& table
) const;
725 bool operator != (const wxRichTextFontTable
& table
) const { return !(*this == table
); }
729 DECLARE_DYNAMIC_CLASS(wxRichTextFontTable
)
733 * wxRichTextRange class declaration
734 * This stores beginning and end positions for a range of data.
735 * TODO: consider renaming wxTextRange and using for all text controls.
738 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
743 wxRichTextRange() { m_start
= 0; m_end
= 0; }
744 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
745 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
746 ~wxRichTextRange() {}
748 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
749 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
750 bool operator !=(const wxRichTextRange
& range
) const { return (m_start
!= range
.m_start
|| m_end
!= range
.m_end
); }
751 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
752 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
754 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
756 void SetStart(long start
) { m_start
= start
; }
757 long GetStart() const { return m_start
; }
759 void SetEnd(long end
) { m_end
= end
; }
760 long GetEnd() const { return m_end
; }
762 /// Returns true if this range is completely outside 'range'
763 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
765 /// Returns true if this range is completely within 'range'
766 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
768 /// Returns true if the given position is within this range. Allow
769 /// for the possibility of an empty range - assume the position
770 /// is within this empty range. NO, I think we should not match with an empty range.
771 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
772 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
774 /// Limit this range to be within 'range'
775 bool LimitTo(const wxRichTextRange
& range
) ;
777 /// Gets the length of the range
778 long GetLength() const { return m_end
- m_start
+ 1; }
780 /// Swaps the start and end
781 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
783 /// Convert to internal form: (n, n) is the range of a single character.
784 wxRichTextRange
ToInternal() const { return wxRichTextRange(m_start
, m_end
-1); }
786 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
787 wxRichTextRange
FromInternal() const { return wxRichTextRange(m_start
, m_end
+1); }
794 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
795 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
798 * wxRichTextObject class declaration
799 * This is the base for drawable objects.
802 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
804 DECLARE_CLASS(wxRichTextObject
)
808 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
809 virtual ~wxRichTextObject();
813 /// Draw the item, within the given range. Some objects may ignore the range (for
814 /// example paragraphs) while others must obey it (lines, to implement wrapping)
815 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
) = 0;
817 /// Lay the item out at the specified position with the given size constraint.
818 /// Layout must set the cached size.
819 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
821 /// Hit-testing: returns a flag indicating hit test details, plus
822 /// information about position
823 virtual int HitTest(wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pt
), long& WXUNUSED(textPosition
)) { return false; }
825 /// Finds the absolute position and row height for the given character position
826 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
828 /// Get the best size, i.e. the ideal starting size for this object irrespective
829 /// of available space. For a short text string, it will be the size that exactly encloses
830 /// the text. For a longer string, it might use the parent width for example.
831 virtual wxSize
GetBestSize() const { return m_size
; }
833 /// Get the object size for the given range. Returns false if the range
834 /// is invalid for this object.
835 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const = 0;
837 /// Do a split, returning an object containing the second part, and setting
838 /// the first part in 'this'.
839 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
841 /// Calculate range. By default, guess that the object is 1 unit long.
842 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
845 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
847 /// Returns true if the object is empty
848 virtual bool IsEmpty() const { return false; }
850 /// Whether this object floatable
851 virtual bool IsFloatable() const { return false; }
853 /// Whether this object is currently floating
854 virtual bool IsFloating() const { return false; }
856 /// Whether this object is a place holding one
857 // virtual bool IsPlaceHolding() const { return false; }
859 /// Floating direction
860 virtual int GetFloatDirection() const { return wxTEXT_BOX_ATTR_FLOAT_NONE
; }
862 /// Get any text in this object for the given range
863 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
865 /// Returns true if this object can merge itself with the given one.
866 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
868 /// Returns true if this object merged itself with the given one.
869 /// The calling code will then delete the given object.
870 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
872 /// Dump to output stream for debugging
873 virtual void Dump(wxTextOutputStream
& stream
);
875 /// Can we edit properties via a GUI?
876 virtual bool CanEditProperties() const { return false; }
878 /// Edit properties via a GUI
879 virtual bool EditProperties(wxWindow
* WXUNUSED(parent
), wxRichTextBuffer
* WXUNUSED(buffer
)) { return false; }
883 /// Get/set the cached object size as calculated by Layout.
884 virtual wxSize
GetCachedSize() const { return m_size
; }
885 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
887 /// Get/set the object position
888 virtual wxPoint
GetPosition() const { return m_pos
; }
889 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
891 /// Get the rectangle enclosing the object
892 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
895 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
898 const wxRichTextRange
& GetRange() const { return m_range
; }
899 wxRichTextRange
& GetRange() { return m_range
; }
901 /// Get/set dirty flag (whether the object needs Layout to be called)
902 virtual bool GetDirty() const { return m_dirty
; }
903 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
905 /// Is this composite?
906 virtual bool IsComposite() const { return false; }
908 /// Get/set the parent.
909 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
910 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
912 /// Set the margin around the object
913 virtual void SetMargins(int margin
);
914 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
915 virtual int GetLeftMargin() const { return m_leftMargin
; }
916 virtual int GetRightMargin() const { return m_rightMargin
; }
917 virtual int GetTopMargin() const { return m_topMargin
; }
918 virtual int GetBottomMargin() const { return m_bottomMargin
; }
920 /// Set attributes object
921 void SetAttributes(const wxRichTextAttr
& attr
) { m_attributes
= attr
; }
922 const wxRichTextAttr
& GetAttributes() const { return m_attributes
; }
923 wxRichTextAttr
& GetAttributes() { return m_attributes
; }
925 /// Set/get stored descent
926 void SetDescent(int descent
) { m_descent
= descent
; }
927 int GetDescent() const { return m_descent
; }
929 /// Gets the containing buffer
930 wxRichTextBuffer
* GetBuffer() const;
935 virtual wxRichTextObject
* Clone() const { return NULL
; }
938 void Copy(const wxRichTextObject
& obj
);
940 /// Reference-counting allows us to use the same object in multiple
941 /// lists (not yet used)
942 void Reference() { m_refCount
++; }
945 /// Convert units in tenths of a millimetre to device units
946 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
947 static int ConvertTenthsMMToPixels(int ppi
, int units
);
949 /// Convert units in pixels to tenths of a millimetre
950 int ConvertPixelsToTenthsMM(wxDC
& dc
, int pixels
) const;
951 static int ConvertPixelsToTenthsMM(int ppi
, int pixels
);
956 int m_descent
; // Descent for this object (if any)
959 wxRichTextObject
* m_parent
;
961 /// The range of this object (start position to end position)
962 wxRichTextRange m_range
;
971 wxRichTextAttr m_attributes
;
974 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
977 * wxRichTextCompositeObject class declaration
978 * Objects of this class can contain other objects.
981 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
983 DECLARE_CLASS(wxRichTextCompositeObject
)
987 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
988 virtual ~wxRichTextCompositeObject();
992 /// Hit-testing: returns a flag indicating hit test details, plus
993 /// information about position
994 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
996 /// Finds the absolute position and row height for the given character position
997 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1000 virtual void CalculateRange(long start
, long& end
);
1003 virtual bool DeleteRange(const wxRichTextRange
& range
);
1005 /// Get any text in this object for the given range
1006 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1008 /// Dump to output stream for debugging
1009 virtual void Dump(wxTextOutputStream
& stream
);
1013 /// Get the children
1014 wxRichTextObjectList
& GetChildren() { return m_children
; }
1015 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
1017 /// Get the child count
1018 size_t GetChildCount() const ;
1020 /// Get the nth child
1021 wxRichTextObject
* GetChild(size_t n
) const ;
1023 /// Get/set dirty flag
1024 virtual bool GetDirty() const { return m_dirty
; }
1025 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
1027 /// Is this composite?
1028 virtual bool IsComposite() const { return true; }
1030 /// Returns true if the buffer is empty
1031 virtual bool IsEmpty() const { return GetChildCount() == 0; }
1036 void Copy(const wxRichTextCompositeObject
& obj
);
1039 void operator= (const wxRichTextCompositeObject
& obj
) { Copy(obj
); }
1041 /// Append a child, returning the position
1042 size_t AppendChild(wxRichTextObject
* child
) ;
1044 /// Insert the child in front of the given object, or at the beginning
1045 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
1047 /// Delete the child
1048 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
1050 /// Delete all children
1051 bool DeleteChildren() ;
1053 /// Recursively merge all pieces that can be merged.
1054 bool Defragment(const wxRichTextRange
& range
= wxRICHTEXT_ALL
);
1057 wxRichTextObjectList m_children
;
1061 * wxRichTextBox class declaration
1062 * This defines a 2D space to lay out objects
1065 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextCompositeObject
1067 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
1071 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
1072 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
1077 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1079 /// Lay the item out
1080 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1082 /// Get/set the object size for the given range. Returns false if the range
1083 /// is invalid for this object.
1084 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1091 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
1094 void Copy(const wxRichTextBox
& obj
);
1100 * wxRichTextParagraphBox class declaration
1101 * This box knows how to lay out paragraphs.
1104 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextBox
1106 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
1110 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
1111 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
): wxRichTextBox() { Init(); Copy(obj
); }
1112 ~wxRichTextParagraphLayoutBox();
1116 /// Hit-testing: returns a flag indicating hit test details, plus
1117 /// information about position
1118 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1121 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1123 /// Lay the item out
1124 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1126 /// Get/set the object size for the given range. Returns false if the range
1127 /// is invalid for this object.
1128 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1131 virtual bool DeleteRange(const wxRichTextRange
& range
);
1133 /// Get any text in this object for the given range
1134 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1138 /// Associate a control with the buffer, for operations that for example require refreshing the window.
1139 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
1141 /// Get the associated control.
1142 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
1144 /// Get/set whether the last paragraph is partial or complete
1145 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
1146 bool GetPartialParagraph() const { return m_partialParagraph
; }
1148 /// If this is a buffer, returns the current style sheet. The base layout box
1149 /// class doesn't have an associated style sheet.
1150 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return NULL
; }
1153 /// Draw the floats of this buffer
1154 void DrawFloats(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1156 /// Move an anchored object to another paragraph
1157 void MoveAnchoredObjectToParagraph(wxRichTextParagraph
* from
, wxRichTextParagraph
* to
, wxRichTextAnchoredObject
* obj
);
1159 /// Initialize the object.
1162 /// Clear all children
1163 virtual void Clear();
1165 /// Clear and initialize with one blank paragraph
1166 virtual void Reset();
1168 /// Convenience function to add a paragraph of text
1169 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
);
1171 /// Convenience function to add an image
1172 virtual wxRichTextRange
AddImage(const wxImage
& image
, wxRichTextAttr
* paraStyle
= NULL
);
1174 /// Adds multiple paragraphs, based on newlines.
1175 virtual wxRichTextRange
AddParagraphs(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
);
1177 /// Get the line at the given position. If caretPosition is true, the position is
1178 /// a caret position, which is normally a smaller number.
1179 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
1181 /// Get the line at the given y pixel position, or the last line.
1182 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
1184 /// Get the paragraph at the given character or caret position
1185 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
1187 /// Get the line size at the given position
1188 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
1190 /// Given a position, get the number of the visible line (potentially many to a paragraph),
1191 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
1192 /// that indicates whether the caret is being shown at the end of the previous line or at the start
1193 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
1195 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
1197 /// Given a line number, get the corresponding wxRichTextLine object.
1198 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
1200 /// Get the leaf object in a paragraph at this position.
1201 /// Given a line number, get the corresponding wxRichTextLine object.
1202 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
1204 /// Get the paragraph by number
1205 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
1207 /// Get the paragraph for a given line
1208 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
1210 /// Get the length of the paragraph
1211 virtual int GetParagraphLength(long paragraphNumber
) const;
1213 /// Get the number of paragraphs
1214 virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); }
1216 /// Get the number of visible lines
1217 virtual int GetLineCount() const;
1219 /// Get the text of the paragraph
1220 virtual wxString
GetParagraphText(long paragraphNumber
) const;
1222 /// Convert zero-based line column and paragraph number to a position.
1223 virtual long XYToPosition(long x
, long y
) const;
1225 /// Convert zero-based position to line column and paragraph number
1226 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
1228 /// Set text attributes: character and/or paragraph styles.
1229 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1231 /// Set image attribute
1232 void SetImageStyle(wxRichTextImage
*image
, const wxRichTextAttr
& textAttr
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1234 /// Get the conbined text attributes for this position.
1235 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
1237 /// Get the content (uncombined) attributes for this position.
1238 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
1240 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1241 /// context attributes.
1242 virtual bool DoGetStyle(long position
, wxRichTextAttr
& style
, bool combineStyles
= true);
1244 /// Get the combined style for a range - if any attribute is different within the range,
1245 /// that attribute is not present within the flags
1246 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
);
1248 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1250 bool CollectStyle(wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
& clashingAttr
, wxRichTextAttr
& absentAttr
);
1253 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1254 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1256 /// Clear list for given range
1257 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
1259 /// Number/renumber any list elements in the given range.
1260 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1261 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1262 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
1264 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1265 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1266 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1267 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
1269 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1270 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1271 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);
1273 /// Fills in the attributes for numbering a paragraph after previousParagraph.
1274 virtual bool FindNextParagraphNumber(wxRichTextParagraph
* previousParagraph
, wxRichTextAttr
& attr
) const;
1276 /// Test if this whole range has character attributes of the specified kind. If any
1277 /// of the attributes are different within the range, the test fails. You
1278 /// can use this to implement, for example, bold button updating. style must have
1279 /// flags indicating which attributes are of interest.
1280 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1282 /// Test if this whole range has paragraph attributes of the specified kind. If any
1283 /// of the attributes are different within the range, the test fails. You
1284 /// can use this to implement, for example, centering button updating. style must have
1285 /// flags indicating which attributes are of interest.
1286 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const;
1289 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1291 /// Insert fragment into this box at the given position. If partialParagraph is true,
1292 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1294 virtual bool InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
);
1296 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1297 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
);
1299 /// Apply the style sheet to the buffer, for example if the styles have changed.
1300 virtual bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1303 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
1306 void operator= (const wxRichTextParagraphLayoutBox
& obj
) { Copy(obj
); }
1308 /// Calculate ranges
1309 virtual void UpdateRanges() { long end
; CalculateRange(0, end
); }
1311 /// Get all the text
1312 virtual wxString
GetText() const;
1314 /// Set default style for new content. Setting it to a default attribute
1315 /// makes new content take on the 'basic' style.
1316 virtual bool SetDefaultStyle(const wxRichTextAttr
& style
);
1318 /// Get default style
1319 virtual const wxRichTextAttr
& GetDefaultStyle() const { return m_defaultAttributes
; }
1321 /// Set basic (overall) style
1322 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { m_attributes
= style
; }
1324 /// Get basic (overall) style
1325 virtual const wxRichTextAttr
& GetBasicStyle() const { return m_attributes
; }
1327 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1328 void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
1330 /// Gather information about floating objects. If untilObj is non-NULL,
1331 /// will stop getting information if the current object is this, since we
1332 /// will collect the rest later.
1333 virtual bool UpdateFloatingObjects(int width
, wxRichTextObject
* untilObj
= NULL
);
1335 /// Get invalid range, rounding to entire paragraphs if argument is true.
1336 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
1338 /// Get the wxRichTextFloatCollector of this object
1339 wxRichTextFloatCollector
* GetFloatCollector() { return m_floatCollector
; }
1342 wxRichTextCtrl
* m_ctrl
;
1343 wxRichTextAttr m_defaultAttributes
;
1345 /// The invalidated range that will need full layout
1346 wxRichTextRange m_invalidRange
;
1348 // Is the last paragraph partial or complete?
1349 bool m_partialParagraph
;
1351 // The floating layout state
1352 wxRichTextFloatCollector
* m_floatCollector
;
1356 * wxRichTextLine class declaration
1357 * This object represents a line in a paragraph, and stores
1358 * offsets from the start of the paragraph representing the
1359 * start and end positions of the line.
1362 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
1367 wxRichTextLine(wxRichTextParagraph
* parent
);
1368 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
1369 virtual ~wxRichTextLine() {}
1376 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1377 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
1379 /// Get the parent paragraph
1380 wxRichTextParagraph
* GetParent() { return m_parent
; }
1383 const wxRichTextRange
& GetRange() const { return m_range
; }
1384 wxRichTextRange
& GetRange() { return m_range
; }
1386 /// Get the absolute range
1387 wxRichTextRange
GetAbsoluteRange() const;
1389 /// Get/set the line size as calculated by Layout.
1390 virtual wxSize
GetSize() const { return m_size
; }
1391 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
1393 /// Get/set the object position relative to the parent
1394 virtual wxPoint
GetPosition() const { return m_pos
; }
1395 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
1397 /// Get the absolute object position
1398 virtual wxPoint
GetAbsolutePosition() const;
1400 /// Get the rectangle enclosing the line
1401 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1403 /// Set/get stored descent
1404 void SetDescent(int descent
) { m_descent
= descent
; }
1405 int GetDescent() const { return m_descent
; }
1407 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1408 wxArrayInt
& GetObjectSizes() { return m_objectSizes
; }
1409 const wxArrayInt
& GetObjectSizes() const { return m_objectSizes
; }
1415 void Init(wxRichTextParagraph
* parent
);
1418 void Copy(const wxRichTextLine
& obj
);
1421 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1425 /// The range of the line (start position to end position)
1426 /// This is relative to the parent paragraph.
1427 wxRichTextRange m_range
;
1429 /// Size and position measured relative to top of paragraph
1433 /// Maximum descent for this line (location of text baseline)
1436 // The parent object
1437 wxRichTextParagraph
* m_parent
;
1439 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1440 wxArrayInt m_objectSizes
;
1444 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
1447 * wxRichTextParagraph class declaration
1448 * This object represents a single paragraph (or in a straight text editor, a line).
1451 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextBox
1453 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
1457 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* style
= NULL
);
1458 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* paraStyle
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
1459 virtual ~wxRichTextParagraph();
1460 wxRichTextParagraph(const wxRichTextParagraph
& obj
): wxRichTextBox() { Copy(obj
); }
1465 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1467 /// Lay the item out
1468 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1470 /// Get/set the object size for the given range. Returns false if the range
1471 /// is invalid for this object.
1472 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1474 /// Finds the absolute position and row height for the given character position
1475 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1477 /// Hit-testing: returns a flag indicating hit test details, plus
1478 /// information about position
1479 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1482 virtual void CalculateRange(long start
, long& end
);
1486 /// Get the cached lines
1487 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
1492 void Copy(const wxRichTextParagraph
& obj
);
1495 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
1497 /// Clear the cached lines
1502 /// Apply paragraph styles such as centering to the wrapped lines
1503 virtual void ApplyParagraphStyle(const wxRichTextAttr
& attr
, const wxRect
& rect
, wxDC
& dc
);
1505 /// Insert text at the given position
1506 virtual bool InsertText(long pos
, const wxString
& text
);
1508 /// Split an object at this position if necessary, and return
1509 /// the previous object, or NULL if inserting at beginning.
1510 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
1512 /// Move content to a list from this point
1513 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
1515 /// Add content back from list
1516 virtual void MoveFromList(wxList
& list
);
1518 /// Get the plain text searching from the start or end of the range.
1519 /// The resulting string may be shorter than the range given.
1520 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
1522 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1524 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
, wxArrayInt
* partialExtents
);
1526 /// Find the object at the given position
1527 wxRichTextObject
* FindObjectAtPosition(long position
);
1529 /// Get the bullet text for this paragraph.
1530 wxString
GetBulletText();
1532 /// Allocate or reuse a line object
1533 wxRichTextLine
* AllocateLine(int pos
);
1535 /// Clear remaining unused line objects, if any
1536 bool ClearUnusedLines(int lineCount
);
1538 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1539 /// retrieve the actual style.
1540 wxRichTextAttr
GetCombinedAttributes(const wxRichTextAttr
& contentStyle
) const;
1542 /// Get combined attributes of the base style and paragraph style.
1543 wxRichTextAttr
GetCombinedAttributes() const;
1545 /// Get the first position from pos that has a line break character.
1546 long GetFirstLineBreakPosition(long pos
);
1548 /// Create default tabstop array
1549 static void InitDefaultTabs();
1551 /// Clear default tabstop array
1552 static void ClearDefaultTabs();
1554 /// Get default tabstop array
1555 static const wxArrayInt
& GetDefaultTabs() { return sm_defaultTabs
; }
1557 /// Layout the floats object
1558 void LayoutFloat(wxDC
& dc
, const wxRect
& rect
, int style
, wxRichTextFloatCollector
* floatCollector
);
1561 /// The lines that make up the wrapped paragraph
1562 wxRichTextLineList m_cachedLines
;
1564 /// Default tabstops
1565 static wxArrayInt sm_defaultTabs
;
1567 friend class wxRichTextFloatCollector
;
1571 * wxRichTextPlainText class declaration
1572 * This object represents a single piece of text.
1575 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
1577 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
1581 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* style
= NULL
);
1582 wxRichTextPlainText(const wxRichTextPlainText
& obj
): wxRichTextObject() { Copy(obj
); }
1587 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1589 /// Lay the item out
1590 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1592 /// Get/set the object size for the given range. Returns false if the range
1593 /// is invalid for this object.
1594 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1596 /// Get any text in this object for the given range
1597 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1599 /// Do a split, returning an object containing the second part, and setting
1600 /// the first part in 'this'.
1601 virtual wxRichTextObject
* DoSplit(long pos
);
1604 virtual void CalculateRange(long start
, long& end
);
1607 virtual bool DeleteRange(const wxRichTextRange
& range
);
1609 /// Returns true if the object is empty
1610 virtual bool IsEmpty() const { return m_text
.empty(); }
1612 /// Returns true if this object can merge itself with the given one.
1613 virtual bool CanMerge(wxRichTextObject
* object
) const;
1615 /// Returns true if this object merged itself with the given one.
1616 /// The calling code will then delete the given object.
1617 virtual bool Merge(wxRichTextObject
* object
);
1619 /// Dump to output stream for debugging
1620 virtual void Dump(wxTextOutputStream
& stream
);
1622 /// Get the first position from pos that has a line break character.
1623 long GetFirstLineBreakPosition(long pos
);
1628 const wxString
& GetText() const { return m_text
; }
1631 void SetText(const wxString
& text
) { m_text
= text
; }
1636 void Copy(const wxRichTextPlainText
& obj
);
1639 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
1641 bool DrawTabbedString(wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
1648 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1651 class WXDLLIMPEXP_FWD_BASE wxDataInputStream
;
1652 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream
;
1654 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
1657 wxRichTextImageBlock();
1658 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
1659 virtual ~wxRichTextImageBlock();
1664 // Load the original image into a memory block.
1665 // If the image is not a JPEG, we must convert it into a JPEG
1666 // to conserve space.
1667 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1668 // load the image a 2nd time.
1669 virtual bool MakeImageBlock(const wxString
& filename
, wxBitmapType imageType
,
1670 wxImage
& image
, bool convertToJPEG
= true);
1672 // Make an image block from the wxImage in the given
1674 virtual bool MakeImageBlock(wxImage
& image
, wxBitmapType imageType
, int quality
= 80);
1676 // Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG)
1677 virtual bool MakeImageBlockDefaultQuality(const wxImage
& image
, wxBitmapType imageType
);
1679 // Makes the image block
1680 virtual bool DoMakeImageBlock(const wxImage
& image
, wxBitmapType imageType
);
1683 bool Write(const wxString
& filename
);
1685 // Write data in hex to a stream
1686 bool WriteHex(wxOutputStream
& stream
);
1688 // Read data in hex from a stream
1689 bool ReadHex(wxInputStream
& stream
, int length
, wxBitmapType imageType
);
1691 // Copy from 'block'
1692 void Copy(const wxRichTextImageBlock
& block
);
1694 // Load a wxImage from the block
1695 bool Load(wxImage
& image
);
1698 void operator=(const wxRichTextImageBlock
& block
);
1702 unsigned char* GetData() const { return m_data
; }
1703 size_t GetDataSize() const { return m_dataSize
; }
1704 wxBitmapType
GetImageType() const { return m_imageType
; }
1706 void SetData(unsigned char* image
) { m_data
= image
; }
1707 void SetDataSize(size_t size
) { m_dataSize
= size
; }
1708 void SetImageType(wxBitmapType imageType
) { m_imageType
= imageType
; }
1710 bool Ok() const { return IsOk(); }
1711 bool IsOk() const { return GetData() != NULL
; }
1713 // Gets the extension for the block's type
1714 wxString
GetExtension() const;
1718 // Allocate and read from stream as a block of memory
1719 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
1720 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
1722 // Write memory block to stream
1723 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
1725 // Write memory block to file
1726 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
1729 // Size in bytes of the image stored.
1730 // This is in the raw, original form such as a JPEG file.
1731 unsigned char* m_data
;
1733 wxBitmapType m_imageType
;
1737 * wxRichTextAnchoredObject class declaration
1738 * This object is an abstract one that represent some objects which can floats
1740 class WXDLLIMPEXP_RICHTEXT wxRichTextAnchoredObject
: public wxRichTextObject
1742 DECLARE_CLASS(wxRichTextAnchoredObject
)
1745 wxRichTextAnchoredObject(wxRichTextObject
* parent
= NULL
, const wxRichTextAttr
& attr
= wxRichTextAttr());
1746 wxRichTextAnchoredObject(const wxRichTextAnchoredObject
& obj
) : wxRichTextObject(obj
) /* , m_ph(NULL) */ { Copy(obj
); }
1747 ~wxRichTextAnchoredObject();
1750 virtual bool IsFloatable() const { return true; }
1752 /// Whether this object is currently floating
1753 virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); }
1755 virtual void SetParent(wxRichTextObject
* parent
);
1759 /// The floating direction
1760 virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); }
1762 void operator=(const wxRichTextAnchoredObject
&) { wxASSERT("Nobody can reset this object using ="); }
1765 void Copy(const wxRichTextAnchoredObject
& obj
);
1772 * wxRichTextImage class declaration
1773 * This object represents an image.
1776 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextAnchoredObject
1778 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
1782 wxRichTextImage(wxRichTextObject
* parent
= NULL
): wxRichTextAnchoredObject(parent
) { }
1783 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
1784 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
, wxRichTextAttr
* charStyle
= NULL
);
1785 wxRichTextImage(const wxRichTextImage
& obj
): wxRichTextAnchoredObject(obj
) { Copy(obj
); }
1790 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1792 /// Lay the item out
1793 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1795 /// Get the object size for the given range. Returns false if the range
1796 /// is invalid for this object.
1797 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1799 /// Returns true if the object is empty
1800 virtual bool IsEmpty() const { return !m_imageBlock
.Ok(); }
1802 /// Can we edit properties via a GUI?
1803 virtual bool CanEditProperties() const { return true; }
1805 /// Edit properties via a GUI
1806 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
1810 /// Get the image cache (scaled bitmap)
1811 const wxBitmap
& GetImageCache() const { return m_imageCache
; }
1813 /// Set the image cache
1814 void SetImageCache(const wxBitmap
& bitmap
) { m_imageCache
= bitmap
; }
1816 /// Reset the image cache
1817 void ResetImageCache() { m_imageCache
= wxNullBitmap
; }
1819 /// Get the image block containing the raw data
1820 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
1825 void Copy(const wxRichTextImage
& obj
);
1828 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
1830 /// Create a cached image at the required size
1831 virtual bool LoadImageCache(wxDC
& dc
, bool resetCache
= false);
1834 wxRichTextImageBlock m_imageBlock
;
1835 wxBitmap m_imageCache
;
1840 * wxRichTextBuffer class declaration
1841 * This is a kind of box, used to represent the whole buffer
1844 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand
;
1845 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
1847 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
1849 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
1853 wxRichTextBuffer() { Init(); }
1854 wxRichTextBuffer(const wxRichTextBuffer
& obj
): wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
1855 virtual ~wxRichTextBuffer() ;
1859 /// Gets the command processor
1860 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
1862 /// Set style sheet, if any.
1863 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
1864 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
1866 /// Set style sheet and notify of the change
1867 bool SetStyleSheetAndNotify(wxRichTextStyleSheet
* sheet
);
1869 /// Push style sheet to top of stack
1870 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1872 /// Pop style sheet from top of stack
1873 wxRichTextStyleSheet
* PopStyleSheet();
1875 /// Set/get table storing fonts
1876 wxRichTextFontTable
& GetFontTable() { return m_fontTable
; }
1877 const wxRichTextFontTable
& GetFontTable() const { return m_fontTable
; }
1878 void SetFontTable(const wxRichTextFontTable
& table
) { m_fontTable
= table
; }
1885 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1886 virtual void ResetAndClearCommands();
1889 virtual bool LoadFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1892 virtual bool SaveFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1894 /// Load from a stream
1895 virtual bool LoadFile(wxInputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1897 /// Save to a stream
1898 virtual bool SaveFile(wxOutputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1900 /// Set the handler flags, controlling loading and saving
1901 void SetHandlerFlags(int flags
) { m_handlerFlags
= flags
; }
1903 /// Get the handler flags, controlling loading and saving
1904 int GetHandlerFlags() const { return m_handlerFlags
; }
1906 /// Convenience function to add a paragraph of text
1907 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxRichTextAttr
* paraStyle
= NULL
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
, paraStyle
); }
1909 /// Begin collapsing undo/redo commands. Note that this may not work properly
1910 /// if combining commands that delete or insert content, changing ranges for
1911 /// subsequent actions.
1912 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1914 /// End collapsing undo/redo commands
1915 virtual bool EndBatchUndo();
1917 /// Collapsing commands?
1918 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
1920 /// Submit immediately, or delay according to whether collapsing is on
1921 virtual bool SubmitAction(wxRichTextAction
* action
);
1923 /// Get collapsed command
1924 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
1926 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1927 /// differently by each command. If not dealt with by a command implementation, then
1928 /// it will be implemented automatically by not storing the command in the undo history
1929 /// when the action is submitted to the command processor.
1930 virtual bool BeginSuppressUndo();
1932 /// End suppressing undo/redo commands.
1933 virtual bool EndSuppressUndo();
1935 /// Collapsing commands?
1936 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
1938 /// Copy the range to the clipboard
1939 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
1941 /// Paste the clipboard content to the buffer
1942 virtual bool PasteFromClipboard(long position
);
1944 /// Can we paste from the clipboard?
1945 virtual bool CanPasteFromClipboard() const;
1947 /// Begin using a style
1948 virtual bool BeginStyle(const wxRichTextAttr
& style
);
1951 virtual bool EndStyle();
1954 virtual bool EndAllStyles();
1956 /// Clear the style stack
1957 virtual void ClearStyleStack();
1959 /// Get the size of the style stack, for example to check correct nesting
1960 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
1962 /// Begin using bold
1966 bool EndBold() { return EndStyle(); }
1968 /// Begin using italic
1971 /// End using italic
1972 bool EndItalic() { return EndStyle(); }
1974 /// Begin using underline
1975 bool BeginUnderline();
1977 /// End using underline
1978 bool EndUnderline() { return EndStyle(); }
1980 /// Begin using point size
1981 bool BeginFontSize(int pointSize
);
1983 /// End using point size
1984 bool EndFontSize() { return EndStyle(); }
1986 /// Begin using this font
1987 bool BeginFont(const wxFont
& font
);
1989 /// End using a font
1990 bool EndFont() { return EndStyle(); }
1992 /// Begin using this colour
1993 bool BeginTextColour(const wxColour
& colour
);
1995 /// End using a colour
1996 bool EndTextColour() { return EndStyle(); }
1998 /// Begin using alignment
1999 bool BeginAlignment(wxTextAttrAlignment alignment
);
2002 bool EndAlignment() { return EndStyle(); }
2004 /// Begin left indent
2005 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
2008 bool EndLeftIndent() { return EndStyle(); }
2010 /// Begin right indent
2011 bool BeginRightIndent(int rightIndent
);
2013 /// End right indent
2014 bool EndRightIndent() { return EndStyle(); }
2016 /// Begin paragraph spacing
2017 bool BeginParagraphSpacing(int before
, int after
);
2019 /// End paragraph spacing
2020 bool EndParagraphSpacing() { return EndStyle(); }
2022 /// Begin line spacing
2023 bool BeginLineSpacing(int lineSpacing
);
2025 /// End line spacing
2026 bool EndLineSpacing() { return EndStyle(); }
2028 /// Begin numbered bullet
2029 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
2031 /// End numbered bullet
2032 bool EndNumberedBullet() { return EndStyle(); }
2034 /// Begin symbol bullet
2035 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
2037 /// End symbol bullet
2038 bool EndSymbolBullet() { return EndStyle(); }
2040 /// Begin standard bullet
2041 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
2043 /// End standard bullet
2044 bool EndStandardBullet() { return EndStyle(); }
2046 /// Begin named character style
2047 bool BeginCharacterStyle(const wxString
& characterStyle
);
2049 /// End named character style
2050 bool EndCharacterStyle() { return EndStyle(); }
2052 /// Begin named paragraph style
2053 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
2055 /// End named character style
2056 bool EndParagraphStyle() { return EndStyle(); }
2058 /// Begin named list style
2059 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
2061 /// End named character style
2062 bool EndListStyle() { return EndStyle(); }
2065 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
);
2068 bool EndURL() { return EndStyle(); }
2072 /// Add an event handler
2073 bool AddEventHandler(wxEvtHandler
* handler
);
2075 /// Remove an event handler
2076 bool RemoveEventHandler(wxEvtHandler
* handler
, bool deleteHandler
= false);
2078 /// Clear event handlers
2079 void ClearEventHandlers();
2081 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
2082 /// otherwise will stop at the first successful one.
2083 bool SendEvent(wxEvent
& event
, bool sendToAll
= true);
2088 void Copy(const wxRichTextBuffer
& obj
);
2091 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
2093 /// Submit command to insert paragraphs
2094 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2096 /// Submit command to insert the given text
2097 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2099 /// Submit command to insert a newline
2100 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
2102 /// Submit command to insert the given image
2103 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
= 0,
2104 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
2106 /// Submit command to insert an object
2107 bool InsertObjectWithUndo(long pos
, wxRichTextObject
*object
, wxRichTextCtrl
* ctrl
, int flags
);
2109 /// Submit command to delete this range
2110 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, wxRichTextCtrl
* ctrl
);
2113 void Modify(bool modify
= true) { m_modified
= modify
; }
2114 bool IsModified() const { return m_modified
; }
2116 /// Get the style that is appropriate for a new paragraph at this position.
2117 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
2119 wxRichTextAttr
GetStyleForNewParagraph(long pos
, bool caretPosition
= false, bool lookUpNewParaStyle
=false) const;
2121 /// Dumps contents of buffer for debugging purposes
2122 virtual void Dump();
2123 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
2125 /// Returns the file handlers
2126 static wxList
& GetHandlers() { return sm_handlers
; }
2128 /// Adds a handler to the end
2129 static void AddHandler(wxRichTextFileHandler
*handler
);
2131 /// Inserts a handler at the front
2132 static void InsertHandler(wxRichTextFileHandler
*handler
);
2134 /// Removes a handler
2135 static bool RemoveHandler(const wxString
& name
);
2137 /// Finds a handler by name
2138 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
2140 /// Finds a handler by extension and type
2141 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, wxRichTextFileType imageType
);
2143 /// Finds a handler by filename or, if supplied, type
2144 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
,
2145 wxRichTextFileType imageType
);
2147 /// Finds a handler by type
2148 static wxRichTextFileHandler
*FindHandler(wxRichTextFileType imageType
);
2150 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
2151 /// will be filled with the file type corresponding to each filter. This can be
2152 /// used to determine the type to pass to LoadFile given a selected filter.
2153 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
2155 /// Clean up handlers
2156 static void CleanUpHandlers();
2158 /// Initialise the standard handlers
2159 static void InitStandardHandlers();
2162 static wxRichTextRenderer
* GetRenderer() { return sm_renderer
; }
2164 /// Set renderer, deleting old one
2165 static void SetRenderer(wxRichTextRenderer
* renderer
);
2167 /// Minimum margin between bullet and paragraph in 10ths of a mm
2168 static int GetBulletRightMargin() { return sm_bulletRightMargin
; }
2169 static void SetBulletRightMargin(int margin
) { sm_bulletRightMargin
= margin
; }
2171 /// Factor to multiply by character height to get a reasonable bullet size
2172 static float GetBulletProportion() { return sm_bulletProportion
; }
2173 static void SetBulletProportion(float prop
) { sm_bulletProportion
= prop
; }
2175 /// Scale factor for calculating dimensions
2176 double GetScale() const { return m_scale
; }
2177 void SetScale(double scale
) { m_scale
= scale
; }
2181 /// Command processor
2182 wxCommandProcessor
* m_commandProcessor
;
2184 /// Table storing fonts
2185 wxRichTextFontTable m_fontTable
;
2187 /// Has been modified?
2190 /// Collapsed command stack
2191 int m_batchedCommandDepth
;
2193 /// Name for collapsed command
2194 wxString m_batchedCommandsName
;
2196 /// Current collapsed command accumulating actions
2197 wxRichTextCommand
* m_batchedCommand
;
2199 /// Whether to suppress undo
2202 /// Style sheet, if any
2203 wxRichTextStyleSheet
* m_styleSheet
;
2205 /// List of event handlers that will be notified of events
2206 wxList m_eventHandlers
;
2208 /// Stack of attributes for convenience functions
2209 wxList m_attributeStack
;
2211 /// Flags to be passed to handlers
2215 static wxList sm_handlers
;
2218 static wxRichTextRenderer
* sm_renderer
;
2220 /// Minimum margin between bullet and paragraph in 10ths of a mm
2221 static int sm_bulletRightMargin
;
2223 /// Factor to multiply by character height to get a reasonable bullet size
2224 static float sm_bulletProportion
;
2226 /// Scaling factor in use: needed to calculate correct dimensions when printing
2231 * The command identifiers
2235 enum wxRichTextCommandId
2239 wxRICHTEXT_CHANGE_STYLE
2243 * Command classes for undo/redo
2247 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
2248 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
2251 // Ctor for one action
2252 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
2253 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
2255 // Ctor for multiple actions
2256 wxRichTextCommand(const wxString
& name
);
2258 virtual ~wxRichTextCommand();
2263 void AddAction(wxRichTextAction
* action
);
2264 void ClearActions();
2266 wxList
& GetActions() { return m_actions
; }
2274 * wxRichTextAction class declaration
2275 * There can be more than one action in a command.
2278 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
2281 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
2282 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
2284 virtual ~wxRichTextAction();
2289 /// Update the control appearance
2290 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false,
2291 wxArrayInt
* optimizationLineCharPositions
= NULL
, wxArrayInt
* optimizationLineYPositions
= NULL
, bool isDoCmd
= true);
2293 /// Replace the buffer paragraphs with the given fragment.
2294 void ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
);
2296 /// Get the fragments
2297 wxRichTextParagraphLayoutBox
& GetNewParagraphs() { return m_newParagraphs
; }
2298 wxRichTextParagraphLayoutBox
& GetOldParagraphs() { return m_oldParagraphs
; }
2300 /// Calculate arrays for refresh optimization
2301 void CalculateRefreshOptimizations(wxArrayInt
& optimizationLineCharPositions
, wxArrayInt
& optimizationLineYPositions
);
2303 /// Set/get the position used for e.g. insertion
2304 void SetPosition(long pos
) { m_position
= pos
; }
2305 long GetPosition() const { return m_position
; }
2307 /// Set/get the range for e.g. deletion
2308 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
2309 const wxRichTextRange
& GetRange() const { return m_range
; }
2312 const wxString
& GetName() const { return m_name
; }
2319 wxRichTextBuffer
* m_buffer
;
2322 wxRichTextCtrl
* m_ctrl
;
2324 // Stores the new paragraphs
2325 wxRichTextParagraphLayoutBox m_newParagraphs
;
2327 // Stores the old paragraphs
2328 wxRichTextParagraphLayoutBox m_oldParagraphs
;
2330 // The affected range
2331 wxRichTextRange m_range
;
2333 // The insertion point for this command
2336 // Ignore 1st 'Do' operation because we already did it
2339 // The command identifier
2340 wxRichTextCommandId m_cmdId
;
2347 // Include style sheet when loading and saving
2348 #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
2350 // Save images to memory file system in HTML handler
2351 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
2353 // Save images to files in HTML handler
2354 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
2356 // Save images as inline base64 data in HTML handler
2357 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
2359 // Don't write header and footer (or BODY), so we can include the fragment
2360 // in a larger document
2361 #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080
2363 // Convert the more common face names to names that will work on the current platform
2364 // in a larger document
2365 #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100
2368 * wxRichTextFileHandler
2369 * Base class for file handlers
2372 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
2374 DECLARE_CLASS(wxRichTextFileHandler
)
2376 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
2377 : m_name(name
), m_extension(ext
), m_type(type
), m_flags(0), m_visible(true)
2381 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
2382 { return DoLoadFile(buffer
, stream
); }
2383 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
2384 { return DoSaveFile(buffer
, stream
); }
2387 #if wxUSE_FFILE && wxUSE_STREAMS
2388 virtual bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
2389 virtual bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
2390 #endif // wxUSE_STREAMS && wxUSE_STREAMS
2392 /// Can we handle this filename (if using files)? By default, checks the extension.
2393 virtual bool CanHandle(const wxString
& filename
) const;
2395 /// Can we save using this handler?
2396 virtual bool CanSave() const { return false; }
2398 /// Can we load using this handler?
2399 virtual bool CanLoad() const { return false; }
2401 /// Should this handler be visible to the user?
2402 virtual bool IsVisible() const { return m_visible
; }
2403 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
2405 /// The name of the nandler
2406 void SetName(const wxString
& name
) { m_name
= name
; }
2407 wxString
GetName() const { return m_name
; }
2409 /// The default extension to recognise
2410 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
2411 wxString
GetExtension() const { return m_extension
; }
2413 /// The handler type
2414 void SetType(int type
) { m_type
= type
; }
2415 int GetType() const { return m_type
; }
2417 /// Flags controlling how loading and saving is done
2418 void SetFlags(int flags
) { m_flags
= flags
; }
2419 int GetFlags() const { return m_flags
; }
2421 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
2422 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
2423 const wxString
& GetEncoding() const { return m_encoding
; }
2428 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
2429 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
2433 wxString m_encoding
;
2434 wxString m_extension
;
2441 * wxRichTextPlainTextHandler
2442 * Plain text handler
2445 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
2447 DECLARE_CLASS(wxRichTextPlainTextHandler
)
2449 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"),
2450 const wxString
& ext
= wxT("txt"),
2451 wxRichTextFileType type
= wxRICHTEXT_TYPE_TEXT
)
2452 : wxRichTextFileHandler(name
, ext
, type
)
2455 /// Can we save using this handler?
2456 virtual bool CanSave() const { return true; }
2458 /// Can we load using this handler?
2459 virtual bool CanLoad() const { return true; }
2464 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
2465 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
2473 * The data object for a wxRichTextBuffer
2476 class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject
: public wxDataObjectSimple
2479 // ctor doesn't copy the pointer, so it shouldn't go away while this object
2481 wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
= NULL
);
2482 virtual ~wxRichTextBufferDataObject();
2484 // after a call to this function, the buffer is owned by the caller and it
2485 // is responsible for deleting it
2486 wxRichTextBuffer
* GetRichTextBuffer();
2488 // Returns the id for the new data format
2489 static const wxChar
* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId
; }
2491 // base class pure virtuals
2493 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
2494 virtual size_t GetDataSize() const;
2495 virtual bool GetDataHere(void *pBuf
) const;
2496 virtual bool SetData(size_t len
, const void *buf
);
2500 virtual size_t GetDataSize(const wxDataFormat
&) const { return GetDataSize(); }
2501 virtual bool GetDataHere(const wxDataFormat
&, void *buf
) const { return GetDataHere(buf
); }
2502 virtual bool SetData(const wxDataFormat
&, size_t len
, const void *buf
) { return SetData(len
, buf
); }
2505 wxDataFormat m_formatRichTextBuffer
; // our custom format
2506 wxRichTextBuffer
* m_richTextBuffer
; // our data
2507 static const wxChar
* ms_richTextBufferFormatId
; // our format id
2513 * wxRichTextRenderer isolates common drawing functionality
2516 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer
: public wxObject
2519 wxRichTextRenderer() {}
2520 virtual ~wxRichTextRenderer() {}
2522 /// Draw a standard bullet, as specified by the value of GetBulletName
2523 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
) = 0;
2525 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2526 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
) = 0;
2528 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2529 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
) = 0;
2531 /// Enumerate the standard bullet names currently supported
2532 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
) = 0;
2536 * wxRichTextStdRenderer: standard renderer
2539 class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer
: public wxRichTextRenderer
2542 wxRichTextStdRenderer() {}
2544 /// Draw a standard bullet, as specified by the value of GetBulletName
2545 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
);
2547 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2548 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
);
2550 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2551 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxRichTextAttr
& attr
, const wxRect
& rect
);
2553 /// Enumerate the standard bullet names currently supported
2554 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
);
2562 inline bool wxRichTextHasStyle(int flags
, int style
)
2564 return ((flags
& style
) == style
);
2567 /// Compare two attribute objects
2568 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
2569 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
2571 /// Compare two attribute objects, but take into account the flags
2572 /// specifying attributes of interest.
2573 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEqPartial(const wxRichTextAttr
& attr1
, const wxRichTextAttr
& attr2
);
2575 /// Apply one style to another
2576 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
= NULL
);
2578 // Remove attributes
2579 WXDLLIMPEXP_RICHTEXT
bool wxRichTextRemoveStyle(wxRichTextAttr
& destStyle
, const wxRichTextAttr
& style
);
2581 /// Combine two bitlists
2582 WXDLLIMPEXP_RICHTEXT
bool wxRichTextCombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
);
2584 /// Compare two bitlists
2585 WXDLLIMPEXP_RICHTEXT
bool wxRichTextBitlistsEqPartial(int valueA
, int valueB
, int flags
);
2587 /// Split into paragraph and character styles
2588 WXDLLIMPEXP_RICHTEXT
bool wxRichTextSplitParaCharStyles(const wxRichTextAttr
& style
, wxRichTextAttr
& parStyle
, wxRichTextAttr
& charStyle
);
2591 WXDLLIMPEXP_RICHTEXT
bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
);
2593 /// Convert a decimal to Roman numerals
2594 WXDLLIMPEXP_RICHTEXT wxString
wxRichTextDecimalToRoman(long n
);
2596 // Collects the attributes that are common to a range of content, building up a note of
2597 // which attributes are absent in some objects and which clash in some objects.
2598 WXDLLIMPEXP_RICHTEXT
void wxTextAttrCollectCommonAttributes(wxTextAttr
& currentStyle
, const wxTextAttr
& attr
, wxTextAttr
& clashingAttr
, wxTextAttr
& absentAttr
);
2600 WXDLLIMPEXP_RICHTEXT
void wxRichTextModuleInit();
2606 // _WX_RICHTEXTBUFFER_H_