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
This commit is contained in:
oneeyeman1
2019-05-04 13:28:59 -05:00
committed by Vadim Zeitlin
parent 02adddfa1a
commit 28a84486bd
4 changed files with 26 additions and 3 deletions

View File

@@ -53,6 +53,11 @@ public:
// fill data with data on the clipboard (if available) // fill data with data on the clipboard (if available)
virtual bool GetData( wxDataObject& data ) wxOVERRIDE; 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 // clears wxTheClipboard and the system's clipboard if possible
virtual void Clear() wxOVERRIDE; virtual void Clear() wxOVERRIDE;

View File

@@ -96,8 +96,8 @@ public:
(possibly eating memory), otherwise the clipboard will be emptied on (possibly eating memory), otherwise the clipboard will be emptied on
exit. exit.
Currently this method is not implemented in X11-based ports, i.e. Currently this method is implemented in MSW and GTK and always returns @false
wxGTK, wxX11 and wxMotif and always returns @false there. otherwise.
@return @false if the operation is unsuccessful for any reason. @return @false if the operation is unsuccessful for any reason.
*/ */

View File

@@ -50,6 +50,7 @@ public:
void OnQuit(wxCommandEvent&event); void OnQuit(wxCommandEvent&event);
void OnAbout(wxCommandEvent&event); void OnAbout(wxCommandEvent&event);
void OnFlush(wxCommandEvent &event);
void OnWriteClipboardContents(wxCommandEvent&event); void OnWriteClipboardContents(wxCommandEvent&event);
void OnUpdateUI(wxUpdateUIEvent&event); void OnUpdateUI(wxUpdateUIEvent&event);
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST #if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
@@ -71,12 +72,14 @@ enum
ID_Quit = wxID_EXIT, ID_Quit = wxID_EXIT,
ID_About = wxID_ABOUT, ID_About = wxID_ABOUT,
ID_Write = 100, ID_Write = 100,
ID_Text = 101 ID_Text = 101,
ID_Flush = 102
}; };
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit) EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout) EVT_MENU(ID_About, MyFrame::OnAbout)
EVT_MENU(ID_Flush, MyFrame::OnFlush)
EVT_BUTTON(ID_Write, MyFrame::OnWriteClipboardContents) EVT_BUTTON(ID_Write, MyFrame::OnWriteClipboardContents)
EVT_UPDATE_UI(ID_Write, MyFrame::OnUpdateUI) EVT_UPDATE_UI(ID_Write, MyFrame::OnUpdateUI)
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST #if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
@@ -116,6 +119,7 @@ MyFrame::MyFrame(const wxString& title)
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
helpMenu->Append(ID_About, "&About\tF1", "Show about dialog"); 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"); fileMenu->Append(ID_Quit, "E&xit\tAlt-X", "Quit this program");
// now append the freshly created menu to the menu bar... // now append the freshly created menu to the menu bar...
@@ -137,6 +141,14 @@ MyFrame::MyFrame(const wxString& title)
panel->SetSizer( main_sizer ); 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)) void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event))
{ {
if (wxTheClipboard->Open()) if (wxTheClipboard->Open())

View File

@@ -593,6 +593,12 @@ void wxClipboard::Clear()
m_formatSupported = false; m_formatSupported = false;
} }
bool wxClipboard::Flush()
{
gtk_clipboard_store( gtk_clipboard_get( GTKGetClipboardAtom() ) );
return true;
}
bool wxClipboard::Open() bool wxClipboard::Open()
{ {
wxCHECK_MSG( !m_open, false, wxT("clipboard already open") ); wxCHECK_MSG( !m_open, false, wxT("clipboard already open") );