From 847c750b6991fb2ffba88fa79f5d3e47b35df522 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Mar 2024 19:33:50 +0100 Subject: [PATCH] Refactor clipboard selection in text sample Factor out the call to UsePrimarySelection() and accompanying comment in its own function. This doesn't make much sense yet, but will allow to avoid modifying two copies of this code and comment in the upcoming commits. No real changes yet. --- samples/text/text.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/samples/text/text.cpp b/samples/text/text.cpp index bf8b7050a0..b197abcde6 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -152,6 +152,10 @@ public: #endif // wxUSE_LOG private: +#if wxUSE_CLIPBOARD + void SelectClipboardSelection(); +#endif // wxUSE_CLIPBOARD + // get the currently focused text control or return the default one // (m_multitext) is no text ctrl has focus -- in any case, returns // something non null @@ -1309,12 +1313,17 @@ wxTextCtrl *MyPanel::GetFocusedText() const } #if wxUSE_CLIPBOARD -void MyPanel::DoPasteFromClipboard() +void MyPanel::SelectClipboardSelection() { // On X11, we want to get the data from the primary selection instead // of the normal clipboard (which isn't normal under X11 at all). This // call has no effect under MSW. wxTheClipboard->UsePrimarySelection(); +} + +void MyPanel::DoPasteFromClipboard() +{ + SelectClipboardSelection(); if (!wxTheClipboard->Open()) { @@ -1368,10 +1377,7 @@ void MyPanel::DoPasteFromClipboard() void MyPanel::DoCopyToClipboard() { - // On X11, we want to get the data from the primary selection instead - // of the normal clipboard (which isn't normal under X11 at all). This - // call has no effect under MSW. - wxTheClipboard->UsePrimarySelection(); + SelectClipboardSelection(); wxString text( GetFocusedText()->GetStringSelection() );