+static GdkAtom utf8_atom;
+static GdkAtom text_atom;
+static GdkAtom ctext_atom;
+static GdkAtom text_plain_atom;
+static GdkAtom text_plain_utf8_atom;
+static GdkAtom text_plain_locale_atom;
+static GdkAtom text_uri_list_atom;
+
+static void
+init_atoms (void)
+{
+ gchar *tmp;
+ const gchar *charset;
+
+ if (!utf8_atom)
+ {
+ utf8_atom = gdk_atom_intern_static_string ("UTF8_STRING");
+ text_atom = gdk_atom_intern_static_string ("TEXT");
+ ctext_atom = gdk_atom_intern_static_string ("COMPOUND_TEXT");
+ text_plain_atom = gdk_atom_intern_static_string ("text/plain");
+ text_plain_utf8_atom = gdk_atom_intern_static_string ("text/plain;charset=utf-8");
+ g_get_charset (&charset);
+ tmp = g_strdup_printf ("text/plain;charset=%s", charset);
+ text_plain_locale_atom = gdk_atom_intern (tmp, FALSE);
+ g_free (tmp);
+
+ text_uri_list_atom = gdk_atom_intern_static_string ("text/uri-list");
+ }
+}
+
+/**
+ * gtk_target_list_add_text_targets:
+ * @list: a #GtkTargetList
+ * @info: an ID that will be passed back to the application
+ *
+ * Appends the text targets supported by #GtkSelection to
+ * the target list. All targets are added with the same @info.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_target_list_add_text_targets (GtkTargetList *list,
+ guint info)
+{
+ g_return_if_fail (list != NULL);
+
+ init_atoms ();
+
+ /* Keep in sync with gtk_selection_data_targets_include_text()
+ */
+ gtk_target_list_add (list, utf8_atom, 0, info);
+ gtk_target_list_add (list, ctext_atom, 0, info);
+ gtk_target_list_add (list, text_atom, 0, info);
+ gtk_target_list_add (list, GDK_TARGET_STRING, 0, info);
+ gtk_target_list_add (list, text_plain_utf8_atom, 0, info);
+ gtk_target_list_add (list, text_plain_locale_atom, 0, info);
+ gtk_target_list_add (list, text_plain_atom, 0, info);
+}
+
+/**
+ * gtk_target_list_add_rich_text_targets:
+ * @list: a #GtkTargetList
+ * @info: an ID that will be passed back to the application
+ * @deserializable: if %TRUE, then deserializable rich text formats
+ * will be added, serializable formats otherwise.
+ * @buffer: a #GtkTextBuffer.
+ *
+ * Appends the rich text targets registered with
+ * gtk_text_buffer_register_serialize_format() or
+ * gtk_text_buffer_register_deserialize_format() to the target list. All
+ * targets are added with the same @info.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_target_list_add_rich_text_targets (GtkTargetList *list,
+ guint info,
+ gboolean deserializable,
+ GtkTextBuffer *buffer)
+{
+ GdkAtom *atoms;
+ gint n_atoms;
+ gint i;
+
+ g_return_if_fail (list != NULL);
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+
+ if (deserializable)
+ atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms);
+ else
+ atoms = gtk_text_buffer_get_serialize_formats (buffer, &n_atoms);
+
+ for (i = 0; i < n_atoms; i++)
+ gtk_target_list_add (list, atoms[i], 0, info);
+
+ g_free (atoms);
+}
+
+/**
+ * gtk_target_list_add_image_targets:
+ * @list: a #GtkTargetList
+ * @info: an ID that will be passed back to the application
+ * @writable: whether to add only targets for which GTK+ knows
+ * how to convert a pixbuf into the format
+ *
+ * Appends the image targets supported by #GtkSelection to
+ * the target list. All targets are added with the same @info.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_target_list_add_image_targets (GtkTargetList *list,
+ guint info,
+ gboolean writable)
+{
+ GSList *formats, *f;
+ gchar **mimes, **m;
+ GdkAtom atom;
+
+ g_return_if_fail (list != NULL);
+
+ formats = gdk_pixbuf_get_formats ();
+
+ /* Make sure png comes first */
+ for (f = formats; f; f = f->next)
+ {
+ GdkPixbufFormat *fmt = f->data;
+ gchar *name;
+
+ name = gdk_pixbuf_format_get_name (fmt);
+ if (strcmp (name, "png") == 0)
+ {
+ formats = g_slist_delete_link (formats, f);
+ formats = g_slist_prepend (formats, fmt);
+
+ g_free (name);
+
+ break;
+ }
+
+ g_free (name);
+ }
+
+ for (f = formats; f; f = f->next)
+ {
+ GdkPixbufFormat *fmt = f->data;
+
+ if (writable && !gdk_pixbuf_format_is_writable (fmt))
+ continue;
+
+ mimes = gdk_pixbuf_format_get_mime_types (fmt);
+ for (m = mimes; *m; m++)
+ {
+ atom = gdk_atom_intern (*m, FALSE);
+ gtk_target_list_add (list, atom, 0, info);
+ }
+ g_strfreev (mimes);
+ }
+
+ g_slist_free (formats);
+}
+
+/**
+ * gtk_target_list_add_uri_targets:
+ * @list: a #GtkTargetList
+ * @info: an ID that will be passed back to the application
+ *
+ * Appends the URI targets supported by #GtkSelection to
+ * the target list. All targets are added with the same @info.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_target_list_add_uri_targets (GtkTargetList *list,
+ guint info)
+{
+ g_return_if_fail (list != NULL);
+
+ init_atoms ();
+
+ gtk_target_list_add (list, text_uri_list_atom, 0, info);
+}
+
+/**
+ * gtk_target_list_add_table:
+ * @list: a #GtkTargetList
+ * @targets: the table of #GtkTargetEntry
+ * @ntargets: number of targets in the table
+ *
+ * Prepends a table of #GtkTargetEntry to a target list.
+ **/