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