From 401e1d16ffe91fb71bfc85b621f5b8b2b0920e8b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Mar 2024 19:37:09 +0100 Subject: [PATCH] Allow selecting between primary and clipboard in text sample Add a menu item to switch between using the clipboard and primary selections. This finally makes UsePrimarySelection() call in the sample useful, after 25 years when it didn't do anything, since it was added back in 7e2c43b855 (...Added for primary selection to sample/text., 1999-06-10) --- samples/text/text.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/samples/text/text.cpp b/samples/text/text.cpp index bf4d3545d9..172128b090 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -410,6 +410,7 @@ enum TEXT_CLIPBOARD_COPY = 200, TEXT_CLIPBOARD_PASTE, TEXT_CLIPBOARD_VETO, + TEXT_CLIPBOARD_USE_PRIMARY, // tooltip menu TEXT_TOOLTIPS_SETDELAY = 300, @@ -491,6 +492,10 @@ bool MyApp::OnInit() menuClipboard->Append(TEXT_CLIPBOARD_PASTE, "&Paste\tCtrl-Shift-V", "Paste from clipboard to the text control"); menuClipboard->AppendSeparator(); + menuClipboard->AppendCheckItem(TEXT_CLIPBOARD_USE_PRIMARY, + "Use &primary selection\tCtrl-Shift-P", + "If checked, use primary selection instead of clipboard"); + menuClipboard->AppendSeparator(); menuClipboard->AppendCheckItem(TEXT_CLIPBOARD_VETO, "Vet&o\tCtrl-Shift-O", "Veto all clipboard operations"); menu_bar->Append(menuClipboard, "&Clipboard"); @@ -1315,9 +1320,11 @@ wxTextCtrl *MyPanel::GetFocusedText() const #if wxUSE_CLIPBOARD void MyPanel::SelectClipboardSelection() { - // On X11, we want to exchange data with the clipboard selection instead - // of the primary selection -- which is actually the case by default. - wxTheClipboard->UsePrimarySelection(false); + wxFrame *frame = wxDynamicCast(wxGetTopLevelParent(this), wxFrame); + wxCHECK_RET( frame, "no parent frame?" ); + + wxTheClipboard->UsePrimarySelection( + frame->GetMenuBar()->IsChecked(TEXT_CLIPBOARD_USE_PRIMARY)); } void MyPanel::DoPasteFromClipboard()