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