wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
-GdkAtom g_textAtom = 0;
GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0;
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
{
+ char *name = gdk_atom_name (atoms[i]);
+ if (name) printf( "Format available: %s.\n", name );
+
if (atoms[i] == clipboard->m_targetRequested)
{
clipboard->m_formatSupported = TRUE;
(gpointer) NULL );
if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
- if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
m_formatSupported = FALSE;
return TRUE;
}
-bool wxClipboard::SetData( wxDataBroker *data )
+bool wxClipboard::SetData( wxDataObject *data )
{
+ wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+
wxCHECK_MSG( data, FALSE, "data is invalid" );
Clear();
+
+ return AddData( data );
+}
+
+bool wxClipboard::AddData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
- m_dataBroker = data;
+ wxCHECK_MSG( data, FALSE, "data is invalid" );
- if (!m_dataBroker) return FALSE;
+ /* if clipboard has been cleared before, create new data broker */
- wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+ if (!m_dataBroker) m_dataBroker = new wxDataBroker();
- wxNode *node = m_dataBroker->m_dataObjects.First();
- while (node)
- {
- wxDataObject *dobj = (wxDataObject*)node->Data();
-
- GdkAtom format = dobj->GetFormat().GetAtom();
+ /* 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();
- if (format != (GdkAtom) 0)
- {
- /* This should happen automatically */
+ wxCHECK_MSG( format, FALSE, "data has invalid format" );
+
+ /* This should happen automatically, but to be on the safe side */
- m_ownsClipboard = FALSE;
- m_ownsPrimarySelection = FALSE;
+ m_ownsClipboard = FALSE;
+ m_ownsPrimarySelection = FALSE;
- /* Add handlers if someone requests data */
+ /* Add handlers if someone requests data */
- gtk_selection_add_handler( m_clipboardWidget,
+
+#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,
+ gtk_selection_add_handler( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
format,
selection_handler,
(gpointer) NULL );
+#endif
- /* Tell the world we offer clipboard data */
+ /* Tell the world we offer clipboard data */
- if (!gtk_selection_owner_set( m_clipboardWidget,
+ if (!gtk_selection_owner_set( m_clipboardWidget,
g_clipboardAtom,
GDK_CURRENT_TIME ))
- {
- return FALSE;
- }
- m_ownsClipboard = TRUE;
+ {
+ return FALSE;
+ }
+ m_ownsClipboard = TRUE;
- if (!gtk_selection_owner_set( m_clipboardWidget,
+ if (!gtk_selection_owner_set( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME ))
- {
- return FALSE;
- }
- m_ownsPrimarySelection = TRUE;
- }
-
- node = node->Next();
+ {
+ return FALSE;
}
-
+ m_ownsPrimarySelection = TRUE;
+
return TRUE;
}
m_open = FALSE;
}
-bool wxClipboard::GetData( wxDataObject *data )
+bool wxClipboard::IsSupported( wxDataFormat format )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
- m_receivedData = data;
-
- wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" );
-
- /* STEP ONE: check if there is such data in the clipboard */
+ /* store requested format to be asked for by callbacks */
- m_targetRequested = data->GetFormat().GetAtom();
+ m_targetRequested = format.GetAtom();
wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
- if (m_targetRequested == 0) return FALSE;
-
/* add handler for target (= format) query */
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
(gpointer) this );
if (!m_formatSupported) return FALSE;
+
+ return TRUE;
+}
+
+bool wxClipboard::GetData( wxDataObject *data )
+{
+ wxCHECK_MSG( m_open, FALSE, "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();
- /* STEP TWO: get the data from the clipboard */
+ wxCHECK_MSG( m_targetRequested, FALSE, "invalid clipboard format" );
+
+ /* start query */
m_formatSupported = FALSE;
GTK_SIGNAL_FUNC( selection_received ),
(gpointer) this );
+ /* ask for clipboard contents */
+
gtk_selection_convert( m_clipboardWidget,
g_clipboardAtom,
m_targetRequested,