psppire-data-sheet: Obtain data sheet targets via callback.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 6 May 2013 01:04:03 +0000 (18:04 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 6 May 2013 01:04:25 +0000 (18:04 -0700)
Calling gtk_clipboard_wait_is_target_available() within on_owner_change()
seems to cause Window|Split to act oddly (the right panes were empty),
perhaps because gtk_clipboard_wait_is_target_available() has a nested main
loop.  Switching to gtk_clipboard_request_targets() fixes the problem.

Reported by John Darrington.

src/ui/gui/psppire-data-sheet.c

index f2cdc5bd5e77ce0b425b9aeaf5c1721b4abc3485..201fa8cd79cd9e0d3102986545b3c99a84b0b060 100644 (file)
@@ -2474,23 +2474,40 @@ psppire_data_sheet_clip_received_cb (GtkClipboard *clipboard,
 }
 
 static void
-on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
+psppire_data_sheet_targets_received_cb (GtkClipboard *clipboard,
+                                        GdkAtom *atoms,
+                                        gint n_atoms,
+                                        gpointer data)
 {
-  PsppireDataSheet *data_sheet = PSPPIRE_DATA_SHEET (data);
-  gboolean compatible_target = FALSE;
-  GtkAction *action;
+  GtkAction *action = GTK_ACTION (data);
+  gboolean compatible_target;
   gint i;
 
+  compatible_target = FALSE;
   for (i = 0; i < G_N_ELEMENTS (targets); i++)
     {
-      GdkAtom atom = gdk_atom_intern (targets[i].target, TRUE);
-      if (gtk_clipboard_wait_is_target_available (clip, atom))
-        {
-          compatible_target = TRUE;
-          break;
-        }
+      GdkAtom target = gdk_atom_intern (targets[i].target, TRUE);
+      gint j;
+
+      for (j = 0; j < n_atoms; j++)
+        if (target == atoms[j])
+          {
+            compatible_target = TRUE;
+            break;
+          }
     }
 
-  action = get_action_assert (data_sheet->builder, "edit_paste");
   gtk_action_set_sensitive (action, compatible_target);
+  g_object_unref (action);
+}
+
+static void
+on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
+{
+  PsppireDataSheet *data_sheet = PSPPIRE_DATA_SHEET (data);
+  GtkAction *action = get_action_assert (data_sheet->builder, "edit_paste");
+
+  g_object_ref (action);
+  gtk_clipboard_request_targets (clip, psppire_data_sheet_targets_received_cb,
+                                 action);
 }