+
+bool wxClipboard::IsSupported( const wxDataFormat& format )
+{
+ if ( DoIsSupported(format) )
+ return true;
+
+#if wxUSE_UNICODE
+ if ( format == wxDF_UNICODETEXT )
+ {
+ // also with plain STRING format
+ return DoIsSupported(g_altTextAtom);
+ }
+#endif // wxUSE_UNICODE
+
+ return false;
+}
+
+bool wxClipboard::GetData( wxDataObject& data )
+{
+ wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
+
+ // get all supported formats from wxDataObjects: notice that we are setting
+ // the object data, so we need them in "Set" direction
+ const size_t count = data.GetFormatCount(wxDataObject::Set);
+ wxDataFormatArray formats(new wxDataFormat[count]);
+ data.GetAllFormats(formats.get(), wxDataObject::Set);
+
+ for ( size_t i = 0; i < count; i++ )
+ {
+ const wxDataFormat format(formats[i]);
+
+ // is this format supported by clipboard ?
+ if ( !DoIsSupported(format) )
+ continue;
+
+ wxLogTrace(TRACE_CLIPBOARD, wxT("Requesting format %s"),
+ format.GetId().c_str());
+
+ // these variables will be used by our GTKOnSelectionReceived()
+ m_receivedData = &data;
+ m_formatSupported = false;
+
+ {
+ wxClipboardSync sync(*this);
+
+ gtk_selection_convert(m_clipboardWidget,
+ GTKGetClipboardAtom(),
+ format,
+ (guint32) GDK_CURRENT_TIME );
+ } // wait until we get the results
+
+ /*
+ Normally this is a true error as we checked for the presence of such
+ data before, but there are applications that may return an empty
+ string (e.g. Gnumeric-1.6.1 on Linux if an empty cell is copied)
+ which would produce a false error message here, so we check for the
+ size of the string first. With ANSI, GetDataSize returns an extra
+ value (for the closing null?), with unicode, the exact number of
+ tokens is given (that is more than 1 for non-ASCII characters)
+ (tested with Gnumeric-1.6.1 and OpenOffice.org-2.0.2)
+ */
+#if wxUSE_UNICODE
+ if ( format != wxDF_UNICODETEXT || data.GetDataSize(format) > 0 )
+#else // !UNICODE
+ if ( format != wxDF_TEXT || data.GetDataSize(format) > 1 )
+#endif // UNICODE / !UNICODE
+ {
+ wxCHECK_MSG( m_formatSupported, false,
+ wxT("error retrieving data from clipboard") );
+ }
+
+ return true;
+ }
+
+ wxLogTrace(TRACE_CLIPBOARD, wxT("GetData(): format not found"));
+
+ return false;
+}
+
+wxDataObject* wxClipboard::GTKGetDataObject( GdkAtom atom )
+{
+ if ( atom == GDK_NONE )
+ return Data();
+
+ if ( atom == GDK_SELECTION_PRIMARY )
+ {
+ wxLogTrace(TRACE_CLIPBOARD, wxT("Primary selection requested" ));
+
+ return Data( wxClipboard::Primary );
+ }
+ else if ( atom == g_clipboardAtom )
+ {
+ wxLogTrace(TRACE_CLIPBOARD, wxT("Clipboard data requested" ));
+
+ return Data( wxClipboard::Clipboard );
+ }
+ else // some other selection, we're not concerned
+ {
+ return (wxDataObject*)NULL;
+ }
+}
+
+#endif // wxUSE_CLIPBOARD