[gtk+] Fix Quartz clipboard image retrieval.



commit 3bf1151051045591243e23c900a01c55cc057d42
Author: John Ralls <jralls ceridwen us>
Date:   Thu Feb 11 13:49:07 2016 -0800

    Fix Quartz clipboard image retrieval.
    
    It does no good to iterate through a series of mime types to call a
    function when the eventually-called function,
    _gtk_quartz_get_selection_data_from_pasteboard() in this case, gives the
    wrong answer and stops the iteration on all but one especially if that
    one isn't first.
    
    The one is "image/tiff" and the quartz pasteboard function will return
    any image type Quartz knows about for it, so lose the iteration and use
    only "image/tiff".

 gtk/gtkclipboard-quartz.c |  119 +++++++++++++++++++++-----------------------
 1 files changed, 57 insertions(+), 62 deletions(-)
---
diff --git a/gtk/gtkclipboard-quartz.c b/gtk/gtkclipboard-quartz.c
index b0625f1..40f1c56 100644
--- a/gtk/gtkclipboard-quartz.c
+++ b/gtk/gtkclipboard-quartz.c
@@ -142,7 +142,7 @@ static GtkClipboard *clipboard_peek       (GdkDisplay       *display,
 {
   self = [super init];
 
-  if (self) 
+  if (self)
     {
       clipboard = aClipboard;
       setting_same_owner = FALSE;
@@ -164,7 +164,7 @@ GType
 gtk_clipboard_get_type (void)
 {
   static GType clipboard_type = 0;
-  
+
   if (!clipboard_type)
     {
       const GTypeInfo clipboard_info =
@@ -179,11 +179,11 @@ gtk_clipboard_get_type (void)
        0,              /* n_preallocs */
        (GInstanceInitFunc) NULL,
       };
-      
+
       clipboard_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkClipboard"),
                                               &clipboard_info, 0);
     }
-  
+
   return clipboard_type;
 }
 
@@ -193,7 +193,7 @@ gtk_clipboard_class_init (GtkClipboardClass *class)
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
 
   parent_class = g_type_class_peek_parent (class);
-  
+
   gobject_class->finalize = gtk_clipboard_finalize;
 
   class->owner_change = gtk_clipboard_owner_change;
@@ -227,7 +227,7 @@ gtk_clipboard_finalize (GObject *object)
     g_warning ("GtkClipboard prematurely finalized");
 
   clipboard_unset (clipboard);
-  
+
   clipboards = g_object_get_data (G_OBJECT (clipboard->display), "gtk-clipboard-list");
   clipboards = g_slist_remove (clipboards, clipboard);
   g_object_set_data (G_OBJECT (clipboard->display), I_("gtk-clipboard-list"), clipboards);
@@ -312,7 +312,7 @@ clipboard_owner_destroyed (gpointer data)
 
       tmp_list = tmp_list->next;
     }
-  
+
   g_slist_free (clipboards);
 }
 
@@ -321,7 +321,7 @@ clipboard_add_owner_notify (GtkClipboard *clipboard)
 {
   if (!clipboards_owned_key_id)
     clipboards_owned_key_id = g_quark_from_static_string (clipboards_owned_key);
-  
+
   if (clipboard->have_owner)
     g_object_set_qdata_full (clipboard->user_data, clipboards_owned_key_id,
                             g_slist_prepend (g_object_steal_qdata (clipboard->user_data,
@@ -502,12 +502,12 @@ clipboard_unset (GtkClipboard *clipboard)
   gpointer old_data;
   gboolean old_have_owner;
   gint old_n_storable_targets;
-  
+
   old_clear_func = clipboard->clear_func;
   old_data = clipboard->user_data;
   old_have_owner = clipboard->have_owner;
   old_n_storable_targets = clipboard->n_storable_targets;
-  
+
   if (old_have_owner)
     {
       clipboard_remove_owner_notify (clipboard);
@@ -522,7 +522,7 @@ clipboard_unset (GtkClipboard *clipboard)
   clipboard->get_func = NULL;
   clipboard->clear_func = NULL;
   clipboard->user_data = NULL;
-  
+
   if (old_clear_func)
     old_clear_func (clipboard, old_data);
 
@@ -548,7 +548,7 @@ gtk_clipboard_clear (GtkClipboard *clipboard)
   [clipboard->pasteboard declareTypes:nil owner:nil];
 }
 
-static void 
+static void
 text_get_func (GtkClipboard     *clipboard,
               GtkSelectionData *selection_data,
               guint             info,
@@ -557,14 +557,14 @@ text_get_func (GtkClipboard     *clipboard,
   gtk_selection_data_set_text (selection_data, data, -1);
 }
 
-static void 
+static void
 text_clear_func (GtkClipboard *clipboard,
                 gpointer      data)
 {
   g_free (data);
 }
 
-void 
+void
 gtk_clipboard_set_text (GtkClipboard *clipboard,
                        const gchar  *text,
                        gint          len)
@@ -573,11 +573,11 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
 
   g_return_if_fail (clipboard != NULL);
   g_return_if_fail (text != NULL);
-  
+
   if (len < 0)
     len = strlen (text);
-  
-  gtk_clipboard_set_with_data (clipboard, 
+
+  gtk_clipboard_set_with_data (clipboard,
                               &target, 1,
                               text_get_func, text_clear_func,
                               g_strndup (text, len));
@@ -585,7 +585,7 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
 }
 
 
-static void 
+static void
 pixbuf_get_func (GtkClipboard     *clipboard,
                 GtkSelectionData *selection_data,
                 guint             info,
@@ -594,7 +594,7 @@ pixbuf_get_func (GtkClipboard     *clipboard,
   gtk_selection_data_set_pixbuf (selection_data, data);
 }
 
-static void 
+static void
 pixbuf_clear_func (GtkClipboard *clipboard,
                   gpointer      data)
 {
@@ -624,7 +624,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
       targets[i].target = gdk_atom_name (pair->target);
     }
 
-  gtk_clipboard_set_with_data (clipboard, 
+  gtk_clipboard_set_with_data (clipboard,
                               targets, n_targets,
                               pixbuf_get_func, pixbuf_clear_func,
                               g_object_ref (pixbuf));
@@ -643,7 +643,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
  * @callback: (scope async):
  * @user_data:
  */
-void 
+void
 gtk_clipboard_request_contents (GtkClipboard            *clipboard,
                                GdkAtom                  target,
                                GtkClipboardReceivedFunc callback,
@@ -664,7 +664,7 @@ gtk_clipboard_request_contents (GtkClipboard            *clipboard,
  * @callback: (scope async):
  * @user_data:
  */
-void 
+void
 gtk_clipboard_request_text (GtkClipboard                *clipboard,
                            GtkClipboardTextReceivedFunc callback,
                            gpointer                     user_data)
@@ -718,7 +718,7 @@ gtk_clipboard_wait_for_rich_text (GtkClipboard  *clipboard,
  * @callback: (scope async):
  * @user_data:
  */
-void 
+void
 gtk_clipboard_request_image (GtkClipboard                  *clipboard,
                             GtkClipboardImageReceivedFunc  callback,
                             gpointer                       user_data)
@@ -737,7 +737,7 @@ gtk_clipboard_request_image (GtkClipboard                  *clipboard,
  * @callback: (scope async):
  * @user_data:
  */
-void 
+void
 gtk_clipboard_request_uris (GtkClipboard                *clipboard,
                            GtkClipboardURIReceivedFunc  callback,
                            gpointer                     user_data)
@@ -755,7 +755,7 @@ gtk_clipboard_request_uris (GtkClipboard                *clipboard,
  * @callback: (scope async):
  * @user_data:
  */
-void 
+void
 gtk_clipboard_request_targets (GtkClipboard                *clipboard,
                               GtkClipboardTargetsReceivedFunc callback,
                               gpointer                     user_data)
@@ -788,7 +788,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
       clipboard->change_count = [clipboard->pasteboard changeCount];
     }
 
-  if (target == gdk_atom_intern_static_string ("TARGETS")) 
+  if (target == gdk_atom_intern_static_string ("TARGETS"))
     {
       NSArray *types = [clipboard->pasteboard types];
       int i, length;
@@ -841,7 +841,7 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
   GtkSelectionData *data;
   gchar *result;
 
-  data = gtk_clipboard_wait_for_contents (clipboard, 
+  data = gtk_clipboard_wait_for_contents (clipboard,
                                          gdk_atom_intern_static_string ("UTF8_STRING"));
 
   result = (gchar *)gtk_selection_data_get_text (data);
@@ -860,23 +860,18 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
 GdkPixbuf *
 gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
 {
-  const gchar *priority[] = { "image/png", "image/tiff", "image/jpeg", "image/gif", "image/bmp" };
+  GdkAtom target = gdk_atom_intern_static_string("image/tiff")
   int i;
   GtkSelectionData *data;
 
-  for (i = 0; i < G_N_ELEMENTS (priority); i++) 
-    {    
-      data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string (priority[i]));
-
-      if (data)
-       {
-         GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
-
-         gtk_selection_data_free (data);
+  data = gtk_clipboard_wait_for_contents (clipboard, target);
 
-         return pixbuf;
-       }  
-  }
+  if (data && data->data)
+    {
+      GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
+      gtk_selection_data_free (data);
+      return pixbuf;
+    }
 
   return NULL;
 }
@@ -901,7 +896,7 @@ gtk_clipboard_wait_for_uris (GtkClipboard *clipboard)
       gtk_selection_data_free (data);
 
       return uris;
-    }  
+    }
 
   return NULL;
 }
@@ -962,7 +957,7 @@ gtk_clipboard_wait_is_image_available (GtkClipboard *clipboard)
   GtkSelectionData *data;
   gboolean result = FALSE;
 
-  data = gtk_clipboard_wait_for_contents (clipboard, 
+  data = gtk_clipboard_wait_for_contents (clipboard,
                                          gdk_atom_intern_static_string ("TARGETS"));
   if (data)
     {
@@ -979,7 +974,7 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard)
   GtkSelectionData *data;
   gboolean result = FALSE;
 
-  data = gtk_clipboard_wait_for_contents (clipboard, 
+  data = gtk_clipboard_wait_for_contents (clipboard,
                                          gdk_atom_intern_static_string ("TARGETS"));
   if (data)
     {
@@ -997,13 +992,13 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard)
  * @n_targets: (out):
  */
 gboolean
-gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard, 
+gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard,
                                GdkAtom      **targets,
                                gint          *n_targets)
 {
   GtkSelectionData *data;
   gboolean result = FALSE;
-  
+
   g_return_val_if_fail (clipboard != NULL, FALSE);
 
   /* If the display supports change notification we cache targets */
@@ -1012,19 +1007,19 @@ gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard,
     {
       if (n_targets)
        *n_targets = clipboard->n_cached_targets;
- 
+
       if (targets)
        *targets = g_memdup (clipboard->cached_targets,
                             clipboard->n_cached_targets * sizeof (GdkAtom));
 
        return TRUE;
     }
-  
+
   if (n_targets)
     *n_targets = 0;
-      
+
   if (targets)
-    *targets = NULL;      
+    *targets = NULL;
 
   data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string ("TARGETS"));
 
@@ -1032,24 +1027,24 @@ gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard,
     {
       GdkAtom *tmp_targets;
       gint tmp_n_targets;
-       
+
       result = gtk_selection_data_get_targets (data, &tmp_targets, &tmp_n_targets);
- 
+
       if (gdk_display_supports_selection_notification (gtk_clipboard_get_display (clipboard)))
        {
          clipboard->n_cached_targets = tmp_n_targets;
          clipboard->cached_targets = g_memdup (tmp_targets,
                                                tmp_n_targets * sizeof (GdkAtom));
        }
- 
+
       if (n_targets)
        *n_targets = tmp_n_targets;
- 
+
       if (targets)
        *targets = tmp_targets;
       else
        g_free (tmp_targets);
-      
+
       gtk_selection_data_free (data);
     }
 
@@ -1057,7 +1052,7 @@ gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard,
 }
 
 static GtkClipboard *
-clipboard_peek (GdkDisplay *display, 
+clipboard_peek (GdkDisplay *display,
                GdkAtom     selection,
                gboolean    only_if_exists)
 {
@@ -1086,13 +1081,13 @@ clipboard_peek (GdkDisplay *display,
       NSString *pasteboard_name;
       clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
 
-      if (selection == GDK_SELECTION_CLIPBOARD) 
+      if (selection == GDK_SELECTION_CLIPBOARD)
        pasteboard_name = NSGeneralPboard;
-      else 
+      else
        {
          char *atom_string = gdk_atom_name (selection);
 
-         pasteboard_name = [NSString stringWithFormat:@"_GTK_%@", 
+         pasteboard_name = [NSString stringWithFormat:@"_GTK_%@",
                             [NSString stringWithUTF8String:atom_string]];
          g_free (atom_string);
        }
@@ -1111,7 +1106,7 @@ clipboard_peek (GdkDisplay *display,
                        G_CALLBACK (clipboard_display_closed), clipboard);
       gdk_display_request_selection_notification (display, selection);
     }
-  
+
   return clipboard;
 }
 
@@ -1133,7 +1128,7 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
   GdkAtom *targets;
   gint i, n_targets;
   gboolean retval = FALSE;
-    
+
   if (!gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets))
     return FALSE;
 
@@ -1147,11 +1142,11 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
     }
 
   g_free (targets);
-  
+
   return retval;
 }
 
-void 
+void
 _gtk_clipboard_handle_event (GdkEventOwnerChange *event)
 {
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]