From 28a84486bdf54c8f8718f0fd77312b8a28553cdd Mon Sep 17 00:00:00 2001 From: oneeyeman1 Date: Sat, 4 May 2019 13:28:59 -0500 Subject: [PATCH] Implement wxClipboard::Flush() in wxGTK Update the documentation and also add a call of Flush() to the sample. Closes #10515. Closes https://github.com/wxWidgets/wxWidgets/pull/1316 --- include/wx/gtk/clipbrd.h | 5 +++++ interface/wx/clipbrd.h | 4 ++-- samples/clipboard/clipboard.cpp | 14 +++++++++++++- src/gtk/clipbrd.cpp | 6 ++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/wx/gtk/clipbrd.h b/include/wx/gtk/clipbrd.h index b2316067e5..588472e8c8 100644 --- a/include/wx/gtk/clipbrd.h +++ b/include/wx/gtk/clipbrd.h @@ -53,6 +53,11 @@ public: // fill data with data on the clipboard (if available) virtual bool GetData( wxDataObject& data ) wxOVERRIDE; + // flushes the clipboard; that means that the data which is currently on + // clipboard will stay available even after the application exits (possibly + // eating memory), otherwise the clipboard will be emptied on exit + virtual bool Flush() wxOVERRIDE; + // clears wxTheClipboard and the system's clipboard if possible virtual void Clear() wxOVERRIDE; diff --git a/interface/wx/clipbrd.h b/interface/wx/clipbrd.h index 21bd70b19a..d1d337123a 100644 --- a/interface/wx/clipbrd.h +++ b/interface/wx/clipbrd.h @@ -96,8 +96,8 @@ public: (possibly eating memory), otherwise the clipboard will be emptied on exit. - Currently this method is not implemented in X11-based ports, i.e. - wxGTK, wxX11 and wxMotif and always returns @false there. + Currently this method is implemented in MSW and GTK and always returns @false + otherwise. @return @false if the operation is unsuccessful for any reason. */ diff --git a/samples/clipboard/clipboard.cpp b/samples/clipboard/clipboard.cpp index 27e2836e76..5d86167607 100644 --- a/samples/clipboard/clipboard.cpp +++ b/samples/clipboard/clipboard.cpp @@ -50,6 +50,7 @@ public: void OnQuit(wxCommandEvent&event); void OnAbout(wxCommandEvent&event); + void OnFlush(wxCommandEvent &event); void OnWriteClipboardContents(wxCommandEvent&event); void OnUpdateUI(wxUpdateUIEvent&event); #if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST @@ -71,12 +72,14 @@ enum ID_Quit = wxID_EXIT, ID_About = wxID_ABOUT, ID_Write = 100, - ID_Text = 101 + ID_Text = 101, + ID_Flush = 102 }; wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_Quit, MyFrame::OnQuit) EVT_MENU(ID_About, MyFrame::OnAbout) + EVT_MENU(ID_Flush, MyFrame::OnFlush) EVT_BUTTON(ID_Write, MyFrame::OnWriteClipboardContents) EVT_UPDATE_UI(ID_Write, MyFrame::OnUpdateUI) #if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST @@ -116,6 +119,7 @@ MyFrame::MyFrame(const wxString& title) wxMenu *helpMenu = new wxMenu; helpMenu->Append(ID_About, "&About\tF1", "Show about dialog"); + fileMenu->Append(ID_Flush, "Flush the clipboard" ); fileMenu->Append(ID_Quit, "E&xit\tAlt-X", "Quit this program"); // now append the freshly created menu to the menu bar... @@ -137,6 +141,14 @@ MyFrame::MyFrame(const wxString& title) panel->SetSizer( main_sizer ); } +void MyFrame::OnFlush(wxCommandEvent &WXUNUSED(event)) +{ + if ( wxTheClipboard->Flush() ) + m_textctrl->SetValue( "Clipboard flushed successfully!!\n" ); + else + m_textctrl->SetValue( "Flushing clipboard failed!!\n" ); +} + void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event)) { if (wxTheClipboard->Open()) diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 1777b25a06..b1daebc085 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -593,6 +593,12 @@ void wxClipboard::Clear() m_formatSupported = false; } +bool wxClipboard::Flush() +{ + gtk_clipboard_store( gtk_clipboard_get( GTKGetClipboardAtom() ) ); + return true; +} + bool wxClipboard::Open() { wxCHECK_MSG( !m_open, false, wxT("clipboard already open") );