+ if (style.HasParagraphSpacingBefore() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_PARA_SPACING_BEFORE))
+ {
+ if (currentStyle.HasParagraphSpacingBefore())
+ {
+ if (currentStyle.GetParagraphSpacingBefore() != style.GetParagraphSpacingBefore())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_PARA_SPACING_BEFORE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_PARA_SPACING_BEFORE);
+ }
+ }
+ else
+ currentStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore());
+ }
+
+ if (style.HasLineSpacing() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LINE_SPACING))
+ {
+ if (currentStyle.HasLineSpacing())
+ {
+ if (currentStyle.GetLineSpacing() != style.GetLineSpacing())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_LINE_SPACING;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_LINE_SPACING);
+ }
+ }
+ else
+ currentStyle.SetLineSpacing(style.GetLineSpacing());
+ }
+
+ if (style.HasCharacterStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_CHARACTER_STYLE_NAME))
+ {
+ if (currentStyle.HasCharacterStyleName())
+ {
+ if (currentStyle.GetCharacterStyleName() != style.GetCharacterStyleName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_CHARACTER_STYLE_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_CHARACTER_STYLE_NAME);
+ }
+ }
+ else
+ currentStyle.SetCharacterStyleName(style.GetCharacterStyleName());
+ }
+
+ if (style.HasParagraphStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_PARAGRAPH_STYLE_NAME))
+ {
+ if (currentStyle.HasParagraphStyleName())
+ {
+ if (currentStyle.GetParagraphStyleName() != style.GetParagraphStyleName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_PARAGRAPH_STYLE_NAME);
+ }
+ }
+ else
+ currentStyle.SetParagraphStyleName(style.GetParagraphStyleName());
+ }
+
+ if (style.HasListStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LIST_STYLE_NAME))
+ {
+ if (currentStyle.HasListStyleName())
+ {
+ if (currentStyle.GetListStyleName() != style.GetListStyleName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_LIST_STYLE_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_LIST_STYLE_NAME);
+ }
+ }
+ else
+ currentStyle.SetListStyleName(style.GetListStyleName());
+ }
+
+ if (style.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_STYLE))
+ {
+ if (currentStyle.HasBulletStyle())
+ {
+ if (currentStyle.GetBulletStyle() != style.GetBulletStyle())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BULLET_STYLE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_STYLE);
+ }
+ }
+ else
+ currentStyle.SetBulletStyle(style.GetBulletStyle());
+ }
+
+ if (style.HasBulletNumber() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NUMBER))
+ {
+ if (currentStyle.HasBulletNumber())
+ {
+ if (currentStyle.GetBulletNumber() != style.GetBulletNumber())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NUMBER;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_NUMBER);
+ }
+ }
+ else
+ currentStyle.SetBulletNumber(style.GetBulletNumber());
+ }
+
+ if (style.HasBulletText() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_TEXT))
+ {
+ if (currentStyle.HasBulletText())
+ {
+ if (currentStyle.GetBulletText() != style.GetBulletText())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BULLET_TEXT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_TEXT);
+ }
+ }
+ else
+ {
+ currentStyle.SetBulletText(style.GetBulletText());
+ currentStyle.SetBulletFont(style.GetBulletFont());
+ }
+ }
+
+ if (style.HasBulletName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NAME))
+ {
+ if (currentStyle.HasBulletName())
+ {
+ if (currentStyle.GetBulletName() != style.GetBulletName())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NAME;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BULLET_NAME);
+ }
+ }
+ else
+ {
+ currentStyle.SetBulletName(style.GetBulletName());
+ }
+ }
+
+ if (style.HasURL() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_URL))
+ {
+ if (currentStyle.HasURL())
+ {
+ if (currentStyle.GetURL() != style.GetURL())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_URL;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_URL);
+ }
+ }
+ else
+ {
+ currentStyle.SetURL(style.GetURL());
+ }
+ }
+
+ if (style.HasTextEffects() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_EFFECTS))
+ {
+ if (currentStyle.HasTextEffects())
+ {
+ // We need to find the bits in the new style that are different:
+ // just look at those bits that are specified by the new style.
+
+ int currentRelevantTextEffects = currentStyle.GetTextEffects() & style.GetTextEffectFlags();
+ int newRelevantTextEffects = style.GetTextEffects() & style.GetTextEffectFlags();
+
+ if (currentRelevantTextEffects != newRelevantTextEffects)
+ {
+ // Find the text effects that were different, using XOR
+ int differentEffects = currentRelevantTextEffects ^ newRelevantTextEffects;
+
+ // Clash of style - mark as such
+ multipleTextEffectAttributes |= differentEffects;
+ currentStyle.SetTextEffectFlags(currentStyle.GetTextEffectFlags() & ~differentEffects);
+ }
+ }
+ else
+ {
+ currentStyle.SetTextEffects(style.GetTextEffects());
+ currentStyle.SetTextEffectFlags(style.GetTextEffectFlags());
+ }
+ }
+
+ if (style.HasOutlineLevel() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_OUTLINE_LEVEL))
+ {
+ if (currentStyle.HasOutlineLevel())
+ {
+ if (currentStyle.GetOutlineLevel() != style.GetOutlineLevel())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_OUTLINE_LEVEL;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_OUTLINE_LEVEL);
+ }
+ }
+ else
+ currentStyle.SetOutlineLevel(style.GetOutlineLevel());
+ }
+
+ return true;
+}
+
+/// Get the combined style for a range - if any attribute is different within the range,
+/// that attribute is not present within the flags.
+/// *** Note that this is not recursive, and so assumes that content inside a paragraph is not itself
+/// nested.
+bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style)
+{
+ style = wxTextAttrEx();
+
+ // The attributes that aren't valid because of multiple styles within the range
+ long multipleStyleAttributes = 0;
+ int multipleTextEffectAttributes = 0;
+
+ wxRichTextObjectList::compatibility_iterator node = GetChildren().GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = (wxRichTextParagraph*) node->GetData();
+ if (!(para->GetRange().GetStart() > range.GetEnd() || para->GetRange().GetEnd() < range.GetStart()))
+ {
+ if (para->GetChildren().GetCount() == 0)
+ {
+ wxTextAttrEx paraStyle = para->GetCombinedAttributes();
+
+ CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes);
+ }
+ else
+ {
+ wxRichTextRange paraRange(para->GetRange());
+ paraRange.LimitTo(range);
+
+ // First collect paragraph attributes only
+ wxTextAttrEx paraStyle = para->GetCombinedAttributes();
+ paraStyle.SetFlags(paraStyle.GetFlags() & wxTEXT_ATTR_PARAGRAPH);
+ CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes);
+
+ wxRichTextObjectList::compatibility_iterator childNode = para->GetChildren().GetFirst();
+
+ while (childNode)
+ {
+ wxRichTextObject* child = childNode->GetData();
+ if (!(child->GetRange().GetStart() > range.GetEnd() || child->GetRange().GetEnd() < range.GetStart()))
+ {
+ wxTextAttrEx childStyle = para->GetCombinedAttributes(child->GetAttributes());
+
+ // Now collect character attributes only
+ childStyle.SetFlags(childStyle.GetFlags() & wxTEXT_ATTR_CHARACTER);
+
+ CollectStyle(style, childStyle, multipleStyleAttributes, multipleTextEffectAttributes);
+ }
+
+ childNode = childNode->GetNext();
+ }
+ }
+ }
+ node = node->GetNext();
+ }
+ return true;
+}
+
+/// Set default style
+bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttrEx& style)
+{
+ m_defaultAttributes = style;
+ return true;
+}
+
+/// Test if this whole range has character attributes of the specified kind. If any
+/// of the attributes are different within the range, the test fails. You
+/// can use this to implement, for example, bold button updating. style must have
+/// flags indicating which attributes are of interest.
+bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
+{
+ int foundCount = 0;
+ int matchingCount = 0;
+
+ wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+ wxASSERT (para != NULL);
+
+ if (para)
+ {
+ // Stop searching if we're beyond the range of interest
+ if (para->GetRange().GetStart() > range.GetEnd())
+ return foundCount == matchingCount;
+
+ if (!para->GetRange().IsOutside(range))
+ {
+ wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst();
+
+ while (node2)
+ {
+ wxRichTextObject* child = node2->GetData();
+ if (!child->GetRange().IsOutside(range) && child->IsKindOf(CLASSINFO(wxRichTextPlainText)))
+ {
+ foundCount ++;
+ wxTextAttrEx textAttr = para->GetCombinedAttributes(child->GetAttributes());
+
+ if (wxTextAttrEqPartial(textAttr, style, style.GetFlags()))
+ matchingCount ++;
+ }
+
+ node2 = node2->GetNext();
+ }
+ }
+ }
+
+ node = node->GetNext();
+ }
+
+ return foundCount == matchingCount;
+}
+
+bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
+{
+ wxRichTextAttr richStyle = style;
+ return HasCharacterAttributes(range, richStyle);
+}
+
+/// Test if this whole range has paragraph attributes of the specified kind. If any
+/// of the attributes are different within the range, the test fails. You
+/// can use this to implement, for example, centering button updating. style must have
+/// flags indicating which attributes are of interest.
+bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
+{
+ int foundCount = 0;
+ int matchingCount = 0;
+
+ wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+ wxASSERT (para != NULL);
+
+ if (para)
+ {
+ // Stop searching if we're beyond the range of interest
+ if (para->GetRange().GetStart() > range.GetEnd())
+ return foundCount == matchingCount;
+
+ if (!para->GetRange().IsOutside(range))
+ {
+ wxTextAttrEx textAttr = GetAttributes();
+ // Apply the paragraph style
+ wxRichTextApplyStyle(textAttr, para->GetAttributes());
+
+ foundCount ++;
+ if (wxTextAttrEqPartial(textAttr, style, style.GetFlags()))
+ matchingCount ++;
+ }
+ }
+
+ node = node->GetNext();
+ }
+ return foundCount == matchingCount;
+}
+
+bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
+{