]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/clipbrd.cpp
don't return void values
[wxWidgets.git] / src / gtk / clipbrd.cpp
index 8f586d58ae5247ddb67aa00543fbb1b8ba487a77..e5aec7830b4a85b0ae521afabffc8e28e872b3e6 100644 (file)
@@ -18,9 +18,7 @@
 #include "wx/utils.h"
 #include "wx/log.h"
 
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
+#include "wx/gtk/private.h"
 
 //-----------------------------------------------------------------------------
 // thread system
@@ -35,6 +33,7 @@
 
 GdkAtom  g_clipboardAtom   = 0;
 GdkAtom  g_targetsAtom     = 0;
+GdkAtom  g_timestampAtom   = 0;
 
 #if defined(__WXGTK20__) && wxUSE_UNICODE
 extern GdkAtom g_altTextAtom;
@@ -87,7 +86,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
         GdkAtom type = selection_data->type;
         if ( type != GDK_SELECTION_TYPE_ATOM )
         {
-            if ( strcmp(gdk_atom_name(type), "TARGETS") )
+            if ( strcmp(wxGtkString(gdk_atom_name(type)), "TARGETS") )
             {
                 wxLogTrace( TRACE_CLIPBOARD,
                             _T("got unsupported clipboard target") );
@@ -243,7 +242,7 @@ selection_handler( GtkWidget *WXUNUSED(widget),
                    GtkSelectionData *selection_data,
                    guint WXUNUSED(info),
                    guint WXUNUSED(time),
-                   gpointer WXUNUSED(data) )
+                   gpointer signal_data )
 {
     if (!wxTheClipboard) return;
 
@@ -251,15 +250,34 @@ selection_handler( GtkWidget *WXUNUSED(widget),
 
     wxDataObject *data = wxTheClipboard->m_data;
 
+    // ICCCM says that TIMESTAMP is a required atom.
+    // In particular, it satisfies Klipper, which polls
+    // TIMESTAMP to see if the clipboards content has changed.
+    // It shall return the time which was used to set the data.
+    if (selection_data->target == g_timestampAtom)
+    {
+        uint timestamp = GPOINTER_TO_UINT (signal_data);
+        gtk_selection_data_set(selection_data,
+                               GDK_SELECTION_TYPE_INTEGER,
+                               32,
+                               (guchar*)&(timestamp),
+                               sizeof(timestamp));
+        wxLogTrace(TRACE_CLIPBOARD,
+                   _T("Clipboard TIMESTAMP requested, returning timestamp=%u"),
+                   timestamp);
+        return;
+    }
+
     wxDataFormat format( selection_data->target );
 
 #ifdef __WXDEBUG__
     wxLogTrace(TRACE_CLIPBOARD,
-               _T("clipboard data in format %s, GtkSelectionData is target=%s type=%s selection=%s"),
+               _T("clipboard data in format %s, GtkSelectionData is target=%s type=%s selection=%s timestamp=%u"),
                format.GetId().c_str(),
-               wxString::FromAscii(gdk_atom_name(selection_data->target)).c_str(),
-               wxString::FromAscii(gdk_atom_name(selection_data->type)).c_str(),
-               wxString::FromAscii(gdk_atom_name(selection_data->selection)).c_str()
+               wxString::FromAscii(wxGtkString(gdk_atom_name(selection_data->target))).c_str(),
+               wxString::FromAscii(wxGtkString(gdk_atom_name(selection_data->type))).c_str(),
+               wxString::FromAscii(wxGtkString(gdk_atom_name(selection_data->selection))).c_str(),
+               GPOINTER_TO_UINT( signal_data )
                );
 #endif
 
@@ -282,7 +300,7 @@ selection_handler( GtkWidget *WXUNUSED(widget),
         gtk_selection_data_set_text(
             selection_data,
             (const gchar*)d,
-            size-1 );
+            size );
     }
     else
     {
@@ -291,7 +309,7 @@ selection_handler( GtkWidget *WXUNUSED(widget),
             GDK_SELECTION_TYPE_STRING,
             8*sizeof(gchar),
             (unsigned char*) d,
-            size-1 );
+            size );
     }
 
     free(d);
@@ -320,28 +338,23 @@ wxClipboard::wxClipboard()
     m_targetsWidget = gtk_window_new( GTK_WINDOW_POPUP );
     gtk_widget_realize( m_targetsWidget );
 
-    gtk_signal_connect( GTK_OBJECT(m_targetsWidget),
-                        "selection_received",
-                        GTK_SIGNAL_FUNC( targets_selection_received ),
-                        (gpointer) this );
+    g_signal_connect (m_targetsWidget, "selection_received",
+                      G_CALLBACK (targets_selection_received), this);
 
     /* we use m_clipboardWidget to get and to offer data */
 
     m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
     gtk_widget_realize( m_clipboardWidget );
 
-    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
-                        "selection_received",
-                        GTK_SIGNAL_FUNC( selection_received ),
-                        (gpointer) this );
+    g_signal_connect (m_clipboardWidget, "selection_received",
+                      G_CALLBACK (selection_received), this);
 
-    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
-                        "selection_clear_event",
-                        GTK_SIGNAL_FUNC( selection_clear_clip ),
-                        (gpointer) NULL );
+    g_signal_connect (m_clipboardWidget, "selection_clear_event",
+                      G_CALLBACK (selection_clear_clip), NULL);
 
     if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
     if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
+    if (!g_timestampAtom) g_timestampAtom = gdk_atom_intern ("TIMESTAMP", FALSE);
 
     m_formatSupported = FALSE;
     m_targetRequested = 0;
@@ -441,6 +454,11 @@ bool wxClipboard::AddData( wxDataObject *data )
     GdkAtom clipboard = m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                                      : g_clipboardAtom;
 
+    // by default provide TIMESTAMP as a target
+    gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
+                              clipboard,
+                              g_timestampAtom,
+                              0 );
 
     for (size_t i = 0; i < m_data->GetFormatCount(); i++)
     {
@@ -459,10 +477,9 @@ bool wxClipboard::AddData( wxDataObject *data )
 
     delete[] array;
 
-    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
-                        "selection_get",
-                        GTK_SIGNAL_FUNC(selection_handler),
-                        (gpointer) NULL );
+    g_signal_connect (m_clipboardWidget, "selection_get",
+                      G_CALLBACK (selection_handler),
+                      GUINT_TO_POINTER (gtk_get_current_event_time()) );
 
 #if wxUSE_THREADS
     /* disable GUI threads */
@@ -639,4 +656,3 @@ bool wxClipboard::GetData( wxDataObject& data )
 
 #endif
   // wxUSE_CLIPBOARD
-