]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/clipbrd.cpp
The usual amount of trash over my telephone fixed
[wxWidgets.git] / src / gtk / clipbrd.cpp
index 253a7157a75b8ab9c27b7e37e4299ef22b95fe47..4314ac726b504ed67dc55ea4830eebd65951e2ef 100644 (file)
 
 #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
+