1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _richtextbuffer.i
3 // Purpose: wxRichTextAttr
7 // Created: 11-April-2006
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include <wx/sstream.h>
20 #include "wx/wxPython/pyistream.h"
23 //---------------------------------------------------------------------------
38 * Flags determining the available space, passed to Layout
40 wxRICHTEXT_FIXED_WIDTH,
41 wxRICHTEXT_FIXED_HEIGHT,
42 wxRICHTEXT_VARIABLE_WIDTH,
43 wxRICHTEXT_VARIABLE_HEIGHT,
46 wxRICHTEXT_LAYOUT_SPECIFIED_RECT,
47 wxRICHTEXT_DRAW_IGNORE_CACHE,
51 * Flags returned from hit-testing
53 wxRICHTEXT_HITTEST_NONE,
54 wxRICHTEXT_HITTEST_BEFORE,
55 wxRICHTEXT_HITTEST_AFTER,
56 wxRICHTEXT_HITTEST_ON,
57 wxRICHTEXT_HITTEST_OUTSIDE,
60 * Flags for GetRangeSize
63 wxRICHTEXT_UNFORMATTED,
66 * Flags for SetStyle/SetListStyle
68 wxRICHTEXT_SETSTYLE_NONE,
69 wxRICHTEXT_SETSTYLE_WITH_UNDO,
70 wxRICHTEXT_SETSTYLE_OPTIMIZE,
71 wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY,
72 wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY,
73 wxRICHTEXT_SETSTYLE_RENUMBER,
74 wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL,
75 wxRICHTEXT_SETSTYLE_RESET,
76 wxRICHTEXT_SETSTYLE_REMOVE,
79 * Flags for text insertion
81 wxRICHTEXT_INSERT_NONE,
82 wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE,
85 // TODO: Rename these to be wxRICHTEXT_* ??
87 wxTEXT_ATTR_TEXT_COLOUR,
88 wxTEXT_ATTR_BACKGROUND_COLOUR,
89 wxTEXT_ATTR_FONT_FACE,
90 wxTEXT_ATTR_FONT_SIZE,
91 wxTEXT_ATTR_FONT_WEIGHT,
92 wxTEXT_ATTR_FONT_ITALIC,
93 wxTEXT_ATTR_FONT_UNDERLINE,
95 wxTEXT_ATTR_ALIGNMENT,
96 wxTEXT_ATTR_LEFT_INDENT,
97 wxTEXT_ATTR_RIGHT_INDENT,
100 wxTEXT_ATTR_PARA_SPACING_AFTER,
101 wxTEXT_ATTR_PARA_SPACING_BEFORE,
102 wxTEXT_ATTR_LINE_SPACING,
103 wxTEXT_ATTR_CHARACTER_STYLE_NAME,
104 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME,
105 wxTEXT_ATTR_BULLET_STYLE,
106 wxTEXT_ATTR_BULLET_NUMBER,
107 wxTEXT_ATTR_BULLET_TEXT,
108 wxTEXT_ATTR_BULLET_NAME,
110 wxTEXT_ATTR_PAGE_BREAK,
112 wxTEXT_ATTR_OUTLINE_LEVEL,
115 * Styles for wxTextAttrEx::SetBulletStyle
117 wxTEXT_ATTR_BULLET_STYLE_NONE,
118 wxTEXT_ATTR_BULLET_STYLE_ARABIC,
119 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER,
120 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER,
121 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER,
122 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER,
123 wxTEXT_ATTR_BULLET_STYLE_SYMBOL,
124 wxTEXT_ATTR_BULLET_STYLE_BITMAP,
125 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES,
126 wxTEXT_ATTR_BULLET_STYLE_PERIOD,
127 wxTEXT_ATTR_BULLET_STYLE_STANDARD,
128 wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS,
129 wxTEXT_ATTR_BULLET_STYLE_OUTLINE,
131 wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT,
132 wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT,
133 wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE,
136 * Styles for wxTextAttrEx::SetTextEffects
138 wxTEXT_ATTR_EFFECT_NONE,
139 wxTEXT_ATTR_EFFECT_CAPITALS,
140 wxTEXT_ATTR_EFFECT_SMALL_CAPITALS,
141 wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
142 wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH,
143 wxTEXT_ATTR_EFFECT_SHADOW,
144 wxTEXT_ATTR_EFFECT_EMBOSS,
145 wxTEXT_ATTR_EFFECT_OUTLINE,
146 wxTEXT_ATTR_EFFECT_ENGRAVE,
147 wxTEXT_ATTR_EFFECT_SUPERSCRIPT,
148 wxTEXT_ATTR_EFFECT_SUBSCRIPT,
151 * Line spacing values
153 wxTEXT_ATTR_LINE_SPACING_NORMAL,
154 wxTEXT_ATTR_LINE_SPACING_HALF,
155 wxTEXT_ATTR_LINE_SPACING_TWICE,
158 * Character and paragraph combined styles
160 wxTEXT_ATTR_CHARACTER,
161 wxTEXT_ATTR_PARAGRAPH,
167 //---------------------------------------------------------------------------
172 %typemap(in) wxRichTextRange& (wxRichTextRange temp) {
174 if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail;
176 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& {
177 $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2);
182 bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj)
184 if (source == Py_None) {
185 **obj = wxRICHTEXT_NONE;
188 return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange"));
194 DocStr(wxRichTextRange,
195 "RichTextRange is a data structure that represents a range of text
196 within a `RichTextCtrl`. It simply contains integer ``start`` and
197 ``end`` properties and a few operations useful for dealing with
198 ranges. In most places in wxPython where a RichTextRange is expected a
199 2-tuple containing (start, end) can be used instead.", "");
201 // Turn off the generation of code that aquires the Global Interpreter Lock
204 class wxRichTextRange
208 wxRichTextRange(long start=0, long end=0),
209 "Creates a new range object.", "");
214 DocStr(__eq__, "Test for equality of RichTextRange objects.", "");
215 bool __eq__(PyObject* other) {
216 wxRichTextRange temp, *obj = &temp;
217 if ( other == Py_None ) return false;
218 if ( ! wxRichTextRange_helper(other, &obj) ) {
222 return self->operator==(*obj);
228 wxRichTextRange , operator -(const wxRichTextRange& range) const,
232 wxRichTextRange , operator +(const wxRichTextRange& range) const,
237 void , SetRange(long start, long end),
242 void , SetStart(long start),
245 long , GetStart() const,
247 %pythoncode { start = property(GetStart, SetStart) }
251 void , SetEnd(long end),
254 long , GetEnd() const,
256 %pythoncode { end = property(GetEnd, SetEnd) }
260 bool , IsOutside(const wxRichTextRange& range) const,
261 "Returns true if this range is completely outside 'range'", "");
265 bool , IsWithin(const wxRichTextRange& range) const,
266 "Returns true if this range is completely within 'range'", "");
270 bool , Contains(long pos) const,
271 "Returns true if the given position is within this range. Allow for the
272 possibility of an empty range - assume the position is within this
277 bool , LimitTo(const wxRichTextRange& range) ,
278 "Limit this range to be within 'range'", "");
282 long , GetLength() const,
283 "Gets the length of the range", "");
288 "Swaps the start and end", "");
292 wxRichTextRange , ToInternal() const,
293 "Convert to internal form: (n, n) is the range of a single character.", "");
297 wxRichTextRange , FromInternal() const,
298 "Convert from internal to public API form: (n, n+1) is the range of a
299 single character.", "");
304 "Get() -> (start,end)",
305 "Returns the start and end properties as a tuple.", "");
307 PyObject* tup = PyTuple_New(2);
308 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart()));
309 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd()));
314 def __str__(self): return str(self.Get())
315 def __repr__(self): return 'RichTextRange'+str(self.Get())
316 def __len__(self): return len(self.Get())
317 def __getitem__(self, index): return self.Get()[index]
318 def __setitem__(self, index, val):
319 if index == 0: self.start = val
320 elif index == 1: self.end = val
321 else: raise IndexError
322 def __nonzero__(self): return self.Get() != (0,0)
323 __safe_for_unpickling__ = True
324 def __reduce__(self): return (RichTextRange, self.Get())
327 %property(End, GetEnd, SetEnd, doc="See `GetEnd` and `SetEnd`");
328 %property(Length, GetLength, doc="See `GetLength`");
329 %property(Start, GetStart, SetStart, doc="See `GetStart` and `SetStart`");
335 wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL);
336 wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE);
339 %rename(RICHTEXT_ALL) wxPy_RTR_ALL;
340 %rename(RICHTEXT_NONE) wxPy_RTR_NONE;
343 wxRichTextRange wxPy_RTR_ALL;
344 wxRichTextRange wxPy_RTR_NONE;
347 // Turn back on the generation of code that aquires the Global Interpreter Lock
353 //---------------------------------------------------------------------------
357 DocStr(wxRichTextAttr,
358 "The RichTextAttr class stores information about the various attributes
359 for a block of text, including font, colour, indents, alignments, and
366 wxRichTextAttr(const wxColour& colText = wxNullColour,
367 const wxColour& colBack = wxNullColour,
368 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
372 // // Making a wxTextAttrEx object.
373 // operator wxTextAttrEx () const ;
375 // // Copy to a wxTextAttr
376 // void CopyTo(wxTextAttrEx& attr) const;
381 "Initialise this object.", "");
385 void , Copy(const wxRichTextAttr& attr),
386 "Copy from attr to self.", "");
390 bool operator== (const wxRichTextAttr& attr) const;
395 wxFont , CreateFont() const,
396 "Create font from the font attributes in this attr object.", "");
400 bool , GetFontAttributes(const wxFont& font),
401 "Set our font attributes from the font.", "");
406 return self.CreateFont()
407 def SetFont(self, font):
408 return self.GetFontAttributes(font)
412 void SetTextColour(const wxColour& colText);
413 void SetBackgroundColour(const wxColour& colBack);
414 void SetAlignment(wxTextAttrAlignment alignment);
415 void SetTabs(const wxArrayInt& tabs);
416 void SetLeftIndent(int indent, int subIndent = 0);
417 void SetRightIndent(int indent);
419 void SetFontSize(int pointSize);
420 void SetFontStyle(int fontStyle);
421 void SetFontWeight(int fontWeight);
422 void SetFontFaceName(const wxString& faceName);
423 void SetFontUnderlined(bool underlined);
425 void SetFlags(long flags);
427 void SetCharacterStyleName(const wxString& name);
428 void SetParagraphStyleName(const wxString& name);
429 void SetListStyleName(const wxString& name);
430 void SetParagraphSpacingAfter(int spacing);
431 void SetParagraphSpacingBefore(int spacing);
432 void SetLineSpacing(int spacing);
433 void SetBulletStyle(int style);
434 void SetBulletNumber(int n);
435 void SetBulletText(wxChar symbol);
436 void SetBulletFont(const wxString& bulletFont);
437 void SetBulletName(const wxString& name);
438 void SetURL(const wxString& url);
439 void SetPageBreak(bool pageBreak = true);
440 void SetTextEffects(int effects);
441 void SetTextEffectFlags(int effects);
442 void SetOutlineLevel(int level);
444 const wxColour& GetTextColour() const;
445 const wxColour& GetBackgroundColour() const;
446 wxTextAttrAlignment GetAlignment() const;
447 const wxArrayInt& GetTabs() const;
448 long GetLeftIndent() const;
449 long GetLeftSubIndent() const;
450 long GetRightIndent() const;
451 long GetFlags() const;
453 int GetFontSize() const;
454 int GetFontStyle() const;
455 int GetFontWeight() const;
456 bool GetFontUnderlined() const;
457 const wxString& GetFontFaceName() const;
459 const wxString& GetCharacterStyleName() const;
460 const wxString& GetParagraphStyleName() const;
461 const wxString& GetListStyleName() const;
462 int GetParagraphSpacingAfter() const;
463 int GetParagraphSpacingBefore() const;
464 int GetLineSpacing() const;
465 int GetBulletStyle() const;
466 int GetBulletNumber() const;
467 const wxString& GetBulletText() const;
468 const wxString& GetBulletFont() const;
469 const wxString& GetBulletName() const;
470 const wxString& GetURL() const;
471 int GetTextEffects() const;
472 int GetTextEffectFlags() const;
473 int GetOutlineLevel() const;
476 bool HasTextColour() const;
477 bool HasBackgroundColour() const;
478 bool HasAlignment() const;
479 bool HasTabs() const;
480 bool HasLeftIndent() const;
481 bool HasRightIndent() const;
482 bool HasFontWeight() const;
483 bool HasFontSize() const;
484 bool HasFontItalic() const;
485 bool HasFontUnderlined() const;
486 bool HasFontFaceName() const;
487 bool HasFont() const;
489 bool HasParagraphSpacingAfter() const;
490 bool HasParagraphSpacingBefore() const;
491 bool HasLineSpacing() const;
492 bool HasCharacterStyleName() const;
493 bool HasParagraphStyleName() const;
494 bool HasListStyleName() const;
495 bool HasBulletStyle() const;
496 bool HasBulletNumber() const;
497 bool HasBulletText() const;
498 bool HasBulletName() const;
500 bool HasPageBreak() const;
501 bool HasTextEffects() const;
502 bool HasTextEffect(int effect) const;
503 bool HasOutlineLevel() const;
505 bool HasFlag(long flag) const;
507 bool IsCharacterStyle() const;
508 bool IsParagraphStyle() const;
512 bool , IsDefault() const,
513 "Returns false if we have any attributes set, true otherwise", "");
517 bool , Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL),
518 "Merges the given attributes. Does not affect self. If compareWith is
519 not None, then it will be used to mask out those attributes that are
520 the same in style and compareWith, for situations where we don't want
521 to explicitly set inherited attributes.
526 wxRichTextAttr , Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const,
527 "Merges the given attributes and returns the result. Does not affect
528 self. If compareWith is not None, then it will be used to mask out
529 those attributes that are the same in style and compareWith, for
530 situations where we don't want to explicitly set inherited attributes.
535 %property(Alignment, GetAlignment, SetAlignment);
536 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour);
537 %property(BulletFont, GetBulletFont, SetBulletFont);
538 %property(BulletNumber, GetBulletNumber, SetBulletNumber);
539 %property(BulletStyle, GetBulletStyle, SetBulletStyle);
540 %property(BulletText, GetBulletText, SetBulletText);
541 %property(CharacterStyleName, GetCharacterStyleName, SetCharacterStyleName);
542 %property(Flags, GetFlags, SetFlags);
543 %property(Font, GetFont, SetFont);
544 %property(FontAttributes, GetFontAttributes);
545 %property(FontFaceName, GetFontFaceName, SetFontFaceName);
546 %property(FontSize, GetFontSize, SetFontSize);
547 %property(FontStyle, GetFontStyle, SetFontStyle);
548 %property(FontUnderlined, GetFontUnderlined, SetFontUnderlined);
549 %property(FontWeight, GetFontWeight, SetFontWeight);
550 %property(LeftIndent, GetLeftIndent, SetLeftIndent);
551 %property(LeftSubIndent, GetLeftSubIndent);
552 %property(LineSpacing, GetLineSpacing, SetLineSpacing);
553 %property(ParagraphSpacingAfter, GetParagraphSpacingAfter, SetParagraphSpacingAfter);
554 %property(ParagraphSpacingBefore, GetParagraphSpacingBefore, SetParagraphSpacingBefore);
555 %property(ParagraphStyleName, GetParagraphStyleName, SetParagraphStyleName);
556 %property(RightIndent, GetRightIndent, SetRightIndent);
557 %property(Tabs, GetTabs, SetTabs);
558 %property(TextColour, GetTextColour, SetTextColour);
560 %property(ListStyleName, GetListStyleName, SetListStyleName);
561 %property(BulletName, GetBulletName, SetBulletName);
562 %property(URL, GetURL, SetURL);
563 %property(TextEffects, GetTextEffects, SetTextEffects);
564 %property(TextEffectFlags, GetTextEffectFlags, SetTextEffectFlags);
565 %property(OutlineLevel, GetOutlineLevel, SetOutlineLevel);
570 //---------------------------------------------------------------------------
571 //---------------------------------------------------------------------------
575 // There's still lots to do for these classes...
577 // 1. Decide how to coalesce overloaded methods and ctors
578 // 2. correctly set disown flags and re-ownership as needed
579 // 3. Implement PyRichTextObject
580 // 4. Decide how to typemap and tweak the virtuals that pass back
581 // values in their parameters (yuck! damn C++)
582 // 5. better handling of streams
583 // 6. list-like wrapper for C++ wxLists
584 // 7. wrappers for wxTextAttrEx --> wxRichTextAttr (as needed)
585 // 8. Add more properties
589 DocStr(wxRichTextObject,
590 "This is the base class for all drawable objects in a `RichTextCtrl`.
592 The data displayed in a `RichTextCtrl` is handled by `RichTextBuffer`,
593 and a `RichTextCtrl` always has one such buffer.
595 The content is represented by a hierarchy of objects, all derived from
596 `RichTextObject`. An object might be an image, a fragment of text, a
597 paragraph, or a whole buffer. Objects store a an attribute object
598 containing style information; a paragraph object can contain both
599 paragraph and character information, but content objects such as text
600 can only store character information. The final style displayed in the
601 control or in a printout is a combination of base style, paragraph
602 style and content (character) style.
604 The top of the hierarchy is the buffer, a kind of
605 `RichTextParagraphLayoutBox`. containing further `RichTextParagraph`
606 objects, each of which can include text, images and potentially other
609 Each object maintains a range (start and end position) measured from
610 the start of the main parent object.
612 When Layout is called on an object, it is given a size which the
613 object must limit itself to, or one or more flexible directions
614 (vertical or horizontal). So, for example, a centred paragraph is
615 given the page width to play with (minus any margins), but can extend
616 indefinitely in the vertical direction. The implementation of Layout
617 caches the calculated size and position.
619 When the buffer is modified, a range is invalidated (marked as
620 requiring layout), so that only the minimum amount of layout is
623 A paragraph of pure text with the same style contains just one further
624 object, a `RichTextPlainText` object. When styling is applied to part
625 of this object, the object is decomposed into separate objects, one
626 object for each different character style. So each object within a
627 paragraph always has just one attribute object to denote its character
628 style. Of course, this can lead to fragmentation after a lot of edit
629 operations, potentially leading to several objects with the same style
630 where just one would do. So a Defragment function is called when
631 updating the control's display, to ensure that the minimum number of
634 To implement your own RichTextObjects in Python you must derive a
635 class from `PyRichTextObject`, which has been instrumented to forward
636 the virtual C++ method calls to the Python methods in the derived
637 class. (This class hasn't been implemented yet!)", "");
639 // argout typemap for wxPoint
640 %typemap(in, numinputs=0, noblock=1) wxPoint& OUTPUT (wxPoint temp) {
643 %typemap(argout, noblock=1) wxPoint& OUTPUT {
644 %append_output(SWIG_NewPointerObj((void*)new wxPoint(*$1), $1_descriptor, SWIG_POINTER_OWN));
647 // argout typemap for wxSize
648 %typemap(in, numinputs=0, noblock=1) wxSize& OUTPUT (wxSize temp) {
651 %typemap(argout, noblock=1) wxSize& OUTPUT {
652 %append_output(SWIG_NewPointerObj((void*)new wxSize(*$1), $1_descriptor, SWIG_POINTER_OWN));
656 class wxRichTextObject: public wxObject
659 // wxRichTextObject(wxRichTextObject* parent = NULL); // **** This is an ABC
660 virtual ~wxRichTextObject();
665 /// Draw the item, within the given range. Some objects may ignore the range (for
666 /// example paragraphs) while others must obey it (lines, to implement wrapping)
667 virtual bool Draw(wxDC& dc, const wxRichTextRange& range,
668 const wxRichTextRange& selectionRange, const wxRect& rect,
669 int descent, int style);
671 /// Lay the item out at the specified position with the given size constraint.
672 /// Layout must set the cached size.
673 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
675 /// Hit-testing: returns a flag indicating hit test details, plus
676 /// information about position
677 virtual int HitTest(wxDC& dc, const wxPoint& pt, long& OUTPUT /*textPosition*/);
679 /// Finds the absolute position and row height for the given character position
680 virtual bool FindPosition(wxDC& dc, long index, wxPoint& OUTPUT /*pt*/,
681 int* OUTPUT /*height*/, bool forceLineStart);
684 /// Get the best size, i.e. the ideal starting size for this object irrespective
685 /// of available space. For a short text string, it will be the size that exactly encloses
686 /// the text. For a longer string, it might use the parent width for example.
687 virtual wxSize GetBestSize() const;
689 /// Get the object size for the given range. Returns false if the range
690 /// is invalid for this object.
691 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& OUTPUT /*size*/,
692 int& OUTPUT /*descent*/, wxDC& dc, int flags,
693 wxPoint position = wxPoint(0,0)) const;
695 /// Do a split, returning an object containing the second part, and setting
696 /// the first part in 'this'.
697 virtual wxRichTextObject* DoSplit(long pos);
699 /// Calculate range. By default, guess that the object is 1 unit long.
700 virtual void CalculateRange(long start, long& OUTPUT /*end*/);
703 virtual bool DeleteRange(const wxRichTextRange& range);
705 /// Returns true if the object is empty
706 virtual bool IsEmpty() const;
708 /// Get any text in this object for the given range
709 virtual wxString GetTextForRange(const wxRichTextRange& range) const;
711 /// Returns true if this object can merge itself with the given one.
712 virtual bool CanMerge(wxRichTextObject* object) const;
714 /// Returns true if this object merged itself with the given one.
715 /// The calling code will then delete the given object.
716 virtual bool Merge(wxRichTextObject* object);
718 /// Dump to output stream for debugging
719 //virtual void Dump(wxTextOutputStream& stream);
722 wxStringOutputStream strstream;
723 wxTextOutputStream txtstream(strstream);
724 self->Dump(txtstream);
725 return strstream.GetString();
731 /// Get/set the cached object size as calculated by Layout.
732 virtual wxSize GetCachedSize() const;
733 virtual void SetCachedSize(const wxSize& sz);
734 %property(CachedSize, GetCachedSize, SetCachedSize);
736 /// Get/set the object position
737 virtual wxPoint GetPosition() const;
738 virtual void SetPosition(const wxPoint& pos);
739 %property(Position, GetPosition, SetPosition);
741 /// Get the rectangle enclosing the object
742 virtual wxRect GetRect() const;
743 %property(Rect, GetRect);
747 void SetRange(const wxRichTextRange& range);
749 wxRichTextRange GetRange();
750 %property(Range, GetRange, SetRange);
753 /// Get/set dirty flag (whether the object needs Layout to be called)
754 virtual bool GetDirty() const;
755 virtual void SetDirty(bool dirty);
756 %property(Dirty, GetDirty, SetDirty);
759 /// Is this composite?
760 virtual bool IsComposite() const;
762 /// Get/set the parent.
763 virtual wxRichTextObject* GetParent() const;
764 virtual void SetParent(wxRichTextObject* parent);
765 %property(Parent, GetParent, SetParent);
768 // TODO: Morph these into SetLeftMargin and etc. for wxPython so
769 // there can be proper properties
771 /// Set the margin around the object
772 %Rename(SetSameMargins,
773 virtual void , SetMargins(int margin));
774 virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin);
775 virtual int GetLeftMargin() const;
776 virtual int GetRightMargin() const;
777 virtual int GetTopMargin() const;
778 virtual int GetBottomMargin() const;
781 /// Set attributes object
782 void SetAttributes(const wxRichTextAttr& attr);
783 wxRichTextAttr GetAttributes();
784 %property(Attributes, GetAttributes, SetAttributes);
786 /// Set/get stored descent
787 void SetDescent(int descent);
788 int GetDescent() const;
789 %property(Descent, GetDescent, SetDescent);
791 /// Gets the containing buffer
792 wxRichTextBuffer* GetBuffer() const;
797 virtual wxRichTextObject* Clone() const;
800 void Copy(const wxRichTextObject& obj);
802 /// Reference-counting allows us to use the same object in multiple
803 /// lists (not yet used)
807 /// Convert units in tenths of a millimetre to device units
808 %Rename(ConvertTenthsMMToPixelsDC,
809 int, ConvertTenthsMMToPixels(wxDC& dc, int units));
810 static int ConvertTenthsMMToPixels(int ppi, int units);
817 wxLIST_WRAPPER(wxRichTextObjectList, wxRichTextObject);
820 DocStr(wxRichTextCompositeObject,
821 "Objects of this class can contain other rich text objects.", "");
824 class wxRichTextCompositeObject: public wxRichTextObject
827 // wxRichTextCompositeObject(wxRichTextObject* parent = NULL); **** This is an ABC
828 virtual ~wxRichTextCompositeObject();
833 wxRichTextObjectList& GetChildren();
835 /// Get the child count
836 size_t GetChildCount() const ;
838 /// Get the nth child
839 wxRichTextObject* GetChild(size_t n) const ;
844 void Copy(const wxRichTextCompositeObject& obj);
846 %disownarg(wxRichTextObject* child);
848 /// Append a child, returning the position
849 size_t AppendChild(wxRichTextObject* child) ;
851 /// Insert the child in front of the given object, or at the beginning
852 bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ;
854 %cleardisown(wxRichTextObject* child);
858 %feature("shadow") RemoveChild %{
859 def RemoveChild(self, child, deleteChild=False):
860 val = _richtext.RichTextCompositeObject_RemoveChild(self, child, deleteChild)
861 self.this.own(not deleteChild)
864 bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ;
866 /// Delete all children
867 bool DeleteChildren();
869 /// Recursively merge all pieces that can be merged.
878 DocStr(wxRichTextBox,
879 "This defines a 2D space to lay out objects.", "");
881 class wxRichTextBox: public wxRichTextCompositeObject
884 wxRichTextBox(wxRichTextObject* parent = NULL);
886 virtual wxRichTextObject* Clone() const;
887 void Copy(const wxRichTextBox& obj);
895 DocStr(wxRichTextParagraphBox,
896 "This box knows how to lay out paragraphs.", "");
898 class wxRichTextParagraphLayoutBox: public wxRichTextBox
902 wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
906 /// Associate a control with the buffer, for operations that for example require refreshing the window.
907 void SetRichTextCtrl(wxRichTextCtrl* ctrl);
909 /// Get the associated control.
910 wxRichTextCtrl* GetRichTextCtrl() const;
912 /// Get/set whether the last paragraph is partial or complete
913 void SetPartialParagraph(bool partialPara);
914 bool GetPartialParagraph() const;
916 /// If this is a buffer, returns the current style sheet. The base layout box
917 /// class doesn't have an associated style sheet.
918 virtual wxRichTextStyleSheet* GetStyleSheet() const;
922 /// Initialize the object.
925 /// Clear all children
926 virtual void Clear();
928 /// Clear and initialize with one blank paragraph
929 virtual void Reset();
931 /// Convenience function to add a paragraph of text
932 virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL);
934 /// Convenience function to add an image
935 virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL);
937 /// Adds multiple paragraphs, based on newlines.
938 virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL);
940 /// Get the line at the given position. If caretPosition is true, the position is
941 /// a caret position, which is normally a smaller number.
942 virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const;
944 /// Get the line at the given y pixel position, or the last line.
945 virtual wxRichTextLine* GetLineAtYPosition(int y) const;
947 /// Get the paragraph at the given character or caret position
948 virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const;
950 /// Get the line size at the given position
951 virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const;
953 /// Given a position, get the number of the visible line (potentially many to a paragraph),
954 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
955 /// that indicates whether the caret is being shown at the end of the previous line or at the start
956 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
958 virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const;
960 /// Given a line number, get the corresponding wxRichTextLine object.
961 virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const;
963 /// Get the leaf object in a paragraph at this position.
964 /// Given a line number, get the corresponding wxRichTextLine object.
965 virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
967 /// Get the paragraph by number
968 virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
970 /// Get the paragraph for a given line
971 virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
973 /// Get the length of the paragraph
974 virtual int GetParagraphLength(long paragraphNumber) const;
976 /// Get the number of paragraphs
977 virtual int GetParagraphCount() const { return GetChildCount(); }
979 /// Get the number of visible lines
980 virtual int GetLineCount() const;
982 /// Get the text of the paragraph
983 virtual wxString GetParagraphText(long paragraphNumber) const;
985 /// Convert zero-based line column and paragraph number to a position.
986 virtual long XYToPosition(long x, long y) const;
988 /// Convert zero-based position to line column and paragraph number
989 virtual bool PositionToXY(long pos, long* x, long* y) const;
991 /// Set text attributes: character and/or paragraph styles.
992 virtual bool SetStyle(const wxRichTextRange& range,
993 const wxRichTextAttr& style,
994 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
995 // virtual bool SetStyle(const wxRichTextRange& range,
996 // const wxTextAttrEx& style,
997 // int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
999 /// Get the conbined text attributes for this position.
1000 // virtual bool GetStyle(long position, wxTextAttrEx& style);
1001 virtual bool GetStyle(long position, wxRichTextAttr& style);
1003 /// Get the content (uncombined) attributes for this position.
1004 // virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
1005 virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
1007 // /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1008 // /// context attributes.
1009 // virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true);
1011 /// Get the combined style for a range - if any attribute is different within the range,
1012 /// that attribute is not present within the flags
1013 virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style);
1015 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1017 bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes);
1020 //virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1021 virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName,
1022 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1023 int startFrom = 1, int specifiedLevel = -1);
1025 /// Clear list for given range
1026 virtual bool ClearListStyle(const wxRichTextRange& range,
1027 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1029 /// Number/renumber any list elements in the given range.
1030 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1031 //virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1032 virtual bool NumberList(const wxRichTextRange& range, const wxString& defName,
1033 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1034 int startFrom = 1, int specifiedLevel = -1);
1036 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1037 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1038 //virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
1039 virtual bool PromoteList(int promoteBy, const wxRichTextRange& range,
1040 const wxString& defName,
1041 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO,
1042 int specifiedLevel = -1);
1044 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1045 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1046 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);
1048 /// Fills in the attributes for numbering a paragraph after previousParagraph.
1049 virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const;
1051 /// Test if this whole range has character attributes of the specified kind. If any
1052 /// of the attributes are different within the range, the test fails. You
1053 /// can use this to implement, for example, bold button updating. style must have
1054 /// flags indicating which attributes are of interest.
1055 //virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1056 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1058 /// Test if this whole range has paragraph attributes of the specified kind. If any
1059 /// of the attributes are different within the range, the test fails. You
1060 /// can use this to implement, for example, centering button updating. style must have
1061 /// flags indicating which attributes are of interest.
1062 //virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1063 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1066 virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1068 /// Insert fragment into this box at the given position. If partialParagraph is true,
1069 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1071 virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
1073 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1074 virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment);
1076 /// Apply the style sheet to the buffer, for example if the styles have changed.
1077 virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
1080 void Copy(const wxRichTextParagraphLayoutBox& obj);
1082 /// Calculate ranges
1083 virtual void UpdateRanges();
1085 /// Get all the text
1086 virtual wxString GetText() const;
1088 /// Set default style for new content. Setting it to a default attribute
1089 /// makes new content take on the 'basic' style.
1090 virtual bool SetDefaultStyle(const wxTextAttrEx& style);
1092 /// Get default style
1093 virtual const wxTextAttrEx& GetDefaultStyle() const;
1095 /// Set basic (overall) style
1096 //virtual void SetBasicStyle(const wxTextAttrEx& style);
1097 virtual void SetBasicStyle(const wxRichTextAttr& style);
1099 /// Get basic (overall) style
1100 virtual const wxTextAttrEx& GetBasicStyle() const;
1102 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1103 void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
1105 /// Get invalid range, rounding to entire paragraphs if argument is true.
1106 wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
1114 DocStr(wxRichTextLine,
1115 "This object represents a line in a paragraph, and stores offsets from
1116 the start of the paragraph representing the start and end positions of
1119 class wxRichTextLine
1122 wxRichTextLine(wxRichTextParagraph* parent);
1123 virtual ~wxRichTextLine();
1126 void SetRange(const wxRichTextRange& range);
1128 /// Get the parent paragraph
1129 wxRichTextParagraph* GetParent();
1132 wxRichTextRange GetRange();
1134 /// Get the absolute range
1135 wxRichTextRange GetAbsoluteRange() const;
1137 /// Get/set the line size as calculated by Layout.
1138 virtual wxSize GetSize() const;
1139 virtual void SetSize(const wxSize& sz);
1141 /// Get/set the object position relative to the parent
1142 virtual wxPoint GetPosition() const;
1143 virtual void SetPosition(const wxPoint& pos);
1145 /// Get the absolute object position
1146 virtual wxPoint GetAbsolutePosition() const;
1148 /// Get the rectangle enclosing the line
1149 virtual wxRect GetRect() const;
1151 /// Set/get stored descent
1152 void SetDescent(int descent);
1153 int GetDescent() const;
1158 void Init(wxRichTextParagraph* parent);
1161 void Copy(const wxRichTextLine& obj);
1164 virtual wxRichTextLine* Clone() const;
1172 DocStr(wxRichTextParagraph,
1173 "This object represents a single paragraph (or in a straight text
1174 editor, a line).", "");
1176 class wxRichTextParagraph: public wxRichTextBox
1180 wxRichTextParagraph(const wxString& text = wxPyEmptyString,
1181 wxRichTextObject* parent = NULL,
1182 wxRichTextAttr* paraStyle = NULL,
1183 wxRichTextAttr* charStyle = NULL)
1185 wxTextAttrEx* psAttr = NULL;
1186 wxTextAttrEx* csAttr = NULL;
1187 wxTextAttrEx psAttr_v;
1188 wxTextAttrEx csAttr_v;
1190 psAttr_v = *paraStyle;
1194 csAttr_v = *charStyle;
1197 return new wxRichTextParagraph(text, parent, psAttr, csAttr);
1200 virtual ~wxRichTextParagraph();
1205 /// Get the cached lines
1206 wxRichTextLineList& GetLines();
1211 void Copy(const wxRichTextParagraph& obj);
1214 virtual wxRichTextObject* Clone() const;
1216 /// Clear the cached lines
1221 /// Apply paragraph styles such as centering to the wrapped lines
1222 virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect);
1224 /// Insert text at the given position
1225 virtual bool InsertText(long pos, const wxString& text);
1227 /// Split an object at this position if necessary, and return
1228 /// the previous object, or NULL if inserting at beginning.
1229 virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL);
1231 /// Move content to a list from this point
1232 virtual void MoveToList(wxRichTextObject* obj, wxList& list);
1234 /// Add content back from list
1235 virtual void MoveFromList(wxList& list);
1237 /// Get the plain text searching from the start or end of the range.
1238 /// The resulting string may be shorter than the range given.
1239 bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true);
1241 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1243 bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition);
1245 /// Find the object at the given position
1246 wxRichTextObject* FindObjectAtPosition(long position);
1248 /// Get the bullet text for this paragraph.
1249 wxString GetBulletText();
1251 /// Allocate or reuse a line object
1252 wxRichTextLine* AllocateLine(int pos);
1254 /// Clear remaining unused line objects, if any
1255 bool ClearUnusedLines(int lineCount);
1257 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1258 /// retrieve the actual style.
1259 // wxTextAttrEx GetCombinedAttributes(const wxTextAttrEx& contentStyle) const;
1261 /// Get combined attributes of the base style and paragraph style.
1262 wxTextAttrEx GetCombinedAttributes() const;
1264 /// Get the first position from pos that has a line break character.
1265 long GetFirstLineBreakPosition(long pos);
1267 /// Create default tabstop array
1268 static void InitDefaultTabs();
1270 /// Clear default tabstop array
1271 static void ClearDefaultTabs();
1273 /// Get default tabstop array
1274 static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; }
1283 DocStr(wxRichTextPlainText,
1284 "This object represents a single piece of text.", "");
1286 class wxRichTextPlainText: public wxRichTextObject
1289 wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
1291 /// Get the first position from pos that has a line break character.
1292 long GetFirstLineBreakPosition(long pos);
1295 const wxString& GetText() const;
1298 void SetText(const wxString& text);
1303 void Copy(const wxRichTextPlainText& obj);
1306 virtual wxRichTextObject* Clone() const;
1316 // TODO: we may not even need wrappers for this class. It looks to me
1317 // like wxRichTextImage might be enough...
1318 DocStr(wxRichTextImageBlock,
1319 "Stores information about an image, in binary in-memory form.", "");
1321 class wxRichTextImageBlock: public wxObject
1324 wxRichTextImageBlock();
1325 virtual ~wxRichTextImageBlock();
1330 // Load the original image into a memory block.
1331 // If the image is not a JPEG, we must convert it into a JPEG
1332 // to conserve space.
1333 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1334 // load the image a 2nd time.
1335 virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true);
1337 // Make an image block from the wxImage in the given
1339 virtual bool MakeImageBlock(wxImage& image, int imageType, int quality = 80);
1342 bool Write(const wxString& filename);
1344 // Write data in hex to a stream
1345 bool WriteHex(wxOutputStream& stream);
1347 // Read data in hex from a stream
1348 bool ReadHex(wxInputStream& stream, int length, int imageType);
1350 // Copy from 'block'
1351 void Copy(const wxRichTextImageBlock& block);
1353 // Load a wxImage from the block
1354 bool Load(wxImage& image);
1359 unsigned char* GetData() const;
1360 size_t GetDataSize() const;
1361 int GetImageType() const;
1363 void SetData(unsigned char* image);
1364 void SetDataSize(size_t size);
1365 void SetImageType(int imageType);
1369 // Gets the extension for the block's type
1370 wxString GetExtension() const;
1374 // Allocate and read from stream as a block of memory
1375 static unsigned char* ReadBlock(wxInputStream& stream, size_t size);
1376 static unsigned char* ReadBlock(const wxString& filename, size_t size);
1378 // Write memory block to stream
1379 static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size);
1381 // Write memory block to file
1382 static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size);
1391 DocStr(wxRichTextImage,
1392 "This object represents an image.", "");
1394 class wxRichTextImage: public wxRichTextObject
1397 // TODO: Which of these constructors?
1398 wxRichTextImage(wxRichTextObject* parent = NULL);
1399 //wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
1400 //wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
1406 const wxImage& GetImage() const;
1409 void SetImage(const wxImage& image);
1411 /// Get the image block containing the raw data
1412 wxRichTextImageBlock& GetImageBlock();
1417 void Copy(const wxRichTextImage& obj);
1420 virtual wxRichTextObject* Clone() const;
1422 /// Load wxImage from the block
1423 virtual bool LoadFromBlock();
1425 /// Make block from the wxImage
1426 virtual bool MakeBlock();
1434 %typemap(out) wxRichTextFileHandler* { $result = wxPyMake_wxObject($1, (bool)$owner); }
1435 wxUNTYPED_LIST_WRAPPER(wxRichTextFileHandlerList, wxRichTextFileHandler);
1437 DocStr(wxRichTextBuffer,
1438 "This is a kind of box, used to represent the whole buffer.", "");
1440 class wxRichTextCommand;
1441 class wxRichTextAction;
1443 class wxRichTextBuffer: public wxRichTextParagraphLayoutBox
1447 virtual ~wxRichTextBuffer() ;
1451 /// Gets the command processor
1452 wxCommandProcessor* GetCommandProcessor() const;
1454 /// Set style sheet, if any.
1455 void SetStyleSheet(wxRichTextStyleSheet* styleSheet);
1456 virtual wxRichTextStyleSheet* GetStyleSheet() const;
1458 /// Set style sheet and notify of the change
1459 bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet);
1461 /// Push style sheet to top of stack
1462 bool PushStyleSheet(wxRichTextStyleSheet* styleSheet);
1464 /// Pop style sheet from top of stack
1465 wxRichTextStyleSheet* PopStyleSheet();
1472 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1473 virtual void ResetAndClearCommands();
1476 virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1479 virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1481 /// Load from a stream
1483 virtual bool , LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY));
1485 /// Save to a stream
1487 virtual bool , SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY));
1489 /// Set the handler flags, controlling loading and saving
1490 void SetHandlerFlags(int flags) { m_handlerFlags = flags; }
1492 /// Get the handler flags, controlling loading and saving
1493 int GetHandlerFlags() const { return m_handlerFlags; }
1495 /// Convenience function to add a paragraph of text
1496 virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); }
1498 /// Begin collapsing undo/redo commands. Note that this may not work properly
1499 /// if combining commands that delete or insert content, changing ranges for
1500 /// subsequent actions.
1501 virtual bool BeginBatchUndo(const wxString& cmdName);
1503 /// End collapsing undo/redo commands
1504 virtual bool EndBatchUndo();
1506 /// Collapsing commands?
1507 virtual bool BatchingUndo() const;
1509 /// Submit immediately, or delay according to whether collapsing is on
1510 virtual bool SubmitAction(wxRichTextAction* action);
1512 /// Get collapsed command
1513 virtual wxRichTextCommand* GetBatchedCommand() const;
1515 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1516 /// differently by each command. If not dealt with by a command implementation, then
1517 /// it will be implemented automatically by not storing the command in the undo history
1518 /// when the action is submitted to the command processor.
1519 virtual bool BeginSuppressUndo();
1521 /// End suppressing undo/redo commands.
1522 virtual bool EndSuppressUndo();
1524 /// Collapsing commands?
1525 virtual bool SuppressingUndo() const;
1527 /// Copy the range to the clipboard
1528 virtual bool CopyToClipboard(const wxRichTextRange& range);
1530 /// Paste the clipboard content to the buffer
1531 virtual bool PasteFromClipboard(long position);
1533 /// Can we paste from the clipboard?
1534 virtual bool CanPasteFromClipboard() const;
1536 /// Begin using a style
1537 virtual bool BeginStyle(const wxTextAttrEx& style);
1540 virtual bool EndStyle();
1543 virtual bool EndAllStyles();
1545 /// Clear the style stack
1546 virtual void ClearStyleStack();
1548 /// Get the size of the style stack, for example to check correct nesting
1549 virtual size_t GetStyleStackSize() const;
1551 /// Begin using bold
1557 /// Begin using italic
1560 /// End using italic
1563 /// Begin using underline
1564 bool BeginUnderline();
1566 /// End using underline
1567 bool EndUnderline();
1569 /// Begin using point size
1570 bool BeginFontSize(int pointSize);
1572 /// End using point size
1575 /// Begin using this font
1576 bool BeginFont(const wxFont& font);
1578 /// End using a font
1581 /// Begin using this colour
1582 bool BeginTextColour(const wxColour& colour);
1584 /// End using a colour
1585 bool EndTextColour();
1587 /// Begin using alignment
1588 bool BeginAlignment(wxTextAttrAlignment alignment);
1591 bool EndAlignment();
1593 /// Begin left indent
1594 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
1597 bool EndLeftIndent();
1599 /// Begin right indent
1600 bool BeginRightIndent(int rightIndent);
1602 /// End right indent
1603 bool EndRightIndent();
1605 /// Begin paragraph spacing
1606 bool BeginParagraphSpacing(int before, int after);
1608 /// End paragraph spacing
1609 bool EndParagraphSpacing();
1611 /// Begin line spacing
1612 bool BeginLineSpacing(int lineSpacing);
1614 /// End line spacing
1615 bool EndLineSpacing();
1617 /// Begin numbered bullet
1618 bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
1620 /// End numbered bullet
1621 bool EndNumberedBullet();
1623 /// Begin symbol bullet
1624 bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
1626 /// End symbol bullet
1627 bool EndSymbolBullet();
1629 /// Begin standard bullet
1630 bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD);
1632 /// End standard bullet
1633 bool EndStandardBullet();
1635 /// Begin named character style
1636 bool BeginCharacterStyle(const wxString& characterStyle);
1638 /// End named character style
1639 bool EndCharacterStyle();
1641 /// Begin named paragraph style
1642 bool BeginParagraphStyle(const wxString& paragraphStyle);
1644 /// End named character style
1645 bool EndParagraphStyle();
1647 /// Begin named list style
1648 bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1);
1650 /// End named character style
1651 bool EndListStyle();
1654 bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString);
1661 /// Add an event handler
1662 bool AddEventHandler(wxEvtHandler* handler);
1664 /// Remove an event handler
1665 bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false);
1667 /// Clear event handlers
1668 void ClearEventHandlers();
1670 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
1671 /// otherwise will stop at the first successful one.
1672 bool SendEvent(wxEvent& event, bool sendToAll = true);
1677 void Copy(const wxRichTextBuffer& obj);
1680 virtual wxRichTextObject* Clone() const;
1682 /// Submit command to insert paragraphs
1683 bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
1685 /// Submit command to insert the given text
1686 bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
1688 /// Submit command to insert a newline
1689 bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
1691 /// Submit command to insert the given image
1692 bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0);
1694 /// Submit command to delete this range
1695 bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl);
1698 void Modify(bool modify = true);
1699 bool IsModified() const;
1701 /// Get the style that is appropriate for a new paragraph at this position.
1702 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1704 wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const;
1707 /// Returns the file handlers
1708 static wxRichTextFileHandlerList_t& GetHandlers();
1710 %disownarg(wxRichTextFileHandler *handler);
1712 /// Adds a handler to the end
1713 static void AddHandler(wxRichTextFileHandler *handler);
1715 /// Inserts a handler at the front
1716 static void InsertHandler(wxRichTextFileHandler *handler);
1718 %cleardisown(wxRichTextFileHandler *handler);
1721 /// Removes a handler
1722 static bool RemoveHandler(const wxString& name);
1724 /// Finds a handler by name
1725 %Rename(FindHandlerByName,
1726 static wxRichTextFileHandler* , FindHandler(const wxString& name));
1728 /// Finds a handler by extension and type
1729 %Rename(FindHandlerByExtension,
1730 static wxRichTextFileHandler*, FindHandler(const wxString& extension, int imageType));
1732 /// Finds a handler by filename or, if supplied, type
1733 %Rename(FindHandlerByFilename,
1734 static wxRichTextFileHandler* , FindHandlerFilenameOrType(const wxString& filename, int imageType));
1736 /// Finds a handler by type
1737 %Rename(FindHandlerByType,
1738 static wxRichTextFileHandler* , FindHandler(int imageType));
1741 // TODO: Handle returning the types array?
1743 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1744 /// will be filled with the file type corresponding to each filter. This can be
1745 /// used to determine the type to pass to LoadFile given a selected filter.
1746 //static wxString GetExtWildcard(bool combine = false, bool save = false,
1747 // wxArrayInt* types = NULL);
1749 KeepGIL(GetExtWildcard);
1750 DocAStr(GetExtWildcard,
1751 "GetExtWildcard(self, bool combine=False, bool save=False) --> (wildcards, types)",
1752 "Gets a wildcard string for the file dialog based on all the currently
1753 loaded richtext file handlers, and a list that can be used to map
1754 those filter types to the file handler type.", "");
1755 static PyObject* GetExtWildcard(bool combine = false, bool save = false) {
1758 wildcards = wxRichTextBuffer::GetExtWildcard(combine, save, &types);
1759 PyObject* tup = PyTuple_New(2);
1760 PyTuple_SET_ITEM(tup, 0, wx2PyString(wildcards));
1761 PyTuple_SET_ITEM(tup, 1, wxArrayInt2PyList_helper(types));
1766 /// Clean up handlers
1767 static void CleanUpHandlers();
1769 /// Initialise the standard handlers
1770 static void InitStandardHandlers();
1773 static wxRichTextRenderer* GetRenderer();
1775 /// Set renderer, deleting old one
1776 static void SetRenderer(wxRichTextRenderer* renderer);
1778 /// Minimum margin between bullet and paragraph in 10ths of a mm
1779 static int GetBulletRightMargin();
1780 static void SetBulletRightMargin(int margin);
1782 /// Factor to multiply by character height to get a reasonable bullet size
1783 static float GetBulletProportion();
1784 static void SetBulletProportion(float prop);
1786 /// Scale factor for calculating dimensions
1787 double GetScale() const;
1788 void SetScale(double scale);
1796 // TODO: Do we need wrappers for the command processor, undo/redo, etc.?
1798 // enum wxRichTextCommandId
1800 // wxRICHTEXT_INSERT,
1801 // wxRICHTEXT_DELETE,
1802 // wxRICHTEXT_CHANGE_STYLE
1804 // class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand
1805 // class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject
1810 //---------------------------------------------------------------------------
1819 // Include style sheet when loading and saving
1820 wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET,
1822 // Save images to memory file system in HTML handler
1823 wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY,
1825 // Save images to files in HTML handler
1826 wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES,
1828 // Save images as inline base64 data in HTML handler
1829 wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64,
1831 // Don't write header and footer (or BODY), so we can include the
1832 // fragment in a larger document
1833 wxRICHTEXT_HANDLER_NO_HEADER_FOOTER,
1839 DocStr(wxRichTextFileHandler,
1840 "Base class for file handlers", "");
1842 class wxRichTextFileHandler: public wxObject
1845 //wxRichTextFileHandler(const wxString& name = wxEmptyString, **** This is an ABC
1846 // const wxString& ext = wxEmptyString,
1849 ~wxRichTextFileHandler();
1852 bool, LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream));
1854 bool, SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream));
1856 bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
1857 bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
1859 /// Can we handle this filename (if using files)? By default, checks the extension.
1860 virtual bool CanHandle(const wxString& filename) const;
1862 /// Can we save using this handler?
1863 virtual bool CanSave() const;
1865 /// Can we load using this handler?
1866 virtual bool CanLoad() const;
1868 /// Should this handler be visible to the user?
1869 virtual bool IsVisible() const;
1870 virtual void SetVisible(bool visible);
1872 /// The name of the nandler
1873 void SetName(const wxString& name);
1874 wxString GetName() const;
1875 %property(Name, GetName, SetName)
1877 /// The default extension to recognise
1878 void SetExtension(const wxString& ext);
1879 wxString GetExtension() const;
1880 %property(Extension, GetExtension, SetExtension)
1882 /// The handler type
1883 void SetType(int type);
1884 int GetType() const;
1885 %property(Type, GetType, SetType)
1887 /// Flags controlling how loading and saving is done
1888 void SetFlags(int flags);
1889 int GetFlags() const;
1890 %property(Flags, GetFlags, SetFlags)
1892 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
1893 void SetEncoding(const wxString& encoding);
1894 const wxString& GetEncoding() const;
1895 %property(Encoding, GetEncoding, SetEncoding)
1900 MAKE_CONST_WXSTRING2(TextName, wxT("Text"));
1901 MAKE_CONST_WXSTRING2(TextExt, wxT("txt"));
1903 class wxRichTextPlainTextHandler: public wxRichTextFileHandler
1906 wxRichTextPlainTextHandler(const wxString& name = wxPyTextName,
1907 const wxString& ext = wxPyTextExt,
1908 int type = wxRICHTEXT_TYPE_TEXT);
1915 //---------------------------------------------------------------------------
1919 // TODO: Make a PyRichTextRenderer class
1923 * wxRichTextRenderer isolates common drawing functionality
1926 class wxRichTextRenderer: public wxObject
1929 wxRichTextRenderer() {}
1930 virtual ~wxRichTextRenderer() {}
1932 /// Draw a standard bullet, as specified by the value of GetBulletName
1933 virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
1935 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
1936 virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) = 0;
1938 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
1939 virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
1941 /// Enumerate the standard bullet names currently supported
1942 virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0;
1946 * wxRichTextStdRenderer: standard renderer
1949 class wxRichTextStdRenderer: public wxRichTextRenderer
1952 wxRichTextStdRenderer() {}
1954 /// Draw a standard bullet, as specified by the value of GetBulletName
1955 virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
1957 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
1958 virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text);
1960 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
1961 virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
1963 /// Enumerate the standard bullet names currently supported
1964 virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames);
1967 //---------------------------------------------------------------------------
1968 //---------------------------------------------------------------------------