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