+IMPLEMENT_CLASS(wxRichTextListStyleDefinition, wxRichTextParagraphStyleDefinition)
+
+/*!
+ * 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;
+}
+
+bool wxRichTextStyleDefinition::Eq(const wxRichTextStyleDefinition& def) const
+{
+ return (m_name == def.m_name && m_baseStyle == def.m_baseStyle && m_style == def.m_style);
+}
+
+/// Gets the style combined with the base style
+wxTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const
+{
+ if (!m_baseStyle.IsEmpty())
+ {
+ wxRichTextStyleDefinition* baseStyle = sheet->FindStyle(m_baseStyle);
+ if (baseStyle)
+ {
+ wxTextAttr baseAttr = baseStyle->GetStyleMergedWithBase(sheet);
+ baseAttr.Apply(m_style, NULL);
+ return baseAttr;
+ }
+ }
+ return m_style;
+}
+
+/*!
+ * 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);
+}
+
+/*!
+ * 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 wxTextAttr& attr)
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ m_levelStyles[i] = attr;
+}
+
+const wxTextAttr* wxRichTextListStyleDefinition::GetLevelAttributes(int i) const
+{
+ wxASSERT( (i >= 0 && i < 10) );
+ if (i >= 0 && i < 10)
+ return & m_levelStyles[i];
+ else
+ return NULL;
+}
+
+wxTextAttr* 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)
+ {
+ wxTextAttr 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)
+wxTextAttr wxRichTextListStyleDefinition::CombineWithParagraphStyle(int indent, const wxTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet)
+{
+ int listLevel = FindLevelForIndent(indent);
+
+ wxTextAttr 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)
+wxTextAttr 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)
+wxTextAttr wxRichTextListStyleDefinition::GetCombinedStyleForLevel(int listLevel, wxRichTextStyleSheet* styleSheet)
+{
+ wxTextAttr 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)));
+}