-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, "clipboard already open" );
+
+ m_open = TRUE;
+
+ return TRUE;
+}
+
+bool wxClipboard::SetData( wxDataObject *data )
+{
+ wxCHECK_MSG( data, FALSE, "data is invalid" );
+
+ wxNode *node = m_dataObjects.First();
+
+ while (node)
+ {
+ wxDataObject *d = (wxDataObject*)node->Data();
+
+ if (d->GetFormat() == data->GetFormat())
+ {
+ m_dataObjects.DeleteNode( node );
+
+ break;
+ }
+
+ node = node->Next();
+ }
+
+ m_dataObjects.Append( data );
+
+ wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+
+ if (data->GetFormat() == wxDF_PRIVATE)
+ {
+ wxPrivateDataObject* pd = (wxPrivateDataObject*) data;
+
+ wxCHECK_MSG( !pd->GetId().IsEmpty(), FALSE, "private clipboard format requires ID string" );
+
+ data->m_formatAtom = GetTargetAtom( data->GetFormat(), pd->GetId() );
+ }
+ else
+ {
+ data->m_formatAtom = GetTargetAtom( data->GetFormat() );
+ }
+
+ // Add handlers if someone requests data
+
+ gtk_selection_add_handler( m_clipboardWidget,
+ g_clipboardAtom,
+ data->m_formatAtom,
+ selection_handler,
+ NULL );
+
+ // Tell the world we offer clipboard data
+
+ if (!gtk_selection_owner_set( m_clipboardWidget,
+ g_clipboardAtom,
+ GDK_CURRENT_TIME ))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void wxClipboard::Close()
+{
+ wxCHECK_RET( m_open, "clipboard not open" );
+
+ m_open = FALSE;
+}
+
+bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString &id )
+{
+ m_targetRequested = GetTargetAtom( format, id );
+
+ if (m_targetRequested == 0) return FALSE;
+
+ // add handler for target (= format) query
+
+ gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
+ "selection_received",
+ GTK_SIGNAL_FUNC( targets_selection_received ),
+ (gpointer) this );
+
+ m_formatSupported = FALSE;
+
+ // perform query. this will set m_formatSupported to
+ // TRUE if m_targetRequested is supported
+
+ 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;