+ wxCHECK_MSG( m_open, FALSE, _T("clipboard not open") );
+
+ wxCHECK_MSG( data, FALSE, _T("data is invalid") );
+
+ /* if clipboard has been cleared before, create new data broker */
+ if (!m_dataBroker) m_dataBroker = new wxDataBroker();
+
+ /* add new data to list of offered data objects */
+ m_dataBroker->Add( data );
+
+ /* get native format id of new data object */
+ GdkAtom format = data->GetFormat().GetAtom();
+
+ wxCHECK_MSG( format, FALSE, _T("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
+
+// printf( "vorher.\n" );
+ /* Tell the world we offer clipboard data */
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ g_clipboardAtom,
+ GDK_CURRENT_TIME ))
+ {
+ return FALSE;
+ }
+ m_ownsClipboard = TRUE;
+
+// printf( "nachher.\n" );
+
+ return TRUE;
+
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ GDK_SELECTION_PRIMARY,
+ GDK_CURRENT_TIME ))
+ {
+ return FALSE;
+ }
+ m_ownsPrimarySelection = TRUE;
+
+ return TRUE;
+}
+
+void wxClipboard::Close()
+{
+ wxCHECK_RET( m_open, _T("clipboard not open") );
+
+ m_open = FALSE;
+}
+
+bool wxClipboard::IsSupported( wxDataFormat format )
+{
+ wxCHECK_MSG( m_open, FALSE, _T("clipboard not open") );
+
+ /* store requested format to be asked for by callbacks */
+
+ m_targetRequested = format.GetAtom();
+
+ wxCHECK_MSG( m_targetRequested, FALSE, _T("invalid clipboard format") );
+
+ m_formatSupported = FALSE;
+
+ /* perform query. this will set m_formatSupported to
+ TRUE if m_targetRequested is supported.
+ alsom we have to wait for the "answer" from the
+ clipboard owner which is an asynchronous process.
+ therefore we set m_waiting = TRUE here and wait
+ until the callback "targets_selection_received"
+ sets it to FALSE */
+
+ m_waiting = TRUE;
+
+ gtk_selection_convert( m_targetsWidget,
+ g_clipboardAtom,
+ g_targetsAtom,
+ GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+
+ if (!m_formatSupported) return FALSE;
+
+ return TRUE;
+}
+
+bool wxClipboard::GetData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, FALSE, _T("clipboard not open") );
+
+ /* is data supported by clipboard ? */
+
+ if (!IsSupported( data->GetFormat() )) return FALSE;
+
+ /* store pointer to data object to be filled up by callbacks */
+
+ m_receivedData = data;
+
+ /* store requested format to be asked for by callbacks */
+
+ m_targetRequested = data->GetFormat().GetAtom();
+
+ wxCHECK_MSG( m_targetRequested, FALSE, _T("invalid clipboard format") );
+
+ /* start query */
+
+ m_formatSupported = FALSE;
+
+ /* ask for clipboard contents. this will set
+ m_formatSupported to TRUE if m_targetRequested
+ is supported.
+ also, we have to wait for the "answer" from the
+ clipboard owner which is an asynchronous process.
+ therefore we set m_waiting = TRUE here and wait
+ until the callback "targets_selection_received"
+ sets it to FALSE */
+
+ m_waiting = TRUE;
+
+ gtk_selection_convert( m_clipboardWidget,
+ g_clipboardAtom,
+ m_targetRequested,
+ GDK_CURRENT_TIME );
+
+ while (m_waiting) gtk_main_iteration();
+
+ /* this is a true error as we checked for the presence of such data before */
+
+ wxCHECK_MSG( m_formatSupported, FALSE, _T("error retrieving data from clipboard") );
+
+ return TRUE;