+ if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT))
+ {
+ if (currentStyle.HasFontWeight())
+ {
+ if (currentStyle.GetFontWeight() != style.GetFontWeight())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_WEIGHT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_WEIGHT);
+ }
+ }
+ else
+ {
+ currentStyle.SetFontWeight(style.GetFontWeight());
+ }
+ }
+
+ if (style.HasFontFaceName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_FACE))
+ {
+ if (currentStyle.HasFontFaceName())
+ {
+ wxString faceName1(currentStyle.GetFontFaceName());
+ wxString faceName2(style.GetFontFaceName());
+
+ if (faceName1 != faceName2)
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_FACE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_FACE);
+ }
+ }
+ else
+ {
+ currentStyle.SetFontFaceName(style.GetFontFaceName());
+ }
+ }
+
+ if (style.HasFontUnderlined() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE))
+ {
+ if (currentStyle.HasFontUnderlined())
+ {
+ if (currentStyle.GetFontUnderlined() != style.GetFontUnderlined())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_UNDERLINE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_UNDERLINE);
+ }
+ }
+ else
+ {
+ currentStyle.SetFontUnderlined(style.GetFontUnderlined());
+ }
+ }
+ }
+
+ if (style.HasTextColour() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_TEXT_COLOUR))
+ {
+ if (currentStyle.HasTextColour())
+ {
+ if (currentStyle.GetTextColour() != style.GetTextColour())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_TEXT_COLOUR;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_TEXT_COLOUR);
+ }
+ }
+ else
+ currentStyle.SetTextColour(style.GetTextColour());
+ }
+
+ if (style.HasBackgroundColour() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BACKGROUND_COLOUR))
+ {
+ if (currentStyle.HasBackgroundColour())
+ {
+ if (currentStyle.GetBackgroundColour() != style.GetBackgroundColour())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_BACKGROUND_COLOUR;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_BACKGROUND_COLOUR);
+ }
+ }
+ else
+ currentStyle.SetBackgroundColour(style.GetBackgroundColour());
+ }
+
+ if (style.HasAlignment() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_ALIGNMENT))
+ {
+ if (currentStyle.HasAlignment())
+ {
+ if (currentStyle.GetAlignment() != style.GetAlignment())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_ALIGNMENT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_ALIGNMENT);
+ }
+ }
+ else
+ currentStyle.SetAlignment(style.GetAlignment());
+ }
+
+ if (style.HasTabs() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_TABS))
+ {
+ if (currentStyle.HasTabs())
+ {
+ if (!wxRichTextTabsEq(currentStyle.GetTabs(), style.GetTabs()))
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_TABS;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_TABS);
+ }
+ }
+ else
+ currentStyle.SetTabs(style.GetTabs());
+ }
+
+ if (style.HasLeftIndent() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_LEFT_INDENT))
+ {
+ if (currentStyle.HasLeftIndent())
+ {
+ if (currentStyle.GetLeftIndent() != style.GetLeftIndent() || currentStyle.GetLeftSubIndent() != style.GetLeftSubIndent())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_LEFT_INDENT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_LEFT_INDENT);
+ }
+ }
+ else
+ currentStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent());
+ }
+
+ if (style.HasRightIndent() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_RIGHT_INDENT))
+ {
+ if (currentStyle.HasRightIndent())
+ {
+ if (currentStyle.GetRightIndent() != style.GetRightIndent())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_RIGHT_INDENT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_RIGHT_INDENT);
+ }
+ }
+ else
+ currentStyle.SetRightIndent(style.GetRightIndent());
+ }
+
+ if (style.HasParagraphSpacingAfter() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_PARA_SPACING_AFTER))
+ {
+ if (currentStyle.HasParagraphSpacingAfter())
+ {
+ if (currentStyle.GetParagraphSpacingAfter() != style.GetParagraphSpacingAfter())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_PARA_SPACING_AFTER;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_PARA_SPACING_AFTER);
+ }
+ }
+ else
+ currentStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter());
+ }
+
+ if (style.HasParagraphSpacingBefore() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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|absentStyleAttributes, 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.
+
+ // We need to remove the bits and flags that are not common between current style
+ // and new style. In so doing we need to take account of the styles absent from one or more of the
+ // previous styles.
+
+ 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());
+ }
+
+ // Mask out the flags and values that cannot be common because they were absent in one or more objecrs
+ // that we've looked at so far
+ currentStyle.SetTextEffects(currentStyle.GetTextEffects() & ~absentTextEffectAttributes);
+ currentStyle.SetTextEffectFlags(currentStyle.GetTextEffectFlags() & ~absentTextEffectAttributes);
+
+ if (currentStyle.GetTextEffectFlags() == 0)
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_EFFECTS);
+ }
+
+ if (style.HasOutlineLevel() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, 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, wxTextAttr& style)
+{
+ style = wxTextAttr();
+
+ // The attributes that aren't valid because of multiple styles within the range
+ long multipleStyleAttributes = 0;
+ int multipleTextEffectAttributes = 0;
+
+ int absentStyleAttributesPara = 0;
+ int absentStyleAttributesChar = 0;
+ int absentTextEffectAttributesPara = 0;
+ int absentTextEffectAttributesChar = 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)
+ {
+ wxTextAttr paraStyle = para->GetCombinedAttributes();
+
+ CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesPara, absentTextEffectAttributesPara);
+ }
+ else
+ {
+ wxRichTextRange paraRange(para->GetRange());
+ paraRange.LimitTo(range);
+
+ // First collect paragraph attributes only
+ wxTextAttr paraStyle = para->GetCombinedAttributes();
+ paraStyle.SetFlags(paraStyle.GetFlags() & wxTEXT_ATTR_PARAGRAPH);
+ CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesPara, absentTextEffectAttributesPara);
+
+ wxRichTextObjectList::compatibility_iterator childNode = para->GetChildren().GetFirst();
+
+ while (childNode)
+ {
+ wxRichTextObject* child = childNode->GetData();
+ if (!(child->GetRange().GetStart() > range.GetEnd() || child->GetRange().GetEnd() < range.GetStart()))
+ {
+ wxTextAttr childStyle = para->GetCombinedAttributes(child->GetAttributes());
+
+ // Now collect character attributes only
+ childStyle.SetFlags(childStyle.GetFlags() & wxTEXT_ATTR_CHARACTER);
+
+ CollectStyle(style, childStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesChar, absentTextEffectAttributesChar);
+ }
+
+ childNode = childNode->GetNext();
+ }
+ }
+ }
+ node = node->GetNext();
+ }
+ return true;
+}
+
+/// Set default style
+bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttr& 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 wxTextAttr& 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 ++;
+ wxTextAttr textAttr = para->GetCombinedAttributes(child->GetAttributes());
+
+ if (wxTextAttrEqPartial(textAttr, style, style.GetFlags()))
+ matchingCount ++;
+ }
+
+ node2 = node2->GetNext();
+ }
+ }
+ }
+
+ node = node->GetNext();
+ }