+static void
+request_rich_text_received_func (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ gpointer data)
+{
+ RequestRichTextInfo *info = data;
+ guint8 *result = NULL;
+ gsize length = 0;
+
+ result = (guint8 *) gtk_selection_data_get_data (selection_data);
+ length = gtk_selection_data_get_length (selection_data);
+
+ info->current_atom++;
+
+ if ((!result || length < 1) && (info->current_atom < info->n_atoms))
+ {
+ gtk_clipboard_request_contents (clipboard, info->atoms[info->current_atom],
+ request_rich_text_received_func,
+ info);
+ return;
+ }
+
+ info->callback (clipboard, gtk_selection_data_get_target (selection_data),
+ result, length,
+ info->user_data);
+ g_free (info->atoms);
+ g_free (info);
+}
+
+/**
+ * gtk_clipboard_request_rich_text:
+ * @clipboard: a #GtkClipboard
+ * @buffer: a #GtkTextBuffer
+ * @callback: (scope async): a function to call when the text is received,
+ * or the retrieval fails. (It will always be called one way or the other.)
+ * @user_data: user data to pass to @callback.
+ *
+ * Requests the contents of the clipboard as rich text. When the rich
+ * text is later received, @callback will be called.
+ *
+ * The @text parameter to @callback will contain the resulting rich
+ * text if the request succeeded, or %NULL if it failed. The @length
+ * parameter will contain @text's length. This function can fail for
+ * various reasons, in particular if the clipboard was empty or if the
+ * contents of the clipboard could not be converted into rich text form.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_clipboard_request_rich_text (GtkClipboard *clipboard,
+ GtkTextBuffer *buffer,
+ GtkClipboardRichTextReceivedFunc callback,
+ gpointer user_data)
+{
+ RequestRichTextInfo *info;
+
+ g_return_if_fail (clipboard != NULL);
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+ g_return_if_fail (callback != NULL);
+
+ info = g_new (RequestRichTextInfo, 1);
+ info->callback = callback;
+ info->atoms = NULL;
+ info->n_atoms = 0;
+ info->current_atom = 0;
+ info->user_data = user_data;
+
+ info->atoms = gtk_text_buffer_get_deserialize_formats (buffer, &info->n_atoms);
+
+ gtk_clipboard_request_contents (clipboard, info->atoms[info->current_atom],
+ request_rich_text_received_func,
+ info);
+}
+
+static void
+request_image_received_func (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ gpointer data)
+{
+ RequestImageInfo *info = data;
+ GdkPixbuf *result = NULL;
+
+ result = gtk_selection_data_get_pixbuf (selection_data);
+
+ if (!result)
+ {
+ /* If we asked for image/png and didn't get it, try image/jpeg;
+ * if we asked for image/jpeg and didn't get it, try image/gif;
+ * if we asked for image/gif and didn't get it, try image/bmp;
+ * If we asked for anything else and didn't get it, give up.
+ */
+ GdkAtom target = gtk_selection_data_get_target (selection_data);
+
+ if (target == gdk_atom_intern_static_string ("image/png"))
+ {
+ gtk_clipboard_request_contents (clipboard,
+ gdk_atom_intern_static_string ("image/jpeg"),
+ request_image_received_func, info);
+ return;
+ }
+ else if (target == gdk_atom_intern_static_string ("image/jpeg"))
+ {
+ gtk_clipboard_request_contents (clipboard,
+ gdk_atom_intern_static_string ("image/gif"),
+ request_image_received_func, info);
+ return;
+ }
+ else if (target == gdk_atom_intern_static_string ("image/gif"))
+ {
+ gtk_clipboard_request_contents (clipboard,
+ gdk_atom_intern_static_string ("image/bmp"),
+ request_image_received_func, info);
+ return;
+ }
+ }
+
+ info->callback (clipboard, result, info->user_data);
+ g_free (info);
+
+ if (result)
+ g_object_unref (result);
+}
+
+/**
+ * gtk_clipboard_request_image:
+ * @clipboard: a #GtkClipboard
+ * @callback: (scope async): a function to call when the image is received,
+ * or the retrieval fails. (It will always be called one way or the other.)
+ * @user_data: user data to pass to @callback.
+ *
+ * Requests the contents of the clipboard as image. When the image is
+ * later received, it will be converted to a #GdkPixbuf, and
+ * @callback will be called.
+ *
+ * The @pixbuf parameter to @callback will contain the resulting
+ * #GdkPixbuf if the request succeeded, or %NULL if it failed. This
+ * could happen for various reasons, in particular if the clipboard
+ * was empty or if the contents of the clipboard could not be
+ * converted into an image.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_clipboard_request_image (GtkClipboard *clipboard,
+ GtkClipboardImageReceivedFunc callback,
+ gpointer user_data)
+{
+ RequestImageInfo *info;
+
+ g_return_if_fail (clipboard != NULL);
+ g_return_if_fail (callback != NULL);
+
+ info = g_new (RequestImageInfo, 1);
+ info->callback = callback;
+ info->user_data = user_data;
+
+ gtk_clipboard_request_contents (clipboard,
+ gdk_atom_intern_static_string ("image/png"),
+ request_image_received_func,
+ info);
+}
+
+static void
+request_uris_received_func (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ gpointer data)
+{
+ RequestURIInfo *info = data;
+ gchar **uris;
+
+ uris = gtk_selection_data_get_uris (selection_data);
+ info->callback (clipboard, uris, info->user_data);
+ g_strfreev (uris);
+
+ g_slice_free (RequestURIInfo, info);
+}
+
+/**
+ * gtk_clipboard_request_uris:
+ * @clipboard: a #GtkClipboard
+ * @callback: (scope async): a function to call when the URIs are received,
+ * or the retrieval fails. (It will always be called one way or the other.)
+ * @user_data: user data to pass to @callback.
+ *
+ * Requests the contents of the clipboard as URIs. When the URIs are
+ * later received @callback will be called.
+ *
+ * The @uris parameter to @callback will contain the resulting array of
+ * URIs if the request succeeded, or %NULL if it failed. This could happen
+ * for various reasons, in particular if the clipboard was empty or if the
+ * contents of the clipboard could not be converted into URI form.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_clipboard_request_uris (GtkClipboard *clipboard,
+ GtkClipboardURIReceivedFunc callback,
+ gpointer user_data)
+{
+ RequestURIInfo *info;
+
+ g_return_if_fail (clipboard != NULL);
+ g_return_if_fail (callback != NULL);
+
+ info = g_slice_new (RequestURIInfo);
+ info->callback = callback;
+ info->user_data = user_data;
+
+ gtk_clipboard_request_contents (clipboard, gdk_atom_intern_static_string ("text/uri-list"),
+ request_uris_received_func,
+ info);
+}
+