X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b53e5a2261d192bce49d40f0019f52f73b1557a..fd323a5e230f2b08227b307ff900698fb85d5519:/src/gtk1/clipbrd.cpp diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 253a7157a7..4314ac726b 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -13,6 +13,12 @@ #include "wx/clipbrd.h" +#if wxUSE_CLIPBOARD + +#include "glib.h" +#include "gdk/gdk.h" +#include "gtk/gtk.h" + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -152,14 +158,32 @@ selection_received( GtkWidget *WXUNUSED(widget), //----------------------------------------------------------------------------- static gint -selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event) ) +selection_clear_clip( GtkWidget *WXUNUSED(widget), GdkEventSelection *event ) { if (!wxTheClipboard) return TRUE; - - // the clipboard is no longer in our hands. we have to delete the - // clipboard data. - wxTheClipboard->m_dataObjects.Clear(); + if (event->selection == GDK_SELECTION_PRIMARY) + { + wxTheClipboard->m_ownsPrimarySelection = FALSE; + } + else + if (event->selection == g_clipboardAtom) + { + wxTheClipboard->m_ownsClipboard = FALSE; + } + else + { + return FALSE; + } + + if ((!wxTheClipboard->m_ownsPrimarySelection) && + (!wxTheClipboard->m_ownsClipboard)) + { + // the clipboard is no longer in our hands. we can the + // clipboard data. + + wxTheClipboard->m_dataObjects.Clear(); + } return TRUE; } @@ -247,6 +271,9 @@ wxClipboard::wxClipboard() { m_open = FALSE; + m_ownsClipboard = FALSE; + m_ownsPrimarySelection = FALSE; + m_dataObjects.DeleteContents( TRUE ); m_receivedData = (wxDataObject*) NULL; @@ -256,7 +283,7 @@ wxClipboard::wxClipboard() gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), "selection_clear_event", - GTK_SIGNAL_FUNC( selection_clear ), + GTK_SIGNAL_FUNC( selection_clear_clip ), (gpointer) NULL ); if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE ); @@ -281,11 +308,16 @@ void wxClipboard::Clear() /* As we have data we also own the clipboard. Once we no longer own it, clear_selection is called which will set m_data to zero */ - if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window) + if (gdk_selection_owner_get( g_clipboardAtom ) == m_clipboardWidget->window) { gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME ); } + if (gdk_selection_owner_get( GDK_SELECTION_PRIMARY ) == m_clipboardWidget->window) + { + gtk_selection_owner_set( (GtkWidget*) NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME ); + } + m_dataObjects.Clear(); } @@ -307,6 +339,22 @@ 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" ); @@ -323,7 +371,12 @@ bool wxClipboard::SetData( wxDataObject *data ) { data->m_formatAtom = GetTargetAtom( data->GetFormat() ); } + + // This should happen automatically + m_ownsClipboard = FALSE; + m_ownsPrimarySelection = FALSE; + // Add handlers if someone requests data gtk_selection_add_handler( m_clipboardWidget, @@ -332,6 +385,12 @@ bool wxClipboard::SetData( wxDataObject *data ) selection_handler, NULL ); + gtk_selection_add_handler( m_clipboardWidget, + GDK_SELECTION_PRIMARY, + data->m_formatAtom, + selection_handler, + NULL ); + // Tell the world we offer clipboard data if (!gtk_selection_owner_set( m_clipboardWidget, @@ -340,6 +399,15 @@ bool wxClipboard::SetData( wxDataObject *data ) { 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; } @@ -481,3 +549,8 @@ void wxClipboardModule::OnExit() if (wxTheClipboard) delete wxTheClipboard; wxTheClipboard = (wxClipboard*) NULL; } + +#endif + + // wxUSE_CLIPBOARD +