+ if (selection_set_compound_text (selection_data, str, len))
+ return TRUE;
+ else if (selection_data->target == text_atom)
+ return selection_set_string (selection_data, str, len);
+ }
+ else if (selection_data->target == text_plain_atom ||
+ selection_data->target == text_plain_utf8_atom ||
+ selection_data->target == text_plain_locale_atom)
+ {
+ return selection_set_text_plain (selection_data, str, len);
+ }
+
+ return FALSE;
+}
+
+/**
+ * gtk_selection_data_get_text:
+ * @selection_data: a #GtkSelectionData
+ *
+ * Gets the contents of the selection data as a UTF-8 string.
+ *
+ * Return value: if the selection data contained a recognized
+ * text type and it could be converted to UTF-8, a newly allocated
+ * string containing the converted text, otherwise %NULL.
+ * If the result is non-%NULL it must be freed with g_free().
+ **/
+guchar *
+gtk_selection_data_get_text (GtkSelectionData *selection_data)
+{
+ guchar *result = NULL;
+
+ g_return_val_if_fail (selection_data != NULL, NULL);
+
+ init_atoms ();
+
+ if (selection_data->length >= 0 &&
+ (selection_data->type == GDK_TARGET_STRING ||
+ selection_data->type == ctext_atom ||
+ selection_data->type == utf8_atom))
+ {
+ gchar **list;
+ gint i;
+ gint count = gdk_text_property_to_utf8_list_for_display (selection_data->display,
+ selection_data->type,
+ selection_data->format,
+ selection_data->data,
+ selection_data->length,
+ &list);
+ if (count > 0)
+ result = (guchar *) list[0];
+
+ for (i = 1; i < count; i++)
+ g_free (list[i]);
+ g_free (list);
+ }
+ else if (selection_data->length >= 0 &&
+ (selection_data->type == text_plain_atom ||
+ selection_data->type == text_plain_utf8_atom ||
+ selection_data->type == text_plain_locale_atom))
+ {
+ result = selection_get_text_plain (selection_data);
+ }
+
+ return result;
+}
+
+/**
+ * gtk_selection_data_set_pixbuf:
+ * @selection_data: a #GtkSelectionData
+ * @pixbuf: a #GdkPixbuf
+ *
+ * Sets the contents of the selection from a #GdkPixbuf
+ * The pixbuf is converted to the form determined by
+ * @selection_data->target.
+ *
+ * Return value: %TRUE if the selection was successfully set,
+ * otherwise %FALSE.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,
+ GdkPixbuf *pixbuf)
+{
+ GSList *formats, *f;
+ gchar **mimes, **m;
+ GdkAtom atom;
+ gboolean result;
+ gchar *str, *type;
+ gsize len;
+
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+ g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
+
+ formats = gdk_pixbuf_get_formats ();
+
+ for (f = formats; f; f = f->next)
+ {
+ GdkPixbufFormat *fmt = f->data;
+
+ mimes = gdk_pixbuf_format_get_mime_types (fmt);
+ for (m = mimes; *m; m++)
+ {
+ atom = gdk_atom_intern (*m, FALSE);
+ if (selection_data->target == atom)
+ {
+ str = NULL;
+ type = gdk_pixbuf_format_get_name (fmt);
+ result = gdk_pixbuf_save_to_buffer (pixbuf, &str, &len,
+ type, NULL,
+ ((strcmp (type, "png") == 0) ?
+ "compression" : NULL), "2",
+ NULL);
+ if (result)
+ gtk_selection_data_set (selection_data,
+ atom, 8, (guchar *)str, len);
+ g_free (type);
+ g_free (str);
+ g_strfreev (mimes);
+ g_slist_free (formats);
+
+ return result;
+ }
+ }
+
+ g_strfreev (mimes);
+ }
+
+ g_slist_free (formats);
+
+ return FALSE;
+}
+
+/**
+ * gtk_selection_data_get_pixbuf:
+ * @selection_data: a #GtkSelectionData
+ *
+ * Gets the contents of the selection data as a #GdkPixbuf.
+ *
+ * Return value: if the selection data contained a recognized
+ * image type and it could be converted to a #GdkPixbuf, a
+ * newly allocated pixbuf is returned, otherwise %NULL.
+ * If the result is non-%NULL it must be freed with g_object_unref().
+ *
+ * Since: 2.6
+ **/
+GdkPixbuf *
+gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data)
+{
+ GdkPixbufLoader *loader;
+ GdkPixbuf *result = NULL;
+
+ g_return_val_if_fail (selection_data != NULL, NULL);
+
+ if (selection_data->length > 0)
+ {
+ loader = gdk_pixbuf_loader_new ();
+
+ gdk_pixbuf_loader_write (loader,
+ selection_data->data,
+ selection_data->length,
+ NULL);
+ gdk_pixbuf_loader_close (loader, NULL);
+ result = gdk_pixbuf_loader_get_pixbuf (loader);
+
+ if (result)
+ g_object_ref (result);
+
+ g_object_unref (loader);
+ }
+
+ return result;
+}
+
+/**
+ * gtk_selection_data_set_uris:
+ * @selection_data: a #GtkSelectionData
+ * @uris: a %NULL-terminated array of strings holding URIs
+ *
+ * Sets the contents of the selection from a list of URIs.
+ * The string is converted to the form determined by
+ * @selection_data->target.
+ *
+ * Return value: %TRUE if the selection was successfully set,
+ * otherwise %FALSE.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gtk_selection_data_set_uris (GtkSelectionData *selection_data,
+ gchar **uris)
+{
+ g_return_val_if_fail (selection_data != NULL, FALSE);
+ g_return_val_if_fail (uris != NULL, FALSE);
+
+ init_atoms ();
+
+ if (selection_data->target == text_uri_list_atom)
+ {
+ GString *list;
+ gint i;
+ gchar *result;
+ gsize length;
+
+ list = g_string_new (NULL);
+ for (i = 0; uris[i]; i++)
+ {
+ g_string_append (list, uris[i]);
+ g_string_append (list, "\r\n");
+ }
+
+ result = g_convert (list->str, list->len,
+ "ASCII", "UTF-8",
+ NULL, &length, NULL);
+ g_string_free (list, TRUE);
+
+ if (result)
+ {
+ gtk_selection_data_set (selection_data,
+ text_uri_list_atom,
+ 8, (guchar *)result, length);
+
+ g_free (result);
+
+ return TRUE;
+ }