]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextbuffer.cpp
Override GetPixelSize on OS X as the base impl creates a wxScreenDC each time, which...
[wxWidgets.git] / src / richtext / richtextbuffer.cpp
index 0921ba0ff1a6007f22d410a54d970ba7ff925123..f1ed9eacf16f3c9e3d0802c576ee3b7a3bcbb664 100644 (file)
@@ -932,7 +932,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text
     size_t i = 0;
     size_t len = text.length();
     wxString line;
-    wxRichTextParagraph* para = new wxRichTextParagraph(wxT(""), this, & style);
+    wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, & style);
     if (paraStyle)
         para->SetAttributes(*paraStyle);
 
@@ -949,7 +949,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text
             wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData();
             plainText->SetText(line);
 
-            para = new wxRichTextParagraph(wxT(""), this, & style);
+            para = new wxRichTextParagraph(wxEmptyString, this, & style);
             if (paraStyle)
                 para->SetAttributes(*paraStyle);
 
@@ -2108,6 +2108,21 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
             currentStyle.SetParagraphStyleName(style.GetParagraphStyleName());
     }
 
+    if (style.HasListStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LIST_STYLE_NAME))
+    {
+        if (currentStyle.HasListStyleName())
+        {
+            if (currentStyle.HasListStyleName() != style.HasListStyleName())
+            {
+                // Clash of style - mark as such
+                multipleStyleAttributes |= wxTEXT_ATTR_LIST_STYLE_NAME;
+                currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_LIST_STYLE_NAME);
+            }
+        }
+        else
+            currentStyle.SetListStyleName(style.GetListStyleName());
+    }
+
     if (style.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_STYLE))
     {
         if (currentStyle.HasBulletStyle())
@@ -2156,6 +2171,23 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons
         }
     }
 
+    if (style.HasBulletName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NAME))
+    {
+        if (currentStyle.HasBulletName())
+        {
+            if (currentStyle.HasBulletName() != style.HasBulletName())
+            {
+                // Clash of style - mark as such
+                multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NAME;
+                currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_NAME);
+            }
+        }
+        else
+        {
+            currentStyle.SetBulletName(style.GetBulletName());
+        }
+    }
+
     return true;
 }
 
@@ -2410,7 +2442,57 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
 
         if (para)
         {
-            if (!para->GetAttributes().GetParagraphStyleName().IsEmpty())
+            // Combine paragraph and list styles. If there is a list style in the original attributes,
+            // the current indentation overrides anything else and is used to find the item indentation.
+            // Also, for applying paragraph styles, consider having 2 modes: (1) we merge with what we have,
+            // thereby taking into account all user changes, (2) reset the style completely (except for indentation/list
+            // exception as above).
+            // Problem: when changing from one list style to another, there's a danger that the level info will get lost.
+            // So when changing a list style interactively, could retrieve level based on current style, then
+            // set appropriate indent and apply new style.
+
+            if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty())
+            {
+                int currentIndent = para->GetAttributes().GetLeftIndent();
+
+                wxRichTextParagraphStyleDefinition* paraDef = styleSheet->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
+                wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
+                if (paraDef && !listDef)
+                {
+                    para->GetAttributes() = paraDef->GetStyle();
+                    foundCount ++;
+                }
+                else if (listDef && !paraDef)
+                {
+                    // Set overall style defined for the list style definition
+                    para->GetAttributes() = listDef->GetStyle();
+
+                    // Apply the style for this level
+                    wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
+                    foundCount ++;
+                }
+                else if (listDef && paraDef)
+                {
+                    // Combines overall list style, style for level, and paragraph style
+                    para->GetAttributes() = listDef->CombineWithParagraphStyle(currentIndent, paraDef->GetStyle());
+                    foundCount ++;
+                }
+            }
+            else if (para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty())
+            {
+                int currentIndent = para->GetAttributes().GetLeftIndent();
+
+                wxRichTextListStyleDefinition* listDef = styleSheet->FindListStyle(para->GetAttributes().GetListStyleName());
+
+                // Overall list definition style
+                para->GetAttributes() = listDef->GetStyle();
+
+                // Style for this level
+                wxRichTextApplyStyle(para->GetAttributes(), * listDef->GetLevelAttributes(listDef->FindLevelForIndent(currentIndent)));
+
+                foundCount ++;
+            }
+            else if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && para->GetAttributes().GetListStyleName().IsEmpty())
             {
                 wxRichTextParagraphStyleDefinition* def = styleSheet->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
                 if (def)
@@ -2426,6 +2508,344 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh
     return foundCount != 0;
 }
 
+/// Set list style
+bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+    bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
+    // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
+    bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0);
+    bool renumber = ((flags & wxRICHTEXT_SETSTYLE_RENUMBER) != 0);
+
+    // Current number, if numbering
+    int n = startFrom;
+
+    wxASSERT (!specifyLevel || (specifyLevel && (specifiedLevel >= 0)));
+
+    // If we are associated with a control, make undoable; otherwise, apply immediately
+    // to the data.
+
+    bool haveControl = (GetRichTextCtrl() != NULL);
+
+    wxRichTextAction* action = NULL;
+
+    if (haveControl && withUndo)
+    {
+        action = new wxRichTextAction(NULL, _("Change List Style"), wxRICHTEXT_CHANGE_STYLE, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
+        action->SetRange(range);
+        action->SetPosition(GetRichTextCtrl()->GetCaretPosition());
+    }
+
+    wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+    while (node)
+    {
+        wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+        wxASSERT (para != NULL);
+
+        if (para && para->GetChildCount() > 0)
+        {
+            // Stop searching if we're beyond the range of interest
+            if (para->GetRange().GetStart() > range.GetEnd())
+                break;
+
+            if (!para->GetRange().IsOutside(range))
+            {
+                // We'll be using a copy of the paragraph to make style changes,
+                // not updating the buffer directly.
+                wxRichTextParagraph* newPara wxDUMMY_INITIALIZE(NULL);
+
+                if (haveControl && withUndo)
+                {
+                    newPara = new wxRichTextParagraph(*para);
+                    action->GetNewParagraphs().AppendChild(newPara);
+
+                    // Also store the old ones for Undo
+                    action->GetOldParagraphs().AppendChild(new wxRichTextParagraph(*para));
+                }
+                else
+                    newPara = para;
+
+                if (def)
+                {
+                    int thisIndent = newPara->GetAttributes().GetLeftIndent();
+                    int thisLevel = specifyLevel ? specifiedLevel : def->FindLevelForIndent(thisIndent);
+
+                    // How is numbering going to work?
+                    // If we are renumbering, or numbering for the first time, we need to keep
+                    // track of the number for each level. But we might be simply applying a different
+                    // list style.
+                    // In Word, applying a style to several paragraphs, even if at different levels,
+                    // reverts the level back to the same one. So we could do the same here.
+                    // 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));
+                    wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
+
+                    // Now we need to check numbering
+                    if (renumber)
+                    {
+                        newPara->GetAttributes().SetBulletNumber(n);
+                    }
+
+                    n ++;
+                }
+                else if (!newPara->GetAttributes().GetListStyleName().IsEmpty())
+                {
+                    // if def is NULL, remove list style, applying any associated paragraph style
+                    // to restore the attributes
+
+                    newPara->GetAttributes().SetListStyleName(wxEmptyString);
+                    newPara->GetAttributes().SetLeftIndent(0, 0);
+
+                    // 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_SYMBOL & 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();
+                        }
+                    }
+                }
+            }
+        }
+
+        node = node->GetNext();
+    }
+
+    // Do action, or delay it until end of batch.
+    if (haveControl && withUndo)
+        GetRichTextCtrl()->GetBuffer().SubmitAction(action);
+
+    return true;
+}
+
+bool wxRichTextParagraphLayoutBox::SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel)
+{
+    if (GetStyleSheet())
+    {
+        wxRichTextListStyleDefinition* def = GetStyleSheet()->FindListStyle(defName);
+        if (def)
+            return SetListStyle(range, def, flags, startFrom, specifiedLevel);
+    }
+    return false;
+}
+
+/// Clear list for given range
+bool wxRichTextParagraphLayoutBox::ClearListStyle(const wxRichTextRange& range, int flags)
+{
+    return SetListStyle(range, NULL, flags);
+}
+
+/// Number/renumber any list elements in the given range
+bool wxRichTextParagraphLayoutBox::NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+    return DoNumberList(range, range, 0, def, flags, startFrom, specifiedLevel);
+}
+
+/// Number/renumber any list elements in the given range. Also do promotion or demotion of items, if specified
+bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy,
+                                                wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel)
+{
+    bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0);
+    // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
+    bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0);
+
+    bool renumber = ((flags & wxRICHTEXT_SETSTYLE_RENUMBER) != 0);
+
+    // Max number of levels
+    const int maxLevels = 10;
+
+    // The level we're looking at now
+    int currentLevel = -1;
+
+    // The item number for each level
+    int levels[maxLevels];
+    int i;
+
+    // Reset all numbering
+    for (i = 0; i < maxLevels; i++)
+    {
+        if (startFrom != -1)
+            levels[i] = startFrom;
+        else if (renumber) // start again
+            levels[i] = 1;
+        else
+            levels[i] = -1; // start from the number we found, if any
+    }
+
+    wxASSERT(!specifyLevel || (specifyLevel && (specifiedLevel >= 0)));
+
+    // If we are associated with a control, make undoable; otherwise, apply immediately
+    // to the data.
+
+    bool haveControl = (GetRichTextCtrl() != NULL);
+
+    wxRichTextAction* action = NULL;
+
+    if (haveControl && withUndo)
+    {
+        action = new wxRichTextAction(NULL, _("Renumber List"), wxRICHTEXT_CHANGE_STYLE, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
+        action->SetRange(range);
+        action->SetPosition(GetRichTextCtrl()->GetCaretPosition());
+    }
+
+    wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+    while (node)
+    {
+        wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+        wxASSERT (para != NULL);
+
+        if (para && para->GetChildCount() > 0)
+        {
+            // Stop searching if we're beyond the range of interest
+            if (para->GetRange().GetStart() > range.GetEnd())
+                break;
+
+            if (!para->GetRange().IsOutside(range))
+            {
+                // We'll be using a copy of the paragraph to make style changes,
+                // not updating the buffer directly.
+                wxRichTextParagraph* newPara wxDUMMY_INITIALIZE(NULL);
+
+                if (haveControl && withUndo)
+                {
+                    newPara = new wxRichTextParagraph(*para);
+                    action->GetNewParagraphs().AppendChild(newPara);
+
+                    // Also store the old ones for Undo
+                    action->GetOldParagraphs().AppendChild(new wxRichTextParagraph(*para));
+                }
+                else
+                    newPara = para;
+
+                wxRichTextListStyleDefinition* defToUse = def;
+                if (!defToUse)
+                {
+                    wxRichTextStyleSheet* sheet = GetStyleSheet();
+
+                    if (sheet && !newPara->GetAttributes().GetListStyleName().IsEmpty())
+                        defToUse = sheet->FindListStyle(newPara->GetAttributes().GetListStyleName());
+                }
+
+                if (defToUse)
+                {
+                    int thisIndent = newPara->GetAttributes().GetLeftIndent();
+                    int thisLevel = defToUse->FindLevelForIndent(thisIndent);
+
+                    // If the paragraph doesn't have an indent, or we've specified a level to apply to all,
+                    // change the level.
+                    if (thisIndent == 0 || specifiedLevel != -1)
+                        thisLevel = specifiedLevel;
+
+                    // Do promotion if specified
+                    if ((promoteBy != 0) && !para->GetRange().IsOutside(promotionRange))
+                    {
+                        thisLevel = thisLevel - promoteBy;
+                        if (thisLevel < 0)
+                            thisLevel = 0;
+                        if (thisLevel > 9)
+                            thisLevel = 9;
+                    }
+
+                    // Apply the overall list style, and item style for this level
+                    wxTextAttrEx listStyle(defToUse->GetCombinedStyleForLevel(thisLevel));
+                    wxRichTextApplyStyle(newPara->GetAttributes(), listStyle);
+
+                    // OK, we've (re)applied the style, now let's get the numbering right.
+
+                    if (currentLevel == -1)
+                        currentLevel = thisLevel;
+
+                    // Same level as before, do nothing except increment level's number afterwards
+                    if (currentLevel == thisLevel)
+                    {
+                    }
+                    // A deeper level: start renumbering all levels after current level
+                    else if (thisLevel > currentLevel)
+                    {
+                        for (i = currentLevel+1; i <= thisLevel; i++)
+                        {
+                            levels[i] = 1;
+                        }
+                        currentLevel = thisLevel;
+                    }
+                    else if (thisLevel < currentLevel)
+                    {
+                        currentLevel = thisLevel;
+                    }
+
+                    // Use the current numbering if -1 and we have a bullet number already
+                    if (levels[currentLevel] == -1)
+                    {
+                        if (newPara->GetAttributes().HasBulletNumber())
+                            levels[currentLevel] = newPara->GetAttributes().GetBulletNumber();
+                        else
+                            levels[currentLevel] = 1;
+                    }
+
+                    newPara->GetAttributes().SetBulletNumber(levels[currentLevel]);
+
+                    levels[currentLevel] ++;
+                }
+            }
+        }
+
+        node = node->GetNext();
+    }
+
+    // Do action, or delay it until end of batch.
+    if (haveControl && withUndo)
+        GetRichTextCtrl()->GetBuffer().SubmitAction(action);
+
+    return true;
+}
+
+bool wxRichTextParagraphLayoutBox::NumberList(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel)
+{
+    if (GetStyleSheet())
+    {
+        wxRichTextListStyleDefinition* def = NULL;
+        if (!defName.IsEmpty())
+            def = GetStyleSheet()->FindListStyle(defName);
+        return NumberList(range, def, flags, startFrom, specifiedLevel);
+    }
+    return false;
+}
+
+/// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
+bool wxRichTextParagraphLayoutBox::PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int specifiedLevel)
+{
+    // TODO
+    // One strategy is to first work out the range within which renumbering must occur. Then could pass these two ranges
+    // to NumberList with a flag indicating promotion is required within one of the ranges.
+    // Find first and last paragraphs in range. Then for first, calculate new indentation and look back until we find
+    // a paragraph that either has no list style, or has one that is different or whose indentation is less.
+    // We start renumbering from the para after that different para we found. We specify that the numbering of that
+    // list position will start from 1.
+    // Similarly, we look after the last para in the promote range for an indentation that is less (or no list style).
+    // We can end the renumbering at this point.
+
+    // For now, only renumber within the promotion range.
+
+    return DoNumberList(range, range, promoteBy, def, flags, 1, specifiedLevel);
+}
+
+bool wxRichTextParagraphLayoutBox::PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags, int specifiedLevel)
+{
+    if (GetStyleSheet())
+    {
+        wxRichTextListStyleDefinition* def = NULL;
+        if (!defName.IsEmpty())
+            def = GetStyleSheet()->FindListStyle(defName);
+        return PromoteList(promoteBy, range, def, flags, specifiedLevel);
+    }
+    return false;
+}
+
 /*!
  * wxRichTextParagraph
  * This object represents a single paragraph (or in a straight text editor, a line).
@@ -2481,6 +2901,62 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& WXUNUSED(range),
             {
                 // TODO
             }
+            else if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_STANDARD)                
+            {
+                wxTextAttrEx bulletAttr(GetCombinedAttributes());
+                if (bulletAttr.GetTextColour().Ok())
+                {
+                    dc.SetPen(wxPen(bulletAttr.GetTextColour()));
+                    dc.SetBrush(wxBrush(bulletAttr.GetTextColour()));
+                }
+                else
+                {
+                    dc.SetPen(*wxBLACK_PEN);
+                    dc.SetBrush(*wxBLACK_BRUSH);
+                }
+
+                wxFont font;
+                if (bulletAttr.GetFont().Ok())
+                    font = bulletAttr.GetFont();
+                else
+                    font = (*wxNORMAL_FONT);
+
+                dc.SetFont(font);
+
+                // Get line height from first line, if any
+                wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL;
+
+                wxPoint linePos;
+                int lineHeight wxDUMMY_INITIALIZE(0);
+                if (line)
+                {
+                    lineHeight = line->GetSize().y;
+                    linePos = line->GetPosition() + GetPosition();
+                }
+                else
+                {
+                    lineHeight = dc.GetCharHeight();
+                    linePos = GetPosition();
+                    linePos.y += spaceBeforePara;
+                }
+
+                int charHeight = dc.GetCharHeight();
+                
+                int bulletWidth = wxMax(2, (charHeight/3 + 1));
+                int bulletHeight = bulletWidth;
+
+                int x = GetPosition().x + leftIndent;
+                int y = linePos.y + (lineHeight - charHeight/2) - bulletHeight/2;
+                
+                if (bulletAttr.GetBulletName() == wxT("standard/square"))
+                {
+                    dc.DrawRectangle(x, y, bulletWidth, bulletHeight);
+                }
+                else // "standard/round", and catch-all
+                {
+                    dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
+                }                
+            }
             else
             {
                 wxString bulletText = GetBulletText();
@@ -3627,12 +4103,12 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
                 // Compensate for kerning difference
                 wxString stringFragment2(m_text.Mid(r1 - offset, fragmentLen+1));
                 wxString stringFragment3(m_text.Mid(r1 - offset + fragmentLen, 1));
-                
+
                 wxCoord w1, h1, w2, h2, w3, h3;
                 dc.GetTextExtent(stringFragment,  & w1, & h1);
                 dc.GetTextExtent(stringFragment2, & w2, & h2);
                 dc.GetTextExtent(stringFragment3, & w3, & h3);
-                
+
                 int kerningDiff = (w1 + w3) - w2;
                 x = x - kerningDiff;
             }
@@ -3658,12 +4134,12 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
                 // Compensate for kerning difference
                 wxString stringFragment2(m_text.Mid(s1 - offset, fragmentLen+1));
                 wxString stringFragment3(m_text.Mid(s1 - offset + fragmentLen, 1));
-                
+
                 wxCoord w1, h1, w2, h2, w3, h3;
                 dc.GetTextExtent(stringFragment,  & w1, & h1);
                 dc.GetTextExtent(stringFragment2, & w2, & h2);
                 dc.GetTextExtent(stringFragment3, & w3, & h3);
-                
+
                 int kerningDiff = (w1 + w3) - w2;
                 x = x - kerningDiff;
             }
@@ -3840,14 +4316,14 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
             tabArray = textAttr.GetTabs();
 
         int tabCount = tabArray.GetCount();
-        
+
         for (int i = 0; i < tabCount; ++i)
         {
             int pos = tabArray[i];
             pos = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, pos);
             tabArray[i] = pos;
         }
-        
+
         int nextTabPos = -1;
 
         while (stringChunk.Find(wxT('\t')) >= 0)
@@ -4027,6 +4503,32 @@ void wxRichTextBuffer::Copy(const wxRichTextBuffer& obj)
     m_suppressUndo = obj.m_suppressUndo;
 }
 
+/// Push style sheet to top of stack
+bool wxRichTextBuffer::PushStyleSheet(wxRichTextStyleSheet* styleSheet)
+{
+    if (m_styleSheet)
+        styleSheet->InsertSheet(m_styleSheet);
+
+    SetStyleSheet(styleSheet);
+
+    return true;
+}
+
+/// Pop style sheet from top of stack
+wxRichTextStyleSheet* wxRichTextBuffer::PopStyleSheet()
+{
+    if (m_styleSheet)
+    {
+        wxRichTextStyleSheet* oldSheet = m_styleSheet;
+        m_styleSheet = oldSheet->GetNextSheet();
+        oldSheet->Unlink();
+
+        return oldSheet;
+    }
+    else
+        return NULL;
+}
+
 /// Submit command to insert paragraphs
 bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags)
 {
@@ -4514,7 +5016,7 @@ bool wxRichTextBuffer::BeginLineSpacing(int lineSpacing)
 bool wxRichTextBuffer::BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle)
 {
     wxTextAttrEx attr;
-    attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_LEFT_INDENT);
+    attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
     attr.SetBulletStyle(bulletStyle);
     attr.SetBulletNumber(bulletNumber);
     attr.SetLeftIndent(leftIndent, leftSubIndent);
@@ -4526,7 +5028,7 @@ bool wxRichTextBuffer::BeginNumberedBullet(int bulletNumber, int leftIndent, int
 bool wxRichTextBuffer::BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle)
 {
     wxTextAttrEx attr;
-    attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_LEFT_INDENT);
+    attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
     attr.SetBulletStyle(bulletStyle);
     attr.SetLeftIndent(leftIndent, leftSubIndent);
     attr.SetBulletSymbol(symbol);
@@ -4534,6 +5036,18 @@ bool wxRichTextBuffer::BeginSymbolBullet(wxChar symbol, int leftIndent, int left
     return BeginStyle(attr);
 }
 
+/// Begin standard bullet
+bool wxRichTextBuffer::BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle)
+{
+    wxTextAttrEx attr;
+    attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
+    attr.SetBulletStyle(bulletStyle);
+    attr.SetLeftIndent(leftIndent, leftSubIndent);
+    attr.SetBulletName(bulletName);
+
+    return BeginStyle(attr);
+}
+
 /// Begin named character style
 bool wxRichTextBuffer::BeginCharacterStyle(const wxString& characterStyle)
 {
@@ -4566,6 +5080,24 @@ bool wxRichTextBuffer::BeginParagraphStyle(const wxString& paragraphStyle)
     return false;
 }
 
+/// Begin named list style
+bool wxRichTextBuffer::BeginListStyle(const wxString& listStyle, int level, int number)
+{
+    if (GetStyleSheet())
+    {
+        wxRichTextListStyleDefinition* def = GetStyleSheet()->FindListStyle(listStyle);
+        if (def)
+        {
+            wxTextAttrEx attr(def->GetCombinedStyleForLevel(level));
+
+            attr.SetBulletNumber(number);
+
+            return BeginStyle(attr);
+        }
+    }
+    return false;
+}
+
 /// Adds a handler to the end
 void wxRichTextBuffer::AddHandler(wxRichTextFileHandler *handler)
 {
@@ -4717,6 +5249,8 @@ wxString wxRichTextBuffer::GetExtWildcard(bool combine, bool save, wxArrayInt* t
 
 /// Load a file
 bool wxRichTextBuffer::LoadFile(const wxString& filename, int type)
+
+
 {
     wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type);
     if (handler)
@@ -4928,12 +5462,24 @@ public:
         wxRichTextBuffer::CleanUpHandlers();
         wxRichTextDecimalToRoman(-1);
         wxRichTextParagraph::ClearDefaultTabs();
+        wxRichTextCtrl::ClearAvailableFontNames();
     };
 };
 
 IMPLEMENT_DYNAMIC_CLASS(wxRichTextModule, wxModule)
 
 
+// If the richtext lib is dynamically loaded after the app has already started
+// (such as from wxPython) then the built-in module system will not init this
+// module.  Provide this function to do it manually.
+void wxRichTextModuleInit()
+{
+    wxModule* module = new wxRichTextModule;
+    module->Init();
+    wxModule::RegisterModule(module);
+}
+
+
 /*!
  * Commands for undo/redo
  *
@@ -5293,24 +5839,7 @@ void wxRichTextImage::Copy(const wxRichTextImage& obj)
 /// Compare two attribute objects
 bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2)
 {
-    return (
-        attr1.GetTextColour() == attr2.GetTextColour() &&
-        attr1.GetBackgroundColour() == attr2.GetBackgroundColour() &&
-        attr1.GetFont() == attr2.GetFont() &&
-        attr1.GetAlignment() == attr2.GetAlignment() &&
-        attr1.GetLeftIndent() == attr2.GetLeftIndent() &&
-        attr1.GetRightIndent() == attr2.GetRightIndent() &&
-        attr1.GetLeftSubIndent() == attr2.GetLeftSubIndent() &&
-        wxRichTextTabsEq(attr1.GetTabs(), attr2.GetTabs()) &&
-        attr1.GetLineSpacing() == attr2.GetLineSpacing() &&
-        attr1.GetParagraphSpacingAfter() == attr2.GetParagraphSpacingAfter() &&
-        attr1.GetParagraphSpacingBefore() == attr2.GetParagraphSpacingBefore() &&
-        attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
-        attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
-        attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
-        attr1.GetBulletFont() == attr2.GetBulletFont() &&
-        attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
-        attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
+    return (attr1 == attr2);
 }
 
 bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2)
@@ -5334,9 +5863,11 @@ bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2)
         attr1.GetBulletStyle() == attr2.GetBulletStyle() &&
         attr1.GetBulletNumber() == attr2.GetBulletNumber() &&
         attr1.GetBulletSymbol() == attr2.GetBulletSymbol() &&
+        attr1.GetBulletName() == attr2.GetBulletName() &&
         attr1.GetBulletFont() == attr2.GetBulletFont() &&
         attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() &&
-        attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName());
+        attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName() &&
+        attr1.GetListStyleName() == attr2.GetListStyleName());
 }
 
 /// Compare two attribute objects, but take into account the flags
@@ -5400,6 +5931,10 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, i
         (attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
         return false;
 
+    if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) &&
+        (attr1.GetListStyleName() != attr2.GetListStyleName()))
+        return false;
+
     if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
         (attr1.GetBulletStyle() != attr2.GetBulletStyle()))
          return false;
@@ -5409,11 +5944,12 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, i
          return false;
 
     if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
-        (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
+        (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()) &&
+        (attr1.GetBulletFont() != attr2.GetBulletFont()))
          return false;
 
-    if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
-        (attr1.GetBulletFont() != attr2.GetBulletFont()))
+    if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
+        (attr1.GetBulletName() != attr2.GetBulletName()))
          return false;
 
     if ((flags & wxTEXT_ATTR_TABS) &&
@@ -5485,6 +6021,10 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2,
         (attr1.GetParagraphStyleName() != attr2.GetParagraphStyleName()))
         return false;
 
+    if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) &&
+        (attr1.GetListStyleName() != attr2.GetListStyleName()))
+        return false;
+
     if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
         (attr1.GetBulletStyle() != attr2.GetBulletStyle()))
          return false;
@@ -5494,11 +6034,12 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2,
          return false;
 
     if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
-        (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()))
+        (attr1.GetBulletSymbol() != attr2.GetBulletSymbol()) &&
+        (attr1.GetBulletFont() != attr2.GetBulletFont()))
          return false;
 
-    if ((flags & wxTEXT_ATTR_BULLET_SYMBOL) &&
-        (attr1.GetBulletFont() != attr2.GetBulletFont()))
+    if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
+        (attr1.GetBulletName() != attr2.GetBulletName()))
          return false;
 
     if ((flags & wxTEXT_ATTR_TABS) &&
@@ -5607,13 +6148,21 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style)
     if (style.HasParagraphStyleName())
         destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
 
+    if (style.HasListStyleName())
+        destStyle.SetListStyleName(style.GetListStyleName());
+
     if (style.HasBulletStyle())
-    {
         destStyle.SetBulletStyle(style.GetBulletStyle());
+
+    if (style.HasBulletSymbol())
+    {
         destStyle.SetBulletSymbol(style.GetBulletSymbol());
         destStyle.SetBulletFont(style.GetBulletFont());
     }
 
+    if (style.HasBulletName())
+        destStyle.SetBulletName(style.GetBulletName());
+
     if (style.HasBulletNumber())
         destStyle.SetBulletNumber(style.GetBulletNumber());
 
@@ -5784,6 +6333,12 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
             destStyle.SetParagraphStyleName(style.GetParagraphStyleName());
     }
 
+    if (style.HasListStyleName())
+    {
+        if (!(compareWith && compareWith->HasListStyleName() && compareWith->GetListStyleName() == style.GetListStyleName()))
+            destStyle.SetListStyleName(style.GetListStyleName());
+    }
+
     if (style.HasBulletStyle())
     {
         if (!(compareWith && compareWith->HasBulletStyle() && compareWith->GetBulletStyle() == style.GetBulletStyle()))
@@ -5805,6 +6360,12 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style,
             destStyle.SetBulletNumber(style.GetBulletNumber());
     }
 
+    if (style.HasBulletName())
+    {
+        if (!(compareWith && compareWith->HasBulletName() && compareWith->GetBulletName() == style.GetBulletName()))
+            destStyle.SetBulletName(style.GetBulletName());
+    }
+
     return true;
 }
 
@@ -5939,10 +6500,12 @@ void wxRichTextAttr::operator= (const wxRichTextAttr& attr)
     m_lineSpacing = attr.m_lineSpacing;
     m_characterStyleName = attr.m_characterStyleName;
     m_paragraphStyleName = attr.m_paragraphStyleName;
+    m_listStyleName = attr.m_listStyleName;
     m_bulletStyle = attr.m_bulletStyle;
     m_bulletNumber = attr.m_bulletNumber;
     m_bulletSymbol = attr.m_bulletSymbol;
     m_bulletFont = attr.m_bulletFont;
+    m_bulletName = attr.m_bulletName;
 }
 
 // operators
@@ -5962,9 +6525,11 @@ void wxRichTextAttr::operator= (const wxTextAttrEx& attr)
     m_lineSpacing = attr.GetLineSpacing();
     m_characterStyleName = attr.GetCharacterStyleName();
     m_paragraphStyleName = attr.GetParagraphStyleName();
+    m_listStyleName = attr.GetListStyleName();
     m_bulletStyle = attr.GetBulletStyle();
     m_bulletNumber = attr.GetBulletNumber();
     m_bulletSymbol = attr.GetBulletSymbol();
+    m_bulletName = attr.GetBulletName();
     m_bulletFont = attr.GetBulletFont();
 
     if (attr.GetFont().Ok())
@@ -5998,11 +6563,13 @@ bool wxRichTextAttr::operator== (const wxRichTextAttr& attr) const
             GetLineSpacing() == attr.GetLineSpacing() &&
             GetCharacterStyleName() == attr.GetCharacterStyleName() &&
             GetParagraphStyleName() == attr.GetParagraphStyleName() &&
+            GetListStyleName() == attr.GetListStyleName() &&
 
             GetBulletStyle() == attr.GetBulletStyle() &&
             GetBulletSymbol() == attr.GetBulletSymbol() &&
             GetBulletNumber() == attr.GetBulletNumber() &&
             GetBulletFont() == attr.GetBulletFont() &&
+            GetBulletName() == attr.GetBulletName() &&
 
             m_fontSize == attr.m_fontSize &&
             m_fontStyle == attr.m_fontStyle &&
@@ -6028,9 +6595,11 @@ void wxRichTextAttr::CopyTo(wxTextAttrEx& attr) const
     attr.SetBulletStyle(m_bulletStyle);
     attr.SetBulletNumber(m_bulletNumber);
     attr.SetBulletSymbol(m_bulletSymbol);
+    attr.SetBulletName(m_bulletName);
     attr.SetBulletFont(m_bulletFont);
     attr.SetCharacterStyleName(m_characterStyleName);
     attr.SetParagraphStyleName(m_paragraphStyleName);
+    attr.SetListStyleName(m_listStyleName);
 
     attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags
 }
@@ -6136,12 +6705,18 @@ wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr,
     if (attr.HasParagraphStyleName())
         newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
 
+    if (attr.HasListStyleName())
+        newAttr.SetListStyleName(attr.GetListStyleName());
+
     if (attr.HasBulletStyle())
         newAttr.SetBulletStyle(attr.GetBulletStyle());
 
     if (attr.HasBulletNumber())
         newAttr.SetBulletNumber(attr.GetBulletNumber());
 
+    if (attr.HasBulletName())
+        newAttr.SetBulletName(attr.GetBulletName());
+
     if (attr.HasBulletSymbol())
     {
         newAttr.SetBulletSymbol(attr.GetBulletSymbol());
@@ -6162,9 +6737,11 @@ wxTextAttrEx::wxTextAttrEx(const wxTextAttrEx& attr): wxTextAttr(attr)
     m_lineSpacing = attr.m_lineSpacing;
     m_paragraphStyleName = attr.m_paragraphStyleName;
     m_characterStyleName = attr.m_characterStyleName;
+    m_listStyleName = attr.m_listStyleName;
     m_bulletStyle = attr.m_bulletStyle;
     m_bulletNumber = attr.m_bulletNumber;
     m_bulletSymbol = attr.m_bulletSymbol;
+    m_bulletName = attr.m_bulletName;
     m_bulletFont = attr.m_bulletFont;
 }
 
@@ -6176,7 +6753,6 @@ void wxTextAttrEx::Init()
     m_lineSpacing = 0;
     m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE;
     m_bulletNumber = 0;
-    m_bulletSymbol = 0;
     m_bulletSymbol = wxT('*');
 }
 
@@ -6190,10 +6766,12 @@ void wxTextAttrEx::operator= (const wxTextAttrEx& attr)
     m_lineSpacing = attr.m_lineSpacing;
     m_characterStyleName = attr.m_characterStyleName;
     m_paragraphStyleName = attr.m_paragraphStyleName;
+    m_listStyleName = attr.m_listStyleName;
     m_bulletStyle = attr.m_bulletStyle;
     m_bulletNumber = attr.m_bulletNumber;
     m_bulletSymbol = attr.m_bulletSymbol;
     m_bulletFont = attr.m_bulletFont;
+    m_bulletName = attr.m_bulletName;
 }
 
 // Assignment from a wxTextAttr object.
@@ -6202,6 +6780,31 @@ void wxTextAttrEx::operator= (const wxTextAttr& attr)
     wxTextAttr::operator= (attr);
 }
 
+// Equality test
+bool wxTextAttrEx::operator== (const wxTextAttrEx& attr) const
+{
+    return (
+        GetTextColour() == attr.GetTextColour() &&
+        GetBackgroundColour() == attr.GetBackgroundColour() &&
+        GetFont() == attr.GetFont() &&
+        GetAlignment() == attr.GetAlignment() &&
+        GetLeftIndent() == attr.GetLeftIndent() &&
+        GetRightIndent() == attr.GetRightIndent() &&
+        GetLeftSubIndent() == attr.GetLeftSubIndent() &&
+        wxRichTextTabsEq(GetTabs(), attr.GetTabs()) &&
+        GetLineSpacing() == attr.GetLineSpacing() &&
+        GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter() &&
+        GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore() &&
+        GetBulletStyle() == attr.GetBulletStyle() &&
+        GetBulletNumber() == attr.GetBulletNumber() &&
+        GetBulletSymbol() == attr.GetBulletSymbol() &&
+        GetBulletName() == attr.GetBulletName() &&
+        GetBulletFont() == attr.GetBulletFont() &&
+        GetCharacterStyleName() == attr.GetCharacterStyleName() &&
+        GetParagraphStyleName() == attr.GetParagraphStyleName() &&
+        GetListStyleName() == attr.GetListStyleName());
+}
+
 wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
                                const wxTextAttrEx& attrDef,
                                const wxTextCtrlBase *text)
@@ -6329,12 +6932,18 @@ wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr,
     if (attr.HasParagraphStyleName())
         newAttr.SetParagraphStyleName(attr.GetParagraphStyleName());
 
+    if (attr.HasListStyleName())
+        newAttr.SetListStyleName(attr.GetListStyleName());
+
     if (attr.HasBulletStyle())
         newAttr.SetBulletStyle(attr.GetBulletStyle());
 
     if (attr.HasBulletNumber())
         newAttr.SetBulletNumber(attr.GetBulletNumber());
 
+    if (attr.HasBulletName())
+        newAttr.SetBulletName(attr.GetBulletName());
+
     if (attr.HasBulletSymbol())
     {
         newAttr.SetBulletSymbol(attr.GetBulletSymbol());
@@ -6818,4 +7427,3 @@ bool wxRichTextBufferDataObject::SetData(size_t WXUNUSED(len), const void *buf)
 
 #endif
     // wxUSE_RICHTEXT
-