]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextctrl.cpp
Fixed #13833: wxRichTextCtrl: 'Copy' can grab an extra character
[wxWidgets.git] / src / richtext / richtextctrl.cpp
index 05b81428377332762bf60750c87383922dbd4fd7..83905493a164b107b543f561f77a8b7f7c212fa1 100644 (file)
@@ -125,6 +125,9 @@ public:
 
     void Notify();
 
+    bool GetRefreshEnabled() const { return m_refreshEnabled; }
+    void EnableRefresh(bool b) { m_refreshEnabled = b; }
+
 protected:
     virtual void DoShow();
     virtual void DoHide();
@@ -144,6 +147,7 @@ private:
     bool          m_flashOn;
     wxRichTextCaretTimer m_timer;
     wxRichTextCtrl* m_richTextCtrl;
+    bool          m_refreshEnabled;
 };
 #endif
 
@@ -406,6 +410,11 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 #if !wxRICHTEXT_USE_OWN_CARET
     if (GetCaret() && !IsFrozen())
         GetCaret()->Hide();
+#else
+    // Stop the caret refreshing the control from within the
+    // paint handler
+    if (GetCaret())
+        ((wxRichTextCaret*) GetCaret())->EnableRefresh(false);
 #endif
 
     {
@@ -460,6 +469,7 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
 #if wxRICHTEXT_USE_OWN_CARET
         if (GetCaret()->IsVisible())
         {
+            PositionCaret();
             ((wxRichTextCaret*) GetCaret())->DoDraw(& dc);
         }
 #endif
@@ -470,10 +480,8 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         GetCaret()->Show();
     PositionCaret();
 #else
-#if !defined(__WXMAC__)
-    // Causes caret dropouts on Mac
-    PositionCaret();
-#endif
+    if (GetCaret())
+        ((wxRichTextCaret*) GetCaret())->EnableRefresh(true);
 #endif
 }
 
@@ -564,7 +572,7 @@ void wxRichTextCtrl::OnLeftClick(wxMouseEvent& event)
 
 #if wxUSE_DRAG_AND_DROP
     // If there's no selection, or we're not inside it, this isn't an attempt to initiate Drag'n'Drop
-    if (HasSelection() && GetSelectionRange().ToInternal().Contains(position))
+    if (IsEditable() && HasSelection() && GetSelectionRange().ToInternal().Contains(position))
     {
         // This might be an attempt at initiating Drag'n'Drop. So set the time & flags
         m_preDrag = true;
@@ -4413,6 +4421,7 @@ bool wxRichTextDropSource::GiveFeedback(wxDragResult WXUNUSED(effect))
 void wxRichTextCaret::Init()
 {
     m_hasFocus = true;
+    m_refreshEnabled = true;
 
     m_xOld =
     m_yOld = -1;
@@ -4457,7 +4466,7 @@ void wxRichTextCaret::DoMove()
 
         if (m_xOld != -1 && m_yOld != -1)
         {
-            if (m_richTextCtrl)
+            if (m_richTextCtrl && m_refreshEnabled)
             {
                 wxRect rect(GetPosition(), GetSize());
                 m_richTextCtrl->RefreshRect(rect, false);
@@ -4508,7 +4517,7 @@ void wxRichTextCaret::OnKillFocus()
 
 void wxRichTextCaret::Refresh()
 {
-    if (m_richTextCtrl)
+    if (m_richTextCtrl && m_refreshEnabled)
     {
         wxRect rect(GetPosition(), GetSize());
         m_richTextCtrl->RefreshRect(rect, false);