+/// The adjusted caret position is the character position adjusted to take
+/// into account whether we're at the start of a paragraph, in which case
+/// style information should be taken from the next position, not current one.
+long wxRichTextCtrl::GetAdjustedCaretPosition(long caretPos) const
+{
+ wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(caretPos+1);
+
+ if (para && (caretPos+1 == para->GetRange().GetStart()))
+ caretPos ++;
+ return caretPos;
+}
+
+/// Get/set the selection range in character positions. -1, -1 means no selection.
+/// The range is in API convention, i.e. a single character selection is denoted
+/// by (n, n+1)
+wxRichTextRange wxRichTextCtrl::GetSelectionRange() const
+{
+ wxRichTextRange range = GetInternalSelectionRange();
+ if (range != wxRichTextRange(-2,-2) && range != wxRichTextRange(-1,-1))
+ range.SetEnd(range.GetEnd() + 1);
+ return range;
+}
+
+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);
+}
+