From e4db8a879fef81e8d75d32b471a3ffa262e4c04f Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 1 Feb 2010 12:07:28 +0000 Subject: [PATCH] Simplify SetSelectionRange and make consistent with SetSelection. Fix a bug that returns true for character and paragraph style tests if no characters or paragraphs were found. Fix SetSelection to position caret at end. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@63345 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/richtext/richtextbuffer.cpp | 4 ++-- src/richtext/richtextctrl.cpp | 16 +++++----------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b57c80e1aa..492a5d0fa5 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -120,6 +120,7 @@ All (GUI): - wxRTC: added wxRICHTEXT_HANDLER_USE_CSS flag for HTML handler to use CSS where possible. - wxRTC: corrected centring and right-justification spacing. +- wxRTC: corrected some problems with SelectAll. Caret is now set to end. - Paper size conversion from dimensions to id now uses definition ordering in order to use common types where there are duplications, fixing problems where invalid sizes caused incorrect second invocation of page setup diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 0a12324254..7e56e147a9 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -3012,7 +3012,7 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& node = node->GetNext(); } - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; } bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const @@ -3056,7 +3056,7 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& node = node->GetNext(); } - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; } bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 2d02453b18..1964551d13 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -2175,8 +2175,7 @@ wxRichTextRange wxRichTextCtrl::AddImage(const wxImage& image) void wxRichTextCtrl::SelectAll() { - SetSelection(0, GetLastPosition()+1); - m_selectionAnchor = -1; + SetSelection(-1, -1); } /// Select none @@ -2598,8 +2597,9 @@ void wxRichTextCtrl::DoSetSelection(long from, long to, bool WXUNUSED(scrollCare wxRichTextRange oldSelection = m_selectionRange; m_selectionAnchor = from; m_selectionRange.SetRange(from, to-1); - if (from > -2) - m_caretPosition = from-1; + + // Have to subtract 2, one because of endPos+1 rule (SetSelection docs) and another to turn into caret position. + m_caretPosition = wxMax(-1, to-2); wxRichTextCtrlRefreshForSelectionChange(*this, oldSelection, m_selectionRange); PositionCaret(); @@ -3420,13 +3420,7 @@ wxRichTextRange wxRichTextCtrl::GetSelectionRange() const void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange& range) { - wxRichTextRange range1(range); - if (range1 != wxRichTextRange(-2,-2) && range1 != wxRichTextRange(-1,-1) ) - range1.SetEnd(range1.GetEnd() - 1); - - wxASSERT( range1.GetStart() > range1.GetEnd() ); - - SetInternalSelectionRange(range1); + SetSelection(range.GetStart(), range.GetEnd()); } /// Set list style