-void wxClipboard::SetData( wxDataObject *data )
-{
- if (m_data) delete m_data;
- m_data = data;
- if (!m_data) return;
-
- if (!gtk_selection_owner_set( m_clipboardWidget,
- g_clipboardAtom,
- GDK_CURRENT_TIME))
- {
- delete m_data;
- m_data = (wxDataObject*) NULL;
- return;
- }
-
- switch (m_data->GetPreferredFormat())
- {
-/*
- case wxDF_STRING:
- gtk_selection_add_handler( m_clipboardWidget,
- g_clipboardAtom,
- GDK_TARGET_STRING,
- selection_handler,
- NULL );
- break;
-*/
- case wxDF_TEXT:
- gtk_selection_add_handler( m_clipboardWidget,
- g_clipboardAtom,
- g_textAtom,
- selection_handler,
- NULL );
- break;
- default:
- break;
- }
+bool wxClipboard::Open()
+{
+ wxCHECK_MSG( !m_open, FALSE, _T("clipboard already open") );
+
+ m_open = TRUE;
+
+ return TRUE;
+}
+
+bool wxClipboard::SetData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, FALSE, _T("clipboard not open") );
+
+ wxCHECK_MSG( data, FALSE, _T("data is invalid") );
+
+ Clear();
+
+ return AddData( data );
+}
+
+bool wxClipboard::AddData( wxDataObject *data )
+{
+ 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
+
+ /* Tell the world we offer clipboard data */
+
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ g_clipboardAtom,
+ GDK_CURRENT_TIME ))
+ {
+ return FALSE;
+ }
+ m_ownsClipboard = TRUE;
+
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ GDK_SELECTION_PRIMARY,
+ GDK_CURRENT_TIME ))
+ {
+ return FALSE;
+ }
+ m_ownsPrimarySelection = TRUE;
+
+ return TRUE;