1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     Classes for wxRichTExtCtrl and support classes
 
   7 // Created:     11-April-2006
 
   9 // Copyright:   (c) 2006 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  17 %module(package="wx", docstring=DOCSTRING) richtext
 
  20 #include "wx/wxPython/wxPython.h"
 
  21 #include "wx/wxPython/pyclasses.h"
 
  22 #include "wx/wxPython/printfw.h"
 
  23 #include "wx/wxPython/twoitem.h"
 
  25 #include <wx/richtext/richtextctrl.h>
 
  30 class wxBufferedPaintDC;
 
  37 #define USE_TEXTATTREX 0
 
  39 //----------------------------------------------------------------------
 
  44 %pythoncode { wx = _core }
 
  45 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
 
  47 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
 
  49 //----------------------------------------------------------------------
 
  55     wxRICHTEXT_SHIFT_DOWN,
 
  71     wxRICHTEXT_FIXED_WIDTH,
 
  72     wxRICHTEXT_FIXED_HEIGHT,
 
  73     wxRICHTEXT_VARIABLE_WIDTH,
 
  74     wxRICHTEXT_VARIABLE_HEIGHT,
 
  77     wxRICHTEXT_HITTEST_NONE,
 
  78     wxRICHTEXT_HITTEST_BEFORE,
 
  79     wxRICHTEXT_HITTEST_AFTER,
 
  80     wxRICHTEXT_HITTEST_ON,
 
  83     wxRICHTEXT_UNFORMATTED,
 
  86     // TODO:  Rename these to be wxRICHTEXT_* ??
 
  88     wxTEXT_ATTR_TEXT_COLOUR,
 
  89     wxTEXT_ATTR_BACKGROUND_COLOUR,
 
  90     wxTEXT_ATTR_FONT_FACE,
 
  91     wxTEXT_ATTR_FONT_SIZE,
 
  92     wxTEXT_ATTR_FONT_WEIGHT,
 
  93     wxTEXT_ATTR_FONT_ITALIC,
 
  94     wxTEXT_ATTR_FONT_UNDERLINE,
 
  96     wxTEXT_ATTR_ALIGNMENT,
 
  97     wxTEXT_ATTR_LEFT_INDENT,
 
  98     wxTEXT_ATTR_RIGHT_INDENT,
 
 101     wxTEXT_ATTR_PARA_SPACING_AFTER,
 
 102     wxTEXT_ATTR_PARA_SPACING_BEFORE,
 
 103     wxTEXT_ATTR_LINE_SPACING,
 
 104     wxTEXT_ATTR_CHARACTER_STYLE_NAME,
 
 105     wxTEXT_ATTR_PARAGRAPH_STYLE_NAME,
 
 106     wxTEXT_ATTR_BULLET_STYLE,
 
 107     wxTEXT_ATTR_BULLET_NUMBER,
 
 108     wxTEXT_ATTR_BULLET_SYMBOL,
 
 110     wxTEXT_ATTR_BULLET_STYLE_NONE,
 
 111     wxTEXT_ATTR_BULLET_STYLE_ARABIC,
 
 112     wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER,
 
 113     wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER,
 
 114     wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER,
 
 115     wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER,
 
 116     wxTEXT_ATTR_BULLET_STYLE_SYMBOL,
 
 117     wxTEXT_ATTR_BULLET_STYLE_BITMAP,
 
 118     wxTEXT_ATTR_BULLET_STYLE_PARENTHESES,
 
 119     wxTEXT_ATTR_BULLET_STYLE_PERIOD,
 
 121     wxTEXT_ATTR_LINE_SPACING_NORMAL,
 
 122     wxTEXT_ATTR_LINE_SPACING_HALF,
 
 123     wxTEXT_ATTR_LINE_SPACING_TWICE,
 
 127 enum wxTextAttrAlignment
 
 129     wxTEXT_ALIGNMENT_DEFAULT,
 
 130     wxTEXT_ALIGNMENT_LEFT,
 
 131     wxTEXT_ALIGNMENT_CENTRE,
 
 132     wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
 
 133     wxTEXT_ALIGNMENT_RIGHT,
 
 134     wxTEXT_ALIGNMENT_JUSTIFIED
 
 137 //----------------------------------------------------------------------
 
 139 %typemap(in) wxRichTextRange& (wxRichTextRange temp) {
 
 141     if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail;
 
 143 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& {
 
 144     $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2);
 
 150 bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj)
 
 152     if (source == Py_None) {
 
 153         **obj = wxRICHTEXT_NONE;
 
 156     return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange"));
 
 162 DocStr(wxRichTextRange,
 
 163 "RichTextRange is a data structure that represents a range of text
 
 164 within a `RichTextCtrl`.  It simply contains integer ``start`` and
 
 165 ``end`` properties and a few operations useful for dealing with
 
 166 ranges.  In most places in wxPython where a RichTextRange is expected a
 
 167 2-tuple containing (start, end) can be used instead.", "");
 
 169 class wxRichTextRange
 
 173         wxRichTextRange(long start=0, long end=0),
 
 174         "Creates a new range object.", "");
 
 180         DocStr(__eq__, "Test for equality of RichTextRange objects.", "");
 
 181         bool __eq__(PyObject* other) {
 
 182             wxRichTextRange  temp, *obj = &temp;
 
 183             if ( other == Py_None ) return false;
 
 184             if ( ! wxRichTextRange_helper(other, &obj) ) {
 
 188             return self->operator==(*obj);
 
 194         wxRichTextRange , operator -(const wxRichTextRange& range) const,
 
 198         wxRichTextRange , operator +(const wxRichTextRange& range) const,
 
 203         void , SetRange(long start, long end),
 
 208         void , SetStart(long start),
 
 212         long , GetStart() const,
 
 215     %pythoncode { start = property(GetStart, SetStart) }
 
 218         void , SetEnd(long end),
 
 222         long , GetEnd() const,
 
 225     %pythoncode { end = property(GetEnd, SetEnd) }
 
 229         bool , IsOutside(const wxRichTextRange& range) const,
 
 230         "Returns true if this range is completely outside 'range'", "");
 
 234         bool , IsWithin(const wxRichTextRange& range) const,
 
 235         "Returns true if this range is completely within 'range'", "");
 
 239         bool , Contains(long pos) const,
 
 240         "Returns true if the given position is within this range. Allow for the
 
 241 possibility of an empty range - assume the position is within this
 
 246         bool , LimitTo(const wxRichTextRange& range) ,
 
 247         "Limit this range to be within 'range'", "");
 
 251         long , GetLength() const,
 
 252         "Gets the length of the range", "");
 
 257         "Swaps the start and end", "");
 
 262                "Get() -> (start,end)",
 
 263                "Returns the start and end properties as a tuple.", "");
 
 265             wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
 266             PyObject* tup = PyTuple_New(2);
 
 267             PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart()));
 
 268             PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd()));
 
 269             wxPyEndBlockThreads(blocked);
 
 274     def __str__(self):                   return str(self.Get())
 
 275     def __repr__(self):                  return 'RichTextRange'+str(self.Get())
 
 276     def __len__(self):                   return len(self.Get())
 
 277     def __getitem__(self, index):        return self.Get()[index]
 
 278     def __setitem__(self, index, val):
 
 279         if index == 0: self.start = val
 
 280         elif index == 1: self.end = val
 
 281         else: raise IndexError
 
 282     def __nonzero__(self):               return self.Get() != (0,0)
 
 283     __safe_for_unpickling__ = True
 
 284     def __reduce__(self):                return (RichTextRange, self.Get())
 
 291     wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL);
 
 292     wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE);
 
 295 %rename(RICHTEXT_ALL)   wxPy_RTR_ALL;
 
 296 %rename(RICHTEXT_NONE)  wxPy_RTR_NONE;
 
 299 wxRichTextRange wxPy_RTR_ALL;
 
 300 wxRichTextRange wxPy_RTR_NONE;
 
 303 //----------------------------------------------------------------------
 
 305 DocStr(wxRichTextAttr,
 
 306 "The RichTextAttr class stored information about the various attributes
 
 307 for a block of text, including font, colour, indents, alignments, and
 
 314     wxRichTextAttr(const wxColour& colText = wxNullColour,
 
 315                    const wxColour& colBack = wxNullColour,
 
 316                    wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
 
 320 //     // Making a wxTextAttrEx object.
 
 321 //     operator wxTextAttrEx () const ;
 
 323 //     // Copy to a wxTextAttr
 
 324 //     void CopyTo(wxTextAttrEx& attr) const;
 
 328     // Create font from font attributes.
 
 330         wxFont , CreateFont() const,
 
 334     // Get attributes from font.
 
 335     bool GetFontAttributes(const wxFont& font);
 
 339             return self.CreateFont()
 
 340         def SetFont(self, font):
 
 341             return self.GetFontAttributes(font)
 
 345     void SetTextColour(const wxColour& colText);
 
 346     void SetBackgroundColour(const wxColour& colBack);
 
 347     void SetAlignment(wxTextAttrAlignment alignment);
 
 348     void SetTabs(const wxArrayInt& tabs);
 
 349     void SetLeftIndent(int indent, int subIndent = 0);
 
 350     void SetRightIndent(int indent);
 
 352     void SetFontSize(int pointSize);
 
 353     void SetFontStyle(int fontStyle);
 
 354     void SetFontWeight(int fontWeight);
 
 355     void SetFontFaceName(const wxString& faceName);
 
 356     void SetFontUnderlined(bool underlined);
 
 358     void SetFlags(long flags);
 
 360     void SetCharacterStyleName(const wxString& name);
 
 361     void SetParagraphStyleName(const wxString& name);
 
 362     void SetParagraphSpacingAfter(int spacing);
 
 363     void SetParagraphSpacingBefore(int spacing);
 
 364     void SetLineSpacing(int spacing);
 
 365     void SetBulletStyle(int style);
 
 366     void SetBulletNumber(int n);
 
 367     void SetBulletSymbol(wxChar symbol);
 
 369     const wxColour& GetTextColour() const;
 
 370     const wxColour& GetBackgroundColour() const;
 
 371     wxTextAttrAlignment GetAlignment() const;
 
 372     const wxArrayInt& GetTabs() const;
 
 373     long GetLeftIndent() const;
 
 374     long GetLeftSubIndent() const;
 
 375     long GetRightIndent() const;
 
 376     long GetFlags() const;
 
 378     int GetFontSize() const;
 
 379     int GetFontStyle() const;
 
 380     int GetFontWeight() const;
 
 381     bool GetFontUnderlined() const;
 
 382     const wxString& GetFontFaceName() const;
 
 384     const wxString& GetCharacterStyleName() const;
 
 385     const wxString& GetParagraphStyleName() const;
 
 386     int GetParagraphSpacingAfter() const;
 
 387     int GetParagraphSpacingBefore() const;
 
 388     int GetLineSpacing() const;
 
 389     int GetBulletStyle() const;
 
 390     int GetBulletNumber() const { return m_bulletNumber; }
 
 391     wxChar GetBulletSymbol() const;
 
 394     bool HasTextColour() const;
 
 395     bool HasBackgroundColour() const;
 
 396     bool HasAlignment() const;
 
 397     bool HasTabs() const;
 
 398     bool HasLeftIndent() const;
 
 399     bool HasRightIndent() const;
 
 400     bool HasWeight() const;
 
 401     bool HasSize() const;
 
 402     bool HasItalic() const;
 
 403     bool HasUnderlined() const;
 
 404     bool HasFaceName() const;
 
 405     bool HasFont() const;
 
 407     bool HasParagraphSpacingAfter() const;
 
 408     bool HasParagraphSpacingBefore() const;
 
 409     bool HasLineSpacing() const;
 
 410     bool HasCharacterStyleName() const;
 
 411     bool HasParagraphStyleName() const;
 
 412     bool HasBulletStyle() const;
 
 413     bool HasBulletNumber() const;
 
 414     bool HasBulletSymbol() const;
 
 416     bool HasFlag(long flag) const;
 
 418     // Is this a character style?
 
 419     bool IsCharacterStyle() const;
 
 420     bool IsParagraphStyle() const;
 
 422     // returns false if we have any attributes set, true otherwise
 
 423     bool IsDefault() const;
 
 426 //     // return the attribute having the valid font and colours: it uses the
 
 427 //     // attributes set in attr and falls back first to attrDefault and then to
 
 428 //     // the text control font/colours for those attributes which are not set
 
 429 //     static wxRichTextAttr Combine(const wxRichTextAttr& attr,
 
 430 //                               const wxRichTextAttr& attrDef,
 
 431 //                               const wxTextCtrlBase *text);
 
 436     wxTEXT_ATTR_CHARACTER,
 
 437     wxTEXT_ATTR_PARAGRAPH,
 
 442 //----------------------------------------------------------------------
 
 443 //----------------------------------------------------------------------
 
 445 MustHaveApp(wxRichTextCtrl);
 
 446 DocStr(wxRichTextCtrl,
 
 449 class wxRichTextCtrl : public wxScrolledWindow
 
 452     %pythonAppend wxRichTextCtrl         "self._setOORInfo(self)"
 
 453     %pythonAppend wxRichTextCtrl()       ""
 
 455     wxRichTextCtrl( wxWindow* parent,
 
 457                     const wxString& value = wxPyEmptyString,
 
 458                     const wxPoint& pos = wxDefaultPosition,
 
 459                     const wxSize& size = wxDefaultSize,
 
 460                     long style = wxRE_MULTILINE );
 
 461     %RenameCtor(PreRichTextCtrl, wxRichTextCtrl());
 
 464     bool Create( wxWindow* parent,
 
 466                  const wxString& value = wxPyEmptyString,
 
 467                  const wxPoint& pos = wxDefaultPosition,
 
 468                  const wxSize& size = wxDefaultSize,
 
 469                  long style = wxRE_MULTILINE );
 
 473         virtual wxString , GetValue() const,
 
 477         virtual void , SetValue(const wxString& value),
 
 482         virtual wxString , GetRange(long from, long to) const,
 
 487         virtual int , GetLineLength(long lineNo) const ,
 
 491         virtual wxString , GetLineText(long lineNo) const ,
 
 495         virtual int , GetNumberOfLines() const ,
 
 500         virtual bool , IsModified() const ,
 
 504         virtual bool , IsEditable() const ,
 
 508     // more readable flag testing methods
 
 510         bool , IsSingleLine() const,
 
 514         bool , IsMultiLine() const,
 
 519         virtual void , GetSelection(long* OUTPUT, long* OUTPUT) const,
 
 520         "GetSelection() --> (start, end)",
 
 521         "Returns the start and end positions of the current selection.  If the
 
 522 values are the same then there is no selection.", "");
 
 526         virtual wxString , GetStringSelection() const,
 
 531         wxString , GetFilename() const,
 
 536         void , SetFilename(const wxString& filename),
 
 541         void , SetDelayedLayoutThreshold(long threshold),
 
 542         "Set the threshold in character positions for doing layout optimization
 
 543 during sizing.", "");
 
 547         long , GetDelayedLayoutThreshold() const,
 
 548         "Get the threshold in character positions for doing layout optimization
 
 549 during sizing.", "");
 
 554         virtual void , Clear(),
 
 558         virtual void , Replace(long from, long to, const wxString& value),
 
 562         virtual void , Remove(long from, long to),
 
 567         virtual bool , LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY),
 
 568         "Load the contents of the document from the given filename.", "");
 
 571         virtual bool , SaveFile(const wxString& file = wxPyEmptyString,
 
 572                                 int type = wxRICHTEXT_TYPE_ANY),
 
 573         "Save the contents of the document to the given filename, or if the
 
 574 empty string is passed then to the filename set with `SetFilename`.", "");
 
 577     // sets/clears the dirty flag
 
 579         virtual void , MarkDirty(),
 
 580         "Sets the dirty flag, meaning that the contents of the control have
 
 581 changed and need to be saved.", "");
 
 584         virtual void , DiscardEdits(),
 
 585         "Clears the dirty flag.
 
 586 :see: `MarkDirty`", "");
 
 590         virtual void , SetMaxLength(unsigned long len),
 
 591         "Set the max number of characters which may be entered in a single line
 
 596         virtual void , WriteText(const wxString& text),
 
 597         "Insert text at the current position.", "");
 
 600         virtual void , AppendText(const wxString& text),
 
 601         "Append text to the end of the document.", "");
 
 605         virtual bool , SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style),
 
 606         "Set the style for the text in ``range`` to ``style``", "");
 
 609         virtual bool , GetStyle(long position, wxRichTextAttr& style) const,
 
 610         "Retrieve the style used at the given position.  Copies the style
 
 611 values at ``position`` into the ``style`` parameter returns ``True``
 
 612 if successful.  Returns ``False`` otherwise.", "");
 
 616         virtual bool , SetDefaultStyle(const wxRichTextAttr& style),
 
 617         "Set the style used by default for the rich text document.", "");
 
 621         virtual const wxRichTextAttr , GetDefaultStyleEx() const,
 
 622         "Retrieves a copy of the default style object.", "",
 
 627         virtual long , XYToPosition(long x, long y) const,
 
 628         "Translate a col,row coordinants into a document position.", "");
 
 631         virtual void , PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
 
 632         "PositionToXY(self, long pos) --> (x, y)",
 
 633         "Retrieves the col,row for the given position within the document", "");
 
 637         virtual void , ShowPosition(long position),
 
 638         "Ensure that the given position in the document is visible.", "");
 
 642         virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
 
 643         "HitTest(self, Point pt) --> (result, pos)",
 
 644         "Returns the character position at the given point in pixels.  Note
 
 645 that ``pt`` should be given in device coordinates, and not be adjusted
 
 646 for the client area origin nor for scrolling.  The return value is a
 
 647 tuple of the hit test result and the position.", "
 
 649 Possible result values are a bitmask of these flags:
 
 651     =========================  ====================================
 
 652     RICHTEXT_HITTEST_NONE      The point was not on this object.
 
 653     RICHTEXT_HITTEST_BEFORE    The point was before the position
 
 654                                   returned from HitTest.
 
 655     RICHTEXT_HITTEST_AFTER     The point was after the position
 
 656                                returned from HitTest.
 
 657     RICHTEXT_HITTEST_ON        The point was on the position
 
 658                                returned from HitTest
 
 659     =========================  ====================================
 
 663         virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt,
 
 665                                                   wxTextCoord *OUTPUT) const,
 
 666         "HitTestRC(self, Point pt) --> (result, col, row)",
 
 667         "Returns the column and row of the given point in pixels.  Note that
 
 668 ``pt`` should be given in device coordinates, and not be adjusted for
 
 669 the client area origin nor for scrolling.  The return value is a tuple
 
 670 of the hit test result and the column and row values.", "
 
 675     // Clipboard operations
 
 677         virtual void , Copy(),
 
 678         "Copies the selected text to the clipboard.", "");
 
 681         virtual void , Cut(),
 
 682         "Copies the selected text to the clipboard and removes the selection.", "");
 
 685         virtual void , Paste(),
 
 686         "Pastes text from the clipboard into the document at the current
 
 687 insertion point.", "");
 
 690         virtual void , DeleteSelection(),
 
 691         "Remove the current selection.", "");
 
 695         virtual bool , CanCopy() const,
 
 696         "Returns ``True`` if the selection can be copied to the clipboard.", "");
 
 699         virtual bool , CanCut() const,
 
 700         "Returns ``True`` if the selection can be cut to the clipboard.", "");
 
 703         virtual bool , CanPaste() const,
 
 704         "Returns ``True`` if the current contents of the clipboard can be
 
 705 pasted into the document.", "");
 
 708         virtual bool , CanDeleteSelection() const,
 
 709         "Returns ``True`` if the selection can be removed from the document.", "");
 
 714         virtual void , Undo(),
 
 715         "If the last operation can be undone, undoes the last operation.", "");
 
 718         virtual void , Redo(),
 
 719         "If the last operation can be redone, redoes the last operation.", "");
 
 723         virtual bool , CanUndo() const,
 
 724         "Returns ``True`` if the last operation can be undone.", "");
 
 727         virtual bool , CanRedo() const,
 
 728         "Returns ``True`` if the last operation can be redone.", "");
 
 733         virtual void , SetInsertionPoint(long pos),
 
 734         "Sets the insertion point at the given position.", "");
 
 737         virtual void , SetInsertionPointEnd(),
 
 738         "Moves the insertion point to the end of the document.", "");
 
 741         virtual long , GetInsertionPoint() const,
 
 742         "Returns the insertion point. This is defined as the zero based index
 
 743 of the character position to the right of the insertion point.", "");
 
 746         virtual long , GetLastPosition() const,
 
 747         "Returns the zero based index of the last position in the document.", "");
 
 751         virtual void , SetSelection(long from, long to),
 
 752         "Selects the text starting at the first position up to (but not
 
 753 including) the character at the last position. If both parameters are
 
 754 equal to -1 then all text in the control is selected.", "");
 
 757         virtual void , SelectAll(),
 
 758         "Select all text in the document.", "");
 
 761         virtual void , SetEditable(bool editable),
 
 762         "Makes the document editable or read-only, overriding the RE_READONLY
 
 766 //     /// Call Freeze to prevent refresh
 
 767 //     virtual void Freeze();
 
 769 //     /// Call Thaw to refresh
 
 770 //     virtual void Thaw();
 
 772 //     /// Call Thaw to refresh
 
 774 //         virtual bool , IsFrozen() const,
 
 779         virtual bool , HasSelection() const,
 
 783 ///// Functionality specific to wxRichTextCtrl
 
 785     /// Write an image at the current insertion point. Supply optional type to use
 
 786     /// for internal and file storage of the raw data.
 
 788         virtual bool , WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG),
 
 792     /// Write a bitmap at the current insertion point. Supply optional type to use
 
 793     /// for internal and file storage of the raw data.
 
 795         virtual bool , WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG),
 
 800     /// Load an image from file and write at the current insertion point.
 
 802         virtual bool , WriteImage(const wxString& filename, int bitmapType),
 
 807     /// Write an image block at the current insertion point.
 
 809         virtual bool , WriteImage(const wxRichTextImageBlock& imageBlock),
 
 814     /// Insert a newline (actually paragraph) at the current insertion point.
 
 816         virtual bool , Newline(),
 
 821 /// Set basic (overall) style
 
 823         virtual void , SetBasicStyle(const wxTextAttrEx& style),
 
 828         virtual void , SetBasicStyle(const wxRichTextAttr& style),
 
 833     /// Get basic (overall) style
 
 835         virtual const wxTextAttrEx& , GetBasicStyle() const,
 
 839     /// Begin using a style
 
 841         virtual bool , BeginStyle(const wxTextAttrEx& style),
 
 847         virtual bool , EndStyle(),
 
 853         virtual bool , EndAllStyles(),
 
 869     /// Begin using italic
 
 871         bool , BeginItalic(),
 
 881     /// Begin using underline
 
 883         bool , BeginUnderline(),
 
 887     /// End using underline
 
 889         bool , EndUnderline(),
 
 893     /// Begin using point size
 
 895         bool , BeginFontSize(int pointSize),
 
 899     /// End using point size
 
 901         bool , EndFontSize(),
 
 905     /// Begin using this font
 
 907         bool , BeginFont(const wxFont& font),
 
 917     /// Begin using this colour
 
 919         bool , BeginTextColour(const wxColour& colour),
 
 923     /// End using a colour
 
 925         bool , EndTextColour(),
 
 929     /// Begin using alignment
 
 931         bool , BeginAlignment(wxTextAttrAlignment alignment),
 
 937         bool , EndAlignment(),
 
 941     /// Begin left indent
 
 943         bool , BeginLeftIndent(int leftIndent, int leftSubIndent = 0),
 
 949         bool , EndLeftIndent(),
 
 953     /// Begin right indent
 
 955         bool , BeginRightIndent(int rightIndent),
 
 961         bool , EndRightIndent(),
 
 965     /// Begin paragraph spacing
 
 967         bool , BeginParagraphSpacing(int before, int after),
 
 971     /// End paragraph spacing
 
 973         bool , EndParagraphSpacing(),
 
 977     /// Begin line spacing
 
 979         bool , BeginLineSpacing(int lineSpacing),
 
 985         bool , EndLineSpacing(),
 
 989     /// Begin numbered bullet
 
 991         bool , BeginNumberedBullet(int bulletNumber,
 
 994                                    int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD),
 
 998     /// End numbered bullet
 
1000         bool , EndNumberedBullet(),
 
1004     /// Begin symbol bullet
 
1006         bool , BeginSymbolBullet(char symbol,
 
1009                                  int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL),
 
1013     /// End symbol bullet
 
1015         bool , EndSymbolBullet(),
 
1019     /// Begin named character style
 
1021         bool , BeginCharacterStyle(const wxString& characterStyle),
 
1025     /// End named character style
 
1027         bool , EndCharacterStyle(),
 
1031     /// Begin named paragraph style
 
1033         bool , BeginParagraphStyle(const wxString& paragraphStyle),
 
1037     /// End named character style
 
1039         bool , EndParagraphStyle(),
 
1043     /// Sets the default style to the style under the cursor
 
1045         bool , SetDefaultStyleToCursorStyle(),
 
1049     /// Clear the selection
 
1051         virtual void , SelectNone(),
 
1055     /// Get/set the selection range in character positions. -1, -1 means no selection.
 
1057         const wxRichTextRange& , GetSelectionRange() const,
 
1061         void , SetSelectionRange(const wxRichTextRange& range),
 
1065     /// Add a new paragraph of text to the end of the buffer
 
1067         virtual wxRichTextRange , AddParagraph(const wxString& text),
 
1073         virtual wxRichTextRange , AddImage(const wxImage& image),
 
1077     /// Layout the buffer: which we must do before certain operations, such as
 
1078     /// setting the caret position.
 
1080         virtual bool , LayoutContent(bool onlyVisibleRect = false),
 
1084     /// Move the caret to the given character position
 
1086         virtual bool , MoveCaret(long pos, bool showAtLineStart = false),
 
1092         virtual bool , MoveRight(int noPositions = 1, int flags = 0),
 
1098         virtual bool , MoveLeft(int noPositions = 1, int flags = 0),
 
1104         virtual bool , MoveUp(int noLines = 1, int flags = 0),
 
1110         virtual bool , MoveDown(int noLines = 1, int flags = 0),
 
1114     /// Move to the end of the line
 
1116         virtual bool , MoveToLineEnd(int flags = 0),
 
1120     /// Move to the start of the line
 
1122         virtual bool , MoveToLineStart(int flags = 0),
 
1126     /// Move to the end of the paragraph
 
1128         virtual bool , MoveToParagraphEnd(int flags = 0),
 
1132     /// Move to the start of the paragraph
 
1134         virtual bool , MoveToParagraphStart(int flags = 0),
 
1138     /// Move to the start of the buffer
 
1140         virtual bool , MoveHome(int flags = 0),
 
1144     /// Move to the end of the buffer
 
1146         virtual bool , MoveEnd(int flags = 0),
 
1152         virtual bool , PageUp(int noPages = 1, int flags = 0),
 
1156     /// Move n pages down
 
1158         virtual bool , PageDown(int noPages = 1, int flags = 0),
 
1162     /// Move n words left
 
1164         virtual bool , WordLeft(int noPages = 1, int flags = 0),
 
1168     /// Move n words right
 
1170         virtual bool , WordRight(int noPages = 1, int flags = 0),
 
1174     /// Returns the buffer associated with the control.
 
1175 //    wxRichTextBuffer& GetBuffer();
 
1177         const wxRichTextBuffer& , GetBuffer() const,
 
1181     /// Start batching undo history for commands.
 
1183         virtual bool , BeginBatchUndo(const wxString& cmdName),
 
1187     /// End batching undo history for commands.
 
1189         virtual bool , EndBatchUndo(),
 
1193     /// Are we batching undo history for commands?
 
1195         virtual bool , BatchingUndo() const,
 
1199     /// Start suppressing undo history for commands.
 
1201         virtual bool , BeginSuppressUndo(),
 
1205     /// End suppressing undo history for commands.
 
1207         virtual bool , EndSuppressUndo(),
 
1211     /// Are we suppressing undo history for commands?
 
1213         virtual bool , SuppressingUndo() const,
 
1217     /// Test if this whole range has character attributes of the specified kind. If any
 
1218     /// of the attributes are different within the range, the test fails. You
 
1219     /// can use this to implement, for example, bold button updating. style must have
 
1220     /// flags indicating which attributes are of interest.
 
1223         virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
 
1224                                               const wxTextAttrEx& style) const,
 
1229         virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
 
1230                                               const wxRichTextAttr& style) const,
 
1235     /// Test if this whole range has paragraph attributes of the specified kind. If any
 
1236     /// of the attributes are different within the range, the test fails. You
 
1237     /// can use this to implement, for example, centering button updating. style must have
 
1238     /// flags indicating which attributes are of interest.
 
1241         virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
 
1242                                               const wxTextAttrEx& style) const,
 
1247         virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
 
1248                                               const wxRichTextAttr& style) const,
 
1253     /// Is all of the selection bold?
 
1255         virtual bool , IsSelectionBold() const,
 
1259     /// Is all of the selection italics?
 
1261         virtual bool , IsSelectionItalics() const,
 
1265     /// Is all of the selection underlined?
 
1267         virtual bool , IsSelectionUnderlined() const,
 
1271     /// Is all of the selection aligned according to the specified flag?
 
1273         virtual bool , IsSelectionAligned(wxTextAttrAlignment alignment) const,
 
1277     /// Apply bold to the selection
 
1279         virtual bool , ApplyBoldToSelection(),
 
1283     /// Apply italic to the selection
 
1285         virtual bool , ApplyItalicToSelection(),
 
1289     /// Apply underline to the selection
 
1291         virtual bool , ApplyUnderlineToSelection(),
 
1295     /// Apply alignment to the selection
 
1297         virtual bool , ApplyAlignmentToSelection(wxTextAttrAlignment alignment),
 
1301     /// Set style sheet, if any.
 
1303         void , SetStyleSheet(wxRichTextStyleSheet* styleSheet),
 
1307         wxRichTextStyleSheet* , GetStyleSheet() const,
 
1313 // TODO: Which of these should be exposed to Python?
 
1315 //     /// Set font, and also default attributes
 
1316 //     virtual bool SetFont(const wxFont& font);
 
1318 //     /// Set up scrollbars, e.g. after a resize
 
1319 //     virtual void SetupScrollbars(bool atTop = false);
 
1321 //     /// Keyboard navigation
 
1322 //     virtual bool KeyboardNavigate(int keyCode, int flags);
 
1324 //     /// Paint the background
 
1325 //     virtual void PaintBackground(wxDC& dc);
 
1327 //     /// Recreate buffer bitmap if necessary
 
1328 //     virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
 
1330 //     /// Set the selection
 
1331 //     virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
 
1334 //     virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
 
1336 //     /// Send an update event
 
1337 //     virtual bool SendUpdateEvent();
 
1339 //     /// Init command event
 
1340 //     void InitCommandEvent(wxCommandEvent& event) const;
 
1342 //     /// do the window-specific processing after processing the update event
 
1343 //     //  (duplicated code from wxTextCtrlBase)
 
1344 // #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
 
1345 //     virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
 
1348 //     /// Should we inherit colours?
 
1349 //     virtual bool ShouldInheritColours() const;
 
1351 //     /// Position the caret
 
1352 //     virtual void PositionCaret();
 
1354 //     /// Extend the selection, returning true if the selection was
 
1355 //     /// changed. Selections are in caret positions.
 
1356 //     virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
 
1358 //     /// Scroll into view. This takes a _caret_ position.
 
1359 //     virtual bool ScrollIntoView(long position, int keyCode);
 
1361 //     /// The caret position is the character position just before the caret.
 
1362 //     /// A value of -1 means the caret is at the start of the buffer.
 
1363 //     void SetCaretPosition(long position, bool showAtLineStart = false) ;
 
1364 //     long GetCaretPosition() const;
 
1366 //     /// Move caret one visual step forward: this may mean setting a flag
 
1367 //     /// and keeping the same position if we're going from the end of one line
 
1368 //     /// to the start of the next, which may be the exact same caret position.
 
1369 //     void MoveCaretForward(long oldPosition) ;
 
1371 //     /// Move caret one visual step forward: this may mean setting a flag
 
1372 //     /// and keeping the same position if we're going from the end of one line
 
1373 //     /// to the start of the next, which may be the exact same caret position.
 
1374 //     void MoveCaretBack(long oldPosition) ;
 
1376 //     /// Get the caret height and position for the given character position
 
1377 //     bool GetCaretPositionForIndex(long position, wxRect& rect);
 
1379 //     /// Gets the line for the visible caret position. If the caret is
 
1380 //     /// shown at the very end of the line, it means the next character is actually
 
1381 //     /// on the following line. So let's get the line we're expecting to find
 
1382 //     /// if this is the case.
 
1383 //     wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
 
1385 //     /// Gets the command processor
 
1386 //     wxCommandProcessor* GetCommandProcessor() const;
 
1388 //     /// Delete content if there is a selection, e.g. when pressing a key.
 
1389 //     /// Returns the new caret position in newPos, or leaves it if there
 
1390 //     /// was no action.
 
1391 //     bool DeleteSelectedContent(long* newPos= NULL);
 
1393 //     /// Transform logical to physical
 
1394 //     wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
 
1396 //     /// Transform physical to logical
 
1397 //     wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
 
1399 //     /// Finds the caret position for the next word. Direction
 
1400 //     /// is 1 (forward) or -1 (backwards).
 
1401 //     virtual long FindNextWordPosition(int direction = 1) const;
 
1403 //     /// Is the given position visible on the screen?
 
1404 //     bool IsPositionVisible(long pos) const;
 
1406 //     /// Returns the first visible position in the current view
 
1407 //     long GetFirstVisiblePosition() const;
 
1411 //----------------------------------------------------------------------
 
1414 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED;
 
1415 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED;
 
1416 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_CLICK;
 
1417 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK;
 
1418 %constant wxEventType wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK;
 
1419 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK;
 
1420 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RETURN;
 
1424 EVT_RICHTEXT_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 1)
 
1425 EVT_RICHTEXT_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 1)
 
1426 EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
 
1427 EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
 
1428 EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
 
1429 EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
 
1430 EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
 
1434 class wxRichTextEvent : public wxNotifyEvent
 
1437     wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
 
1439     int GetIndex() const;
 
1440     void SetIndex(int n);
 
1442     int GetFlags() const;
 
1443     void SetFlags(int flags);
 
1446 //----------------------------------------------------------------------
 
1451 //----------------------------------------------------------------------