]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextstyles.cpp
added wxCSConv::IsOk() (patch 1637944)
[wxWidgets.git] / src / richtext / richtextstyles.cpp
index 37ac00b4fc48d998077be821661bf87bf67647b1..da627387e28dcad805ca919f14a78db84ccb9f3f 100644 (file)
@@ -401,7 +401,7 @@ bool wxRichTextStyleSheet::AddStyle(wxRichTextStyleDefinition* def)
     wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
     if (charDef)
         return AddCharacterStyle(charDef);
-    
+
     return false;
 }
 
@@ -419,8 +419,8 @@ wxRichTextStyleDefinition* wxRichTextStyleSheet::FindStyle(const wxString& name,
     wxRichTextCharacterStyleDefinition* charDef = FindCharacterStyle(name, recurse);
     if (charDef)
         return charDef;
-    
-    return NULL;    
+
+    return NULL;
 }
 
 /// Copy
@@ -447,7 +447,7 @@ void wxRichTextStyleSheet::Copy(const wxRichTextStyleSheet& sheet)
         wxRichTextListStyleDefinition* def = (wxRichTextListStyleDefinition*) node->GetData();
         AddListStyle(new wxRichTextListStyleDefinition(*def));
     }
-    
+
     SetName(sheet.GetName());
     SetDescription(sheet.GetDescription());
 }
@@ -509,32 +509,10 @@ wxRichTextStyleDefinition* wxRichTextStyleListBox::GetStyle(size_t i) const
     if (!GetStyleSheet())
         return NULL;
 
-    if (GetStyleType() == wxRICHTEXT_STYLE_ALL)
-    {
-        // First paragraph styles, then character, then list
-        if (i < GetStyleSheet()->GetParagraphStyleCount())
-            return GetStyleSheet()->GetParagraphStyle(i);
-
-        if ((i - GetStyleSheet()->GetParagraphStyleCount()) < GetStyleSheet()->GetCharacterStyleCount())
-            return GetStyleSheet()->GetCharacterStyle(i - GetStyleSheet()->GetParagraphStyleCount());
-
-        if ((i - GetStyleSheet()->GetParagraphStyleCount() - GetStyleSheet()->GetCharacterStyleCount()) < GetStyleSheet()->GetListStyleCount())
-            return GetStyleSheet()->GetListStyle(i - GetStyleSheet()->GetParagraphStyleCount() - GetStyleSheet()->GetCharacterStyleCount());
-    }
-    else if ((GetStyleType() == wxRICHTEXT_STYLE_PARAGRAPH) && (i < GetStyleSheet()->GetParagraphStyleCount()))
-    {
-        return GetStyleSheet()->GetParagraphStyle(i);
-    }
-    else if ((GetStyleType() == wxRICHTEXT_STYLE_CHARACTER) && (i < GetStyleSheet()->GetCharacterStyleCount()))
-    {
-        return GetStyleSheet()->GetCharacterStyle(i);
-    }
-    else if ((GetStyleType() == wxRICHTEXT_STYLE_LIST) && (i < GetStyleSheet()->GetListStyleCount()))
-    {
-        return GetStyleSheet()->GetListStyle(i);
-    }
+    if (i >= m_styleNames.GetCount() /* || i < 0 */ )
+        return NULL;
 
-    return NULL;
+    return GetStyleSheet()->FindStyle(m_styleNames[i]);
 }
 
 /// Updates the list
@@ -544,14 +522,27 @@ void wxRichTextStyleListBox::UpdateStyles()
     {
         SetSelection(wxNOT_FOUND);
 
-        if (GetStyleType() == wxRICHTEXT_STYLE_ALL)
-            SetItemCount(GetStyleSheet()->GetParagraphStyleCount()+GetStyleSheet()->GetCharacterStyleCount()+GetStyleSheet()->GetListStyleCount());
-        else if (GetStyleType() == wxRICHTEXT_STYLE_PARAGRAPH)
-            SetItemCount(GetStyleSheet()->GetParagraphStyleCount());
-        else if (GetStyleType() == wxRICHTEXT_STYLE_CHARACTER)
-            SetItemCount(GetStyleSheet()->GetCharacterStyleCount());
-        else if (GetStyleType() == wxRICHTEXT_STYLE_LIST)
-            SetItemCount(GetStyleSheet()->GetListStyleCount());
+        m_styleNames.Clear();
+
+        size_t i;
+        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_PARAGRAPH)
+        {
+            for (i = 0; i < GetStyleSheet()->GetParagraphStyleCount(); i++)
+                m_styleNames.Add(GetStyleSheet()->GetParagraphStyle(i)->GetName());
+        }
+        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_CHARACTER)
+        {
+            for (i = 0; i < GetStyleSheet()->GetCharacterStyleCount(); i++)
+                m_styleNames.Add(GetStyleSheet()->GetCharacterStyle(i)->GetName());
+        }
+        if (GetStyleType() == wxRICHTEXT_STYLE_ALL || GetStyleType() == wxRICHTEXT_STYLE_LIST)
+        {
+            for (i = 0; i < GetStyleSheet()->GetListStyleCount(); i++)
+                m_styleNames.Add(GetStyleSheet()->GetListStyle(i)->GetName());
+        }
+
+        m_styleNames.Sort();
+        SetItemCount(m_styleNames.GetCount());
 
         Refresh();
 
@@ -566,19 +557,7 @@ void wxRichTextStyleListBox::UpdateStyles()
 // Get index for style name
 int wxRichTextStyleListBox::GetIndexForStyle(const wxString& name) const
 {
-    if (GetStyleSheet())
-    {
-        int count = GetItemCount();
-
-        int i;
-        for (i = 0; i < (int) count; i++)
-        {
-            wxRichTextStyleDefinition* def = GetStyle(i);
-            if (def->GetName() == name)
-                return i;
-        }
-    }
-    return -1;
+    return m_styleNames.Index(name);
 }
 
 /// Set selection for string
@@ -610,7 +589,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
     wxString str;
 
     bool isCentred = false;
-    
+
     wxRichTextAttr attr(def->GetStyleMergedWithBase(GetStyleSheet()));
 
     if (attr.HasAlignment() && attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
@@ -619,7 +598,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
     if (isCentred)
         str << wxT("<center>");
 
-    
+
     str << wxT("<table><tr>");
 
     if (attr.GetLeftIndent() > 0)
@@ -743,15 +722,20 @@ wxString wxRichTextStyleListBox::GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl,
     // Take into account current default style just chosen by user
     if (ctrl->IsDefaultStyleShowing())
     {
+        wxTextAttrEx attr;
+
+        ctrl->GetStyle(adjustedCaretPos, attr);
+        wxRichTextApplyStyle(attr, ctrl->GetDefaultStyleEx());
+
         if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
-                          !ctrl->GetDefaultStyleEx().GetCharacterStyleName().IsEmpty())
-            styleName = ctrl->GetDefaultStyleEx().GetCharacterStyleName();
+                          !attr.GetCharacterStyleName().IsEmpty())
+            styleName = attr.GetCharacterStyleName();
         else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_PARAGRAPH) &&
-                          !ctrl->GetDefaultStyleEx().GetParagraphStyleName().IsEmpty())
-            styleName = ctrl->GetDefaultStyleEx().GetParagraphStyleName();
+                          !attr.GetParagraphStyleName().IsEmpty())
+            styleName = attr.GetParagraphStyleName();
         else if ((styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_LIST) &&
-                          !ctrl->GetDefaultStyleEx().GetListStyleName().IsEmpty())
-            styleName = ctrl->GetDefaultStyleEx().GetListStyleName();
+                          !attr.GetListStyleName().IsEmpty())
+            styleName = attr.GetListStyleName();
     }
     else if (obj && (styleType == wxRICHTEXT_STYLE_ALL || styleType == wxRICHTEXT_STYLE_CHARACTER) &&
              !obj->GetAttributes().GetCharacterStyleName().IsEmpty())