X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c738608b41554435c69e5f947d309d7e7f5848c..cd8b0a991448550915d00c57cacbcc34ccf3d833:/src/richtext/richtextbuffer.cpp?ds=sidebyside diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 891aae4042..2ac10201af 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -85,12 +85,6 @@ void wxRichTextObject::Copy(const wxRichTextObject& obj) m_range = obj.m_range; m_attributes = obj.m_attributes; m_descent = obj.m_descent; -/* - if (!m_attributes.GetFont().Ok()) - wxLogDebug(wxT("No font!")); - if (!obj.m_attributes.GetFont().Ok()) - wxLogDebug(wxT("Parent has no font!")); -*/ } void wxRichTextObject::SetMargins(int margin) @@ -907,21 +901,18 @@ wxSize wxRichTextParagraphLayoutBox::GetLineSizeAtPosition(long pos, bool caretP /// Convenience function to add a paragraph of text wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text, wxTextAttrEx* paraStyle) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES // Don't use the base style, just the default style, and the base style will - // be combined at display time - wxTextAttrEx style(GetDefaultStyle()); -#else - wxTextAttrEx style(GetAttributes()); + // be combined at display time. + // Divide into paragraph and character styles. + + wxTextAttrEx defaultCharStyle; + wxTextAttrEx defaultParaStyle; - // Apply default style. If the style has no attributes set, - // then the attributes will remain the 'basic style' (i.e. the - // layout box's style). - wxRichTextApplyStyle(style, GetDefaultStyle()); -#endif - wxRichTextParagraph* para = new wxRichTextParagraph(text, this, & style); - if (paraStyle) - para->SetAttributes(*paraStyle); + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); + wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle; + wxTextAttrEx* cStyle = & defaultCharStyle; + + wxRichTextParagraph* para = new wxRichTextParagraph(text, this, pStyle, cStyle); AppendChild(para); @@ -934,24 +925,16 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text, /// Adds multiple paragraphs, based on newlines. wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES // Don't use the base style, just the default style, and the base style will - // be combined at display time - wxTextAttrEx style(GetDefaultStyle()); -#else - wxTextAttrEx style(GetAttributes()); - - //wxLogDebug("Initial style = %s", style.GetFont().GetFaceName()); - //wxLogDebug("Initial size = %d", style.GetFont().GetPointSize()); - - // Apply default style. If the style has no attributes set, - // then the attributes will remain the 'basic style' (i.e. the - // layout box's style). - wxRichTextApplyStyle(style, GetDefaultStyle()); + // be combined at display time. + // Divide into paragraph and character styles. + + wxTextAttrEx defaultCharStyle; + wxTextAttrEx defaultParaStyle; + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); - //wxLogDebug("Style after applying default style = %s", style.GetFont().GetFaceName()); - //wxLogDebug("Size after applying default style = %d", style.GetFont().GetPointSize()); -#endif + wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle; + wxTextAttrEx* cStyle = & defaultCharStyle; wxRichTextParagraph* firstPara = NULL; wxRichTextParagraph* lastPara = NULL; @@ -961,9 +944,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text size_t i = 0; size_t len = text.length(); wxString line; - wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, & style); - if (paraStyle) - para->SetAttributes(*paraStyle); + wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); AppendChild(para); @@ -978,15 +959,10 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData(); plainText->SetText(line); - para = new wxRichTextParagraph(wxEmptyString, this, & style); - if (paraStyle) - para->SetAttributes(*paraStyle); + para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); AppendChild(para); - //if (!firstPara) - // firstPara = para; - lastPara = para; line = wxEmptyString; } @@ -1002,18 +978,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text plainText->SetText(line); } -/* - if (firstPara) - range.SetStart(firstPara->GetRange().GetStart()); - else if (lastPara) - range.SetStart(lastPara->GetRange().GetStart()); - - if (lastPara) - range.SetEnd(lastPara->GetRange().GetEnd()); - else if (firstPara) - range.SetEnd(firstPara->GetRange().GetEnd()); -*/ - UpdateRanges(); SetDirty(false); @@ -1024,25 +988,20 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text /// Convenience function to add an image wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxTextAttrEx* paraStyle) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES // Don't use the base style, just the default style, and the base style will - // be combined at display time - wxTextAttrEx style(GetDefaultStyle()); -#else - wxTextAttrEx style(GetAttributes()); + // be combined at display time. + // Divide into paragraph and character styles. + + wxTextAttrEx defaultCharStyle; + wxTextAttrEx defaultParaStyle; + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); - // Apply default style. If the style has no attributes set, - // then the attributes will remain the 'basic style' (i.e. the - // layout box's style). - wxRichTextApplyStyle(style, GetDefaultStyle()); -#endif + wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle; + wxTextAttrEx* cStyle = & defaultCharStyle; - wxRichTextParagraph* para = new wxRichTextParagraph(this, & style); + wxRichTextParagraph* para = new wxRichTextParagraph(this, pStyle); AppendChild(para); - para->AppendChild(new wxRichTextImage(image, this)); - - if (paraStyle) - para->SetAttributes(*paraStyle); + para->AppendChild(new wxRichTextImage(image, this, cStyle)); UpdateRanges(); SetDirty(true); @@ -1054,8 +1013,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxT /// Insert fragment into this box at the given position. If partialParagraph is true, /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph /// marker. -/// TODO: if fragment is inserted inside styled fragment, must apply that style to -/// to the data (if it has a default style, anyway). bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment) { @@ -1085,6 +1042,11 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph); wxASSERT (firstPara != NULL); + // Apply the new paragraph attributes to the existing paragraph + wxTextAttrEx attr(para->GetAttributes()); + wxRichTextApplyStyle(attr, firstPara->GetAttributes()); + para->SetAttributes(attr); + wxRichTextObjectList::compatibility_iterator objectNode = firstPara->GetChildren().GetFirst(); while (objectNode) { @@ -1191,9 +1153,6 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag if (finalPara->GetChildCount() == 0) { wxRichTextPlainText* text = new wxRichTextPlainText(wxEmptyString); -#if !wxRICHTEXT_USE_DYNAMIC_STYLES - text->SetAttributes(finalPara->GetAttributes()); -#endif finalPara->AppendChild(text); } @@ -1599,11 +1558,29 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0); bool parasOnly = ((flags & wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY) != 0); bool charactersOnly = ((flags & wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY) != 0); + bool resetExistingStyle = ((flags & wxRICHTEXT_SETSTYLE_RESET) != 0); + + // Apply paragraph style first, if any + wxRichTextAttr wholeStyle(style); + + if (wholeStyle.HasParagraphStyleName() && GetStyleSheet()) + { + wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(wholeStyle.GetParagraphStyleName()); + if (def) + wxRichTextApplyStyle(wholeStyle, def->GetStyle()); + } // Limit the attributes to be set to the content to only character attributes. - wxRichTextAttr characterAttributes(style); + wxRichTextAttr characterAttributes(wholeStyle); characterAttributes.SetFlags(characterAttributes.GetFlags() & (wxTEXT_ATTR_CHARACTER)); + if (characterAttributes.HasCharacterStyleName() && GetStyleSheet()) + { + wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterAttributes.GetCharacterStyleName()); + if (def) + wxRichTextApplyStyle(characterAttributes, def->GetStyle()); + } + // If we are associated with a control, make undoable; otherwise, apply immediately // to the data. @@ -1647,21 +1624,27 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const else newPara = para; - if (paragraphStyle && !charactersOnly) + // If we're specifying paragraphs only, then we really mean character formatting + // to be included in the paragraph style + if ((paragraphStyle || parasOnly) && !charactersOnly) { - if (applyMinimal) + if (resetExistingStyle) + newPara->GetAttributes() = wholeStyle; + else { - // Only apply attributes that will make a difference to the combined - // style as seen on the display - wxRichTextAttr combinedAttr(para->GetCombinedAttributes()); - wxRichTextApplyStyle(newPara->GetAttributes(), style, & combinedAttr); + if (applyMinimal) + { + // Only apply attributes that will make a difference to the combined + // style as seen on the display + wxRichTextAttr combinedAttr(para->GetCombinedAttributes()); + wxRichTextApplyStyle(newPara->GetAttributes(), wholeStyle, & combinedAttr); + } + else + wxRichTextApplyStyle(newPara->GetAttributes(), wholeStyle); } - else - wxRichTextApplyStyle(newPara->GetAttributes(), style); } -#if wxRICHTEXT_USE_DYNAMIC_STYLES - // If applying paragraph styles dynamically, don't change the text objects' attributes + // When applying paragraph styles dynamically, don't change the text objects' attributes // since they will computed as needed. Only apply the character styling if it's _only_ // character styling. This policy is subject to change and might be put under user control. @@ -1673,9 +1656,6 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const // if (!paragraphStyle && characterStyle && range.GetStart() != newPara->GetRange().GetEnd()) if (!parasOnly && characterStyle && range.GetStart() != newPara->GetRange().GetEnd()) -#else - if (characterStyle && range.GetStart() != newPara->GetRange().GetEnd()) -#endif { wxRichTextRange childRange(range); childRange.LimitTo(newPara->GetRange()); @@ -1723,15 +1703,20 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const { wxRichTextObject* child = node2->GetData(); - if (applyMinimal) + if (resetExistingStyle) + child->GetAttributes() = characterAttributes; + else { - // Only apply attributes that will make a difference to the combined - // style as seen on the display - wxRichTextAttr combinedAttr(newPara->GetCombinedAttributes(child->GetAttributes())); - wxRichTextApplyStyle(child->GetAttributes(), characterAttributes, & combinedAttr); + if (applyMinimal) + { + // Only apply attributes that will make a difference to the combined + // style as seen on the display + wxRichTextAttr combinedAttr(newPara->GetCombinedAttributes(child->GetAttributes())); + wxRichTextApplyStyle(child->GetAttributes(), characterAttributes, & combinedAttr); + } + else + wxRichTextApplyStyle(child->GetAttributes(), characterAttributes); } - else - wxRichTextApplyStyle(child->GetAttributes(), characterAttributes); if (node2 == lastNode) break; @@ -1807,7 +1792,6 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style obj = GetParagraphAtPosition(position); if (obj) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES if (combineStyles) { // Start with the base style @@ -1818,9 +1802,7 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style } else style = obj->GetAttributes(); -#else - style = obj->GetAttributes(); -#endif + return true; } } @@ -1829,7 +1811,6 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style obj = GetLeafObjectAtPosition(position); if (obj) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES if (combineStyles) { wxRichTextParagraph* para = wxDynamicCast(obj->GetParent(), wxRichTextParagraph); @@ -1837,9 +1818,7 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style } else style = obj->GetAttributes(); -#else - style = obj->GetAttributes(); -#endif + return true; } } @@ -1853,7 +1832,7 @@ static bool wxHasStyle(long flags, long style) /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of /// content. -bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes) +bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes) { if (style.HasFont()) { @@ -2066,7 +2045,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasParagraphSpacingAfter()) { - if (currentStyle.HasParagraphSpacingAfter() != style.HasParagraphSpacingAfter()) + if (currentStyle.GetParagraphSpacingAfter() != style.GetParagraphSpacingAfter()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_PARA_SPACING_AFTER; @@ -2081,7 +2060,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasParagraphSpacingBefore()) { - if (currentStyle.HasParagraphSpacingBefore() != style.HasParagraphSpacingBefore()) + if (currentStyle.GetParagraphSpacingBefore() != style.GetParagraphSpacingBefore()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_PARA_SPACING_BEFORE; @@ -2096,7 +2075,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasLineSpacing()) { - if (currentStyle.HasLineSpacing() != style.HasLineSpacing()) + if (currentStyle.GetLineSpacing() != style.GetLineSpacing()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_LINE_SPACING; @@ -2111,7 +2090,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasCharacterStyleName()) { - if (currentStyle.HasCharacterStyleName() != style.HasCharacterStyleName()) + if (currentStyle.GetCharacterStyleName() != style.GetCharacterStyleName()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; @@ -2126,7 +2105,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasParagraphStyleName()) { - if (currentStyle.HasParagraphStyleName() != style.HasParagraphStyleName()) + if (currentStyle.GetParagraphStyleName() != style.GetParagraphStyleName()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; @@ -2141,7 +2120,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasListStyleName()) { - if (currentStyle.HasListStyleName() != style.HasListStyleName()) + if (currentStyle.GetListStyleName() != style.GetListStyleName()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_LIST_STYLE_NAME; @@ -2156,7 +2135,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasBulletStyle()) { - if (currentStyle.HasBulletStyle() != style.HasBulletStyle()) + if (currentStyle.GetBulletStyle() != style.GetBulletStyle()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_BULLET_STYLE; @@ -2171,7 +2150,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasBulletNumber()) { - if (currentStyle.HasBulletNumber() != style.HasBulletNumber()) + if (currentStyle.GetBulletNumber() != style.GetBulletNumber()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NUMBER; @@ -2186,7 +2165,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasBulletText()) { - if (currentStyle.HasBulletText() != style.HasBulletText()) + if (currentStyle.GetBulletText() != style.GetBulletText()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_BULLET_TEXT; @@ -2204,7 +2183,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasBulletName()) { - if (currentStyle.HasBulletName() != style.HasBulletName()) + if (currentStyle.GetBulletName() != style.GetBulletName()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_BULLET_NAME; @@ -2221,7 +2200,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons { if (currentStyle.HasURL()) { - if (currentStyle.HasURL() != style.HasURL()) + if (currentStyle.GetURL() != style.GetURL()) { // Clash of style - mark as such multipleStyleAttributes |= wxTEXT_ATTR_URL; @@ -2234,6 +2213,48 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx& currentStyle, cons } } + 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; } @@ -2247,7 +2268,8 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range // 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) { @@ -2258,7 +2280,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range { wxTextAttrEx paraStyle = para->GetCombinedAttributes(); - CollectStyle(style, paraStyle, multipleStyleAttributes); + CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes); } else { @@ -2268,7 +2290,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range // First collect paragraph attributes only wxTextAttrEx paraStyle = para->GetCombinedAttributes(); paraStyle.SetFlags(paraStyle.GetFlags() & wxTEXT_ATTR_PARAGRAPH); - CollectStyle(style, paraStyle, multipleStyleAttributes); + CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes); wxRichTextObjectList::compatibility_iterator childNode = para->GetChildren().GetFirst(); @@ -2282,7 +2304,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range // Now collect character attributes only childStyle.SetFlags(childStyle.GetFlags() & wxTEXT_ATTR_CHARACTER); - CollectStyle(style, childStyle, multipleStyleAttributes); + CollectStyle(style, childStyle, multipleStyleAttributes, multipleTextEffectAttributes); } childNode = childNode->GetNext(); @@ -2297,19 +2319,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range /// Set default style bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttrEx& style) { - // I don't think the default style should be combined with the previous - // default style. m_defaultAttributes = style; - -#if 0 - // keep the old attributes if the new style doesn't specify them unless the - // new style is empty - then reset m_defaultStyle (as there is no other way - // to do it) - if ( style.IsDefault() ) - m_defaultAttributes = style; - else - m_defaultAttributes = wxTextAttrEx::CombineEx(style, m_defaultAttributes, NULL); -#endif return true; } @@ -2344,11 +2354,8 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& if (!child->GetRange().IsOutside(range) && child->IsKindOf(CLASSINFO(wxRichTextPlainText))) { foundCount ++; -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx textAttr = para->GetCombinedAttributes(child->GetAttributes()); -#else - const wxTextAttrEx& textAttr = child->GetAttributes(); -#endif + if (wxTextAttrEqPartial(textAttr, style, style.GetFlags())) matchingCount ++; } @@ -2393,14 +2400,10 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& if (!para->GetRange().IsOutside(range)) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx textAttr = GetAttributes(); // Apply the paragraph style wxRichTextApplyStyle(textAttr, para->GetAttributes()); -#else - const wxTextAttrEx& textAttr = para->GetAttributes(); -#endif foundCount ++; if (wxTextAttrEqPartial(textAttr, style, style.GetFlags())) matchingCount ++; @@ -2915,13 +2918,6 @@ bool wxRichTextParagraphLayoutBox::PromoteList(int promoteBy, const wxRichTextRa /// position of the paragraph that it had to start looking from. bool wxRichTextParagraphLayoutBox::FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const { -#if 0 - wxRichTextObjectList::compatibility_iterator node = m_children.Find(previousParagraph); - - if (!node) - return false; -#endif - if (!previousParagraph->GetAttributes().HasFlag(wxTEXT_ATTR_BULLET_STYLE) || previousParagraph->GetAttributes().GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE) return false; @@ -2985,21 +2981,17 @@ wxArrayInt wxRichTextParagraph::sm_defaultTabs; wxRichTextParagraph::wxRichTextParagraph(wxRichTextObject* parent, wxTextAttrEx* style): wxRichTextBox(parent) { - if (parent && !style) - SetAttributes(parent->GetAttributes()); if (style) SetAttributes(*style); } -wxRichTextParagraph::wxRichTextParagraph(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* style): +wxRichTextParagraph::wxRichTextParagraph(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* paraStyle, wxTextAttrEx* charStyle): wxRichTextBox(parent) { - if (parent && !style) - SetAttributes(parent->GetAttributes()); - if (style) - SetAttributes(*style); + if (paraStyle) + SetAttributes(*paraStyle); - AppendChild(new wxRichTextPlainText(text, this)); + AppendChild(new wxRichTextPlainText(text, this, charStyle)); } wxRichTextParagraph::~wxRichTextParagraph() @@ -3010,11 +3002,7 @@ wxRichTextParagraph::~wxRichTextParagraph() /// Draw the item bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& WXUNUSED(rect), int WXUNUSED(descent), int style) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx attr = GetCombinedAttributes(); -#else - const wxTextAttrEx& attr = GetAttributes(); -#endif // Draw the bullet, if any if (attr.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE) @@ -3126,11 +3114,7 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR /// Lay the item out bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx attr = GetCombinedAttributes(); -#else - const wxTextAttrEx& attr = GetAttributes(); -#endif // ClearLines(); @@ -4105,8 +4089,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxRichTextPlainText, wxRichTextObject) wxRichTextPlainText::wxRichTextPlainText(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* style): wxRichTextObject(parent) { - if (parent && !style) - SetAttributes(parent->GetAttributes()); if (style) SetAttributes(*style); @@ -4118,19 +4100,17 @@ wxRichTextPlainText::wxRichTextPlainText(const wxString& text, wxRichTextObject* /// Draw the item bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int WXUNUSED(style)) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph); wxASSERT (para != NULL); wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes()); -#else - wxTextAttrEx textAttr(GetAttributes()); -#endif int offset = GetRange().GetStart(); long len = range.GetLength(); wxString stringChunk = m_text.Mid(range.GetStart() - offset, (size_t) len); + if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) + stringChunk.MakeUpper(); int charHeight = dc.GetCharHeight(); @@ -4303,6 +4283,15 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, c dc.DrawRectangle(selRect); } dc.DrawText(stringChunk, x, y); + + if (attr.HasTextEffects() && (attr.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)) + { + wxPen oldPen = dc.GetPen(); + dc.SetPen(wxPen(attr.GetTextColour(), 1)); + dc.DrawLine(x, (int) (y+(h/2)+0.5), x+w, (int) (y+(h/2)+0.5)); + dc.SetPen(oldPen); + } + x = nextTabPos; } } @@ -4318,6 +4307,15 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, c dc.DrawRectangle(selRect); } dc.DrawText(str, x, y); + + if (attr.HasTextEffects() && (attr.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)) + { + wxPen oldPen = dc.GetPen(); + dc.SetPen(wxPen(attr.GetTextColour(), 1)); + dc.DrawLine(x, (int) (y+(h/2)+0.5), x+w, (int) (y+(h/2)+0.5)); + dc.SetPen(oldPen); + } + x += w; } return true; @@ -4327,20 +4325,20 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, c /// Lay the item out bool wxRichTextPlainText::Layout(wxDC& dc, const wxRect& WXUNUSED(rect), int WXUNUSED(style)) { -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph); wxASSERT (para != NULL); wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes()); -#else - wxTextAttrEx textAttr(GetAttributes()); -#endif if (textAttr.GetFont().Ok()) dc.SetFont(textAttr.GetFont()); + wxString str = m_text; + if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) + str.MakeUpper(); + wxCoord w, h; - dc.GetTextExtent(m_text, & w, & h, & m_descent); + dc.GetTextExtent(str, & w, & h, & m_descent); m_size = wxSize(w, dc.GetCharHeight()); return true; @@ -4361,14 +4359,10 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz if (!range.IsWithin(GetRange())) return false; -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph); wxASSERT (para != NULL); wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes()); -#else - wxTextAttrEx textAttr(GetAttributes()); -#endif // Always assume unformatted text, since at this level we have no knowledge // of line breaks - and we don't need it, since we'll calculate size within @@ -4380,6 +4374,10 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz int startPos = range.GetStart() - GetRange().GetStart(); long len = range.GetLength(); wxString stringChunk = m_text.Mid(startPos, (size_t) len); + + if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) + stringChunk.MakeUpper(); + wxCoord w, h; int width = 0; if (stringChunk.Find(wxT('\t')) != wxNOT_FOUND) @@ -4609,6 +4607,8 @@ bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagr { wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, this, ctrl, false); + wxTextAttrEx attr(GetDefaultStyle()); + wxTextAttrEx* p = NULL; wxTextAttrEx paraAttr; if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE) @@ -4617,13 +4617,8 @@ bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagr if (!paraAttr.IsDefault()) p = & paraAttr; } - -#if wxRICHTEXT_USE_DYNAMIC_STYLES - wxTextAttrEx attr(GetDefaultStyle()); -#else - wxTextAttrEx attr(GetBasicStyle()); - wxRichTextApplyStyle(attr, GetDefaultStyle()); -#endif + else + p = & attr; action->GetNewParagraphs() = paragraphs; @@ -4662,13 +4657,6 @@ bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRich p = & paraAttr; } -#if wxRICHTEXT_USE_DYNAMIC_STYLES - wxTextAttrEx attr(GetDefaultStyle()); -#else - wxTextAttrEx attr(GetBasicStyle()); - wxRichTextApplyStyle(attr, GetDefaultStyle()); -#endif - action->GetNewParagraphs().AddParagraphs(text, p); int length = action->GetNewParagraphs().GetRange().GetLength(); @@ -4704,12 +4692,7 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int p = & paraAttr; } -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx attr(GetDefaultStyle()); -#else - wxTextAttrEx attr(GetBasicStyle()); - wxRichTextApplyStyle(attr, GetDefaultStyle()); -#endif wxRichTextParagraph* newPara = new wxRichTextParagraph(wxEmptyString, this, & attr); action->GetNewParagraphs().AppendChild(newPara); @@ -4742,12 +4725,7 @@ bool wxRichTextBuffer::InsertImageWithUndo(long pos, const wxRichTextImageBlock& p = & paraAttr; } -#if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx attr(GetDefaultStyle()); -#else - wxTextAttrEx attr(GetBasicStyle()); - wxRichTextApplyStyle(attr, GetDefaultStyle()); -#endif wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr); if (p) @@ -4832,11 +4810,11 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos } /// Submit command to delete this range -bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long WXUNUSED(newCaretPositon), wxRichTextCtrl* ctrl) +bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl) { wxRichTextAction* action = new wxRichTextAction(NULL, _("Delete"), wxRICHTEXT_DELETE, this, ctrl); - action->SetPosition(initialCaretPosition); + action->SetPosition(ctrl->GetCaretPosition()); // Set the range to delete action->SetRange(range); @@ -5159,8 +5137,7 @@ bool wxRichTextBuffer::BeginCharacterStyle(const wxString& characterStyle) wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle); if (def) { - wxTextAttrEx attr; - def->GetStyle().CopyTo(attr); + wxTextAttrEx attr = def->GetStyle(); return BeginStyle(attr); } } @@ -5175,8 +5152,7 @@ bool wxRichTextBuffer::BeginParagraphStyle(const wxString& paragraphStyle) wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(paragraphStyle); if (def) { - wxTextAttrEx attr; - def->GetStyle().CopyTo(attr); + wxTextAttrEx attr = def->GetStyle(); return BeginStyle(attr); } } @@ -5211,7 +5187,7 @@ bool wxRichTextBuffer::BeginURL(const wxString& url, const wxString& characterSt wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle); if (def) { - def->GetStyle().CopyTo(attr); + attr = def->GetStyle(); } } attr.SetURL(url); @@ -5953,8 +5929,8 @@ bool wxRichTextAction::Do() if (pt.y > lastY) { - node2 = NULL; - node = NULL; + node2 = wxRichTextLineList::compatibility_iterator(); + node = wxRichTextObjectList::compatibility_iterator(); } else if (range.GetStart() > GetPosition() && pt.y >= firstVisiblePt.y) { @@ -5985,13 +5961,21 @@ bool wxRichTextAction::Do() if (m_newParagraphs.GetPartialParagraph()) newCaretPosition --; - newCaretPosition = wxMin(newCaretPosition, (m_buffer->GetRange().GetEnd()-1)); - + newCaretPosition = wxMin(newCaretPosition, (m_buffer->GetRange().GetEnd()-1)); if (optimizationLineCharPositions.GetCount() > 0) UpdateAppearance(newCaretPosition, true /* send update event */, & optimizationLineCharPositions, & optimizationLineYPositions); else UpdateAppearance(newCaretPosition, true /* send update event */); + + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); break; } @@ -6003,6 +5987,15 @@ bool wxRichTextAction::Do() UpdateAppearance(GetRange().GetStart()-1, true /* send update event */); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); + break; } case wxRICHTEXT_CHANGE_STYLE: @@ -6012,6 +6005,15 @@ bool wxRichTextAction::Do() UpdateAppearance(GetPosition()); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); + break; } default: @@ -6034,11 +6036,18 @@ bool wxRichTextAction::Undo() m_buffer->Invalidate(wxRichTextRange(GetRange().GetStart(), GetRange().GetStart())); long newCaretPosition = GetPosition() - 1; - // if (m_newParagraphs.GetPartialParagraph()) - // newCaretPosition --; UpdateAppearance(newCaretPosition, true /* send update event */); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); + break; } case wxRICHTEXT_DELETE: @@ -6049,6 +6058,15 @@ bool wxRichTextAction::Undo() UpdateAppearance(GetPosition(), true /* send update event */); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); + break; } case wxRICHTEXT_CHANGE_STYLE: @@ -6058,6 +6076,15 @@ bool wxRichTextAction::Undo() UpdateAppearance(GetPosition()); + wxRichTextEvent cmdEvent( + wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, + m_ctrl ? m_ctrl->GetId() : -1); + cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer); + cmdEvent.SetRange(GetRange()); + cmdEvent.SetPosition(GetRange().GetStart()); + + m_buffer->SendEvent(cmdEvent); + break; } default: @@ -6118,8 +6145,8 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent if (pt.y > lastY) // going past the end of the window, no more info { - node2 = NULL; - node = NULL; + node2 = wxRichTextLineList::compatibility_iterator(); + node = wxRichTextObjectList::compatibility_iterator(); } else { @@ -6139,8 +6166,9 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent foundEnd = true; lastY = pt.y - firstVisiblePt.y; - node2 = NULL; - node = NULL; + node2 = wxRichTextLineList::compatibility_iterator(); + node = wxRichTextObjectList::compatibility_iterator(); + break; } } @@ -6233,17 +6261,21 @@ bool wxRichTextRange::LimitTo(const wxRichTextRange& range) IMPLEMENT_DYNAMIC_CLASS(wxRichTextImage, wxRichTextObject) -wxRichTextImage::wxRichTextImage(const wxImage& image, wxRichTextObject* parent): +wxRichTextImage::wxRichTextImage(const wxImage& image, wxRichTextObject* parent, wxTextAttrEx* charStyle): wxRichTextObject(parent) { m_image = image; + if (charStyle) + SetAttributes(*charStyle); } -wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent): +wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent, wxTextAttrEx* charStyle): wxRichTextObject(parent) { m_imageBlock = imageBlock; m_imageBlock.Load(m_image); + if (charStyle) + SetAttributes(*charStyle); } /// Load wxImage from the block @@ -6354,6 +6386,8 @@ bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2) attr1.GetFont().GetWeight() == attr2.GetFontWeight() && attr1.GetFont().GetFaceName() == attr2.GetFontFaceName() && attr1.GetFont().GetUnderlined() == attr2.GetFontUnderlined() && + attr1.GetTextEffects() == attr2.GetTextEffects() && + attr1.GetTextEffectFlags() == attr2.GetTextEffectFlags() && attr1.GetAlignment() == attr2.GetAlignment() && attr1.GetLeftIndent() == attr2.GetLeftIndent() && attr1.GetRightIndent() == attr2.GetRightIndent() && @@ -6367,6 +6401,7 @@ bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2) attr1.GetBulletText() == attr2.GetBulletText() && attr1.GetBulletName() == attr2.GetBulletName() && attr1.GetBulletFont() == attr2.GetBulletFont() && + attr1.GetOutlineLevel() == attr2.GetOutlineLevel() && attr1.GetCharacterStyleName() == attr2.GetCharacterStyleName() && attr1.GetParagraphStyleName() == attr2.GetParagraphStyleName() && attr1.GetListStyleName() == attr2.GetListStyleName() && @@ -6463,6 +6498,18 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, i (attr1.HasPageBreak() != attr2.HasPageBreak())) return false; + if (flags & wxTEXT_ATTR_EFFECTS) + { + if (attr1.HasTextEffects() != attr2.HasTextEffects()) + return false; + if (!wxRichTextBitlistsEqPartial(attr1.GetTextEffects(), attr2.GetTextEffects(), attr2.GetTextEffectFlags())) + return false; + } + + if ((flags & wxTEXT_ATTR_OUTLINE_LEVEL) && + (attr1.GetOutlineLevel() != attr2.GetOutlineLevel())) + return false; + return true; } @@ -6557,6 +6604,18 @@ bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2, (attr1.HasPageBreak() != attr2.HasPageBreak())) return false; + if (flags & wxTEXT_ATTR_EFFECTS) + { + if (attr1.HasTextEffects() != attr2.HasTextEffects()) + return false; + if (!wxRichTextBitlistsEqPartial(attr1.GetTextEffects(), attr2.GetTextEffects(), attr2.GetTextEffectFlags())) + return false; + } + + if ((flags & wxTEXT_ATTR_OUTLINE_LEVEL) && + (attr1.GetOutlineLevel() != attr2.GetOutlineLevel())) + return false; + return true; } @@ -6575,7 +6634,6 @@ bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2) return true; } - /// Apply one style to another bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style) { @@ -6683,13 +6741,29 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style) if (style.HasPageBreak()) destStyle.SetPageBreak(); + if (style.HasTextEffects()) + { + int destBits = destStyle.GetTextEffects(); + int destFlags = destStyle.GetTextEffectFlags(); + + int srcBits = style.GetTextEffects(); + int srcFlags = style.GetTextEffectFlags(); + + wxRichTextCombineBitlists(destBits, srcBits, destFlags, srcFlags); + + destStyle.SetTextEffects(destBits); + destStyle.SetTextEffectFlags(destFlags); + } + + if (style.HasOutlineLevel()) + destStyle.SetOutlineLevel(style.GetOutlineLevel()); + return true; } bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style) { - wxTextAttrEx destStyle2; - destStyle.CopyTo(destStyle2); + wxTextAttrEx destStyle2 = destStyle; wxRichTextApplyStyle(destStyle2, style); destStyle = destStyle2; return true; @@ -6903,6 +6977,71 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, destStyle.SetPageBreak(); } + if (style.HasTextEffects()) + { + if (!(compareWith && compareWith->HasTextEffects() && compareWith->GetTextEffects() == style.GetTextEffects())) + { + int destBits = destStyle.GetTextEffects(); + int destFlags = destStyle.GetTextEffectFlags(); + + int srcBits = style.GetTextEffects(); + int srcFlags = style.GetTextEffectFlags(); + + wxRichTextCombineBitlists(destBits, srcBits, destFlags, srcFlags); + + destStyle.SetTextEffects(destBits); + destStyle.SetTextEffectFlags(destFlags); + } + } + + if (style.HasOutlineLevel()) + { + if (!(compareWith && compareWith->HasOutlineLevel() && compareWith->GetOutlineLevel() == style.GetOutlineLevel())) + destStyle.SetOutlineLevel(style.GetOutlineLevel()); + } + + return true; +} + +/// Combine two bitlists, specifying the bits of interest with separate flags. +bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB) +{ + // We want to apply B's bits to A, taking into account each's flags which indicate which bits + // are to be taken into account. A zero in B's bits should reset that bit in A but only if B's flags + // indicate it. + + // First, reset the 0 bits from B. We make a mask so we're only dealing with B's zero + // bits at this point, ignoring any 1 bits in B or 0 bits in B that are not relevant. + int valueA2 = ~(~valueB & flagsB) & valueA; + + // Now combine the 1 bits. + int valueA3 = (valueB & flagsB) | valueA2; + + valueA = valueA3; + flagsA = (flagsA | flagsB); + + return true; +} + +/// Compare two bitlists +bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags) +{ + int relevantBitsA = valueA & flags; + int relevantBitsB = valueB & flags; + return (relevantBitsA != relevantBitsB); +} + +/// Split into paragraph and character styles +bool wxRichTextSplitParaCharStyles(const wxTextAttrEx& style, wxTextAttrEx& parStyle, wxTextAttrEx& charStyle) +{ + wxTextAttrEx defaultCharStyle1(style); + wxTextAttrEx defaultParaStyle1(style); + defaultCharStyle1.SetFlags(defaultCharStyle1.GetFlags()&wxTEXT_ATTR_CHARACTER); + defaultParaStyle1.SetFlags(defaultParaStyle1.GetFlags()&wxTEXT_ATTR_PARAGRAPH); + + wxRichTextApplyStyle(charStyle, defaultCharStyle1); + wxRichTextApplyStyle(parStyle, defaultParaStyle1); + return true; } @@ -7014,6 +7153,9 @@ void wxRichTextAttr::Init() m_paragraphSpacingBefore = 0; m_lineSpacing = 0; m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE; + m_textEffects = wxTEXT_ATTR_EFFECT_NONE; + m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE; + m_outlineLevel = 0; m_bulletNumber = 0; } @@ -7034,6 +7176,8 @@ void wxRichTextAttr::Copy(const wxRichTextAttr& attr) m_fontWeight = attr.m_fontWeight; m_fontUnderlined = attr.m_fontUnderlined; m_fontFaceName = attr.m_fontFaceName; + m_textEffects = attr.m_textEffects; + m_textEffectFlags = attr.m_textEffectFlags; m_paragraphSpacingAfter = attr.m_paragraphSpacingAfter; m_paragraphSpacingBefore = attr.m_paragraphSpacingBefore; @@ -7046,6 +7190,7 @@ void wxRichTextAttr::Copy(const wxRichTextAttr& attr) m_bulletText = attr.m_bulletText; m_bulletFont = attr.m_bulletFont; m_bulletName = attr.m_bulletName; + m_outlineLevel = attr.m_outlineLevel; m_urlTarget = attr.m_urlTarget; } @@ -7059,6 +7204,8 @@ void wxRichTextAttr::operator= (const wxRichTextAttr& attr) // operators void wxRichTextAttr::operator= (const wxTextAttrEx& attr) { + m_flags = attr.GetFlags(); + m_colText = attr.GetTextColour(); m_colBack = attr.GetBackgroundColour(); m_textAlignment = attr.GetAlignment(); @@ -7066,7 +7213,8 @@ void wxRichTextAttr::operator= (const wxTextAttrEx& attr) m_leftSubIndent = attr.GetLeftSubIndent(); m_rightIndent = attr.GetRightIndent(); m_tabs = attr.GetTabs(); - m_flags = attr.GetFlags(); + m_textEffects = attr.GetTextEffects(); + m_textEffectFlags = attr.GetTextEffectFlags(); m_paragraphSpacingAfter = attr.GetParagraphSpacingAfter(); m_paragraphSpacingBefore = attr.GetParagraphSpacingBefore(); @@ -7079,6 +7227,7 @@ void wxRichTextAttr::operator= (const wxTextAttrEx& attr) m_bulletText = attr.GetBulletText(); m_bulletName = attr.GetBulletName(); m_bulletFont = attr.GetBulletFont(); + m_outlineLevel = attr.GetOutlineLevel(); m_urlTarget = attr.GetURL(); @@ -7090,7 +7239,32 @@ void wxRichTextAttr::operator= (const wxTextAttrEx& attr) wxRichTextAttr::operator wxTextAttrEx () const { wxTextAttrEx attr; - CopyTo(attr); + attr.SetTextColour(GetTextColour()); + attr.SetBackgroundColour(GetBackgroundColour()); + attr.SetAlignment(GetAlignment()); + attr.SetTabs(GetTabs()); + attr.SetLeftIndent(GetLeftIndent(), GetLeftSubIndent()); + attr.SetRightIndent(GetRightIndent()); + attr.SetFont(CreateFont()); + + attr.SetParagraphSpacingAfter(m_paragraphSpacingAfter); + attr.SetParagraphSpacingBefore(m_paragraphSpacingBefore); + attr.SetLineSpacing(m_lineSpacing); + attr.SetBulletStyle(m_bulletStyle); + attr.SetBulletNumber(m_bulletNumber); + attr.SetBulletText(m_bulletText); + attr.SetBulletName(m_bulletName); + attr.SetBulletFont(m_bulletFont); + attr.SetCharacterStyleName(m_characterStyleName); + attr.SetParagraphStyleName(m_paragraphStyleName); + attr.SetListStyleName(m_listStyleName); + attr.SetTextEffects(m_textEffects); + attr.SetTextEffectFlags(m_textEffectFlags); + attr.SetOutlineLevel(m_outlineLevel); + + attr.SetURL(m_urlTarget); + + attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags return attr; } @@ -7121,41 +7295,18 @@ bool wxRichTextAttr::operator== (const wxRichTextAttr& attr) const GetBulletFont() == attr.GetBulletFont() && GetBulletName() == attr.GetBulletName() && - m_fontSize == attr.m_fontSize && - m_fontStyle == attr.m_fontStyle && - m_fontWeight == attr.m_fontWeight && - m_fontUnderlined == attr.m_fontUnderlined && - m_fontFaceName == attr.m_fontFaceName && - - m_urlTarget == attr.m_urlTarget; -} - -// Copy to a wxTextAttr -void wxRichTextAttr::CopyTo(wxTextAttrEx& attr) const -{ - attr.SetTextColour(GetTextColour()); - attr.SetBackgroundColour(GetBackgroundColour()); - attr.SetAlignment(GetAlignment()); - attr.SetTabs(GetTabs()); - attr.SetLeftIndent(GetLeftIndent(), GetLeftSubIndent()); - attr.SetRightIndent(GetRightIndent()); - attr.SetFont(CreateFont()); - - attr.SetParagraphSpacingAfter(m_paragraphSpacingAfter); - attr.SetParagraphSpacingBefore(m_paragraphSpacingBefore); - attr.SetLineSpacing(m_lineSpacing); - attr.SetBulletStyle(m_bulletStyle); - attr.SetBulletNumber(m_bulletNumber); - attr.SetBulletText(m_bulletText); - attr.SetBulletName(m_bulletName); - attr.SetBulletFont(m_bulletFont); - attr.SetCharacterStyleName(m_characterStyleName); - attr.SetParagraphStyleName(m_paragraphStyleName); - attr.SetListStyleName(m_listStyleName); + GetTextEffects() == attr.GetTextEffects() && + GetTextEffectFlags() == attr.GetTextEffectFlags() && - attr.SetURL(m_urlTarget); + GetOutlineLevel() == attr.GetOutlineLevel() && - attr.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags + GetFontSize() == attr.GetFontSize() && + GetFontStyle() == attr.GetFontStyle() && + GetFontWeight() == attr.GetFontWeight() && + GetFontUnderlined() == attr.GetFontUnderlined() && + GetFontFaceName() == attr.GetFontFaceName() && + + GetURL() == attr.GetURL(); } // Create font from font attributes. @@ -7283,6 +7434,15 @@ wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr, if (attr.HasPageBreak()) newAttr.SetPageBreak(); + if (attr.HasTextEffects()) + { + newAttr.SetTextEffects(attr.GetTextEffects()); + newAttr.SetTextEffectFlags(attr.GetTextEffectFlags()); + } + + if (attr.HasOutlineLevel()) + newAttr.SetOutlineLevel(attr.GetOutlineLevel()); + return newAttr; } @@ -7302,7 +7462,10 @@ void wxTextAttrEx::Init() m_paragraphSpacingBefore = 0; m_lineSpacing = 0; m_bulletStyle = wxTEXT_ATTR_BULLET_STYLE_NONE; + m_textEffects = wxTEXT_ATTR_EFFECT_NONE; + m_textEffectFlags = wxTEXT_ATTR_EFFECT_NONE; m_bulletNumber = 0; + m_outlineLevel = 0; } // Copy @@ -7322,6 +7485,9 @@ void wxTextAttrEx::Copy(const wxTextAttrEx& attr) m_bulletFont = attr.m_bulletFont; m_bulletName = attr.m_bulletName; m_urlTarget = attr.m_urlTarget; + m_textEffects = attr.m_textEffects; + m_textEffectFlags = attr.m_textEffectFlags; + m_outlineLevel = attr.m_outlineLevel; } // Assignment from a wxTextAttrEx object @@ -7340,9 +7506,12 @@ void wxTextAttrEx::operator= (const wxTextAttr& attr) bool wxTextAttrEx::operator== (const wxTextAttrEx& attr) const { return ( + GetFlags() == attr.GetFlags() && GetTextColour() == attr.GetTextColour() && GetBackgroundColour() == attr.GetBackgroundColour() && GetFont() == attr.GetFont() && + GetTextEffects() == attr.GetTextEffects() && + GetTextEffectFlags() == attr.GetTextEffectFlags() && GetAlignment() == attr.GetAlignment() && GetLeftIndent() == attr.GetLeftIndent() && GetRightIndent() == attr.GetRightIndent() && @@ -7359,6 +7528,7 @@ bool wxTextAttrEx::operator== (const wxTextAttrEx& attr) const GetCharacterStyleName() == attr.GetCharacterStyleName() && GetParagraphStyleName() == attr.GetParagraphStyleName() && GetListStyleName() == attr.GetListStyleName() && + GetOutlineLevel() == attr.GetOutlineLevel() && GetURL() == attr.GetURL()); } @@ -7510,6 +7680,15 @@ wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr, if (attr.HasURL()) newAttr.SetURL(attr.GetURL()); + if (attr.HasTextEffects()) + { + newAttr.SetTextEffects(attr.GetTextEffects()); + newAttr.SetTextEffectFlags(attr.GetTextEffectFlags()); + } + + if (attr.HasOutlineLevel()) + newAttr.SetOutlineLevel(attr.GetOutlineLevel()); + return newAttr; } @@ -7582,12 +7761,12 @@ bool wxRichTextPlainTextHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStr } } + buffer->ResetAndClearCommands(); buffer->Clear(); buffer->AddParagraphs(str); buffer->UpdateRanges(); return true; - } bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)