Added pseudo-asynchronous clipboard implemenation to all ports excepts for GTK+
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57510 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -60,6 +60,9 @@ public:
|
|||||||
// ask if data in correct format is available
|
// ask if data in correct format is available
|
||||||
virtual bool IsSupported( const wxDataFormat& format ) = 0;
|
virtual bool IsSupported( const wxDataFormat& format ) = 0;
|
||||||
|
|
||||||
|
// ask if data in correct format is available
|
||||||
|
virtual bool IsSupportedAsync( wxEvtHandler *sink );
|
||||||
|
|
||||||
// fill data with data on the clipboard (if available)
|
// fill data with data on the clipboard (if available)
|
||||||
virtual bool GetData( wxDataObject& data ) = 0;
|
virtual bool GetData( wxDataObject& data ) = 0;
|
||||||
|
|
||||||
|
@@ -26,18 +26,23 @@
|
|||||||
#include "../sample.xpm"
|
#include "../sample.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define USE_ASYNCHRONOUS_CLIPBOARD_REQUEST 0
|
||||||
|
|
||||||
class MyApp : public wxApp
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
enum AsyncRequestState
|
enum AsyncRequestState
|
||||||
{
|
{
|
||||||
Idle,
|
Idle,
|
||||||
Waiting,
|
Waiting,
|
||||||
Finished
|
Finished
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class MyFrame : public wxFrame
|
class MyFrame : public wxFrame
|
||||||
{
|
{
|
||||||
@@ -48,12 +53,16 @@ public:
|
|||||||
void OnAbout(wxCommandEvent&event);
|
void OnAbout(wxCommandEvent&event);
|
||||||
void OnWriteClipboardContents(wxCommandEvent&event);
|
void OnWriteClipboardContents(wxCommandEvent&event);
|
||||||
void OnUpdateUI(wxUpdateUIEvent&event);
|
void OnUpdateUI(wxUpdateUIEvent&event);
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
void OnClipboardChange(wxClipboardEvent&event);
|
void OnClipboardChange(wxClipboardEvent&event);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTextCtrl *m_textctrl;
|
wxTextCtrl *m_textctrl;
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
AsyncRequestState m_request;
|
AsyncRequestState m_request;
|
||||||
bool m_clipboardSupportsText;
|
bool m_clipboardSupportsText;
|
||||||
|
#endif
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
@@ -71,7 +80,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(ID_About, MyFrame::OnAbout)
|
EVT_MENU(ID_About, MyFrame::OnAbout)
|
||||||
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
|
||||||
EVT_CLIPBOARD_CHANGED(MyFrame::OnClipboardChange)
|
EVT_CLIPBOARD_CHANGED(MyFrame::OnClipboardChange)
|
||||||
|
#endif
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
@@ -93,8 +104,10 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
// set the frame icon
|
// set the frame icon
|
||||||
SetIcon(wxICON(sample));
|
SetIcon(wxICON(sample));
|
||||||
|
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
m_request = Idle;
|
m_request = Idle;
|
||||||
m_clipboardSupportsText = false;
|
m_clipboardSupportsText = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if wxUSE_MENUS
|
#if wxUSE_MENUS
|
||||||
// create a menu bar
|
// create a menu bar
|
||||||
@@ -125,7 +138,7 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
panel->SetSizer( main_sizer );
|
panel->SetSizer( main_sizer );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnWriteClipboardContents(wxCommandEvent& event)
|
void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (wxTheClipboard->Open())
|
if (wxTheClipboard->Open())
|
||||||
{
|
{
|
||||||
@@ -141,14 +154,17 @@ void MyFrame::OnWriteClipboardContents(wxCommandEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
void MyFrame::OnClipboardChange(wxClipboardEvent&event)
|
void MyFrame::OnClipboardChange(wxClipboardEvent&event)
|
||||||
{
|
{
|
||||||
m_clipboardSupportsText = event.SupportsFormat( wxDF_UNICODETEXT );
|
m_clipboardSupportsText = event.SupportsFormat( wxDF_UNICODETEXT );
|
||||||
m_request = Finished;
|
m_request = Finished;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void MyFrame::OnUpdateUI(wxUpdateUIEvent&event)
|
void MyFrame::OnUpdateUI(wxUpdateUIEvent&event)
|
||||||
{
|
{
|
||||||
|
#if USE_ASYNCHRONOUS_CLIPBOARD_REQUEST
|
||||||
if (m_request == Idle)
|
if (m_request == Idle)
|
||||||
{
|
{
|
||||||
wxTheClipboard->IsSupportedAsync( this );
|
wxTheClipboard->IsSupportedAsync( this );
|
||||||
@@ -164,6 +180,9 @@ void MyFrame::OnUpdateUI(wxUpdateUIEvent&event)
|
|||||||
event.Enable( m_clipboardSupportsText );
|
event.Enable( m_clipboardSupportsText );
|
||||||
m_request = Idle;
|
m_request = Idle;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
event.Enable( wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
|
@@ -43,10 +43,20 @@ DEFINE_EVENT_TYPE(wxEVT_CLIPBOARD_CHANGED)
|
|||||||
|
|
||||||
bool wxClipboardEvent::SupportsFormat( const wxDataFormat &format ) const
|
bool wxClipboardEvent::SupportsFormat( const wxDataFormat &format ) const
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
// GTK has an asynchronnous API which reports
|
||||||
|
// the supported formats one by one.
|
||||||
|
// We may have to add X11 and Motif later.
|
||||||
wxVector<wxDataFormat>::size_type n;
|
wxVector<wxDataFormat>::size_type n;
|
||||||
for (n = 0; n < m_formats.size(); n++)
|
for (n = 0; n < m_formats.size(); n++)
|
||||||
{ if (m_formats[n] == format) return true; }
|
{ if (m_formats[n] == format) return true; }
|
||||||
return false;
|
return false;
|
||||||
|
#else
|
||||||
|
// All other ports just query the clipboard directly
|
||||||
|
// from here
|
||||||
|
wxClipboard* clipboard = (wxClipboard*) GetEventObject();
|
||||||
|
return clipboard->IsSupported( format );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboardEvent::AddFormat( const wxDataFormat &format )
|
void wxClipboardEvent::AddFormat( const wxDataFormat &format )
|
||||||
@@ -69,6 +79,19 @@ static wxClipboard *gs_clipboard = NULL;
|
|||||||
return gs_clipboard;
|
return gs_clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxClipboardBase::IsSupportedAsync( wxEvtHandler *sink )
|
||||||
|
{
|
||||||
|
// We just imitate an asynchronous API on most platforms.
|
||||||
|
// This method is overridden uner GTK.
|
||||||
|
wxClipboardEvent *event = new wxClipboardEvent(wxEVT_CLIPBOARD_CHANGED);
|
||||||
|
event->SetEventObject( this );
|
||||||
|
|
||||||
|
sink->QueueEvent( event );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxClipboardModule: module responsible for destroying the global clipboard
|
// wxClipboardModule: module responsible for destroying the global clipboard
|
||||||
// object
|
// object
|
||||||
|
@@ -362,6 +362,7 @@ async_targets_selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wxClipboardEvent *event = new wxClipboardEvent(wxEVT_CLIPBOARD_CHANGED);
|
wxClipboardEvent *event = new wxClipboardEvent(wxEVT_CLIPBOARD_CHANGED);
|
||||||
|
event->SetEventObject( clipboard );
|
||||||
|
|
||||||
if ( !selection_data || selection_data->length <= 0 )
|
if ( !selection_data || selection_data->length <= 0 )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user