]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/richtext/richtextbuffer.h
change UpdateSelection() parameter type to int from size_t; also replaced remaining...
[wxWidgets.git] / include / wx / richtext / richtextbuffer.h
index 68e1fefd458d3f7d0ab501d90db80328242b492b..a2c3fb982c1716c0bc27039d302b39646866ff7a 100644 (file)
@@ -9,6 +9,9 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
+#ifndef _WX_RICHTEXTBUFFER_H_
+#define _WX_RICHTEXTBUFFER_H_
+
 /*
 
   Data structures
 /*
 
   Data structures
@@ -19,9 +22,9 @@
 
   The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox.
   These boxes will allow flexible placement of text boxes on a page, but
 
   The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox.
   These boxes will allow flexible placement of text boxes on a page, but
-  for now there will be a single box representing the document,
-  and this box will a wxRichTextParagraphLayoutBox which contains further
-  wxRichTextParagraph objects, each of which can include text and images.
+  for now there is a single box representing the document, and this box is
+  a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph
+  objects, each of which can include text and images.
 
   Each object maintains a range (start and end position) measured
   from the start of the main parent box.
 
   Each object maintains a range (start and end position) measured
   from the start of the main parent box.
   a position relative to that text box. For now, we will not be dealing with
   embedded objects but it's something to bear in mind for later.
 
   a position relative to that text box. For now, we will not be dealing with
   embedded objects but it's something to bear in mind for later.
 
+  Note that internally, a range (5,5) represents a range of one character.
+  In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection
+  as (5,6). A paragraph with one character might have an internal range of (0, 1)
+  since the end of the paragraph takes up one position.
+
   Layout
   ======
 
   Layout
   ======
 
   in the vertical direction. The implementation of Layout can then
   cache the calculated size and position within the parent.
 
   in the vertical direction. The implementation of Layout can then
   cache the calculated size and position within the parent.
 
-  Note that position and size should be calculated separately, because
-  for example inserting a paragraph may result in the following paragraphs
-  moving down, but not changing in size.
-
-  Need to determine how objects specify their position. Absolute coordinates,
-  or relative to last object? May be hard to determine that. So should probably
-  be in absolute coordinates, in which case we'll need a Move virtual function
-  that allows quick movement of all elements without layout.
-
-  Let's work through a simple example of layout. Say we're laying out
-  a document with the buffer as the top box, with a wxRichTextParagraphLayoutBox
-  inside that that consists of wxRichTextParagraph objects.
-
-  We're in a mode whereby changes of window size change the width of the
-  page (useful for text editors, as opposed to word processors). The
-  window width is 600.
-
-  We pass (600, -1) to the top-level Layout (i.e. restrict size in horizontal
-  direction only). The wxRichTextBuffer box doesn't currently have
-  well-defined layout behaviour so we simply assume it has one child
-  that fills its parent (later we can define sizer-like box layout behaviour).
-  So it passes the same dimensions to the child, which is a wxRichTextParagraphLayoutBox.
-  This then looks at each child in turn (wxRichTextParagraph) and determines
-  the size the paragraph will take up, setting the cached size, and
-  splitting the paragraph into lines.
-
-  When the layout for one paragraph returns, the next paragraph is
-  fed the position of the previous, so it can position itself.
-
-  Each time Layout is called, the cached list of lines for each paragraph
-  is recreated, since it can change for example if the parent object width
-  changes.
-
-  Reporting size
-  ==============
-
-  Each object can report its size for a given range. It's important that
-  it can report a partial size, so that wrapping can be implemented,
-  hit test calculations performed, etc. So GetRangeSize must be implemented
-  for each object.
-
  */
 
  */
 
-#ifndef _WX_RICHTEXTBUFFER_H_
-#define _WX_RICHTEXTBUFFER_H_
-
 /*!
  * Includes
  */
 
 /*!
  * Includes
  */
 
-#include "wx/list.h"
+#include "wx/defs.h"
 
 #if wxUSE_RICHTEXT
 
 
 #if wxUSE_RICHTEXT
 
+#include "wx/list.h"
+#include "wx/textctrl.h"
+#include "wx/bitmap.h"
 #include "wx/image.h"
 #include "wx/cmdproc.h"
 #include "wx/txtstrm.h"
 
 #include "wx/image.h"
 #include "wx/cmdproc.h"
 #include "wx/txtstrm.h"
 
+#if wxUSE_DATAOBJ
+#include "wx/dataobj.h"
+#endif
+
+// Experimental dynamic styles to avoid user-specific character styles from being
+// overwritten by paragraph styles.
+#define wxRICHTEXT_USE_DYNAMIC_STYLES 1
+
 /*!
  * File types
  */
 /*!
  * File types
  */
  * Forward declarations
  */
 
  * 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 wxRichTextFileHandler;
+class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet;
+class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
 
 /*!
  * Flags determining the available space, passed to Layout
 
 /*!
  * Flags determining the available space, passed to Layout
@@ -158,6 +132,36 @@ class WXDLLIMPEXP_ADV wxTextAttrEx;
 #define wxRICHTEXT_FORMATTED        0x01
 #define wxRICHTEXT_UNFORMATTED      0x02
 
 #define wxRICHTEXT_FORMATTED        0x01
 #define wxRICHTEXT_UNFORMATTED      0x02
 
+/*!
+ * Flags for SetStyle
+ */
+
+#define wxRICHTEXT_SETSTYLE_NONE            0x00
+
+// Specifies that this operation should be undoable
+#define wxRICHTEXT_SETSTYLE_WITH_UNDO       0x01
+
+// Specifies that the style should not be applied if the
+// combined style at this point is already the style in question.
+#define wxRICHTEXT_SETSTYLE_OPTIMIZE        0x02
+
+// Specifies that the style should only be applied to paragraphs,
+// and not the content. This allows content styling to be
+// preserved independently from that of e.g. a named paragraph style.
+#define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
+
+// Specifies that the style should only be applied to characters,
+// and not the paragraph. This allows content styling to be
+// preserved independently from that of e.g. a named paragraph style.
+#define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
+
+/*!
+ * Flags for text insertion
+ */
+
+#define wxRICHTEXT_INSERT_NONE                              0x00
+#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE     0x01
+
 /*!
  * Extra formatting flags not in wxTextAttr
  */
 /*!
  * Extra formatting flags not in wxTextAttr
  */
@@ -199,7 +203,7 @@ class WXDLLIMPEXP_ADV wxTextAttrEx;
  * This stores beginning and end positions for a range of data.
  */
 
  * This stores beginning and end positions for a range of data.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextRange
+class WXDLLIMPEXP_RICHTEXT wxRichTextRange
 {
 public:
 // Constructors
 {
 public:
 // Constructors
@@ -211,6 +215,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); }
 
     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); }
 
     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); }
 
@@ -243,6 +248,12 @@ public:
     /// Swaps the start and end
     void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; }
 
     /// 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;
 protected:
     long m_start;
     long m_end;
@@ -255,11 +266,12 @@ protected:
  * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
  */
 
  * 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);
 {
 public:
     // ctors
     wxTextAttrEx(const wxTextAttrEx& attr);
+    wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
     wxTextAttrEx() { Init(); }
 
     // Initialise this object.
     wxTextAttrEx() { Init(); }
 
     // Initialise this object.
@@ -272,14 +284,15 @@ public:
     void operator= (const wxTextAttr& attr);
 
     // setters
     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); }
+    void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
 
     const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
     const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
 
     const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
     const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
@@ -289,12 +302,19 @@ public:
     int GetBulletStyle() const { return m_bulletStyle; }
     int GetBulletNumber() const { return m_bulletNumber; }
     wxChar GetBulletSymbol() const { return m_bulletSymbol; }
     int GetBulletStyle() const { return m_bulletStyle; }
     int GetBulletNumber() const { return m_bulletNumber; }
     wxChar GetBulletSymbol() const { return m_bulletSymbol; }
+    const wxString& GetBulletFont() const { return m_bulletFont; }
+
+    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 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); }
     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); }
@@ -313,6 +333,14 @@ public:
                !HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
                !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
     }
                !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;
 private:
     // Paragraph styles
     int                 m_paragraphSpacingAfter;
@@ -321,6 +349,7 @@ private:
     int                 m_bulletStyle;
     int                 m_bulletNumber;
     wxChar              m_bulletSymbol;
     int                 m_bulletStyle;
     int                 m_bulletNumber;
     wxChar              m_bulletSymbol;
+    wxString            m_bulletFont;
 
     // Character style
     wxString            m_characterStyleName;
 
     // Character style
     wxString            m_characterStyleName;
@@ -334,7 +363,7 @@ private:
  * efficient way to query styles.
  */
 
  * efficient way to query styles.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextAttr
+class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
 {
 public:
     // ctors
 {
 public:
     // ctors
@@ -353,6 +382,9 @@ public:
     // Assignment from a wxTextAttrEx object.
     void operator= (const wxTextAttrEx& attr);
 
     // 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 ;
 
     // Making a wxTextAttrEx object.
     operator wxTextAttrEx () const ;
 
@@ -381,14 +413,15 @@ public:
 
     void SetFlags(long flags) { m_flags = flags; }
 
 
     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; }
+    void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
 
     const wxColour& GetTextColour() const { return m_colText; }
     const wxColour& GetBackgroundColour() const { return m_colBack; }
 
     const wxColour& GetTextColour() const { return m_colText; }
     const wxColour& GetBackgroundColour() const { return m_colBack; }
@@ -413,6 +446,7 @@ public:
     int GetBulletStyle() const { return m_bulletStyle; }
     int GetBulletNumber() const { return m_bulletNumber; }
     wxChar GetBulletSymbol() const { return m_bulletSymbol; }
     int GetBulletStyle() const { return m_bulletStyle; }
     int GetBulletNumber() const { return m_bulletNumber; }
     wxChar GetBulletSymbol() const { return m_bulletSymbol; }
+    const wxString& GetBulletFont() const { return m_bulletFont; }
 
     // accessors
     bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
 
     // accessors
     bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
@@ -431,8 +465,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 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; }
     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; }
@@ -454,6 +488,12 @@ public:
                !HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
     }
 
                !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;
 
 private:
     long                m_flags;
 
@@ -472,6 +512,7 @@ private:
     int                 m_bulletStyle;
     int                 m_bulletNumber;
     wxChar              m_bulletSymbol;
     int                 m_bulletStyle;
     int                 m_bulletNumber;
     wxChar              m_bulletSymbol;
+    wxString            m_bulletFont;
 
     // Character styles
     wxColour            m_colText,
 
     // Character styles
     wxColour            m_colText,
@@ -489,27 +530,27 @@ private:
     wxString            m_paragraphStyleName;
 };
 
     wxString            m_paragraphStyleName;
 };
 
-#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT) | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR
+#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR | wxTEXT_ATTR_CHARACTER_STYLE_NAME)
 
 
-#define wxTEXT_ATTR_PARAGRAPH  wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
+#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
     wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
     wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
-    wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL
+    wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME)
 
 
-#define wxTEXT_ATTR_ALL wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH
+#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
 
 /*!
  * wxRichTextObject class declaration
  * This is the base for drawable objects.
  */
 
 
 /*!
  * wxRichTextObject class declaration
  * 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);
 {
     DECLARE_CLASS(wxRichTextObject)
 public:
 // Constructors
 
     wxRichTextObject(wxRichTextObject* parent = NULL);
-    ~wxRichTextObject();
+    virtual ~wxRichTextObject();
 
 // Overrideables
 
 
 // Overrideables
 
@@ -535,7 +576,7 @@ public:
 
     /// Get the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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'.
 
     /// Do a split, returning an object containing the second part, and setting
     /// the first part in 'this'.
@@ -648,21 +689,21 @@ protected:
     wxTextAttrEx            m_attributes;
 };
 
     wxTextAttrEx            m_attributes;
 };
 
-WX_DECLARE_EXPORTED_LIST( wxRichTextObject, wxRichTextObjectList );
+WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
 
 /*!
  * wxRichTextCompositeObject class declaration
  * Objects of this class can contain other objects.
  */
 
 
 /*!
  * 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);
 {
     DECLARE_CLASS(wxRichTextCompositeObject)
 public:
 // Constructors
 
     wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
-    ~wxRichTextCompositeObject();
+    virtual ~wxRichTextCompositeObject();
 
 // Overrideables
 
 
 // Overrideables
 
@@ -712,6 +753,9 @@ public:
     /// Copy
     void Copy(const wxRichTextCompositeObject& obj);
 
     /// Copy
     void Copy(const wxRichTextCompositeObject& obj);
 
+    /// Assignment
+    void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); }
+
     /// Append a child, returning the position
     size_t AppendChild(wxRichTextObject* child) ;
 
     /// Append a child, returning the position
     size_t AppendChild(wxRichTextObject* child) ;
 
@@ -736,7 +780,7 @@ protected:
  * This defines a 2D space to lay out objects
  */
 
  * 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:
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextBox)
 public:
@@ -755,7 +799,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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
 
 
 // Accessors
 
@@ -775,14 +819,14 @@ protected:
  * This box knows how to lay out paragraphs.
  */
 
  * 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:
 // Constructors
 
     wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)
 public:
 // Constructors
 
     wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
-    wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj):wxRichTextBox() { Init(); Copy(obj); }
+    wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextBox() { Init(); Copy(obj); }
 
 // Overrideables
 
 
 // Overrideables
 
@@ -794,7 +838,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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);
 
     /// Delete range
     virtual bool DeleteRange(const wxRichTextRange& range);
@@ -810,6 +854,10 @@ public:
     /// Get the associated control.
     wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; }
 
     /// Get the associated control.
     wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; }
 
+    /// Get/set whether the last paragraph is partial or complete
+    void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
+    bool GetPartialParagraph() const { return m_partialParagraph; }
+
 // Operations
 
     /// Initialize the object.
 // Operations
 
     /// Initialize the object.
@@ -822,13 +870,13 @@ public:
     virtual void Reset();
 
     /// Convenience function to add a paragraph of text
     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
 
     /// 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.
 
     /// 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.
 
     /// Get the line at the given position. If caretPosition is true, the position is
     /// a caret position, which is normally a smaller number.
@@ -882,12 +930,28 @@ public:
     virtual bool PositionToXY(long pos, long* x, long* y) const;
 
     /// Set text attributes: character and/or paragraph styles.
     virtual bool PositionToXY(long pos, long* x, long* y) const;
 
     /// Set text attributes: character and/or paragraph styles.
-    virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, bool withUndo = true);
-    virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, bool withUndo = true);
+    virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
+    virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
+
+    /// 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);
 
 
-    /// 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 combined style for a range - if any attribute is different within the range,
+    /// that attribute is not present within the flags
+    virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style);
+
+    /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
+    /// content.
+    bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes);
 
     /// 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
 
     /// 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
@@ -909,14 +973,20 @@ public:
     /// Insert fragment into this box at the given position. If partialParagraph is true,
     /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
     /// marker.
     /// Insert fragment into this box at the given position. If partialParagraph is true,
     /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
     /// marker.
-    virtual bool InsertFragment(long position, wxRichTextFragment& fragment);
+    virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
 
     /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
 
     /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
-    virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextFragment& fragment);
+    virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& 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);
 
 
     /// Copy
     void Copy(const wxRichTextParagraphLayoutBox& obj);
 
+    /// Assignment
+    void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); }
+
     /// Calculate ranges
     virtual void UpdateRanges() { long end; CalculateRange(0, end); }
 
     /// Calculate ranges
     virtual void UpdateRanges() { long end; CalculateRange(0, end); }
 
@@ -948,47 +1018,10 @@ protected:
     wxTextAttrEx    m_defaultAttributes;
 
     /// The invalidated range that will need full layout
     wxTextAttrEx    m_defaultAttributes;
 
     /// The invalidated range that will need full layout
-    wxRichTextRange         m_invalidRange;
-};
-
-/*!
- * wxRichTextFragment class declaration
- * This is a lind of paragraph layout box used for storing
- * paragraphs for Undo/Redo, for example.
- */
-
-class WXDLLIMPEXP_ADV wxRichTextFragment: public wxRichTextParagraphLayoutBox
-{
-    DECLARE_DYNAMIC_CLASS(wxRichTextFragment)
-public:
-// Constructors
-
-    wxRichTextFragment() { Init(); }
-    wxRichTextFragment(const wxRichTextFragment& obj):wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
-
-// Accessors
-
-    /// Get/set whether the last paragraph is partial or complete
-    void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
-    bool GetPartialParagraph() const { return m_partialParagraph; }
-
-// Overrideables
-
-// Operations
-
-    /// Initialise
-    void Init();
-
-    /// Copy
-    void Copy(const wxRichTextFragment& obj);
-
-    /// Clone
-    virtual wxRichTextObject* Clone() const { return new wxRichTextFragment(*this); }
-
-protected:
+    wxRichTextRange m_invalidRange;
 
     // Is the last paragraph partial or complete?
 
     // Is the last paragraph partial or complete?
-    bool        m_partialParagraph;
+    bool            m_partialParagraph;
 };
 
 /*!
 };
 
 /*!
@@ -998,7 +1031,7 @@ protected:
  * start and end positions of the line.
  */
 
  * start and end positions of the line.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextLine
+class WXDLLIMPEXP_RICHTEXT wxRichTextLine
 {
 public:
 // Constructors
 {
 public:
 // Constructors
@@ -1071,14 +1104,14 @@ protected:
     wxRichTextParagraph* m_parent;
 };
 
     wxRichTextParagraph* m_parent;
 };
 
-WX_DECLARE_EXPORTED_LIST( wxRichTextLine, wxRichTextLineList );
+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).
  */
 
 
 /*!
  * 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:
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextParagraph)
 public:
@@ -1086,8 +1119,8 @@ public:
 
     wxRichTextParagraph(wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
     wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
 
     wxRichTextParagraph(wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
     wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
-    ~wxRichTextParagraph();
-    wxRichTextParagraph(const wxRichTextParagraph& obj):wxRichTextBox() { Copy(obj); }
+    virtual ~wxRichTextParagraph();
+    wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextBox() { Copy(obj); }
 
 // Overrideables
 
 
 // Overrideables
 
@@ -1099,7 +1132,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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);
 
     /// 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);
@@ -1130,7 +1163,7 @@ public:
 // Implementation
 
     /// Apply paragraph styles such as centering to the wrapped lines
 // 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);
 
     /// Insert text at the given position
     virtual bool InsertText(long pos, const wxString& text);
@@ -1165,6 +1198,13 @@ public:
     /// Clear remaining unused line objects, if any
     bool ClearUnusedLines(int lineCount);
 
     /// 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 wxTextAttrEx& 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;
 protected:
     /// The lines that make up the wrapped paragraph
     wxRichTextLineList m_cachedLines;
@@ -1175,14 +1215,14 @@ protected:
  * This object represents a single piece of text.
  */
 
  * 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:
 // Constructors
 
     wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextPlainText)
 public:
 // Constructors
 
     wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
-    wxRichTextPlainText(const wxRichTextPlainText& obj):wxRichTextObject() { Copy(obj); }
+    wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); }
 
 // Overrideables
 
 
 // Overrideables
 
@@ -1194,7 +1234,7 @@ public:
 
     /// Get/set the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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;
 
     /// Get any text in this object for the given range
     virtual wxString GetTextForRange(const wxRichTextRange& range) const;
@@ -1237,6 +1277,8 @@ public:
 
     /// Clone
     virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
 
     /// 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;
 
 protected:
     wxString    m_text;
@@ -1249,12 +1291,12 @@ protected:
 class WXDLLIMPEXP_BASE wxDataInputStream;
 class WXDLLIMPEXP_BASE wxDataOutputStream;
 
 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);
 {
 public:
     wxRichTextImageBlock();
     wxRichTextImageBlock(const wxRichTextImageBlock& block);
-    ~wxRichTextImageBlock();
+    virtual ~wxRichTextImageBlock();
 
     void Init();
     void Clear();
 
     void Init();
     void Clear();
@@ -1298,7 +1340,8 @@ public:
     void SetDataSize(size_t size) { m_dataSize = size; }
     void SetImageType(int imageType) { m_imageType = imageType; }
 
     void SetDataSize(size_t size) { m_dataSize = size; }
     void SetImageType(int imageType) { m_imageType = imageType; }
 
-    bool Ok() const { return GetData() != NULL; }
+    bool Ok() const { return IsOk(); }
+    bool IsOk() const { return GetData() != NULL; }
 
 /// Implementation
 
 
 /// Implementation
 
@@ -1326,16 +1369,16 @@ protected:
  * This object represents an image.
  */
 
  * This object represents an image.
  */
 
-class WXDLLIMPEXP_ADV wxRichTextImage: public wxRichTextObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextImage)
 public:
 // Constructors
 
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextImage)
 public:
 // Constructors
 
-    wxRichTextImage(wxRichTextObject* parent = NULL):wxRichTextObject(parent) { }
+    wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { }
     wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL);
     wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL);
     wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL);
     wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL);
-    wxRichTextImage(const wxRichTextImage& obj):wxRichTextObject() { Copy(obj); }
+    wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject() { Copy(obj); }
 
 // Overrideables
 
 
 // Overrideables
 
@@ -1347,7 +1390,7 @@ public:
 
     /// Get the object size for the given range. Returns false if the range
     /// is invalid for this object.
 
     /// 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(); }
 
     /// Returns true if the object is empty
     virtual bool IsEmpty() const { return !m_image.Ok(); }
@@ -1390,18 +1433,18 @@ protected:
  * This is a kind of box, used to represent the whole buffer
  */
 
  * 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:
 // Constructors
 
     wxRichTextBuffer() { Init(); }
 {
     DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
 public:
 // Constructors
 
     wxRichTextBuffer() { Init(); }
-    wxRichTextBuffer(const wxRichTextBuffer& obj):wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
-    ~wxRichTextBuffer() ;
+    wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
+    virtual ~wxRichTextBuffer() ;
 
 // Accessors
 
 
 // Accessors
 
@@ -1436,7 +1479,7 @@ public:
     virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
 
     /// Convenience function to add a paragraph of text
     virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
 
     /// Convenience function to add a paragraph of text
-    virtual wxRichTextRange AddParagraph(const wxString& text) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text); }
+    virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); }
 
     /// Begin collapsing undo/redo commands. Note that this may not work properly
     /// if combining commands that delete or insert content, changing ranges for
 
     /// Begin collapsing undo/redo commands. Note that this may not work properly
     /// if combining commands that delete or insert content, changing ranges for
@@ -1489,7 +1532,7 @@ public:
     virtual void ClearStyleStack();
 
     /// Get the size of the style stack, for example to check correct nesting
     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();
 
     /// Begin using bold
     bool BeginBold();
@@ -1584,19 +1627,22 @@ public:
 // Implementation
 
     /// Copy
 // Implementation
 
     /// Copy
-    void Copy(const wxRichTextBuffer& obj) { wxRichTextBox::Copy(obj); }
+    void Copy(const wxRichTextBuffer& obj);
 
     /// Clone
     virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
 
 
     /// Clone
     virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
 
+    /// Submit command to insert paragraphs
+    bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
+
     /// Submit command to insert the given text
     /// 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
 
     /// 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
 
     /// 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);
 
     /// Submit command to delete this range
     bool DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long newCaretPositon, wxRichTextCtrl* ctrl);
@@ -1605,6 +1651,11 @@ public:
     void Modify(bool modify = true) { m_modified = modify; }
     bool IsModified() const { return m_modified; }
 
     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); }
     /// Dumps contents of buffer for debugging purposes
     virtual void Dump();
     virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
@@ -1691,8 +1742,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
 {
 public:
     // Ctor for one action
@@ -1702,7 +1753,7 @@ public:
     // Ctor for multiple actions
     wxRichTextCommand(const wxString& name);
 
     // Ctor for multiple actions
     wxRichTextCommand(const wxString& name);
 
-    ~wxRichTextCommand();
+    virtual ~wxRichTextCommand();
 
     bool Do();
     bool Undo();
 
     bool Do();
     bool Undo();
@@ -1722,13 +1773,13 @@ protected:
  * There can be more than one action in a command.
  */
 
  * 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);
 
 {
 public:
     wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
         wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
 
-    ~wxRichTextAction();
+    virtual ~wxRichTextAction();
 
     bool Do();
     bool Undo();
 
     bool Do();
     bool Undo();
@@ -1737,11 +1788,11 @@ public:
     void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false);
 
     /// Replace the buffer paragraphs with the given fragment.
     void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false);
 
     /// Replace the buffer paragraphs with the given fragment.
-    void ApplyParagraphs(const wxRichTextFragment& fragment);
+    void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment);
 
     /// Get the fragments
 
     /// Get the fragments
-    wxRichTextFragment& GetNewParagraphs() { return m_newParagraphs; }
-    wxRichTextFragment& GetOldParagraphs() { return m_oldParagraphs; }
+    wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; }
+    wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; }
 
     /// Set/get the position used for e.g. insertion
     void SetPosition(long pos) { m_position = pos; }
 
     /// Set/get the position used for e.g. insertion
     void SetPosition(long pos) { m_position = pos; }
@@ -1765,10 +1816,10 @@ protected:
     wxRichTextCtrl*                 m_ctrl;
 
     // Stores the new paragraphs
     wxRichTextCtrl*                 m_ctrl;
 
     // Stores the new paragraphs
-    wxRichTextFragment              m_newParagraphs;
+    wxRichTextParagraphLayoutBox    m_newParagraphs;
 
     // Stores the old paragraphs
 
     // Stores the old paragraphs
-    wxRichTextFragment              m_oldParagraphs;
+    wxRichTextParagraphLayoutBox    m_oldParagraphs;
 
     // The affected range
     wxRichTextRange                 m_range;
 
     // The affected range
     wxRichTextRange                 m_range;
@@ -1788,7 +1839,7 @@ protected:
  * Base class for file handlers
  */
 
  * Base class for file handlers
  */
 
-class WXDLLIMPEXP_ADV wxRichTextFileHandler: public wxObject
+class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject
 {
     DECLARE_CLASS(wxRichTextFileHandler)
 public:
 {
     DECLARE_CLASS(wxRichTextFileHandler)
 public:
@@ -1819,15 +1870,22 @@ public:
     virtual bool IsVisible() const { return m_visible; }
     virtual void SetVisible(bool visible) { m_visible = visible; }
 
     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; }
 
     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; }
 
     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; }
 
     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
 protected:
 
 #if wxUSE_STREAMS
@@ -1836,6 +1894,7 @@ protected:
 #endif
 
     wxString  m_name;
 #endif
 
     wxString  m_name;
+    wxString  m_encoding;
     wxString  m_extension;
     int       m_type;
     bool      m_visible;
     wxString  m_extension;
     int       m_type;
     bool      m_visible;
@@ -1846,7 +1905,7 @@ protected:
  * Plain text handler
  */
 
  * Plain text handler
  */
 
-class WXDLLIMPEXP_ADV wxRichTextPlainTextHandler: public wxRichTextFileHandler
+class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler
 {
     DECLARE_CLASS(wxRichTextPlainTextHandler)
 public:
 {
     DECLARE_CLASS(wxRichTextPlainTextHandler)
 public:
@@ -1869,6 +1928,48 @@ protected:
 
 };
 
 
 };
 
+#if wxUSE_DATAOBJ
+
+/*!
+ * The data object for a wxRichTextBuffer
+ */
+
+class wxRichTextBufferDataObject: public wxDataObjectSimple
+{
+public:
+    // ctor doesn't copy the pointer, so it shouldn't go away while this object
+    // is alive
+    wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = (wxRichTextBuffer*) NULL);
+    virtual ~wxRichTextBufferDataObject();
+
+    // after a call to this function, the buffer is owned by the caller and it
+    // is responsible for deleting it
+    wxRichTextBuffer* GetRichTextBuffer();
+
+    // Returns the id for the new data format
+    static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; }
+
+    // base class pure virtuals
+
+    virtual wxDataFormat GetPreferredFormat(Direction dir) const;
+    virtual size_t GetDataSize() const;
+    virtual bool GetDataHere(void *pBuf) const;
+    virtual bool SetData(size_t len, const void *buf);
+
+    // prevent warnings
+
+    virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); }
+    virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); }
+    virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); }
+
+private:
+    wxDataFormat            m_formatRichTextBuffer;     // our custom format
+    wxRichTextBuffer*       m_richTextBuffer;           // our data
+    static const wxChar*    ms_richTextBufferFormatId;  // our format id
+};
+
+#endif
+
 /*!
  * Utilities
  *
 /*!
  * Utilities
  *
@@ -1891,10 +1992,20 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2,
 /// Apply one style to another
 bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style);
 bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style);
 /// Apply one style to another
 bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style);
 bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style);
-bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style);
+bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
+
+/// Compare tabs
+bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2);
+
+/// Set the font without changing the font attributes
+void wxSetFontPreservingStyles(wxTextAttr& attr, const wxFont& font);
+
+/// Convert a decimal to Roman numerals
+wxString wxRichTextDecimalToRoman(long n);
 
 #endif
     // wxUSE_RICHTEXT
 
 #endif
     // _WX_RICHTEXTBUFFER_H_
 
 #endif
     // wxUSE_RICHTEXT
 
 #endif
     // _WX_RICHTEXTBUFFER_H_
+