X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e28b7c297c0aff2b9c74e8f9fada9dd95d2f448a..d3eec3b672ed275fb3b0ab520b8e2464e699cb16:/samples/clipboard/clipboard.cpp diff --git a/samples/clipboard/clipboard.cpp b/samples/clipboard/clipboard.cpp index 3a39b22218..faaa532c72 100644 --- a/samples/clipboard/clipboard.cpp +++ b/samples/clipboard/clipboard.cpp @@ -1,15 +1,15 @@ ///////////////////////////////////////////////////////////////////////////// // Name: clipboard.cpp -// Purpose: clipbaord wxWidgets sample +// Purpose: clipboard wxWidgets sample // Author: Robert Roebling -// RCS-ID: $Id: minimal.cpp 53461 2008-05-05 23:30:33Z VZ $ +// RCS-ID: $Id$ // Copyright: (c) Robert Roebling // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" - + #ifdef __BORLANDC__ #pragma hdrstop #endif @@ -26,18 +26,23 @@ #include "../sample.xpm" #endif + +#define USE_ASYNCHRONOUS_CLIPBOARD_REQUEST 0 + class MyApp : public wxApp { public: virtual bool OnInit(); }; +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST enum AsyncRequestState { Idle, Waiting, Finished }; +#endif class MyFrame : public wxFrame { @@ -48,12 +53,16 @@ public: void OnAbout(wxCommandEvent&event); void OnWriteClipboardContents(wxCommandEvent&event); void OnUpdateUI(wxUpdateUIEvent&event); +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST void OnClipboardChange(wxClipboardEvent&event); +#endif private: wxTextCtrl *m_textctrl; +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST AsyncRequestState m_request; bool m_clipboardSupportsText; +#endif DECLARE_EVENT_TABLE() }; @@ -71,7 +80,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_About, MyFrame::OnAbout) EVT_BUTTON(ID_Write, MyFrame::OnWriteClipboardContents) EVT_UPDATE_UI(ID_Write, MyFrame::OnUpdateUI) +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST EVT_CLIPBOARD_CHANGED(MyFrame::OnClipboardChange) +#endif END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -83,7 +94,7 @@ bool MyApp::OnInit() MyFrame *frame = new MyFrame("wxClipboard sample"); frame->Show(true); - + return true; } @@ -92,9 +103,11 @@ MyFrame::MyFrame(const wxString& title) { // set the frame icon SetIcon(wxICON(sample)); - + +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST m_request = Idle; m_clipboardSupportsText = false; +#endif #if wxUSE_MENUS // create a menu bar @@ -116,7 +129,7 @@ MyFrame::MyFrame(const wxString& title) #endif // wxUSE_MENUS wxPanel *panel = new wxPanel( this, -1 ); - + wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); main_sizer->Add( new wxButton( panel, ID_Write, "Get clipboard text" ) ); m_textctrl = new wxTextCtrl( panel, ID_Text, "", wxDefaultPosition, @@ -125,7 +138,7 @@ MyFrame::MyFrame(const wxString& title) panel->SetSizer( main_sizer ); } -void MyFrame::OnWriteClipboardContents(wxCommandEvent& event) +void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event)) { if (wxTheClipboard->Open()) { @@ -135,26 +148,34 @@ void MyFrame::OnWriteClipboardContents(wxCommandEvent& event) wxTheClipboard->GetData( data ); m_textctrl->Clear(); m_textctrl->SetValue( data.GetText() ); - + } wxTheClipboard->Close(); } } +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST void MyFrame::OnClipboardChange(wxClipboardEvent&event) { m_clipboardSupportsText = event.SupportsFormat( wxDF_UNICODETEXT ); m_request = Finished; } +#endif void MyFrame::OnUpdateUI(wxUpdateUIEvent&event) { +#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST if (m_request == Idle) { - wxTheClipboard->IsSupportedAsync( this ); + if (!wxTheClipboard->IsSupportedAsync( this )) + { + // request failed, try again later + event.Enable( m_clipboardSupportsText ); // not yet known, assume last value + return; + } m_request = Waiting; event.Enable( m_clipboardSupportsText ); // not yet known, assume last value - } + } else if (m_request == Waiting) { event.Enable( m_clipboardSupportsText ); // not yet known, assume last value @@ -164,6 +185,9 @@ void MyFrame::OnUpdateUI(wxUpdateUIEvent&event) event.Enable( m_clipboardSupportsText ); m_request = Idle; } +#else + event.Enable( wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) ); +#endif } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -174,6 +198,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { + wxMessageBox("Clipboard sample", "About clipboard", wxOK|wxICON_INFORMATION, this); }