From: Julian Smart Date: Wed, 7 Feb 2007 12:24:17 +0000 (+0000) Subject: Added flag for removing attributes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/aeb6ebe2a531d2d3125777f1fe6942d7416275bb Added flag for removing attributes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/richtextbuffer.tex b/docs/latex/wx/richtextbuffer.tex index 0879b6a764..fac7924d32 100644 --- a/docs/latex/wx/richtextbuffer.tex +++ b/docs/latex/wx/richtextbuffer.tex @@ -814,6 +814,7 @@ and not the content. This allows content styling to be preserved independently f \item wxRICHTEXT\_SETSTYLE\_CHARACTERS\_ONLY: specifies that the style should only be applied to characters, and not the paragraph. This allows content styling to be preserved independently from that of e.g. a named paragraph style. \item wxRICHTEXT\_SETSTYLE\_RESET: resets (clears) the existing style before applying the new style. +\item wxRICHTEXT\_SETSTYLE\_REMOVE: removes the specified style. Only the style flags are used in this operation. \end{itemize} \membersection{wxRichTextBuffer::SetStyleSheet}\label{wxrichtextbuffersetstylesheet} diff --git a/docs/latex/wx/richtextctrl.tex b/docs/latex/wx/richtextctrl.tex index deb1f91fba..58ebfb411c 100644 --- a/docs/latex/wx/richtextctrl.tex +++ b/docs/latex/wx/richtextctrl.tex @@ -1407,6 +1407,7 @@ and not the content. This allows content styling to be preserved independently f \item wxRICHTEXT\_SETSTYLE\_CHARACTERS\_ONLY: specifies that the style should only be applied to characters, and not the paragraph. This allows content styling to be preserved independently from that of e.g. a named paragraph style. \item wxRICHTEXT\_SETSTYLE\_RESET: resets (clears) the existing style before applying the new style. +\item wxRICHTEXT\_SETSTYLE\_REMOVE: removes the specified style. Only the style flags are used in this operation. \end{itemize} \membersection{wxRichTextCtrl::SetStyleSheet}\label{wxrichtextctrlsetstylesheet} diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 1eb2856bfa..2889221481 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -183,6 +183,9 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer; // Resets the existing style before applying the new style #define wxRICHTEXT_SETSTYLE_RESET 0x40 +// Removes the given style instead of applying it +#define wxRICHTEXT_SETSTYLE_REMOVE 0x80 + /*! * Flags for text insertion */ @@ -2319,6 +2322,9 @@ WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); +// Remove attributes +WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style); + /// Combine two bitlists WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB); diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index d0eaa2a810..47f1e8d8e3 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1561,11 +1561,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const bool parasOnly = ((flags & wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY) != 0); bool charactersOnly = ((flags & wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY) != 0); bool resetExistingStyle = ((flags & wxRICHTEXT_SETSTYLE_RESET) != 0); + bool removeStyle = ((flags & wxRICHTEXT_SETSTYLE_REMOVE) != 0); // Apply paragraph style first, if any wxRichTextAttr wholeStyle(style); - if (wholeStyle.HasParagraphStyleName() && GetStyleSheet()) + if (!removeStyle && wholeStyle.HasParagraphStyleName() && GetStyleSheet()) { wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(wholeStyle.GetParagraphStyleName()); if (def) @@ -1576,7 +1577,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const wxRichTextAttr characterAttributes(wholeStyle); characterAttributes.SetFlags(characterAttributes.GetFlags() & (wxTEXT_ATTR_CHARACTER)); - if (characterAttributes.HasCharacterStyleName() && GetStyleSheet()) + if (!removeStyle && characterAttributes.HasCharacterStyleName() && GetStyleSheet()) { wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterAttributes.GetCharacterStyleName()); if (def) @@ -1630,7 +1631,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const // to be included in the paragraph style if ((paragraphStyle || parasOnly) && !charactersOnly) { - if (resetExistingStyle) + if (removeStyle) + { + // Removes the given style from the paragraph + wxRichTextRemoveStyle(newPara->GetAttributes(), style); + } + else if (resetExistingStyle) newPara->GetAttributes() = wholeStyle; else { @@ -1705,7 +1711,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const { wxRichTextObject* child = node2->GetData(); - if (resetExistingStyle) + if (removeStyle) + { + // Removes the given style from the paragraph + wxRichTextRemoveStyle(child->GetAttributes(), style); + } + else if (resetExistingStyle) child->GetAttributes() = characterAttributes; else { @@ -7099,6 +7110,17 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, return true; } +// Remove attributes +bool wxRichTextRemoveStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style) +{ + int flags = style.GetFlags(); + int destFlags = destStyle.GetFlags(); + + destStyle.SetFlags(destFlags & ~flags); + + return true; +} + /// Combine two bitlists, specifying the bits of interest with separate flags. bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB) {