From 336d8ae9a3feae7b2c3ecd8f64fe0e16984edfe7 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Mon, 24 Jul 2006 18:20:18 +0000
Subject: [PATCH] documentation for wxAppTraits (patch 1518295 from Francesco)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43576 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/richtextattr.tex                |  43 +--
 docs/latex/wx/richtextliststyledefinition.tex |  13 +-
 docs/latex/wx/richtextstyledefinition.tex     |   6 +-
 docs/latex/wx/richtextstylesheet.tex          |  24 +-
 include/wx/richtext/richtextbuffer.h          |  36 +-
 include/wx/richtext/richtextstyles.h          |  20 +-
 src/richtext/richtextbuffer.cpp               | 309 +++++++++++-------
 src/richtext/richtextctrl.cpp                 |   2 +-
 src/richtext/richtextfontpage.cpp             |  10 +-
 src/richtext/richtextliststylepage.cpp        |   5 +-
 src/richtext/richtextstyledlg.cpp             |  12 +-
 src/richtext/richtextstyles.cpp               | 108 +++++-
 src/richtext/richtextxml.cpp                  |  12 +-
 13 files changed, 388 insertions(+), 212 deletions(-)

diff --git a/docs/latex/wx/richtextattr.tex b/docs/latex/wx/richtextattr.tex
index 2f1bcbdfe6..db6401e5e2 100644
--- a/docs/latex/wx/richtextattr.tex
+++ b/docs/latex/wx/richtextattr.tex
@@ -155,11 +155,22 @@ Of these, only wxTEXT\_ATTR\_EFFECT\_CAPITALS and wxTEXT\_ATTR\_EFFECT\_STRIKETH
 
 Constructors.
 
-\membersection{wxRichTextAttr::CopyTo}\label{wxrichtextattrcopyto}
+\membersection{wxRichTextAttr::Apply}\label{wxrichtextattrapply}
 
-\constfunc{void}{CopyTo}{\param{wxTextAttrEx\& }{attr}}
+\func{bool}{Combine}{\param{const wxRichTextAttrEx\& }{style}, \param{const wxRichTextAttrEx* }{compareWith = NULL}}
 
-Copies the wxRichTextAttr attributes to a \helpref{wxTextAttrEx}{wxtextattrex} object.
+Applies the attributes in {\it style} to the original object, but not those attributes from {\it style} that are the same as those in {\it compareWith} (if passed).
+
+See also \helpref{wxRichTextAttr::Combine}{wxrichtextattrcombine} for a function that does almost the same but returns a new object instead of modifying the original object.
+
+\membersection{wxRichTextAttr::Combine}\label{wxrichtextattrcombine}
+
+\constfunc{wxRichTextAttr}{Combine}{\param{const wxRichTextAttrEx\& }{style}, \param{const wxRichTextAttrEx* }{compareWith = NULL}}
+
+Combines 'this' with {\it style}, but not applying attributes from {\it style} that are the same as those in {\it compareWith} (if passed).
+A wxRichTextAttr object is returned and the original object is not changed.
+
+See also \helpref{wxRichTextAttr::Apply}{wxrichtextattrapply} for a function that does almost the same but modifies the original object instead of returning a new one.
 
 \membersection{wxRichTextAttr::CreateFont}\label{wxrichtextattrcreatefont}
 
@@ -404,9 +415,9 @@ Returns \true if the attribute object specifies bullet text (usually specifying
 
 Returns \true if the attribute object specifies a character style name.
 
-\membersection{wxRichTextAttr::HasFaceName}\label{wxrichtextattrhasfacename}
+\membersection{wxRichTextAttr::HasFontFaceName}\label{wxrichtextattrhasfontfacename}
 
-\constfunc{bool}{HasFaceName}{\void}
+\constfunc{bool}{HasFontFaceName}{\void}
 
 Returns \true if the attribute object specifies a font face name.
 
@@ -422,9 +433,9 @@ Returns \true if the {\it flag} is present in the attribute object's flag bitlis
 
 Returns \true if the attribute object specifies any font attributes.
 
-\membersection{wxRichTextAttr::HasItalic}\label{wxrichtextattrhasitalic}
+\membersection{wxRichTextAttr::HasFontItalic}\label{wxrichtextattrhasfontitalic}
 
-\constfunc{bool}{HasItalic}{\void}
+\constfunc{bool}{HasFontItalic}{\void}
 
 Returns \true if the attribute object specifies italic style.
 
@@ -482,9 +493,9 @@ Returns \true if the attribute object specifies a paragraph style name.
 
 Returns \true if the attribute object specifies a right indent.
 
-\membersection{wxRichTextAttr::HasSize}\label{wxrichtextattrhassize}
+\membersection{wxRichTextAttr::HasFontSize}\label{wxrichtextattrhasfontsize}
 
-\constfunc{bool}{HasSize}{\void}
+\constfunc{bool}{HasFontSize}{\void}
 
 Returns \true if the attribute object specifies a font point size.
 
@@ -506,9 +517,9 @@ Returns \true if the attribute object specifies a text foreground colour.
 
 Returns \true if the attribute object specifies text effects.
 
-\membersection{wxRichTextAttr::HasUnderlined}\label{wxrichtextattrhasunderlined}
+\membersection{wxRichTextAttr::HasFontUnderlined}\label{wxrichtextattrhasfontunderlined}
 
-\constfunc{bool}{HasUnderlined}{\void}
+\constfunc{bool}{HasFontUnderlined}{\void}
 
 Returns \true if the attribute object specifies either underlining or no underlining.
 
@@ -518,18 +529,12 @@ Returns \true if the attribute object specifies either underlining or no underli
 
 Returns \true if the attribute object specifies a URL.
 
-\membersection{wxRichTextAttr::HasWeight}\label{wxrichtextattrhasweight}
+\membersection{wxRichTextAttr::HasFontWeight}\label{wxrichtextattrhasfontweight}
 
-\constfunc{bool}{HasWeight}{\void}
+\constfunc{bool}{HasFontWeight}{\void}
 
 Returns \true if the attribute object specifies font weight (bold, light or normal).
 
-\membersection{wxRichTextAttr::Init}\label{wxrichtextattrinit}
-
-\func{void}{Init}{\void}
-
-Initialise the object.
-
 \membersection{wxRichTextAttr::IsCharacterStyle}\label{wxrichtextattrischaracterstyle}
 
 \constfunc{bool}{IsCharacterStyle}{\void}
diff --git a/docs/latex/wx/richtextliststyledefinition.tex b/docs/latex/wx/richtextliststyledefinition.tex
index b2b8f470c5..f51dabb1a8 100644
--- a/docs/latex/wx/richtextliststyledefinition.tex
+++ b/docs/latex/wx/richtextliststyledefinition.tex
@@ -37,9 +37,10 @@ Destructor.
 
 \membersection{wxRichTextListStyleDefinition::CombineWithParagraphStyle}\label{wxrichtextliststyledefinitioncombinewithparagraphstyle}
 
-\func{wxRichTextAttr}{CombineWithParagraphStyle}{\param{int }{indent}, \param{const wxRichTextAttr\&}{ paraStyle}}
+\func{wxRichTextAttr}{CombineWithParagraphStyle}{\param{int }{indent}, \param{const wxRichTextAttr\&}{ paraStyle}, \param{wxRichTextStyleSheet*}{ styleSheet = NULL}}
 
 This function combines the given paragraph style with the list style's base attributes and level style matching the given indent, returning the combined attributes.
+If {\it styleSheet} is specified, the base style for this definition will also be included in the result.
 
 \membersection{wxRichTextListStyleDefinition::FindLevelForIndent}\label{wxrichtextliststyledefinitionfindlevelforindent}
 
@@ -49,9 +50,17 @@ This function finds the level (from 0 to 9) whose indentation attribute mostly c
 
 \membersection{wxRichTextListStyleDefinition::GetCombinedStyle}\label{wxrichtextliststyledefinitioncombinewithparagraphstyle}
 
-\constfunc{wxRichTextAttr}{GetCombinedStyle}{\param{int }{indent}}
+\constfunc{wxRichTextAttr}{GetCombinedStyle}{\param{int }{indent}, \param{wxRichTextStyleSheet*}{ styleSheet = NULL}}
 
 This function combines the list style's base attributes and the level style matching the given indent, returning the combined attributes.
+If {\it styleSheet} is specified, the base style for this definition will also be included in the result.
+
+\membersection{wxRichTextListStyleDefinition::GetCombinedStyleForLevel}\label{wxrichtextliststyledefinitioncombinewithparagraphstyleforlevel}
+
+\constfunc{wxRichTextAttr}{GetCombinedStyleLevel}{\param{int }{level}, \param{wxRichTextStyleSheet*}{ styleSheet = NULL}}
+
+This function combines the list style's base attributes and the style for the specified level, returning the combined attributes.
+If {\it styleSheet} is specified, the base style for this definition will also be included in the result.
 
 \membersection{wxRichTextListStyleDefinition::GetLevelAttributes}\label{wxrichtextliststyledefinitiongetlevelattributes}
 
diff --git a/docs/latex/wx/richtextstyledefinition.tex b/docs/latex/wx/richtextstyledefinition.tex
index 2ed18ab5fa..f9117a59e1 100644
--- a/docs/latex/wx/richtextstyledefinition.tex
+++ b/docs/latex/wx/richtextstyledefinition.tex
@@ -52,11 +52,11 @@ Returns the style name.
 
 Returns the attributes associated with this style.
 
-\membersection{wxRichTextStyleDefinition::Init}\label{wxrichtextstyledefinitioninit}
+\membersection{wxRichTextStyleDefinition::GetStyleMergedWithBase}\label{wxrichtextstyledefinitiongetstylemergedwithbase}
 
-\func{void}{Init}{\void}
+\constfunc{wxRichTextAttr}{GetStyleMergedWithBase}{\param{wxRichTextStyleSheet*}{ sheet}}
 
-Initialises the definition.
+Returns the style attributes combined with the attributes of the specified base style, if any. This function works recursively.
 
 \membersection{wxRichTextStyleDefinition::SetBaseStyle}\label{wxrichtextstyledefinitionsetbasestyle}
 
diff --git a/docs/latex/wx/richtextstylesheet.tex b/docs/latex/wx/richtextstylesheet.tex
index c1b3fe5ce6..613b06b15b 100644
--- a/docs/latex/wx/richtextstylesheet.tex
+++ b/docs/latex/wx/richtextstylesheet.tex
@@ -49,6 +49,12 @@ Adds a definition to the list style list.
 
 Adds a definition to the paragraph style list.
 
+\membersection{wxRichTextStyleSheet::AddStyle}\label{wxrichtextstylesheetaddstyle}
+
+\func{bool}{AddStyle}{\param{wxRichTextStyleDefinition* }{def}}
+
+Adds a definition to the appropriate style list.
+
 \membersection{wxRichTextStyleSheet::DeleteStyles}\label{wxrichtextstylesheetdeletestyles}
 
 \func{void}{DeleteStyles}{\void}
@@ -73,6 +79,12 @@ Finds a list definition by name.
 
 Finds a paragraph definition by name.
 
+\membersection{wxRichTextStyleSheet::FindStyle}\label{wxrichtextstylesheetfindstyle}
+
+\constfunc{wxRichTextStyleDefinition*}{FindStyle}{\param{const wxString\& }{name}}
+
+Finds a style definition by name.
+
 \membersection{wxRichTextStyleSheet::GetCharacterStyle}\label{wxrichtextstylesheetgetcharacterstyle}
 
 \constfunc{wxRichTextCharacterStyleDefinition*}{GetCharacterStyle}{\param{size\_t }{n}}
@@ -121,12 +133,6 @@ Returns the {\it n}th paragraph style.
 
 Returns the number of paragraph styles.
 
-\membersection{wxRichTextStyleSheet::Init}\label{wxrichtextstylesheetinit}
-
-\func{void}{Init}{\void}
-
-Initialises the style sheet.
-
 \membersection{wxRichTextStyleSheet::RemoveCharacterStyle}\label{wxrichtextstylesheetremovecharacterstyle}
 
 \func{bool}{RemoveCharacterStyle}{\param{wxRichTextStyleDefinition* }{def}, \param{bool }{deleteStyle = false}}
@@ -145,6 +151,12 @@ Removes a list style.
 
 Removes a paragraph style.
 
+\membersection{wxRichTextStyleSheet::RemoveStyle}\label{wxrichtextstylesheetremovestyle}
+
+\func{bool}{RemoveStyle}{\param{wxRichTextStyleDefinition* }{def}, \param{bool }{deleteStyle = false}}
+
+Removes a style.
+
 \membersection{wxRichTextStyleSheet::SetDescription}\label{wxrichtextstylesheetsetdescription}
 
 \func{void}{SetDescription}{\param{const wxString\& }{descr}}
diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h
index 011d1b621b..0db98bc056 100644
--- a/include/wx/richtext/richtextbuffer.h
+++ b/include/wx/richtext/richtextbuffer.h
@@ -391,11 +391,11 @@ public:
     int GetTextEffectFlags() const { return m_textEffectFlags; }
     int GetOutlineLevel() const { return m_outlineLevel; }
 
-    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 HasFontWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
+    bool HasFontSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; }
+    bool HasFontItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; }
+    bool HasFontUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
+    bool HasFontFaceName() 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); }
@@ -566,11 +566,11 @@ public:
     bool HasTabs() const { return (m_flags & wxTEXT_ATTR_TABS) != 0 ; }
     bool HasLeftIndent() const { return (m_flags & wxTEXT_ATTR_LEFT_INDENT) != 0 ; }
     bool HasRightIndent() const { return (m_flags & wxTEXT_ATTR_RIGHT_INDENT) != 0 ; }
-    bool HasWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
-    bool HasSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
-    bool HasItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
-    bool HasUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
-    bool HasFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; }
+    bool HasFontWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
+    bool HasFontSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
+    bool HasFontItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
+    bool HasFontUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
+    bool HasFontFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; }
     bool HasFont() const { return (m_flags & (wxTEXT_ATTR_FONT)) != 0; }
 
     bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; }
@@ -601,12 +601,16 @@ public:
         return GetFlags() == 0;
     }
 
-    // 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);
+    // Merges the given attributes. Does not affect 'this'. If compareWith
+    // is non-NULL, then it will be used to mask out those attributes that are the same in style
+    // and compareWith, for situations where we don't want to explicitly set inherited attributes.
+    bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL);
+
+    // Merges the given attributes and returns the result. Does not affect 'this'. If compareWith
+    // is non-NULL, then it will be used to mask out those attributes that are the same in style
+    // and compareWith, for situations where we don't want to explicitly set inherited attributes.
+    wxRichTextAttr Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const;
+
 private:
     long                m_flags;
 
diff --git a/include/wx/richtext/richtextstyles.h b/include/wx/richtext/richtextstyles.h
index 729e5e3f34..b15ee9f94a 100644
--- a/include/wx/richtext/richtextstyles.h
+++ b/include/wx/richtext/richtextstyles.h
@@ -93,11 +93,14 @@ public:
     void SetBaseStyle(const wxString& name) { m_baseStyle = name; }
     const wxString& GetBaseStyle() const { return m_baseStyle; }
 
-    /// Sets the style
+    /// Sets and gets the style
     void SetStyle(const wxRichTextAttr& style) { m_style = style; }
     const wxRichTextAttr& GetStyle() const { return m_style; }
     wxRichTextAttr& GetStyle() { return m_style; }
 
+    /// Gets the style combined with the base style
+    virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const;
+
 protected:
     wxString        m_name;
     wxString        m_baseStyle;
@@ -215,15 +218,15 @@ public:
 
     /// Combine the base and list style with a paragraph style, using the given indent (from which
     /// an appropriate level is found)
-    wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle);
+    wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet = NULL);
 
     /// Combine the base and list style, using the given indent (from which
     /// an appropriate level is found)
-    wxRichTextAttr GetCombinedStyle(int indent);
+    wxRichTextAttr GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet = NULL);
 
     /// Combine the base and list style, using the given level from which
     /// an appropriate level is found)
-    wxRichTextAttr GetCombinedStyleForLevel(int level);
+    wxRichTextAttr GetCombinedStyleForLevel(int level, wxRichTextStyleSheet* styleSheet = NULL);
 
     /// Gets the number of available levels
     int GetLevelCount() const { return 10; }
@@ -276,6 +279,9 @@ public:
     /// Add a definition to the list style list
     bool AddListStyle(wxRichTextListStyleDefinition* def);
 
+    /// Add a definition to the appropriate style list
+    bool AddStyle(wxRichTextStyleDefinition* def);
+
     /// Remove a character style
     bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
 
@@ -285,6 +291,9 @@ public:
     /// Remove a list style
     bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); }
 
+    /// Remove a style
+    bool RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false);
+
     /// Find a character definition by name
     wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); }
 
@@ -294,6 +303,9 @@ public:
     /// Find a list definition by name
     wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); }
 
+    /// Find any definition by name
+    wxRichTextStyleDefinition* FindStyle(const wxString& name, bool recurse = true) const;
+
     /// Return the number of character styles
     size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
 
diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp
index 49c609d053..6388b00489 100644
--- a/src/richtext/richtextbuffer.cpp
+++ b/src/richtext/richtextbuffer.cpp
@@ -1569,7 +1569,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
     {
         wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(wholeStyle.GetParagraphStyleName());
         if (def)
-            wxRichTextApplyStyle(wholeStyle, def->GetStyle());
+            wxRichTextApplyStyle(wholeStyle, def->GetStyleMergedWithBase(GetStyleSheet()));
     }
 
     // Limit the attributes to be set to the content to only character attributes.
@@ -1580,7 +1580,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
     {
         wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterAttributes.GetCharacterStyleName());
         if (def)
-            wxRichTextApplyStyle(characterAttributes, def->GetStyle());
+            wxRichTextApplyStyle(characterAttributes, def->GetStyleMergedWithBase(GetStyleSheet()));
     }
 
     // If we are associated with a control, make undoable; otherwise, apply immediately
@@ -1838,9 +1838,9 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
 {
     if (style.HasFont())
     {
-        if (style.HasSize() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_SIZE))
+        if (style.HasFontSize() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_SIZE))
         {
-            if (currentStyle.GetFont().Ok() && currentStyle.HasSize())
+            if (currentStyle.GetFont().Ok() && currentStyle.HasFontSize())
             {
                 if (currentStyle.GetFont().GetPointSize() != style.GetFont().GetPointSize())
                 {
@@ -1861,9 +1861,9 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
             }
         }
 
-        if (style.HasItalic() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_ITALIC))
+        if (style.HasFontItalic() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_ITALIC))
         {
-            if (currentStyle.GetFont().Ok() && currentStyle.HasItalic())
+            if (currentStyle.GetFont().Ok() && currentStyle.HasFontItalic())
             {
                 if (currentStyle.GetFont().GetStyle() != style.GetFont().GetStyle())
                 {
@@ -1883,9 +1883,9 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
             }
         }
 
-        if (style.HasWeight() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT))
+        if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT))
         {
-            if (currentStyle.GetFont().Ok() && currentStyle.HasWeight())
+            if (currentStyle.GetFont().Ok() && currentStyle.HasFontWeight())
             {
                 if (currentStyle.GetFont().GetWeight() != style.GetFont().GetWeight())
                 {
@@ -1905,9 +1905,9 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
             }
         }
 
-        if (style.HasFaceName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_FACE))
+        if (style.HasFontFaceName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_FACE))
         {
-            if (currentStyle.GetFont().Ok() && currentStyle.HasFaceName())
+            if (currentStyle.GetFont().Ok() && currentStyle.HasFontFaceName())
             {
                 wxString faceName1(currentStyle.GetFont().GetFaceName());
                 wxString faceName2(style.GetFont().GetFaceName());
@@ -1930,9 +1930,9 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
             }
         }
 
-        if (style.HasUnderlined() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE))
+        if (style.HasFontUnderlined() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE))
         {
-            if (currentStyle.GetFont().Ok() && currentStyle.HasUnderlined())
+            if (currentStyle.GetFont().Ok() && currentStyle.HasFontUnderlined())
             {
                 if (currentStyle.GetFont().GetUnderlined() != style.GetFont().GetUnderlined())
                 {
@@ -2512,13 +2512,13 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
                 wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
                 if (paraDef && !listDef)
                 {
-                    para->GetAttributes() = paraDef->GetStyle();
+                    para->GetAttributes() = paraDef->GetStyleMergedWithBase(styleSheet);
                     foundCount ++;
                 }
                 else if (listDef && !paraDef)
                 {
                     // Set overall style defined for the list style definition
-                    para->GetAttributes() = listDef->GetStyle();
+                    para->GetAttributes() = listDef->GetStyleMergedWithBase(styleSheet);
 
                     // Apply the style for this level
                     wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
@@ -2527,7 +2527,7 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
                 else if (listDef && paraDef)
                 {
                     // Combines overall list style, style for level, and paragraph style
-                    para->GetAttributes() = listDef->CombineWithParagraphStyle(currentIndent, paraDef->GetStyle());
+                    para->GetAttributes() = listDef->CombineWithParagraphStyle(currentIndent, paraDef->GetStyleMergedWithBase(styleSheet));
                     foundCount ++;
                 }
             }
@@ -2538,7 +2538,7 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
                 wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
 
                 // Overall list definition style
-                para->GetAttributes() = listDef->GetStyle();
+                para->GetAttributes() = listDef->GetStyleMergedWithBase(styleSheet);
 
                 // Style for this level
                 wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
@@ -2550,7 +2550,7 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
                 wxRichTextParagraphStyleDefinition* def = styleSheet->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
                 if (def)
                 {
-                    para->GetAttributes() = def->GetStyle();
+                    para->GetAttributes() = def->GetStyleMergedWithBase(styleSheet);
                     foundCount ++;
                 }
             }
@@ -2564,6 +2564,8 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
 /// Set list style
 bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
 {
+    wxRichTextStyleSheet* styleSheet = GetStyleSheet();
+    
     bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
     // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
     bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0);
@@ -2631,7 +2633,7 @@ bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, wx
                     // Renumbering will need to be done when we promote/demote a paragraph.
 
                     // Apply the overall list style, and item style for this level
-                    wxTextAttrEx listStyle(def->GetCombinedStyleForLevel(thisLevel));
+                    wxTextAttrEx listStyle(def->GetCombinedStyleForLevel(thisLevel, styleSheet));
                     wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
 
                     // Now we need to do numbering
@@ -2654,13 +2656,12 @@ bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, wx
                     // Eliminate the main list-related attributes
                     newPara->GetAttributes().SetFlags(newPara->GetAttributes().GetFlags() & ~wxTEXT_ATTR_LEFT_INDENT & ~wxTEXT_ATTR_BULLET_STYLE & ~wxTEXT_ATTR_BULLET_NUMBER & ~wxTEXT_ATTR_BULLET_TEXT & wxTEXT_ATTR_LIST_STYLE_NAME);
 
-                    wxRichTextStyleSheet* styleSheet = GetStyleSheet();
                     if (styleSheet && !newPara->GetAttributes().GetParagraphStyleName().IsEmpty())
                     {
                         wxRichTextParagraphStyleDefinition* def = styleSheet->FindParagraphStyle(newPara->GetAttributes().GetParagraphStyleName());
                         if (def)
                         {
-                            newPara->GetAttributes() = def->GetStyle();
+                            newPara->GetAttributes() = def->GetStyleMergedWithBase(styleSheet);
                         }
                     }
                 }
@@ -2704,6 +2705,8 @@ bool wxRichTextParagraphLayoutBox::NumberList(const wxRichTextRange& range, wxRi
 bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy,
                                                 wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
 {
+    wxRichTextStyleSheet* styleSheet = GetStyleSheet();
+
     bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
     // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
 #ifdef __WXDEBUG__
@@ -2781,10 +2784,8 @@ bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, co
                 wxRichTextListStyleDefinition* defToUse = def;
                 if (!defToUse)
                 {
-                    wxRichTextStyleSheet* sheet = GetStyleSheet();
-
-                    if (sheet && !newPara->GetAttributes().GetListStyleName().IsEmpty())
-                        defToUse = sheet->FindListStyle(newPara->GetAttributes().GetListStyleName());
+                    if (styleSheet && !newPara->GetAttributes().GetListStyleName().IsEmpty())
+                        defToUse = styleSheet->FindListStyle(newPara->GetAttributes().GetListStyleName());
                 }
 
                 if (defToUse)
@@ -2807,7 +2808,7 @@ bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, co
                     }
 
                     // Apply the overall list style, and item style for this level
-                    wxTextAttrEx listStyle(defToUse->GetCombinedStyleForLevel(thisLevel));
+                    wxTextAttrEx listStyle(defToUse->GetCombinedStyleForLevel(thisLevel, styleSheet));
                     wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
 
                     // OK, we've (re)applied the style, now let's get the numbering right.
@@ -2923,10 +2924,10 @@ bool wxRichTextParagraphLayoutBox::FindNextParagraphNumber(wxRichTextParagraph*
     if (!previousParagraph->GetAttributes().HasFlag(wxTEXT_ATTR_BULLET_STYLE) || previousParagraph->GetAttributes().GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE)
         return false;
     
-    wxRichTextStyleSheet* sheet = GetStyleSheet();
-    if (sheet && !previousParagraph->GetAttributes().GetListStyleName().IsEmpty())
+    wxRichTextStyleSheet* styleSheet = GetStyleSheet();
+    if (styleSheet && !previousParagraph->GetAttributes().GetListStyleName().IsEmpty())
     {
-        wxRichTextListStyleDefinition* def = sheet->FindListStyle(previousParagraph->GetAttributes().GetListStyleName());
+        wxRichTextListStyleDefinition* def = styleSheet->FindListStyle(previousParagraph->GetAttributes().GetListStyleName());
         if (def)
         {
             // int thisIndent = previousParagraph->GetAttributes().GetLeftIndent();
@@ -4848,7 +4849,7 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos
                     if (nextParaDef)
                     {
                         foundAttributes = true;
-                        attr = nextParaDef->GetStyle();
+                        attr = nextParaDef->GetStyleMergedWithBase(GetStyleSheet());
                     }
                 }
                 
@@ -4856,7 +4857,7 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos
                 if (!foundAttributes)
                 {
                     foundAttributes = true;
-                    attr = paraDef->GetStyle();
+                    attr = paraDef->GetStyleMergedWithBase(GetStyleSheet());
                 }
             }
         }
@@ -5214,7 +5215,7 @@ bool wxRichTextBuffer::BeginCharacterStyle(const wxString& characterStyle)
         wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle);
         if (def)
         {
-            wxTextAttrEx attr = def->GetStyle();
+            wxTextAttrEx attr = def->GetStyleMergedWithBase(GetStyleSheet());
             return BeginStyle(attr);
         }
     }
@@ -5229,7 +5230,7 @@ bool wxRichTextBuffer::BeginParagraphStyle(const wxString& paragraphStyle)
         wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(paragraphStyle);
         if (def)
         {
-            wxTextAttrEx attr = def->GetStyle();
+            wxTextAttrEx attr = def->GetStyleMergedWithBase(GetStyleSheet());
             return BeginStyle(attr);
         }
     }
@@ -5264,7 +5265,7 @@ bool wxRichTextBuffer::BeginURL(const wxString& url, const wxString& characterSt
         wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle);
         if (def)
         {
-            attr = def->GetStyle();
+            attr = def->GetStyleMergedWithBase(GetStyleSheet());
         }
     }
     attr.SetURL(url);
@@ -6848,9 +6849,7 @@ bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style)
 
 bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith)
 {
-    wxTextAttrEx attr(destStyle);
-    wxRichTextApplyStyle(attr, style, compareWith);
-    destStyle = attr;
+    destStyle = destStyle.Combine(style, compareWith);
     return true;
 }
 
@@ -6869,7 +6868,7 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
 
         if (style.GetFlags() & wxTEXT_ATTR_FONT_FACE)
         {
-            if (compareWith && compareWith->HasFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName())
+            if (compareWith && compareWith->HasFontFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName())
             {
                 // The same as currently displayed, so don't set
             }
@@ -6882,7 +6881,7 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
 
         if (style.GetFlags() & wxTEXT_ATTR_FONT_SIZE)
         {
-            if (compareWith && compareWith->HasSize() && compareWith->GetFontSize() == style.GetFontSize())
+            if (compareWith && compareWith->HasFontSize() && compareWith->GetFontSize() == style.GetFontSize())
             {
                 // The same as currently displayed, so don't set
             }
@@ -6895,7 +6894,7 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
 
         if (style.GetFlags() & wxTEXT_ATTR_FONT_ITALIC)
         {
-            if (compareWith && compareWith->HasItalic() && compareWith->GetFontStyle() == style.GetFontStyle())
+            if (compareWith && compareWith->HasFontItalic() && compareWith->GetFontStyle() == style.GetFontStyle())
             {
                 // The same as currently displayed, so don't set
             }
@@ -6908,7 +6907,7 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
 
         if (style.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT)
         {
-            if (compareWith && compareWith->HasWeight() && compareWith->GetFontWeight() == style.GetFontWeight())
+            if (compareWith && compareWith->HasFontWeight() && compareWith->GetFontWeight() == style.GetFontWeight())
             {
                 // The same as currently displayed, so don't set
             }
@@ -6921,7 +6920,7 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
 
         if (style.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE)
         {
-            if (compareWith && compareWith->HasUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined())
+            if (compareWith && compareWith->HasFontUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined())
             {
                 // The same as currently displayed, so don't set
             }
@@ -7411,116 +7410,184 @@ bool wxRichTextAttr::GetFontAttributes(const wxFont& font)
     return true;
 }
 
-wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr,
-                               const wxRichTextAttr& attrDef,
-                               const wxTextCtrlBase *text)
+wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith) const
 {
-    wxColour colFg = attr.GetTextColour();
-    if ( !colFg.Ok() )
-    {
-        colFg = attrDef.GetTextColour();
+    wxRichTextAttr destStyle = (*this);
+    destStyle.Apply(style, compareWith);
+    
+    return destStyle;
+}
 
-        if ( text && !colFg.Ok() )
-            colFg = text->GetForegroundColour();
+bool wxRichTextAttr::Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith)
+{
+    wxRichTextAttr& destStyle = (*this);
+    
+    if (style.HasFontWeight())
+    {
+        if (!(compareWith && compareWith->HasFontWeight() && compareWith->GetFontWeight() == style.GetFontWeight()))
+            destStyle.SetFontWeight(style.GetFontWeight());
     }
 
-    wxColour colBg = attr.GetBackgroundColour();
-    if ( !colBg.Ok() )
+    if (style.HasFontSize())
     {
-        colBg = attrDef.GetBackgroundColour();
-
-        if ( text && !colBg.Ok() )
-            colBg = text->GetBackgroundColour();
+        if (!(compareWith && compareWith->HasFontSize() && compareWith->GetFontSize() == style.GetFontSize()))
+            destStyle.SetFontSize(style.GetFontSize());
     }
 
-    wxRichTextAttr newAttr(colFg, colBg);
+    if (style.HasFontItalic())
+    {
+        if (!(compareWith && compareWith->HasFontItalic() && compareWith->GetFontStyle() == style.GetFontStyle()))
+            destStyle.SetFontStyle(style.GetFontStyle());
+    }
 
-    if (attr.HasWeight())
-        newAttr.SetFontWeight(attr.GetFontWeight());
+    if (style.HasFontUnderlined())
+    {
+        if (!(compareWith && compareWith->HasFontUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined()))
+            destStyle.SetFontUnderlined(style.GetFontUnderlined());
+    }
 
-    if (attr.HasSize())
-        newAttr.SetFontSize(attr.GetFontSize());
+    if (style.HasFontFaceName())
+    {
+        if (!(compareWith && compareWith->HasFontFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName()))
+            destStyle.SetFontFaceName(style.GetFontFaceName());
+    }
 
-    if (attr.HasItalic())
-        newAttr.SetFontStyle(attr.GetFontStyle());
+    if (style.GetTextColour().Ok() && style.HasTextColour())
+    {
+        if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour()))
+            destStyle.SetTextColour(style.GetTextColour());
+    }
 
-    if (attr.HasUnderlined())
-        newAttr.SetFontUnderlined(attr.GetFontUnderlined());
+    if (style.GetBackgroundColour().Ok() && style.HasBackgroundColour())
+    {
+        if (!(compareWith && compareWith->HasBackgroundColour() && compareWith->GetBackgroundColour() == style.GetBackgroundColour()))
+            destStyle.SetBackgroundColour(style.GetBackgroundColour());
+    }
 
-    if (attr.HasFaceName())
-        newAttr.SetFontFaceName(attr.GetFontFaceName());
+    if (style.HasAlignment())
+    {
+        if (!(compareWith && compareWith->HasAlignment() && compareWith->GetAlignment() == style.GetAlignment()))
+            destStyle.SetAlignment(style.GetAlignment());
+    }
 
-    if (attr.HasAlignment())
-        newAttr.SetAlignment(attr.GetAlignment());
-    else if (attrDef.HasAlignment())
-        newAttr.SetAlignment(attrDef.GetAlignment());
+    if (style.HasTabs())
+    {
+        if (!(compareWith && compareWith->HasTabs() && wxRichTextTabsEq(compareWith->GetTabs(), style.GetTabs())))
+            destStyle.SetTabs(style.GetTabs());
+    }
 
-    if (attr.HasTabs())
-        newAttr.SetTabs(attr.GetTabs());
-    else if (attrDef.HasTabs())
-        newAttr.SetTabs(attrDef.GetTabs());
+    if (style.HasLeftIndent())
+    {
+        if (!(compareWith && compareWith->HasLeftIndent() && compareWith->GetLeftIndent() == style.GetLeftIndent()
+                          && compareWith->GetLeftSubIndent() == style.GetLeftSubIndent()))
+            destStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent());
+    }
 
-    if (attr.HasLeftIndent())
-        newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent());
-    else if (attrDef.HasLeftIndent())
-        newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent());
+    if (style.HasRightIndent())
+    {
+        if (!(compareWith && compareWith->HasRightIndent() && compareWith->GetRightIndent() == style.GetRightIndent()))
+            destStyle.SetRightIndent(style.GetRightIndent());
+    }
 
-    if (attr.HasRightIndent())
-        newAttr.SetRightIndent(attr.GetRightIndent());
-    else if (attrDef.HasRightIndent())
-        newAttr.SetRightIndent(attrDef.GetRightIndent());
+    if (style.HasParagraphSpacingAfter())
+    {
+        if (!(compareWith && compareWith->HasParagraphSpacingAfter() && compareWith->GetParagraphSpacingAfter() == style.GetParagraphSpacingAfter()))
+            destStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter());
+    }
 
-    // NEW ATTRIBUTES
+    if (style.HasParagraphSpacingBefore())
+    {
+        if (!(compareWith && compareWith->HasParagraphSpacingBefore() && compareWith->GetParagraphSpacingBefore() == style.GetParagraphSpacingBefore()))
+            destStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore());
+    }
 
-    if (attr.HasParagraphSpacingAfter())
-        newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter());
+    if (style.HasLineSpacing())
+    {
+        if (!(compareWith && compareWith->HasLineSpacing() && compareWith->GetLineSpacing() == style.GetLineSpacing()))
+            destStyle.SetLineSpacing(style.GetLineSpacing());
+    }
 
-    if (attr.HasParagraphSpacingBefore())
-        newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore());
+    if (style.HasCharacterStyleName())
+    {
+        if (!(compareWith && compareWith->HasCharacterStyleName() && compareWith->GetCharacterStyleName() == style.GetCharacterStyleName()))
+            destStyle.SetCharacterStyleName(style.GetCharacterStyleName());
+    }
 
-    if (attr.HasLineSpacing())
-        newAttr.SetLineSpacing(attr.GetLineSpacing());
+    if (style.HasParagraphStyleName())
+    {
+        if (!(compareWith && compareWith->HasParagraphStyleName() && compareWith->GetParagraphStyleName() == style.GetParagraphStyleName()))
+            destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
+    }
 
-    if (attr.HasCharacterStyleName())
-        newAttr.SetCharacterStyleName(attr.GetCharacterStyleName());
+    if (style.HasListStyleName())
+    {
+        if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName()))
+            destStyle.SetListStyleName(style.GetListStyleName());
+    }
 
-    if (attr.HasParagraphStyleName())
-        newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
+    if (style.HasBulletStyle())
+    {
+        if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle()))
+            destStyle.SetBulletStyle(style.GetBulletStyle());
+    }
 
-    if (attr.HasListStyleName())
-        newAttr.SetListStyleName(attr.GetListStyleName());
+    if (style.HasBulletText())
+    {
+        if (!(compareWith && compareWith->HasBulletText() && compareWith->GetBulletText() == style.GetBulletText()))
+        {
+            destStyle.SetBulletText(style.GetBulletText());
+            destStyle.SetBulletFont(style.GetBulletFont());
+        }
+    }
 
-    if (attr.HasBulletStyle())
-        newAttr.SetBulletStyle(attr.GetBulletStyle());
+    if (style.HasBulletNumber())
+    {
+        if (!(compareWith && compareWith->HasBulletNumber() && compareWith->GetBulletNumber() == style.GetBulletNumber()))
+            destStyle.SetBulletNumber(style.GetBulletNumber());
+    }
 
-    if (attr.HasBulletNumber())
-        newAttr.SetBulletNumber(attr.GetBulletNumber());
+    if (style.HasBulletName())
+    {
+        if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName()))
+            destStyle.SetBulletName(style.GetBulletName());
+    }
 
-    if (attr.HasBulletName())
-        newAttr.SetBulletName(attr.GetBulletName());
+    if (style.HasURL())
+    {
+        if (!(compareWith && compareWith->HasURL() && compareWith->GetURL() == style.GetURL()))
+            destStyle.SetURL(style.GetURL());
+    }
 
-    if (attr.HasBulletText())
+    if (style.HasPageBreak())
     {
-        newAttr.SetBulletText(attr.GetBulletText());
-        newAttr.SetBulletFont(attr.GetBulletFont());
+        if (!(compareWith && compareWith->HasPageBreak()))
+            destStyle.SetPageBreak();
     }
 
-    if (attr.HasURL())
-        newAttr.SetURL(attr.GetURL());
+    if (style.HasTextEffects())
+    {
+        if (!(compareWith && compareWith->HasTextEffects() && compareWith->GetTextEffects() == style.GetTextEffects()))
+        {
+            int destBits = destStyle.GetTextEffects();
+            int destFlags = destStyle.GetTextEffectFlags();
 
-    if (attr.HasPageBreak())
-        newAttr.SetPageBreak();
+            int srcBits = style.GetTextEffects();
+            int srcFlags = style.GetTextEffectFlags();
+            
+            wxRichTextCombineBitlists(destBits, srcBits, destFlags, srcFlags);
+            
+            destStyle.SetTextEffects(destBits);
+            destStyle.SetTextEffectFlags(destFlags);
+        }
+    }
 
-    if (attr.HasTextEffects())
+    if (style.HasOutlineLevel())
     {
-        newAttr.SetTextEffects(attr.GetTextEffects());
-        newAttr.SetTextEffectFlags(attr.GetTextEffectFlags());
+        if (!(compareWith && compareWith->HasOutlineLevel() && compareWith->GetOutlineLevel() == style.GetOutlineLevel()))
+            destStyle.SetOutlineLevel(style.GetOutlineLevel());
     }
 
-    if (attr.HasOutlineLevel())
-        newAttr.SetOutlineLevel(attr.GetOutlineLevel());
-
-    return newAttr;
+    return true;
 }
 
 /*!
@@ -7643,27 +7710,27 @@ wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
         // Otherwise, if there are font attributes in attr, apply them
         if (attr.GetFlags() & wxTEXT_ATTR_FONT)
         {
-            if (attr.HasSize())
+            if (attr.HasFontSize())
             {
                 flags |= wxTEXT_ATTR_FONT_SIZE;
                 font.SetPointSize(attr.GetFont().GetPointSize());
             }
-            if (attr.HasItalic())
+            if (attr.HasFontItalic())
             {
                 flags |= wxTEXT_ATTR_FONT_ITALIC;;
                 font.SetStyle(attr.GetFont().GetStyle());
             }
-            if (attr.HasWeight())
+            if (attr.HasFontWeight())
             {
                 flags |= wxTEXT_ATTR_FONT_WEIGHT;
                 font.SetWeight(attr.GetFont().GetWeight());
             }
-            if (attr.HasFaceName())
+            if (attr.HasFontFaceName())
             {
                 flags |= wxTEXT_ATTR_FONT_FACE;
                 font.SetFaceName(attr.GetFont().GetFaceName());
             }
-            if (attr.HasUnderlined())
+            if (attr.HasFontUnderlined())
             {
                 flags |= wxTEXT_ATTR_FONT_UNDERLINE;
                 font.SetUnderlined(attr.GetFont().GetUnderlined());
diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp
index b592eba83d..3dcaa1f4ec 100644
--- a/src/richtext/richtextctrl.cpp
+++ b/src/richtext/richtextctrl.cpp
@@ -2929,7 +2929,7 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def)
 {
     // Flags are defined within each definition, so only certain
     // attributes are applied.
-    wxRichTextAttr attr(def->GetStyle());
+    wxRichTextAttr attr(GetStyleSheet() ? def->GetStyleMergedWithBase(GetStyleSheet()) : def->GetStyle());
 
     int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE;
 
diff --git a/src/richtext/richtextfontpage.cpp b/src/richtext/richtextfontpage.cpp
index a445486597..642bbfd92e 100644
--- a/src/richtext/richtextfontpage.cpp
+++ b/src/richtext/richtextfontpage.cpp
@@ -383,7 +383,7 @@ bool wxRichTextFontPage::TransferDataToWindow()
     m_dontUpdate = true;
     wxTextAttrEx* attr = GetAttributes();
 
-    if (attr->HasFont() && attr->HasFaceName())
+    if (attr->HasFont() && attr->HasFontFaceName())
     {
         m_faceTextCtrl->SetValue(attr->GetFont().GetFaceName());
         m_faceListBox->SetFaceNameSelection(attr->GetFont().GetFaceName());
@@ -394,7 +394,7 @@ bool wxRichTextFontPage::TransferDataToWindow()
         m_faceListBox->SetFaceNameSelection(wxEmptyString);
     }
 
-    if (attr->HasFont() && attr->HasSize())
+    if (attr->HasFont() && attr->HasFontSize())
     {
         wxString strSize = wxString::Format(wxT("%d"), attr->GetFont().GetPointSize());
         m_sizeTextCtrl->SetValue(strSize);
@@ -407,7 +407,7 @@ bool wxRichTextFontPage::TransferDataToWindow()
         m_sizeListBox->SetSelection(wxNOT_FOUND);
     }
 
-    if (attr->HasFont() && attr->HasWeight())
+    if (attr->HasFont() && attr->HasFontWeight())
     {
         if (attr->GetFont().GetWeight() == wxBOLD)
             m_weightCtrl->SetSelection(1);
@@ -419,7 +419,7 @@ bool wxRichTextFontPage::TransferDataToWindow()
         m_weightCtrl->SetSelection(wxNOT_FOUND);
     }
 
-    if (attr->HasFont() && attr->HasItalic())
+    if (attr->HasFont() && attr->HasFontItalic())
     {
         if (attr->GetFont().GetStyle() == wxITALIC)
             m_styleCtrl->SetSelection(1);
@@ -431,7 +431,7 @@ bool wxRichTextFontPage::TransferDataToWindow()
         m_styleCtrl->SetSelection(wxNOT_FOUND);
     }
 
-    if (attr->HasFont() && attr->HasUnderlined())
+    if (attr->HasFont() && attr->HasFontUnderlined())
     {
         if (attr->GetFont().GetUnderlined())
             m_underliningCtrl->SetSelection(1);
diff --git a/src/richtext/richtextliststylepage.cpp b/src/richtext/richtextliststylepage.cpp
index 9645f72870..bc08d77e07 100644
--- a/src/richtext/richtextliststylepage.cpp
+++ b/src/richtext/richtextliststylepage.cpp
@@ -527,8 +527,11 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
 
     wxRichTextListStyleDefinition* def = wxDynamicCast(wxRichTextFormattingDialog::GetDialogStyleDefinition(this),
         wxRichTextListStyleDefinition);
+        
+    wxRichTextStyleSheet* styleSheet = wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
+
+    wxTextAttrEx attr(styleSheet ? def->GetStyle() : def->GetStyleMergedWithBase(styleSheet));
 
-    wxTextAttrEx attr(def->GetStyle());
     attr.SetFlags(attr.GetFlags() &
       (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|
        wxTEXT_ATTR_LINE_SPACING|
diff --git a/src/richtext/richtextstyledlg.cpp b/src/richtext/richtextstyledlg.cpp
index 9383e9f2f8..bdc7637ed5 100644
--- a/src/richtext/richtextstyledlg.cpp
+++ b/src/richtext/richtextstyledlg.cpp
@@ -425,16 +425,8 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n");
     wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel);
 
     wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
-    //wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
-    //wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
-
-    wxTextAttrEx attr(def->GetStyle());
-#if 0
-    attr.SetFlags(attr.GetFlags() &
-      (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|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));
-#endif
+
+    wxTextAttrEx attr(def->GetStyleMergedWithBase(GetStyleSheet()));
 
     wxFont font(m_previewCtrl->GetFont());
     font.SetPointSize(9);
diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp
index b66481a051..37ac00b4fc 100644
--- a/src/richtext/richtextstyles.cpp
+++ b/src/richtext/richtextstyles.cpp
@@ -53,6 +53,22 @@ bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const
     return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style);
 }
 
+/// Gets the style combined with the base style
+wxRichTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const
+{
+    if (!m_baseStyle.IsEmpty())
+    {
+        wxRichTextStyleDefinition* baseStyle = sheet->FindStyle(m_baseStyle);
+        if (baseStyle)
+        {
+            wxRichTextAttr baseAttr = baseStyle->GetStyleMergedWithBase(sheet);
+            baseAttr.Apply(m_style, NULL);
+            return baseAttr;
+        }
+    }
+    return m_style;
+}
+
 /*!
  * Paragraph style definition
  */
@@ -162,7 +178,7 @@ int wxRichTextListStyleDefinition::FindLevelForIndent(int indent) const
 
 /// Combine the list style with a paragraph style, using the given indent (from which
 /// an appropriate level is found)
-wxRichTextAttr wxRichTextListStyleDefinition::CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle)
+wxRichTextAttr wxRichTextListStyleDefinition::CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet)
 {
     int listLevel = FindLevelForIndent(indent);
 
@@ -171,10 +187,13 @@ wxRichTextAttr wxRichTextListStyleDefinition::CombineWithParagraphStyle(int inde
     int oldLeftSubIndent = attr.GetLeftSubIndent();
 
     // First apply the overall paragraph style, if any
-    wxRichTextApplyStyle(attr, GetStyle());
+    if (styleSheet)
+        attr.Apply(GetStyleMergedWithBase(styleSheet));
+    else
+        attr.Apply(GetStyle());
 
     // Then apply paragraph style, e.g. from paragraph style definition
-    wxRichTextApplyStyle(attr, paraStyle);
+    attr.Apply(paraStyle);
 
     // We override the indents according to the list definition
     attr.SetLeftIndent(oldLeftIndent, oldLeftSubIndent);
@@ -184,22 +203,25 @@ wxRichTextAttr wxRichTextListStyleDefinition::CombineWithParagraphStyle(int inde
 
 /// Combine the base and list style, using the given indent (from which
 /// an appropriate level is found)
-wxRichTextAttr wxRichTextListStyleDefinition::GetCombinedStyle(int indent)
+wxRichTextAttr wxRichTextListStyleDefinition::GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet)
 {
     int listLevel = FindLevelForIndent(indent);
-    return GetCombinedStyleForLevel(listLevel);
+    return GetCombinedStyleForLevel(listLevel, styleSheet);
 }
 
 /// Combine the base and list style, using the given indent (from which
 /// an appropriate level is found)
-wxRichTextAttr wxRichTextListStyleDefinition::GetCombinedStyleForLevel(int listLevel)
+wxRichTextAttr wxRichTextListStyleDefinition::GetCombinedStyleForLevel(int listLevel, wxRichTextStyleSheet* styleSheet)
 {
     wxRichTextAttr attr(*GetLevelAttributes(listLevel));
     int oldLeftIndent = attr.GetLeftIndent();
     int oldLeftSubIndent = attr.GetLeftSubIndent();
 
     // Apply the overall paragraph style, if any
-    wxRichTextApplyStyle(attr, GetStyle());
+    if (styleSheet)
+        attr.Apply(GetStyleMergedWithBase(styleSheet));
+    else
+        attr.Apply(GetStyle());
 
     // We override the indents according to the list definition
     attr.SetLeftIndent(oldLeftIndent, oldLeftSubIndent);
@@ -266,6 +288,18 @@ bool wxRichTextStyleSheet::RemoveStyle(wxList& list, wxRichTextStyleDefinition*
         return false;
 }
 
+/// Remove a style
+bool wxRichTextStyleSheet::RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle)
+{
+    if (RemoveParagraphStyle(def, deleteStyle))
+        return true;
+    if (RemoveCharacterStyle(def, deleteStyle))
+        return true;
+    if (RemoveListStyle(def, deleteStyle))
+        return true;
+    return false;
+}
+
 /// Find a definition by name
 wxRichTextStyleDefinition* wxRichTextStyleSheet::FindStyle(const wxList& list, const wxString& name, bool recurse) const
 {
@@ -353,6 +387,42 @@ bool wxRichTextStyleSheet::AddListStyle(wxRichTextListStyleDefinition* def)
     return AddStyle(m_listStyleDefinitions, def);
 }
 
+/// Add a definition to the appropriate style list
+bool wxRichTextStyleSheet::AddStyle(wxRichTextStyleDefinition* def)
+{
+    wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
+    if (listDef)
+        return AddListStyle(listDef);
+
+    wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
+    if (paraDef)
+        return AddParagraphStyle(paraDef);
+
+    wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
+    if (charDef)
+        return AddCharacterStyle(charDef);
+    
+    return false;
+}
+
+/// Find any definition by name
+wxRichTextStyleDefinition* wxRichTextStyleSheet::FindStyle(const wxString& name, bool recurse) const
+{
+    wxRichTextListStyleDefinition* listDef = FindListStyle(name, recurse);
+    if (listDef)
+        return listDef;
+
+    wxRichTextParagraphStyleDefinition* paraDef = FindParagraphStyle(name, recurse);
+    if (paraDef)
+        return paraDef;
+
+    wxRichTextCharacterStyleDefinition* charDef = FindCharacterStyle(name, recurse);
+    if (charDef)
+        return charDef;
+    
+    return NULL;    
+}
+
 /// Copy
 void wxRichTextStyleSheet::Copy(const wxRichTextStyleSheet& sheet)
 {
@@ -540,8 +610,10 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
     wxString str;
 
     bool isCentred = false;
+    
+    wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet()));
 
-    if (def->GetStyle().HasAlignment() && def->GetStyle().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+    if (attr.HasAlignment() && attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
         isCentred = true;
 
     if (isCentred)
@@ -550,11 +622,11 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
     
     str << wxT("<table><tr>");
 
-    if (def->GetStyle().GetLeftIndent() > 0)
+    if (attr.GetLeftIndent() > 0)
     {
         wxClientDC dc((wxWindow*) this);
 
-        str << wxT("<td width=") << wxMin(50, (ConvertTenthsMMToPixels(dc, def->GetStyle().GetLeftIndent())/2)) << wxT("></td>");
+        str << wxT("<td width=") << wxMin(50, (ConvertTenthsMMToPixels(dc, attr.GetLeftIndent())/2)) << wxT("></td>");
     }
 
     if (isCentred)
@@ -569,7 +641,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
 #endif
 
     int stdFontSize = 12;
-    int thisFontSize = ((def->GetStyle().GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? def->GetStyle().GetFontSize() : stdFontSize;
+    int thisFontSize = ((attr.GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? attr.GetFontSize() : stdFontSize;
 
     if (thisFontSize < stdFontSize)
         size ++;
@@ -580,11 +652,11 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
 
     str << wxT(" size=") << size;
 
-    if (!def->GetStyle().GetFontFaceName().IsEmpty())
-        str << wxT(" face=\"") << def->GetStyle().GetFontFaceName() << wxT("\"");
+    if (!attr.GetFontFaceName().IsEmpty())
+        str << wxT(" face=\"") << attr.GetFontFaceName() << wxT("\"");
 
-    if (def->GetStyle().GetTextColour().Ok())
-        str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
+    if (attr.GetTextColour().Ok())
+        str << wxT(" color=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");
 
     str << wxT(">");
 
@@ -592,11 +664,11 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
     bool hasItalic = false;
     bool hasUnderline = false;
 
-    if (def->GetStyle().GetFontWeight() == wxBOLD)
+    if (attr.GetFontWeight() == wxBOLD)
         hasBold = true;
-    if (def->GetStyle().GetFontStyle() == wxITALIC)
+    if (attr.GetFontStyle() == wxITALIC)
         hasItalic = true;
-    if (def->GetStyle().GetFontUnderlined())
+    if (attr.GetFontUnderlined())
         hasUnderline = true;
 
     if (hasBold)
diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp
index 9a22fd4292..3e03c70559 100644
--- a/src/richtext/richtextxml.cpp
+++ b/src/richtext/richtextxml.cpp
@@ -893,22 +893,22 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara
 
     if (attr.GetFont().Ok())
     {
-        if (attr.HasSize())
+        if (attr.HasFontSize())
             str << wxT(" fontsize=\"") << attr.GetFont().GetPointSize() << wxT("\"");
         
-        //if (attr.HasFamily())
+        //if (attr.HasFontFamily())
         //    str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
 
-        if (attr.HasItalic())
+        if (attr.HasFontItalic())
             str << wxT(" fontstyle=\"") << attr.GetFont().GetStyle() << wxT("\"");
 
-        if (attr.HasWeight())
+        if (attr.HasFontWeight())
             str << wxT(" fontweight=\"") << attr.GetFont().GetWeight() << wxT("\"");
 
-        if (attr.HasUnderlined())
+        if (attr.HasFontUnderlined())
             str << wxT(" fontunderlined=\"") << (int) attr.GetFont().GetUnderlined() << wxT("\"");
 
-        if (attr.HasFaceName())
+        if (attr.HasFontFaceName())
             str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
     }
 
-- 
2.50.0

