X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6eff83b827f998748777bb3f76db789fe099d6c1..9bc95da04ca5541783c9aead91769fcde0651d97:/src/richtext/richtextstyles.cpp diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp index 731634e492..6e47ba618e 100644 --- a/src/richtext/richtextstyles.cpp +++ b/src/richtext/richtextstyles.cpp @@ -56,17 +56,35 @@ bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const /// Gets the style combined with the base style wxTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const { - if (!m_baseStyle.IsEmpty()) + if (m_baseStyle.IsEmpty()) + return m_style; + + // Collect the styles, detecting loops + wxArrayString styleNames; + wxList styles; + const wxRichTextStyleDefinition* def = this; + while (def) { - wxRichTextStyleDefinition* baseStyle = sheet->FindStyle(m_baseStyle); - if (baseStyle) - { - wxTextAttr baseAttr = baseStyle->GetStyleMergedWithBase(sheet); - baseAttr.Apply(m_style, NULL); - return baseAttr; - } + styles.Insert((wxObject*) def); + styleNames.Add(def->GetName()); + + wxString baseStyleName = def->GetBaseStyle(); + if (!baseStyleName.IsEmpty() && styleNames.Index(baseStyleName) == wxNOT_FOUND) + def = sheet->FindStyle(baseStyleName); + else + def = NULL; + } + + wxRichTextAttr attr; + wxList::compatibility_iterator node = styles.GetFirst(); + while (node) + { + wxRichTextStyleDefinition* def = (wxRichTextStyleDefinition*) node->GetData(); + attr.Apply(def->GetStyle(), NULL); + node = node->GetNext(); } - return m_style; + + return attr; } /*! @@ -520,6 +538,8 @@ void wxRichTextStyleListBox::UpdateStyles() { if (GetStyleSheet()) { + int oldSel = GetSelection(); + SetSelection(wxNOT_FOUND); m_styleNames.Clear(); @@ -546,9 +566,15 @@ void wxRichTextStyleListBox::UpdateStyles() Refresh(); - if (GetItemCount() > 0) + int newSel = -1; + if (oldSel >= 0 && oldSel < (int) GetItemCount()) + newSel = oldSel; + else if (GetItemCount() > 0) + newSel = 0; + + if (newSel >= 0) { - SetSelection(0); + SetSelection(newSel); SendSelectedEvent(); } } @@ -940,6 +966,7 @@ void wxRichTextStyleListCtrl::OnChooseType(wxCommandEvent& event) return; wxRichTextStyleListBox::wxRichTextStyleType styleType = StyleIndexToType(event.GetSelection()); + m_styleListBox->SetSelection(-1); m_styleListBox->SetStyleType(styleType); } }