]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/richtext/richtextbuffer.h
Several wxBitmapDataCell changes.
[wxWidgets.git] / include / wx / richtext / richtextbuffer.h
index ec08ad73766a6e96a2e08121bb5b4b9358c9cd4b..45eb308cfff92f308766e96599b03e18ca7a0fbb 100644 (file)
 #include "wx/cmdproc.h"
 #include "wx/txtstrm.h"
 
+// Experimental dynamic styles to avoid user-specific character styles from being
+// overwritten by paragraph styles.
+#define wxRICHTEXT_USE_DYNAMIC_STYLES 1
+
 /*!
  * File types
  */
  * Forward declarations
  */
 
-class WXDLLIMPEXP_ADV wxRichTextCtrl;
-class WXDLLIMPEXP_ADV wxRichTextObject;
-class WXDLLIMPEXP_ADV wxRichTextCacheObject;
-class WXDLLIMPEXP_ADV wxRichTextObjectList;
-class WXDLLIMPEXP_ADV wxRichTextLine;
-class WXDLLIMPEXP_ADV wxRichTextParagraph;
-class WXDLLIMPEXP_ADV wxRichTextFragment;
-class WXDLLIMPEXP_ADV wxRichTextFileHandler;
-class WXDLLIMPEXP_ADV wxRichTextStyleSheet;
-class WXDLLIMPEXP_ADV wxTextAttrEx;
+class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl;
+class WXDLLIMPEXP_RICHTEXT wxRichTextObject;
+class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject;
+class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList;
+class WXDLLIMPEXP_RICHTEXT wxRichTextLine;
+class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph;
+class WXDLLIMPEXP_RICHTEXT wxRichTextFragment;
+class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler;
+class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet;
+class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
 
 /*!
  * Flags determining the available space, passed to Layout
@@ -161,6 +165,13 @@ class WXDLLIMPEXP_ADV wxTextAttrEx;
 #define wxRICHTEXT_FORMATTED        0x01
 #define wxRICHTEXT_UNFORMATTED      0x02
 
+/*!
+ * Flags for text insertion
+ */
+
+#define wxRICHTEXT_INSERT_NONE                              0x00
+#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE     0x01
+
 /*!
  * Extra formatting flags not in wxTextAttr
  */
@@ -202,7 +213,7 @@ class WXDLLIMPEXP_ADV wxTextAttrEx;
  * This stores beginning and end positions for a range of data.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextRange
+class WXDLLIMPEXP_RICHTEXT wxRichTextRange
 {
 public:
 // Constructors
@@ -214,6 +225,7 @@ public:
 
     void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
     bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); }
+    bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start && m_end != range.m_end); }
     wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); }
     wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); }
 
@@ -246,6 +258,12 @@ public:
     /// Swaps the start and end
     void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; }
 
+    /// Convert to internal form: (n, n) is the range of a single character.
+    wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); }
+
+    /// Convert from internal to public API form: (n, n+1) is the range of a single character.
+    wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); }
+
 protected:
     long m_start;
     long m_end;
@@ -258,11 +276,12 @@ protected:
  * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
  */
 
-class WXDLLIMPEXP_ADV wxTextAttrEx: public wxTextAttr
+class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr
 {
 public:
     // ctors
     wxTextAttrEx(const wxTextAttrEx& attr);
+    wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
     wxTextAttrEx() { Init(); }
 
     // Initialise this object.
@@ -275,14 +294,14 @@ public:
     void operator= (const wxTextAttr& attr);
 
     // setters
-    void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; }
-    void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; }
-    void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; }
-    void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; }
-    void SetLineSpacing(int spacing) { m_lineSpacing = spacing; }
-    void SetBulletStyle(int style) { m_bulletStyle = style; }
-    void SetBulletNumber(int n) { m_bulletNumber = n; }
-    void SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; }
+    void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME); }
+    void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); }
+    void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER); }
+    void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE); }
+    void SetLineSpacing(int spacing) { m_lineSpacing = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING); }
+    void SetBulletStyle(int style) { m_bulletStyle = style; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE); }
+    void SetBulletNumber(int n) { m_bulletNumber = n; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER); }
+    void SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_SYMBOL); }
 
     const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
     const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
@@ -293,11 +312,17 @@ public:
     int GetBulletNumber() const { return m_bulletNumber; }
     wxChar GetBulletSymbol() const { return m_bulletSymbol; }
 
+    bool HasWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
+    bool HasSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; }
+    bool HasItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; }
+    bool HasUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
+    bool HasFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE) != 0; }
+
     bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); }
     bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); }
     bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); }
-    bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME); }
-    bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); }
+    bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) || !m_characterStyleName.IsEmpty(); }
+    bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) || !m_paragraphStyleName.IsEmpty(); }
     bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
     bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
     bool HasBulletSymbol() const { return HasFlag(wxTEXT_ATTR_BULLET_SYMBOL); }
@@ -316,6 +341,14 @@ public:
                !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
                !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
     }
+
+    // return the attribute having the valid font and colours: it uses the
+    // attributes set in attr and falls back first to attrDefault and then to
+    // the text control font/colours for those attributes which are not set
+    static wxTextAttrEx CombineEx(const wxTextAttrEx& attr,
+                              const wxTextAttrEx& attrDef,
+                              const wxTextCtrlBase *text);
+
 private:
     // Paragraph styles
     int                 m_paragraphSpacingAfter;
@@ -337,7 +370,7 @@ private:
  * efficient way to query styles.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextAttr
+class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
 {
 public:
     // ctors
@@ -356,6 +389,9 @@ public:
     // Assignment from a wxTextAttrEx object.
     void operator= (const wxTextAttrEx& attr);
 
+    // Equality test
+    bool operator== (const wxRichTextAttr& attr) const;
+
     // Making a wxTextAttrEx object.
     operator wxTextAttrEx () const ;
 
@@ -384,14 +420,14 @@ public:
 
     void SetFlags(long flags) { m_flags = flags; }
 
-    void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; }
-    void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; }
-    void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; }
-    void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; }
-    void SetLineSpacing(int spacing) { m_lineSpacing = spacing; }
-    void SetBulletStyle(int style) { m_bulletStyle = style; }
-    void SetBulletNumber(int n) { m_bulletNumber = n; }
-    void SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; }
+    void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; }
+    void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; }
+    void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; }
+    void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; }
+    void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; }
+    void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; }
+    void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
+    void SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
 
     const wxColour& GetTextColour() const { return m_colText; }
     const wxColour& GetBackgroundColour() const { return m_colBack; }
@@ -434,8 +470,8 @@ public:
     bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; }
     bool HasParagraphSpacingBefore() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) != 0; }
     bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; }
-    bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0; }
-    bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0; }
+    bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0 || !m_characterStyleName.IsEmpty(); }
+    bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0 || !m_paragraphStyleName.IsEmpty(); }
     bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
     bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
     bool HasBulletSymbol() const { return (m_flags & wxTEXT_ATTR_BULLET_SYMBOL) != 0; }
@@ -457,6 +493,12 @@ public:
                !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
     }
 
+    // return the attribute having the valid font and colours: it uses the
+    // attributes set in attr and falls back first to attrDefault and then to
+    // the text control font/colours for those attributes which are not set
+    static wxRichTextAttr Combine(const wxRichTextAttr& attr,
+                              const wxRichTextAttr& attrDef,
+                              const wxTextCtrlBase *text);
 private:
     long                m_flags;
 
@@ -505,14 +547,14 @@ private:
  * This is the base for drawable objects.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextObject: public wxObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject
 {
     DECLARE_CLASS(wxRichTextObject)
 public:
 // Constructors
 
     wxRichTextObject(wxRichTextObject* parent = NULL);
-    ~wxRichTextObject();
+    virtual ~wxRichTextObject();
 
 // Overrideables
 
@@ -538,7 +580,7 @@ public:
 
     /// Get the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const  = 0;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const  = 0;
 
     /// Do a split, returning an object containing the second part, and setting
     /// the first part in 'this'.
@@ -651,21 +693,21 @@ protected:
     wxTextAttrEx            m_attributes;
 };
 
-WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_ADV );
+WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
 
 /*!
  * wxRichTextCompositeObject class declaration
  * Objects of this class can contain other objects.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextCompositeObject: public wxRichTextObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject
 {
     DECLARE_CLASS(wxRichTextCompositeObject)
 public:
 // Constructors
 
     wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
-    ~wxRichTextCompositeObject();
+    virtual ~wxRichTextCompositeObject();
 
 // Overrideables
 
@@ -739,7 +781,7 @@ protected:
  * This defines a 2D space to lay out objects
  */
 
-class WXDLLIMPEXP_ADV wxRichTextBox: public wxRichTextCompositeObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextBox)
 public:
@@ -758,7 +800,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
 
 // Accessors
 
@@ -778,7 +820,7 @@ protected:
  * This box knows how to lay out paragraphs.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextParagraphLayoutBox: public wxRichTextBox
+class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)
 public:
@@ -797,7 +839,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
 
     /// Delete range
     virtual bool DeleteRange(const wxRichTextRange& range);
@@ -825,13 +867,13 @@ public:
     virtual void Reset();
 
     /// Convenience function to add a paragraph of text
-    virtual wxRichTextRange AddParagraph(const wxString& text);
+    virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL);
 
     /// Convenience function to add an image
-    virtual wxRichTextRange AddImage(const wxImage& image);
+    virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL);
 
     /// Adds multiple paragraphs, based on newlines.
-    virtual wxRichTextRange AddParagraphs(const wxString& text);
+    virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL);
 
     /// Get the line at the given position. If caretPosition is true, the position is
     /// a caret position, which is normally a smaller number.
@@ -888,9 +930,17 @@ public:
     virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, bool withUndo = true);
     virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, bool withUndo = true);
 
-    /// Get the text attributes for this position.
-    virtual bool GetStyle(long position, wxTextAttrEx& style) const;
-    virtual bool GetStyle(long position, wxRichTextAttr& style) const;
+    /// Get the conbined text attributes for this position.
+    virtual bool GetStyle(long position, wxTextAttrEx& style);
+    virtual bool GetStyle(long position, wxRichTextAttr& style);
+
+    /// Get the content (uncombined) attributes for this position.
+    virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
+    virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
+
+    /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
+    /// context attributes.
+    virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true);
 
     /// Test if this whole range has character attributes of the specified kind. If any
     /// of the attributes are different within the range, the test fails. You
@@ -917,6 +967,9 @@ public:
     /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
     virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextFragment& fragment);
 
+    /// Apply the style sheet to the buffer, for example if the styles have changed.
+    virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
+
     /// Copy
     void Copy(const wxRichTextParagraphLayoutBox& obj);
 
@@ -960,7 +1013,7 @@ protected:
  * paragraphs for Undo/Redo, for example.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextFragment: public wxRichTextParagraphLayoutBox
+class WXDLLIMPEXP_RICHTEXT wxRichTextFragment: public wxRichTextParagraphLayoutBox
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextFragment)
 public:
@@ -1001,7 +1054,7 @@ protected:
  * start and end positions of the line.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextLine
+class WXDLLIMPEXP_RICHTEXT wxRichTextLine
 {
 public:
 // Constructors
@@ -1074,14 +1127,14 @@ protected:
     wxRichTextParagraph* m_parent;
 };
 
-WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_ADV );
+WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT );
 
 /*!
  * wxRichTextParagraph class declaration
  * This object represents a single paragraph (or in a straight text editor, a line).
  */
 
-class WXDLLIMPEXP_ADV wxRichTextParagraph: public wxRichTextBox
+class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextBox
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextParagraph)
 public:
@@ -1089,7 +1142,7 @@ public:
 
     wxRichTextParagraph(wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
     wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
-    ~wxRichTextParagraph();
+    virtual ~wxRichTextParagraph();
     wxRichTextParagraph(const wxRichTextParagraph& obj):wxRichTextBox() { Copy(obj); }
 
 // Overrideables
@@ -1102,7 +1155,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
 
     /// Finds the absolute position and row height for the given character position
     virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart);
@@ -1133,7 +1186,7 @@ public:
 // Implementation
 
     /// Apply paragraph styles such as centering to the wrapped lines
-    virtual void ApplyParagraphStyle(const wxRect& rect);
+    virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect);
 
     /// Insert text at the given position
     virtual bool InsertText(long pos, const wxString& text);
@@ -1168,6 +1221,13 @@ public:
     /// Clear remaining unused line objects, if any
     bool ClearUnusedLines(int lineCount);
 
+    /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
+    /// retrieve the actual style.
+    wxTextAttrEx GetCombinedAttributes(const wxTextAttr& contentStyle) const;
+
+    /// Get combined attributes of the base style and paragraph style.
+    wxTextAttrEx GetCombinedAttributes() const;
+
 protected:
     /// The lines that make up the wrapped paragraph
     wxRichTextLineList m_cachedLines;
@@ -1178,7 +1238,7 @@ protected:
  * This object represents a single piece of text.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextPlainText: public wxRichTextObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextPlainText)
 public:
@@ -1197,7 +1257,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position/* = wxPoint(0,0)*/) const;
 
     /// Get any text in this object for the given range
     virtual wxString GetTextForRange(const wxRichTextRange& range) const;
@@ -1240,6 +1300,8 @@ public:
 
     /// Clone
     virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
+private:
+    bool DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected);
 
 protected:
     wxString    m_text;
@@ -1252,12 +1314,12 @@ protected:
 class WXDLLIMPEXP_BASE wxDataInputStream;
 class WXDLLIMPEXP_BASE wxDataOutputStream;
 
-class WXDLLIMPEXP_ADV wxRichTextImageBlock: public wxObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject
 {
 public:
     wxRichTextImageBlock();
     wxRichTextImageBlock(const wxRichTextImageBlock& block);
-    ~wxRichTextImageBlock();
+    virtual ~wxRichTextImageBlock();
 
     void Init();
     void Clear();
@@ -1329,7 +1391,7 @@ protected:
  * This object represents an image.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextImage: public wxRichTextObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextImage)
 public:
@@ -1350,7 +1412,7 @@ public:
 
     /// Get the object size for the given range. Returns false if the range
     /// is invalid for this object.
-    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const;
+    virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
 
     /// Returns true if the object is empty
     virtual bool IsEmpty() const { return !m_image.Ok(); }
@@ -1393,10 +1455,10 @@ protected:
  * This is a kind of box, used to represent the whole buffer
  */
 
-class WXDLLIMPEXP_ADV wxRichTextCommand;
-class WXDLLIMPEXP_ADV wxRichTextAction;
+class WXDLLIMPEXP_RICHTEXT wxRichTextCommand;
+class WXDLLIMPEXP_RICHTEXT wxRichTextAction;
 
-class WXDLLIMPEXP_ADV wxRichTextBuffer: public wxRichTextParagraphLayoutBox
+class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
 public:
@@ -1404,7 +1466,7 @@ public:
 
     wxRichTextBuffer() { Init(); }
     wxRichTextBuffer(const wxRichTextBuffer& obj):wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
-    ~wxRichTextBuffer() ;
+    virtual ~wxRichTextBuffer() ;
 
 // Accessors
 
@@ -1492,7 +1554,7 @@ public:
     virtual void ClearStyleStack();
 
     /// Get the size of the style stack, for example to check correct nesting
-    virtual int GetStyleStackSize() const { return m_attributeStack.GetCount(); }
+    virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); }
 
     /// Begin using bold
     bool BeginBold();
@@ -1593,13 +1655,13 @@ public:
     virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
 
     /// Submit command to insert the given text
-    bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl);
+    bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
 
     /// Submit command to insert a newline
-    bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl);
+    bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
 
     /// Submit command to insert the given image
-    bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl);
+    bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0);
 
     /// Submit command to delete this range
     bool DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long newCaretPositon, wxRichTextCtrl* ctrl);
@@ -1608,6 +1670,11 @@ public:
     void Modify(bool modify = true) { m_modified = modify; }
     bool IsModified() const { return m_modified; }
 
+    /// Get the style that is appropriate for a new paragraph at this position.
+    /// If the previous paragraph has a paragraph style name, look up the next-paragraph
+    /// style.
+    wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false) const;
+
     /// Dumps contents of buffer for debugging purposes
     virtual void Dump();
     virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
@@ -1694,8 +1761,8 @@ enum wxRichTextCommandId
  *
  */
 
-class WXDLLIMPEXP_ADV wxRichTextAction;
-class WXDLLIMPEXP_ADV wxRichTextCommand: public wxCommand
+class WXDLLIMPEXP_RICHTEXT wxRichTextAction;
+class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand
 {
 public:
     // Ctor for one action
@@ -1705,7 +1772,7 @@ public:
     // Ctor for multiple actions
     wxRichTextCommand(const wxString& name);
 
-    ~wxRichTextCommand();
+    virtual ~wxRichTextCommand();
 
     bool Do();
     bool Undo();
@@ -1725,13 +1792,13 @@ protected:
  * There can be more than one action in a command.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextAction: public wxObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject
 {
 public:
     wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
         wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
 
-    ~wxRichTextAction();
+    virtual ~wxRichTextAction();
 
     bool Do();
     bool Undo();
@@ -1791,7 +1858,7 @@ protected:
  * Base class for file handlers
  */
 
-class WXDLLIMPEXP_ADV wxRichTextFileHandler: public wxObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject
 {
     DECLARE_CLASS(wxRichTextFileHandler)
 public:
@@ -1822,15 +1889,22 @@ public:
     virtual bool IsVisible() const { return m_visible; }
     virtual void SetVisible(bool visible) { m_visible = visible; }
 
+    /// The name of the nandler
     void SetName(const wxString& name) { m_name = name; }
     wxString GetName() const { return m_name; }
 
+    /// The default extension to recognise
     void SetExtension(const wxString& ext) { m_extension = ext; }
     wxString GetExtension() const { return m_extension; }
 
+    /// The handler type
     void SetType(int type) { m_type = type; }
     int GetType() const { return m_type; }
 
+    /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
+    void SetEncoding(const wxString& encoding) { m_encoding = encoding; }
+    const wxString& GetEncoding() const { return m_encoding; }
+
 protected:
 
 #if wxUSE_STREAMS
@@ -1839,6 +1913,7 @@ protected:
 #endif
 
     wxString  m_name;
+    wxString  m_encoding;
     wxString  m_extension;
     int       m_type;
     bool      m_visible;
@@ -1849,7 +1924,7 @@ protected:
  * Plain text handler
  */
 
-class WXDLLIMPEXP_ADV wxRichTextPlainTextHandler: public wxRichTextFileHandler
+class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler
 {
     DECLARE_CLASS(wxRichTextPlainTextHandler)
 public: