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.
This commit is contained in:
Vadim Zeitlin
2024-03-21 18:20:47 +01:00
parent 9a390265bb
commit 847c750b69
+11 -5
View File
@@ -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() );