+ if (style.HasFontSize() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_SIZE))
+ {
+ if (currentStyle.GetFont().Ok() && currentStyle.HasFontSize())
+ {
+ if (currentStyle.GetFont().GetPointSize() != style.GetFont().GetPointSize())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_SIZE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_SIZE);
+ }
+ }
+ else
+ {
+ if (!currentStyle.GetFont().Ok())
+ wxSetFontPreservingStyles(currentStyle, *wxNORMAL_FONT);
+ wxFont font(currentStyle.GetFont());
+ font.SetPointSize(style.GetFont().GetPointSize());
+
+ wxSetFontPreservingStyles(currentStyle, font);
+ currentStyle.SetFlags(currentStyle.GetFlags() | wxTEXT_ATTR_FONT_SIZE);
+ }
+ }
+
+ if (style.HasFontItalic() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_ITALIC))
+ {
+ if (currentStyle.GetFont().Ok() && currentStyle.HasFontItalic())
+ {
+ if (currentStyle.GetFont().GetStyle() != style.GetFont().GetStyle())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_ITALIC;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_ITALIC);
+ }
+ }
+ else
+ {
+ if (!currentStyle.GetFont().Ok())
+ wxSetFontPreservingStyles(currentStyle, *wxNORMAL_FONT);
+ wxFont font(currentStyle.GetFont());
+ font.SetStyle(style.GetFont().GetStyle());
+ wxSetFontPreservingStyles(currentStyle, font);
+ currentStyle.SetFlags(currentStyle.GetFlags() | wxTEXT_ATTR_FONT_ITALIC);
+ }
+ }
+
+ if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT))
+ {
+ if (currentStyle.GetFont().Ok() && currentStyle.HasFontWeight())
+ {
+ if (currentStyle.GetFont().GetWeight() != style.GetFont().GetWeight())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_WEIGHT;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_WEIGHT);
+ }
+ }
+ else
+ {
+ if (!currentStyle.GetFont().Ok())
+ wxSetFontPreservingStyles(currentStyle, *wxNORMAL_FONT);
+ wxFont font(currentStyle.GetFont());
+ font.SetWeight(style.GetFont().GetWeight());
+ wxSetFontPreservingStyles(currentStyle, font);
+ currentStyle.SetFlags(currentStyle.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT);
+ }
+ }
+
+ if (style.HasFontFaceName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_FACE))
+ {
+ if (currentStyle.GetFont().Ok() && currentStyle.HasFontFaceName())
+ {
+ wxString faceName1(currentStyle.GetFont().GetFaceName());
+ wxString faceName2(style.GetFont().GetFaceName());
+
+ if (faceName1 != faceName2)
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_FACE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_FACE);
+ }
+ }
+ else
+ {
+ if (!currentStyle.GetFont().Ok())
+ wxSetFontPreservingStyles(currentStyle, *wxNORMAL_FONT);
+ wxFont font(currentStyle.GetFont());
+ font.SetFaceName(style.GetFont().GetFaceName());
+ wxSetFontPreservingStyles(currentStyle, font);
+ currentStyle.SetFlags(currentStyle.GetFlags() | wxTEXT_ATTR_FONT_FACE);
+ }
+ }
+
+ if (style.HasFontUnderlined() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE))
+ {
+ if (currentStyle.GetFont().Ok() && currentStyle.HasFontUnderlined())
+ {
+ if (currentStyle.GetFont().GetUnderlined() != style.GetFont().GetUnderlined())
+ {
+ // Clash of style - mark as such
+ multipleStyleAttributes |= wxTEXT_ATTR_FONT_UNDERLINE;
+ currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_UNDERLINE);
+ }
+ }
+ else
+ {
+ if (!currentStyle.GetFont().Ok())
+ wxSetFontPreservingStyles(currentStyle, *wxNORMAL_FONT);
+ wxFont font(currentStyle.GetFont());
+ font.SetUnderlined(style.GetFont().GetUnderlined());
+ wxSetFontPreservingStyles(currentStyle, font);
+ currentStyle.SetFlags(currentStyle.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE);
+ }
+ }
+ }
+
+ if (style.HasTextColour() && !wxHasStyle(multipleStyleAttributes, 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, 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, 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, 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, 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, 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, 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, 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);
+