+IMPLEMENT_CLASS(wxRichTextListStyleDefinition, wxRichTextParagraphStyleDefinition)
+IMPLEMENT_CLASS(wxRichTextBoxStyleDefinition, wxRichTextStyleDefinition)
+
+/*!
+ * A definition
+ */
+
+void wxRichTextStyleDefinition::Copy(const wxRichTextStyleDefinition& def)
+{
+ m_name = def.m_name;
+ m_baseStyle = def.m_baseStyle;
+ m_style = def.m_style;
+ m_description = def.m_description;
+ m_properties = def.m_properties;
+}
+
+bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const
+{
+ return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style && m_properties == def.m_properties);
+}
+
+/// Gets the style combined with the base style
+wxRichTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const
+{
+ if (m_baseStyle.IsEmpty())
+ return m_style;
+
+ bool isParaStyle = IsKindOf(wxCLASSINFO(wxRichTextParagraphStyleDefinition));
+ bool isCharStyle = IsKindOf(wxCLASSINFO(wxRichTextCharacterStyleDefinition));
+ bool isListStyle = IsKindOf(wxCLASSINFO(wxRichTextListStyleDefinition));
+ bool isBoxStyle = IsKindOf(wxCLASSINFO(wxRichTextBoxStyleDefinition));
+
+ // Collect the styles, detecting loops
+ wxArrayString styleNames;
+ wxList styles;
+ const wxRichTextStyleDefinition* def = this;
+ while (def)
+ {
+ styles.Insert((wxObject*) def);
+ styleNames.Add(def->GetName());
+
+ wxString baseStyleName = def->GetBaseStyle();
+ if (!baseStyleName.IsEmpty() && styleNames.Index(baseStyleName) == wxNOT_FOUND)
+ {
+ if (isParaStyle)
+ def = sheet->FindParagraphStyle(baseStyleName);
+ else if (isCharStyle)
+ def = sheet->FindCharacterStyle(baseStyleName);
+ else if (isListStyle)
+ def = sheet->FindListStyle(baseStyleName);
+ else if (isBoxStyle)
+ def = sheet->FindBoxStyle(baseStyleName);
+ else
+ 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 attr;
+}
+
+/*!
+ * Paragraph style definition
+ */
+
+void wxRichTextParagraphStyleDefinition::Copy(const wxRichTextParagraphStyleDefinition& def)
+{
+ wxRichTextStyleDefinition::Copy(def);
+
+ m_nextStyle = def.m_nextStyle;
+}
+
+bool wxRichTextParagraphStyleDefinition::operator ==(const wxRichTextParagraphStyleDefinition& def) const
+{
+ return (Eq(def) && m_nextStyle == def.m_nextStyle);
+}
+
+/*!
+ * Box style definition
+ */
+
+void wxRichTextBoxStyleDefinition::Copy(const wxRichTextBoxStyleDefinition& def)
+{
+ wxRichTextStyleDefinition::Copy(def);
+}
+
+bool wxRichTextBoxStyleDefinition::operator ==(const wxRichTextBoxStyleDefinition& def) const
+{
+ return (Eq(def));
+}
+
+/*!
+ * List style definition
+ */
+
+void wxRichTextListStyleDefinition::Copy(const wxRichTextListStyleDefinition& def)
+{
+ wxRichTextParagraphStyleDefinition::Copy(def);
+
+ int i;
+ for (i = 0; i < 10; i++)
+ m_levelStyles[i] = def.m_levelStyles[i];
+}
+
+bool wxRichTextListStyleDefinition::operator ==(const wxRichTextListStyleDefinition& def) const
+{
+ if (!Eq(def))
+ return false;
+ int i;
+ for (i = 0; i < 10; i++)
+ if (!(m_levelStyles[i] == def.m_levelStyles[i]))
+ return false;
+
+ return true;
+}
+
+/// Sets/gets the attributes for the given level
+void wxRichTextListStyleDefinition::SetLevelAttributes(int i, const wxRichTextAttr& attr)
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ m_levelStyles[i] = attr;
+}
+
+const wxRichTextAttr* wxRichTextListStyleDefinition::GetLevelAttributes(int i) const
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ return & m_levelStyles[i];
+ else
+ return NULL;
+}
+
+wxRichTextAttr* wxRichTextListStyleDefinition::GetLevelAttributes(int i)
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ return & m_levelStyles[i];
+ else
+ return NULL;
+}
+
+/// Convenience function for setting the major attributes for a list level specification
+void wxRichTextListStyleDefinition::SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol)
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ {
+ wxRichTextAttr attr;
+
+ attr.SetBulletStyle(bulletStyle);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+
+ if (!bulletSymbol.IsEmpty())
+ {
+ if (bulletStyle & wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
+ attr.SetBulletText(bulletSymbol);
+ else
+ attr.SetBulletName(bulletSymbol);
+ }
+
+ m_levelStyles[i] = attr;
+ }
+}
+
+/// Finds the level corresponding to the given indentation
+int wxRichTextListStyleDefinition::FindLevelForIndent(int indent) const
+{
+ int i;
+ for (i = 0; i < 10; i++)
+ {
+ if (indent < m_levelStyles[i].GetLeftIndent())
+ {
+ if (i > 0)
+ return i - 1;
+ else
+ return 0;
+ }
+ }
+ return 9;
+}
+
+/// 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, wxRichTextStyleSheet* styleSheet)
+{
+ int listLevel = FindLevelForIndent(indent);
+
+ wxRichTextAttr attr(*GetLevelAttributes(listLevel));
+ int oldLeftIndent = attr.GetLeftIndent();
+ int oldLeftSubIndent = attr.GetLeftSubIndent();
+
+ // First apply the overall paragraph style, if any
+ if (styleSheet)
+ attr.Apply(GetStyleMergedWithBase(styleSheet));
+ else
+ attr.Apply(GetStyle());
+
+ // Then apply paragraph style, e.g. from paragraph style definition
+ attr.Apply(paraStyle);
+
+ // We override the indents according to the list definition
+ attr.SetLeftIndent(oldLeftIndent, oldLeftSubIndent);
+
+ return attr;
+}
+
+/// Combine the base and list style, using the given indent (from which
+/// an appropriate level is found)
+wxRichTextAttr wxRichTextListStyleDefinition::GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet)
+{
+ int listLevel = FindLevelForIndent(indent);
+ 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, wxRichTextStyleSheet* styleSheet)
+{
+ wxRichTextAttr attr(*GetLevelAttributes(listLevel));
+ int oldLeftIndent = attr.GetLeftIndent();
+ int oldLeftSubIndent = attr.GetLeftSubIndent();
+
+ // Apply the overall paragraph style, if any
+ if (styleSheet)
+ attr.Apply(GetStyleMergedWithBase(styleSheet));
+ else
+ attr.Apply(GetStyle());
+
+ // We override the indents according to the list definition
+ attr.SetLeftIndent(oldLeftIndent, oldLeftSubIndent);
+
+ return attr;
+}
+
+/// Is this a numbered list?
+bool wxRichTextListStyleDefinition::IsNumbered(int i) const
+{
+ return (0 != (GetLevelAttributes(i)->GetFlags() &
+ (wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER|wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER|
+ wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER|wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER)));
+}