From a7ed48a590148899ebc92f1411a1e22a749fccb2 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 15 Nov 2006 15:59:06 +0000 Subject: [PATCH 1/1] Small bug fixes Added GetStyleForRange to wxRichTextCtrl HasCharacter/ParagraphAttributes range now consistent with other functions in wxRichTextCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43432 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextctrl.h | 12 ++++++++---- src/richtext/richtextbuffer.cpp | 4 +++- src/richtext/richtextctrl.cpp | 28 +++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index 2c6d93de7a..59842b1a14 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -184,6 +184,10 @@ public: virtual bool GetStyle(long position, wxTextAttrEx& style); virtual bool GetStyle(long position, wxRichTextAttr& style); + // get the common set of styles for the range + virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); + virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style); + // extended style setting operation with flags including: // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY // see richtextbuffer.h for more details. @@ -526,11 +530,11 @@ public: /// flags indicating which attributes are of interest. virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const { - return GetBuffer().HasCharacterAttributes(range, style); + return GetBuffer().HasCharacterAttributes(range.ToInternal(), style); } virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const { - return GetBuffer().HasCharacterAttributes(range, style); + return GetBuffer().HasCharacterAttributes(range.ToInternal(), style); } /// Test if this whole range has paragraph attributes of the specified kind. If any @@ -539,11 +543,11 @@ public: /// flags indicating which attributes are of interest. virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const { - return GetBuffer().HasParagraphAttributes(range, style); + return GetBuffer().HasParagraphAttributes(range.ToInternal(), style); } virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const { - return GetBuffer().HasParagraphAttributes(range, style); + return GetBuffer().HasParagraphAttributes(range.ToInternal(), style); } /// Is all of the selection bold? diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index fceaaf7dc1..0b1841d64c 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1647,7 +1647,9 @@ 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) { diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index bac9d50f61..2adf35ae03 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -2525,6 +2525,24 @@ bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style) return GetBuffer().GetStyle(position, style); } +// get the common set of styles for the range +bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style) +{ + wxTextAttrEx styleEx; + if (GetBuffer().GetStyleForRange(range.ToInternal(), styleEx)) + { + style = styleEx; + return true; + } + else + return false; +} + +bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style) +{ + return GetBuffer().GetStyleForRange(range.ToInternal(), style); +} + /// Get the content (uncombined) attributes for this position. bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttr& style) @@ -2705,7 +2723,7 @@ bool wxRichTextCtrl::IsSelectionBold() if (HasSelection()) { wxRichTextAttr attr; - wxRichTextRange range = GetInternalSelectionRange(); + wxRichTextRange range = GetSelectionRange(); attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT); attr.SetFontWeight(wxBOLD); @@ -2734,7 +2752,7 @@ bool wxRichTextCtrl::IsSelectionItalics() { if (HasSelection()) { - wxRichTextRange range = GetInternalSelectionRange(); + wxRichTextRange range = GetSelectionRange(); wxRichTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC); attr.SetFontStyle(wxITALIC); @@ -2764,7 +2782,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() { if (HasSelection()) { - wxRichTextRange range = GetInternalSelectionRange(); + wxRichTextRange range = GetSelectionRange(); wxRichTextAttr attr; attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE); attr.SetFontUnderlined(true); @@ -2836,9 +2854,9 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) { wxRichTextRange range; if (HasSelection()) - range = GetInternalSelectionRange(); + range = GetSelectionRange(); else - range = wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+1); + range = wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2); wxRichTextAttr attr; attr.SetAlignment(alignment); -- 2.45.2