#include "../sample.xpm"
#endif
+
+#define USE_ASYNCHRONOUS_CLIPBOARD_REQUEST 1
+
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
+#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
enum AsyncRequestState
{
Idle,
Waiting,
Finished
};
+#endif
class MyFrame : public wxFrame
{
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()
};
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)
// 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
panel->SetSizer( main_sizer );
}
-void MyFrame::OnWriteClipboardContents(wxCommandEvent& event)
+void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event))
{
if (wxTheClipboard->Open())
{
}
}
+#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
}
event.Enable( m_clipboardSupportsText );
m_request = Idle;
}
+#else
+ event.Enable( wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) );
+#endif
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))