- gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
- "selection_received",
- GTK_SIGNAL_FUNC( targets_selection_received ),
- (gpointer) this );
-
- m_formatSupported = FALSE;
-
- gtk_selection_convert( m_clipboardWidget,
- g_clipboardAtom,
- g_targetsAtom,
- GDK_CURRENT_TIME );
-
- gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget),
- GTK_SIGNAL_FUNC( targets_selection_received ),
- (gpointer) this );
-
- if (!m_formatSupported) return FALSE;
-
- return TRUE;
+ /* get native format id of new data object */
+ GdkAtom format = data->GetFormat();
+
+ wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
+
+ /* This should happen automatically, but to be on the safe side */
+ m_ownsClipboard = FALSE;
+ m_ownsPrimarySelection = FALSE;
+
+ /* Add handlers if someone requests data */
+
+#if (GTK_MINOR_VERSION > 0)
+
+ gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
+ GDK_SELECTION_PRIMARY,
+ format,
+ 0 ); /* what is info ? */
+
+ gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
+ g_clipboardAtom,
+ format,
+ 0 ); /* what is info ? */
+
+ gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
+ "selection_get",
+ GTK_SIGNAL_FUNC(selection_handler),
+ (gpointer) NULL );
+
+#else
+
+ gtk_selection_add_handler( m_clipboardWidget,
+ g_clipboardAtom,
+ format,
+ selection_handler,
+ (gpointer) NULL );
+
+ gtk_selection_add_handler( m_clipboardWidget,
+ GDK_SELECTION_PRIMARY,
+ format,
+ selection_handler,
+ (gpointer) NULL );
+#endif
+
+#if wxUSE_THREADS
+ /* disable GUI threads */
+ wxapp_uninstall_thread_wakeup();
+#endif
+
+ /* Tell the world we offer clipboard data */
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ g_clipboardAtom,
+ GDK_CURRENT_TIME ))
+ {
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+ wxapp_install_thread_wakeup();
+#endif
+ return FALSE;
+ }
+ m_ownsClipboard = TRUE;
+
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ GDK_SELECTION_PRIMARY,
+ GDK_CURRENT_TIME ))
+ {
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+ wxapp_install_thread_wakeup();
+#endif
+ return FALSE;
+ }
+ m_ownsPrimarySelection = TRUE;
+
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+ wxapp_install_thread_wakeup();
+#endif
+
+ return TRUE;