]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied #13763 from dghart, to use primary selections if available
authorJulian Smart <julian@anthemion.co.uk>
Thu, 15 Dec 2011 11:32:58 +0000 (11:32 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 15 Dec 2011 11:32:58 +0000 (11:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70011 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/richtext/richtextctrl.cpp

index 466dc88569fcbadfcfef0d6dd6c5591fe8f698c6..0e1c0c1ed8709076314796facebba84a04700f23 100644 (file)
 #include "wx/fontenum.h"
 #include "wx/accel.h"
 
+#if defined (__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__)
+#define wxHAVE_PRIMARY_SELECTION 1
+#else
+#define wxHAVE_PRIMARY_SELECTION 0
+#endif
+
+#if wxUSE_CLIPBOARD && wxHAVE_PRIMARY_SELECTION
+#include "wx/clipbrd.h"
+#endif
+
 // DLL options compatibility check:
 #include "wx/app.h"
 WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl")
@@ -639,6 +649,19 @@ void wxRichTextCtrl::OnLeftUp(wxMouseEvent& event)
             }
         }
     }
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
+    if (HasSelection() && GetFocusObject() && GetFocusObject()->GetBuffer())
+    {
+        // Put the selection in PRIMARY, if it exists
+        wxTheClipboard->UsePrimarySelection(true);
+
+        wxRichTextRange range = GetInternalSelectionRange();
+        GetFocusObject()->GetBuffer()->CopyToClipboard(range);
+
+        wxTheClipboard->UsePrimarySelection(false);
+    }
+#endif
 }
 
 /// Left-click
@@ -839,6 +862,13 @@ void wxRichTextCtrl::OnMiddleClick(wxMouseEvent& event)
 
     if (!GetEventHandler()->ProcessEvent(cmdEvent))
         event.Skip();
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
+    // Paste any PRIMARY selection, if it exists
+    wxTheClipboard->UsePrimarySelection(true);
+    Paste();
+    wxTheClipboard->UsePrimarySelection(false);
+#endif
 }
 
 /// Key press