+ if (m_data)
+ {
+#if wxUSE_THREADS
+ /* disable GUI threads */
+#endif
+
+ // As we have data we also own the clipboard. Once we no longer own
+ // it, clear_selection is called which will set m_data to zero
+ if (gdk_selection_owner_get( g_clipboardAtom ) == m_clipboardWidget->window)
+ {
+ m_waiting = true;
+
+ gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom,
+ (guint32) GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+ }
+
+ if (gdk_selection_owner_get( GDK_SELECTION_PRIMARY ) == m_clipboardWidget->window)
+ {
+ m_waiting = true;
+
+ gtk_selection_owner_set( (GtkWidget*) NULL, GDK_SELECTION_PRIMARY,
+ (guint32) GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+ }
+
+ if (m_data)
+ {
+ delete m_data;
+ m_data = (wxDataObject*) NULL;
+ }
+
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+#endif
+ }
+
+ m_targetRequested = 0;
+ m_formatSupported = false;
+}
+
+bool wxClipboard::Open()
+{
+ wxCHECK_MSG( !m_open, false, wxT("clipboard already open") );
+
+ m_open = true;
+
+ return true;
+}
+
+bool wxClipboard::SetData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
+
+ wxCHECK_MSG( data, false, wxT("data is invalid") );
+
+ Clear();
+
+ return AddData( data );
+}
+
+bool wxClipboard::AddData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
+
+ wxCHECK_MSG( data, false, wxT("data is invalid") );
+
+ // we can only store one wxDataObject
+ Clear();
+
+ m_data = data;
+
+ // get formats from wxDataObjects
+ wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
+ m_data->GetAllFormats( array );
+
+ // primary selection or clipboard
+ GdkAtom clipboard = m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
+ : g_clipboardAtom;
+
+ // by default provide TIMESTAMP as a target
+ gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
+ clipboard,
+ g_timestampAtom,
+ 0 );
+
+ for (size_t i = 0; i < m_data->GetFormatCount(); i++)
+ {
+ wxLogTrace( TRACE_CLIPBOARD,
+ wxT("wxClipboard now supports atom %s"),
+ array[i].GetId().c_str() );
+
+// printf( "added %s\n",
+// gdk_atom_name( array[i].GetFormatId() ) );
+
+ gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
+ clipboard,
+ array[i],
+ 0 ); /* what is info ? */
+ }
+
+ delete[] array;
+
+ gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
+ "selection_get",
+ GTK_SIGNAL_FUNC(selection_handler),
+ GUINT_TO_POINTER( gdk_event_get_time(gtk_get_current_event()) ) );
+
+#if wxUSE_THREADS
+ /* disable GUI threads */
+#endif
+
+ /* Tell the world we offer clipboard data */
+ bool res = (gtk_selection_owner_set( m_clipboardWidget,
+ clipboard,
+ (guint32) GDK_CURRENT_TIME ));
+
+ if (m_usePrimary)
+ m_ownsPrimarySelection = res;
+ else
+ m_ownsClipboard = res;
+
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+#endif
+
+ return res;
+}
+
+void wxClipboard::Close()
+{
+ wxCHECK_RET( m_open, wxT("clipboard not open") );
+
+ m_open = false;