[gtk+] gdk: Sanitize GdkContentFormats API



commit 1a70ca75e8128cfa4c1a9225301b42b50bdc17bc
Author: Benjamin Otte <otte redhat com>
Date:   Mon Nov 20 04:42:43 2017 +0100

    gdk: Sanitize GdkContentFormats API
    
    Make sure the API reflects the idea that GdkContentFormats is a set
    containing mime types. In particular, treat the object itself as a
    plural - it's named content format`S' after all - and therefor use
    the correct verb form.
    
    Also make GdkContentFormats keep an array instead of a list, now that
    it's immutable.

 docs/reference/gdk/gdk4-sections.txt |    6 +-
 gdk/gdkcontentformats.c              |  144 +++++++++++++++++++++-------------
 gdk/gdkcontentformats.h              |    8 ++-
 gdk/gdkcontentformatsprivate.h       |    2 -
 gdk/wayland/gdkdnd-wayland.c         |   39 ++++------
 gdk/wayland/gdkselection-wayland.c   |   15 ++--
 gdk/x11/gdkdnd-x11.c                 |   27 +++----
 gtk/gtkclipboard.c                   |    9 ++-
 gtk/gtkdnd.c                         |   10 +-
 gtk/gtkdragdest.c                    |    4 +-
 gtk/gtkselection.c                   |   22 +++---
 gtk/gtktextview.c                    |    2 +-
 tests/testdnd.c                      |    2 +-
 13 files changed, 156 insertions(+), 134 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index ca17967..008d095 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -376,10 +376,10 @@ gdk_content_formats_ref
 gdk_content_formats_unref
 gdk_content_formats_print
 gdk_content_formats_to_string
+gdk_content_formats_get_mime_types
 gdk_content_formats_union
-gdk_content_formats_intersects
-gdk_content_formats_remove
-gdk_content_formats_contains
+gdk_content_formats_match
+gdk_content_formats_contain_mime_type
 
 <SUBSECTION>
 GdkContentFormatsBuilder
diff --git a/gdk/gdkcontentformats.c b/gdk/gdkcontentformats.c
index afb6a02..8cca479 100644
--- a/gdk/gdkcontentformats.c
+++ b/gdk/gdkcontentformats.c
@@ -68,8 +68,10 @@
 struct _GdkContentFormats
 {
   /*< private >*/
-  GList *formats;
   guint ref_count;
+
+  const char **mime_types; /* interned */
+  gsize n_mime_types;
 };
 
 G_DEFINE_BOXED_TYPE (GdkContentFormats, gdk_content_formats,
@@ -77,17 +79,17 @@ G_DEFINE_BOXED_TYPE (GdkContentFormats, gdk_content_formats,
                      gdk_content_formats_unref)
 
 
-static void
-gdk_content_formats_add_table (GdkContentFormats  *formats,
-                               const char        **mime_types,
-                               guint               n_mime_types)
+static GdkContentFormats *
+gdk_content_formats_new_take (const char **mime_types,
+                              guint        n_mime_types)
 {
-  gint i;
+  GdkContentFormats *result = g_slice_new0 (GdkContentFormats);
+  result->ref_count = 1;
 
-  for (i = n_mime_types - 1; i >= 0; i--)
-    {
-      formats->formats = g_list_prepend (formats->formats, (gpointer) gdk_atom_intern (mime_types[i], 
FALSE));
-    }
+  result->mime_types = mime_types;
+  result->n_mime_types = n_mime_types;
+
+  return result;
 }
 
 /**
@@ -97,6 +99,10 @@ gdk_content_formats_add_table (GdkContentFormats  *formats,
  * @nmime_types: number of entries in @mime_types.
  * 
  * Creates a new #GdkContentFormats from an array of mime types.
+ *
+ * The mime types must be different or the behavior of the return value
+ * is undefined. If you cannot guarantee this, use #GdkContentFormatsBuilder
+ * instead.
  * 
  * Returns: (transfer full): the new #GdkContentFormats.
  **/
@@ -104,14 +110,18 @@ GdkContentFormats *
 gdk_content_formats_new (const char **mime_types,
                          guint        n_mime_types)
 {
-  GdkContentFormats *result = g_slice_new (GdkContentFormats);
-  result->formats = NULL;
-  result->ref_count = 1;
+  GPtrArray *array;
+  guint i;
 
-  if (mime_types)
-    gdk_content_formats_add_table (result, mime_types, n_mime_types);
-  
-  return result;
+  if (n_mime_types == 0)
+      return gdk_content_formats_new_take (NULL, 0);
+
+  array = g_ptr_array_new ();
+  for (i = 0; i < n_mime_types; i++)
+    g_ptr_array_add (array, (gpointer) g_intern_string (mime_types[i]));
+  g_ptr_array_add (array, NULL);
+
+  return gdk_content_formats_new_take ((const char **) g_ptr_array_free (array, FALSE), n_mime_types);
 }
 
 /**
@@ -149,7 +159,7 @@ gdk_content_formats_unref (GdkContentFormats *formats)
   if (formats->ref_count > 0)
     return;
 
-  g_list_free (formats->formats);
+  g_free (formats->mime_types);
   g_slice_free (GdkContentFormats, formats);
 }
 
@@ -168,17 +178,17 @@ void
 gdk_content_formats_print (GdkContentFormats *formats,
                            GString           *string)
 {
-  GList *l;
+  gsize i;
 
   g_return_if_fail (formats != NULL);
   g_return_if_fail (string != NULL);
 
   g_string_append (string, "{ ");
-  for (l = formats->formats; l; l = l->next)
+  for (i = 0; i < formats->n_mime_types; i++)
     {
-      if (l != formats->formats)
+      if (i > 0)
         g_string_append (string, ", ");
-      g_string_append (string, l->data);
+      g_string_append (string, formats->mime_types[i]);
     }
   g_string_append (string, " }");
 }
@@ -234,8 +244,23 @@ gdk_content_formats_union (GdkContentFormats       *first,
   return gdk_content_formats_builder_free (builder);
 }
 
+static gboolean
+gdk_content_formats_contain_interned_mime_type (const GdkContentFormats *formats,
+                                                const char              *mime_type)
+{
+  gsize i;
+
+  for (i = 0; i < formats->n_mime_types; i++)
+    {
+      if (mime_type == formats->mime_types[i])
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 /**
- * gdk_content_formats_intersects:
+ * gdk_content_formats_match:
  * @first: the primary #GdkContentFormats to intersect
  * @second: the #GdkContentFormats to intersect with
  *
@@ -245,26 +270,26 @@ gdk_content_formats_union (GdkContentFormats       *first,
  * Returns: The first matching #GdkAtom or %NULL if the formatss
  *     do not intersect.
  */
-GdkAtom
-gdk_content_formats_intersects (const GdkContentFormats *first,
-                                const GdkContentFormats *second)
+const char *
+gdk_content_formats_match (const GdkContentFormats *first,
+                           const GdkContentFormats *second)
 {
-  GList *l;
+  gsize i;
 
   g_return_val_if_fail (first != NULL, NULL);
   g_return_val_if_fail (second != NULL, NULL);
 
-  for (l = first->formats; l; l = l->next)
+  for (i = 0; i < first->n_mime_types; i++)
     {
-      if (g_list_find (second->formats, l->data))
-        return l->data;
+      if (gdk_content_formats_contain_interned_mime_type (second, first->mime_types[i]))
+        return first->mime_types[i];
     }
 
   return NULL;
 }
 
 /**
- * gdk_content_formats_contains:
+ * gdk_content_formats_contain_mime_type:
  * @formats: a #GdkContentFormats
  * @mime_type: the mime type to search for
  *
@@ -273,34 +298,39 @@ gdk_content_formats_intersects (const GdkContentFormats *first,
  * Returns: %TRUE if the mime_type was found, otherwise %FALSE
  **/
 gboolean
-gdk_content_formats_contains (const GdkContentFormats *formats,
-                              const char              *mime_type)
+gdk_content_formats_contain_mime_type (const GdkContentFormats *formats,
+                                       const char              *mime_type)
 {
   g_return_val_if_fail (formats != NULL, FALSE);
   g_return_val_if_fail (mime_type != NULL, FALSE);
 
-  return g_list_find (formats->formats, (gpointer) gdk_atom_intern (mime_type, FALSE)) != NULL;
+  return gdk_content_formats_contain_interned_mime_type (formats,
+                                                         g_intern_string (mime_type));
 }
 
-GdkAtom *
-gdk_content_formats_get_atoms (GdkContentFormats *formats,
-                               guint             *n_atoms)
+/**
+ * gdk_content_formats_get_mime_types:
+ * @formats: a #GdkContentFormats
+ * @n_mime_types: (out) (allow-none): optional pointer to take the
+ *     number of mime types contained in the return value
+ *
+ * Gets the mime types included in @formats. Note that @formats may not
+ * contain any mime types, in particular when they are empty. In that
+ * case %NULL will be returned. 
+ *
+ * Returns: (transfer none): %NULL-terminated array of interned
+ *     strings of mime types included in @formats or %NULL if none.
+ **/
+const char * const *
+gdk_content_formats_get_mime_types (GdkContentFormats *formats,
+                                    gsize             *n_mime_types)
 {
-  GdkAtom *atoms;
-  GList *l;
-  guint i, n;
-
-  n = g_list_length (formats->formats);
-  atoms = g_new (GdkAtom, n);
-
-  i = 0;
-  for (l = formats->formats; l; l = l->next)
-    atoms[i++] = l->data;
-
-  if (n_atoms)
-    *n_atoms = n;
+  g_return_val_if_fail (formats != NULL, NULL);
 
-  return atoms;
+  if (n_mime_types)
+    *n_mime_types = formats->n_mime_types;
+  
+  return formats->mime_types;
 }
 
 /**
@@ -357,8 +387,10 @@ gdk_content_formats_builder_free (GdkContentFormatsBuilder *builder)
   for (l = builder->mime_types; l; l = l->next)
     mime_types[i--] = l->data;
 
-  result = gdk_content_formats_new (mime_types, builder->n_mime_types);
-  g_free (mime_types);
+  result = gdk_content_formats_new_take (mime_types, builder->n_mime_types);
+
+  g_slist_free (builder->mime_types);
+  g_slice_free (GdkContentFormatsBuilder, builder);
 
   return result;
 }
@@ -375,13 +407,13 @@ void
 gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder,
                                          const GdkContentFormats  *formats)
 {
-  GList *l;
+  gsize i;
 
   g_return_if_fail (builder != NULL);
   g_return_if_fail (formats != NULL);
 
-  for (l = formats->formats; l; l = l->next)
-    gdk_content_formats_builder_add_mime_type (builder, l->data);
+  for (i = 0; i < formats->n_mime_types; i++)
+    gdk_content_formats_builder_add_mime_type (builder, formats->mime_types[i]);
 }
 
 /**
diff --git a/gdk/gdkcontentformats.h b/gdk/gdkcontentformats.h
index 1172bdc..2bb1e17 100644
--- a/gdk/gdkcontentformats.h
+++ b/gdk/gdkcontentformats.h
@@ -47,13 +47,17 @@ GDK_AVAILABLE_IN_3_94
 char *                  gdk_content_formats_to_string           (GdkContentFormats              *formats);
 
 GDK_AVAILABLE_IN_3_94
+const char * const *    gdk_content_formats_get_mime_types      (GdkContentFormats              *formats,
+                                                                 gsize                          
*n_mime_types);
+
+GDK_AVAILABLE_IN_3_94
 GdkContentFormats *     gdk_content_formats_union               (GdkContentFormats              *first,
                                                                  const GdkContentFormats        *second) 
G_GNUC_WARN_UNUSED_RESULT;
 GDK_AVAILABLE_IN_3_94
-GdkAtom                 gdk_content_formats_intersects          (const GdkContentFormats        *first,
+const char *            gdk_content_formats_match               (const GdkContentFormats        *first,
                                                                  const GdkContentFormats        *second);
 GDK_AVAILABLE_IN_3_94
-gboolean                gdk_content_formats_contains            (const GdkContentFormats        *formats,
+gboolean                gdk_content_formats_contain_mime_type   (const GdkContentFormats        *formats,
                                                                  const char                     *mime_type);
 
 typedef struct _GdkContentFormatsBuilder GdkContentFormatsBuilder;
diff --git a/gdk/gdkcontentformatsprivate.h b/gdk/gdkcontentformatsprivate.h
index 21e993c..cfc8f2e 100644
--- a/gdk/gdkcontentformatsprivate.h
+++ b/gdk/gdkcontentformatsprivate.h
@@ -25,8 +25,6 @@
 G_BEGIN_DECLS
 
 
-GdkAtom *               gdk_content_formats_get_atoms   (GdkContentFormats              *formats,
-                                                         guint                          *n_atoms);
 
 
 G_END_DECLS
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index fb66870..febd0e0 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -22,7 +22,7 @@
 #include "gdkinternals.h"
 #include "gdkproperty.h"
 #include "gdkprivate-wayland.h"
-#include "gdkcontentformatsprivate.h"
+#include "gdkcontentformats.h"
 #include "gdkdisplay-wayland.h"
 #include "gdkseat-wayland.h"
 
@@ -240,26 +240,21 @@ gdk_wayland_drop_context_set_status (GdkDragContext *context,
 
   if (accepted)
     {
-      GdkAtom *atoms;
-      guint i, n_atoms;
+      const char *const *mimetypes;
+      gsize i, n_mimetypes;
       
-      atoms = gdk_content_formats_get_atoms (context->formats, &n_atoms);
-      for (i = 0; i < n_atoms; i++)
+      mimetypes = gdk_content_formats_get_mime_types (context->formats, &n_mimetypes);
+      for (i = 0; i < n_mimetypes; i++)
         {
-          if (atoms[i] != gdk_atom_intern_static_string ("DELETE"))
+          if (mimetypes[i] != gdk_atom_intern_static_string ("DELETE"))
             break;
         }
 
-      if (i < n_atoms)
+      if (i < n_mimetypes)
         {
-          gchar *mimetype = gdk_atom_name (atoms[i]);
-
-          wl_data_offer_accept (wl_offer, context_wayland->serial, mimetype);
-          g_free (atoms);
+          wl_data_offer_accept (wl_offer, context_wayland->serial, mimetypes[i]);
           return;
         }
-      
-      g_free (atoms);
     }
 
   wl_data_offer_accept (wl_offer, context_wayland->serial, NULL);
@@ -521,8 +516,8 @@ _gdk_wayland_window_drag_begin (GdkWindow         *window,
 {
   GdkWaylandDragContext *context_wayland;
   GdkDragContext *context;
-  GdkAtom *atoms;
-  guint i, n_atoms;
+  const char *const *mimetypes;
+  gsize i, n_mimetypes;
 
   context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
@@ -536,18 +531,14 @@ _gdk_wayland_window_drag_begin (GdkWindow         *window,
   context_wayland->dnd_window = create_dnd_window (gdk_window_get_display (window));
   context_wayland->dnd_surface = gdk_wayland_window_get_wl_surface (context_wayland->dnd_window);
   context_wayland->data_source =
-    gdk_wayland_selection_get_data_source (window,
-                                           gdk_wayland_drag_context_get_selection (context));
+  gdk_wayland_selection_get_data_source (window,
+                                         gdk_wayland_drag_context_get_selection (context));
 
-  atoms = gdk_content_formats_get_atoms (context->formats, &n_atoms);
-  for (i = 0; i < n_atoms; i++)
+  mimetypes = gdk_content_formats_get_mime_types (context->formats, &n_mimetypes);
+  for (i = 0; i < n_mimetypes; i++)
     {
-      gchar *mimetype = gdk_atom_name (atoms[i]);
-
-      wl_data_source_offer (context_wayland->data_source, mimetype);
-      g_free (mimetype);
+      wl_data_source_offer (context_wayland->data_source, mimetypes[i]);
     }
-  g_free (atoms);
 
   return context;
 }
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index da0d114..f85071c 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -379,7 +379,7 @@ data_offer_offer (void                 *data,
 
   info = g_hash_table_lookup (selection->offers, wl_data_offer);
 
-  if (!info || gdk_content_formats_contains (info->targets, type))
+  if (!info || gdk_content_formats_contain_mime_type (info->targets, type))
     return;
 
   GDK_NOTE (EVENTS,
@@ -471,7 +471,7 @@ primary_offer_offer (void                               *data,
 
   info = g_hash_table_lookup (selection->offers, gtk_offer);
 
-  if (!info || gdk_content_formats_contains (info->targets, type))
+  if (!info || gdk_content_formats_contain_mime_type (info->targets, type))
     return;
 
   GDK_NOTE (EVENTS,
@@ -1318,7 +1318,7 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
 
   if (target != gdk_atom_intern_static_string ("TARGETS"))
     {
-      if (!gdk_content_formats_contains (formats, GDK_ATOM_TO_POINTER (target)))
+      if (!gdk_content_formats_contain_mime_type (formats, GDK_ATOM_TO_POINTER (target)))
         {
           emit_empty_selection_notify (requestor, selection, target);
           return;
@@ -1338,12 +1338,12 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
     {
       GInputStream *stream = NULL;
       int pipe_fd[2];
-      guint natoms = 0;
-      GdkAtom *targets = NULL;
+      gsize n_targets = 0;
+      const char * const *targets = NULL;
 
       if (target == gdk_atom_intern_static_string ("TARGETS"))
         {
-          targets = gdk_content_formats_get_atoms (formats, &natoms);
+          targets = gdk_content_formats_get_mime_types (formats, &n_targets);
         }
       else
         {
@@ -1367,8 +1367,7 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
       if (targets)
         {
           /* Store directly the local atoms */
-          selection_buffer_append_data (buffer_data, targets, natoms * sizeof (GdkAtom));
-          g_free (targets);
+          selection_buffer_append_data (buffer_data, targets, n_targets * sizeof (const char * const *));
         }
 
       g_hash_table_insert (selection_data->buffers,
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 82bb861..5b3947e 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -339,16 +339,14 @@ precache_target_list (GdkDragContext *context)
 {
   if (context->formats)
     {
-      GdkAtom *atoms;
-      guint n_atoms;
+      const char * const *atoms;
+      gsize n_atoms;
 
-      atoms = gdk_content_formats_get_atoms (context->formats, &n_atoms);
+      atoms = gdk_content_formats_get_mime_types (context->formats, &n_atoms);
 
       _gdk_x11_precache_atoms (GDK_WINDOW_DISPLAY (context->source_window),
                                (const gchar **) atoms,
                                n_atoms);
-
-      g_free (atoms);
     }
 }
 
@@ -1025,14 +1023,14 @@ xdnd_set_targets (GdkX11DragContext *context_x11)
 {
   GdkDragContext *context = GDK_DRAG_CONTEXT (context_x11);
   Atom *atomlist;
-  GdkAtom *atoms;
-  guint i, n_atoms;
+  const char * const *atoms;
+  gsize i, n_atoms;
   GdkDisplay *display = GDK_WINDOW_DISPLAY (context->source_window);
 
-  atoms = gdk_content_formats_get_atoms (context->formats, &n_atoms);
+  atoms = gdk_content_formats_get_mime_types (context->formats, &n_atoms);
   atomlist = g_new (Atom, n_atoms);
   for (i = 0; i < n_atoms; i++)
-    atomlist[i] = gdk_x11_atom_to_xatom_for_display (display, atoms[i]);
+    atomlist[i] = gdk_x11_get_xatom_by_name_for_display (display, atoms[i]);
 
   XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
                    GDK_WINDOW_XID (context->source_window),
@@ -1041,7 +1039,6 @@ xdnd_set_targets (GdkX11DragContext *context_x11)
                    (guchar *)atomlist, n_atoms);
 
   g_free (atomlist);
-  g_free (atoms);
 
   context_x11->xdnd_targets_set = 1;
 }
@@ -1222,8 +1219,8 @@ xdnd_send_enter (GdkX11DragContext *context_x11)
 {
   GdkDragContext *context = GDK_DRAG_CONTEXT (context_x11);
   GdkDisplay *display = GDK_WINDOW_DISPLAY (context->dest_window);
-  GdkAtom *atoms;
-  guint i, n_atoms;
+  const char * const *atoms;
+  gsize i, n_atoms;
   XEvent xev;
 
   xev.xclient.type = ClientMessage;
@@ -1241,7 +1238,7 @@ xdnd_send_enter (GdkX11DragContext *context_x11)
   GDK_NOTE(DND,
            g_message ("Sending enter source window %#lx XDND protocol version %d\n",
                       GDK_WINDOW_XID (context->source_window), context_x11->version));
-  atoms = gdk_content_formats_get_atoms (context->formats, &n_atoms);
+  atoms = gdk_content_formats_get_mime_types (context->formats, &n_atoms);
 
   if (n_atoms > 3)
     {
@@ -2310,8 +2307,8 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
                 /* GTK+ traditionally has used application/x-rootwin-drop,
                  * but the XDND spec specifies x-rootwindow-drop.
                  */
-                if (gdk_content_formats_contains (context->formats, "application/x-rootwindow-drop") ||
-                    gdk_content_formats_contains (context->formats, "application/x-rootwin-drop"))
+                if (gdk_content_formats_contain_mime_type (context->formats, 
"application/x-rootwindow-drop") ||
+                    gdk_content_formats_contain_mime_type (context->formats, "application/x-rootwin-drop"))
                   context->action = context->suggested_action;
                 else
                   context->action = 0;
diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c
index 68d8b15..65b770d 100644
--- a/gtk/gtkclipboard.c
+++ b/gtk/gtkclipboard.c
@@ -2090,7 +2090,6 @@ gtk_clipboard_real_set_can_store (GtkClipboard      *clipboard,
                                  GdkContentFormats *formats)
 {
   GtkWidget *clipboard_widget;
-  guint n_atoms;
 
   if (clipboard->selection != GDK_SELECTION_CLIPBOARD)
     return;
@@ -2117,8 +2116,12 @@ gtk_clipboard_real_set_can_store (GtkClipboard      *clipboard,
   
   if (formats)
     {
-      clipboard->storable_formats = gdk_content_formats_get_atoms (formats, &n_atoms);
-      clipboard->n_storable_formats = n_atoms;
+      const char * const *mime_types;
+      gsize n_mime_types;
+
+      mime_types = gdk_content_formats_get_mime_types (formats, &n_mime_types);
+      clipboard->storable_formats = g_memdup (mime_types, sizeof (char *) * n_mime_types);
+      clipboard->n_storable_formats = n_mime_types;
     }
   else
     {
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 2e8af5a..4015e22 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -818,7 +818,7 @@ gtk_drag_selection_received (GtkWidget        *widget,
 
       if (site && site->target_list)
         {
-          if (gdk_content_formats_contains (site->target_list, target))
+          if (gdk_content_formats_contain_mime_type (site->target_list, target))
             {
               if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
                   gtk_selection_data_get_length (selection_data) >= 0)
@@ -1842,9 +1842,9 @@ gtk_drag_drop (GtkDragSourceInfo *info,
       /* GTK+ traditionally has used application/x-rootwin-drop, but the
        * XDND spec specifies x-rootwindow-drop.
        */
-      if (gdk_content_formats_contains (info->target_list, "application/x-rootwindow-drop"))
+      if (gdk_content_formats_contain_mime_type (info->target_list, "application/x-rootwindow-drop"))
         found = gdk_atom_intern ("application/x-rootwindow-drop", FALSE);
-      if (gdk_content_formats_contains (info->target_list, "application/x-rootwin-drop"))
+      if (gdk_content_formats_contain_mime_type (info->target_list, "application/x-rootwin-drop"))
         found = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
       else found = NULL;
       
@@ -1903,8 +1903,8 @@ gtk_drag_selection_get (GtkWidget        *widget,
                              info->context);
       gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
     }
-  else if (gdk_content_formats_contains (info->target_list, 
-                                         gtk_selection_data_get_target (selection_data)))
+  else if (gdk_content_formats_contain_mime_type (info->target_list, 
+                                                  gtk_selection_data_get_target (selection_data)))
     {
       g_signal_emit_by_name (info->widget, "drag-data-get",
                              info->context,
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index fabbe27..9c37569 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -422,8 +422,8 @@ gtk_drag_dest_find_target (GtkWidget         *widget,
   if (target_list == NULL)
     return NULL;
 
-  result = gdk_content_formats_intersects (target_list,
-                                           gdk_drag_context_get_formats (context));
+  result = gdk_content_formats_match (target_list,
+                                      gdk_drag_context_get_formats (context));
 
   return result;
 }
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index 8d6c1ec..1d7a848 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -734,8 +734,8 @@ gtk_selection_add_targets (GtkWidget         *widget,
                           GdkAtom            selection,
                           GdkContentFormats *targets)
 {
-  GdkAtom *atoms;
-  guint n_targets;
+  const char * const *mime_types;
+  gsize n_mime_types;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (selection != NULL);
@@ -743,9 +743,8 @@ gtk_selection_add_targets (GtkWidget         *widget,
   
   gtk_selection_target_list_add (widget, selection, targets);
 
-  atoms = gdk_content_formats_get_atoms (targets, &n_targets);
-  gdk_selection_add_targets (gtk_widget_get_window (widget), selection, atoms, n_targets);
-  g_free (atoms);
+  mime_types = gdk_content_formats_get_mime_types (targets, &n_mime_types);
+  gdk_selection_add_targets (gtk_widget_get_window (widget), selection, (GdkAtom *) mime_types, 
n_mime_types);
 }
 
 
@@ -1932,7 +1931,7 @@ gtk_targets_include_image (GdkAtom *targets,
   list = gtk_content_formats_add_image_targets (list, writable);
   for (i = 0; i < n_targets && !result; i++)
     {
-      if (gdk_content_formats_contains (list, targets[i]))
+      if (gdk_content_formats_contain_mime_type (list, targets[i]))
         {
           result = TRUE;
           break;
@@ -2908,7 +2907,7 @@ gtk_selection_invoke_handler (GtkWidget          *widget,
   target_list = gtk_selection_target_list_get (widget, data->selection);
   if (data->target != gtk_selection_atoms[SAVE_TARGETS] &&
       target_list &&
-      gdk_content_formats_contains (target_list, data->target))
+      gdk_content_formats_contain_mime_type (target_list, data->target))
     {
       g_signal_emit_by_name (widget,
                             "selection-get",
@@ -2967,13 +2966,14 @@ gtk_selection_default_handler (GtkWidget        *widget,
   else if (data->target == gtk_selection_atoms[TARGETS])
     {
       /* List of all targets supported for this widget/selection pair */
-      GdkAtom *p, *atoms;
-      guint count, i;
+      GdkAtom *p;
+      const char * const *atoms;
+      gsize count, i;
       GdkContentFormats *target_list;
       
       target_list = gtk_selection_target_list_get (widget,
                                                   data->selection);
-      atoms = gdk_content_formats_get_atoms (target_list, &count);
+      atoms = gdk_content_formats_get_mime_types (target_list, &count);
       
       data->type = GDK_SELECTION_TYPE_ATOM;
       data->format = 32;
@@ -2991,8 +2991,6 @@ gtk_selection_default_handler (GtkWidget  *widget,
       
       for (i = 0; i < count; i++)
         *p++ = atoms[i];
-
-      g_free (atoms);
     }
   else if (data->target == gtk_selection_atoms[SAVE_TARGETS])
     {
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 8bf79a9..a4bf36d 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -8158,7 +8158,7 @@ gtk_text_view_drag_data_received (GtkWidget        *widget,
           buffer_formats = gdk_content_formats_new (atoms, n_atoms);
           dnd_formats = gdk_drag_context_get_formats (context);
 
-          target = gdk_content_formats_intersects (dnd_formats, buffer_formats);
+          target = gdk_content_formats_match (dnd_formats, buffer_formats);
 
           gdk_content_formats_unref (buffer_formats);
           g_free (atoms);
diff --git a/tests/testdnd.c b/tests/testdnd.c
index 934fbe5..c3c16df 100644
--- a/tests/testdnd.c
+++ b/tests/testdnd.c
@@ -352,7 +352,7 @@ target_drag_drop       (GtkWidget          *widget,
   gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
 
   formats = gdk_drag_context_get_formats (context);
-  format = gdk_content_formats_intersects (formats, formats);
+  format = gdk_content_formats_match (formats, formats);
   if (format)
     {
       gtk_drag_get_data (widget, context,


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