+ if (m_data)
+ {
+#if wxUSE_THREADS
+ /* disable GUI threads */
+ wxapp_uninstall_thread_wakeup();
+#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 */
+ wxapp_install_thread_wakeup();
+#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++)
+ {
+ wxLogDebug( wxT("wxClipboard now supports atom %s"), array[i].GetId().c_str() );
+
+ 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 */
+ wxapp_uninstall_thread_wakeup();
+#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 */
+ wxapp_install_thread_wakeup();
+#endif
+
+ return res;
+}
+
+void wxClipboard::Close()
+{
+ wxCHECK_RET( m_open, wxT("clipboard not open") );
+
+ m_open = FALSE;
+}
+
+bool wxClipboard::IsOpened() const
+{
+ return m_open;