+ Clear();
+
+ if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
+ if (m_targetsWidget) gtk_widget_destroy( m_targetsWidget );
+}
+
+void wxClipboard::Clear()
+{
+ 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;
+
+
+ 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),
+ (gpointer) NULL );
+
+#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;