GetStyleMergedWithBase no longer hangs if there's a loop implied by based-on styles.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64519 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2010-06-07 07:39:31 +00:00
parent 701aa4d804
commit 519884a03d

View File

@@ -56,17 +56,35 @@ bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const
/// Gets the style combined with the base style /// Gets the style combined with the base style
wxTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const 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); styles.Insert((wxObject*) def);
if (baseStyle) styleNames.Add(def->GetName());
{
wxTextAttr baseAttr = baseStyle->GetStyleMergedWithBase(sheet); wxString baseStyleName = def->GetBaseStyle();
baseAttr.Apply(m_style, NULL); if (!baseStyleName.IsEmpty() && styleNames.Index(baseStyleName) == wxNOT_FOUND)
return baseAttr; def = sheet->FindStyle(baseStyleName);
} else
def = NULL;
} }
return m_style;
wxRichTextAttr attr;
wxList::compatibility_iterator node = styles.GetFirst();
while (node)
{
wxRichTextStyleDefinition* def = (wxRichTextStyleDefinition*) node->GetData();
attr.Apply(def->GetStyle(), NULL);
node = node->GetNext();
}
return attr;
} }
/*! /*!