diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 15 | ||||
-rw-r--r-- | gtk/gtkdnd.c | 48 | ||||
-rw-r--r-- | gtk/gtkdnd.h | 2 | ||||
-rw-r--r-- | gtk/gtkselection.c | 145 | ||||
-rw-r--r-- | gtk/gtkselection.h | 5 |
8 files changed, 260 insertions, 0 deletions
@@ -1,3 +1,18 @@ +2004-10-21 Matthias Clasen <mclasen@redhat.com> + + Add convenience api for image dnd (#150165): + + * gtk/gtkselection.h: + * gtk/gtkselection.c (gtk_target_list_add_image_targets) + (gtk_selection_data_set_pixbuf, gtk_selection_data_get_pixbuf): + New functions to handle the image formats readable/writable + by gdk-pixbuf. + + * gtk/gtkdnd.h: + * gtk/gtkdnd.c (gtk_drag_dest_add_image_targets) + (gtk_drag_source_add_text_targets): New functions to handle + the image formats readable/writable by gdk-pixbuf. + 2004-10-20 Matthias Clasen <mclasen@redhat.com> * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_new): Make diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 2ebf9fe288..7829116898 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,18 @@ +2004-10-21 Matthias Clasen <mclasen@redhat.com> + + Add convenience api for image dnd (#150165): + + * gtk/gtkselection.h: + * gtk/gtkselection.c (gtk_target_list_add_image_targets) + (gtk_selection_data_set_pixbuf, gtk_selection_data_get_pixbuf): + New functions to handle the image formats readable/writable + by gdk-pixbuf. + + * gtk/gtkdnd.h: + * gtk/gtkdnd.c (gtk_drag_dest_add_image_targets) + (gtk_drag_source_add_text_targets): New functions to handle + the image formats readable/writable by gdk-pixbuf. + 2004-10-20 Matthias Clasen <mclasen@redhat.com> * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_new): Make diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 2ebf9fe288..7829116898 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,18 @@ +2004-10-21 Matthias Clasen <mclasen@redhat.com> + + Add convenience api for image dnd (#150165): + + * gtk/gtkselection.h: + * gtk/gtkselection.c (gtk_target_list_add_image_targets) + (gtk_selection_data_set_pixbuf, gtk_selection_data_get_pixbuf): + New functions to handle the image formats readable/writable + by gdk-pixbuf. + + * gtk/gtkdnd.h: + * gtk/gtkdnd.c (gtk_drag_dest_add_image_targets) + (gtk_drag_source_add_text_targets): New functions to handle + the image formats readable/writable by gdk-pixbuf. + 2004-10-20 Matthias Clasen <mclasen@redhat.com> * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_new): Make diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 2ebf9fe288..7829116898 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,18 @@ +2004-10-21 Matthias Clasen <mclasen@redhat.com> + + Add convenience api for image dnd (#150165): + + * gtk/gtkselection.h: + * gtk/gtkselection.c (gtk_target_list_add_image_targets) + (gtk_selection_data_set_pixbuf, gtk_selection_data_get_pixbuf): + New functions to handle the image formats readable/writable + by gdk-pixbuf. + + * gtk/gtkdnd.h: + * gtk/gtkdnd.c (gtk_drag_dest_add_image_targets) + (gtk_drag_source_add_text_targets): New functions to handle + the image formats readable/writable by gdk-pixbuf. + 2004-10-20 Matthias Clasen <mclasen@redhat.com> * gtk/gtktreemodelfilter.c (gtk_tree_model_filter_new): Make diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 61061e3f76..60b88ceac0 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -1049,6 +1049,30 @@ gtk_drag_dest_add_text_targets (GtkWidget *widget) gtk_target_list_unref (target_list); } +/** + * gtk_drag_dest_add_image_targets: + * @widget: a #GtkWidget that's a drag destination + * + * Add the image targets supported by #GtkSelection to + * the target list of the drag destination. + * + * Since: 2.6 + **/ +void +gtk_drag_dest_add_image_targets (GtkWidget *widget) +{ + GtkTargetList *target_list; + + target_list = gtk_drag_dest_get_target_list (widget); + if (target_list) + gtk_target_list_ref (target_list); + else + target_list = gtk_target_list_new (NULL, 0); + gtk_target_list_add_image_targets (target_list, FALSE); + gtk_drag_dest_set_target_list (widget, target_list); + gtk_target_list_unref (target_list); +} + /************************************************************* * _gtk_drag_dest_handle_event: * Called from widget event handling code on Drag events @@ -2216,6 +2240,30 @@ gtk_drag_source_add_text_targets (GtkWidget *widget) gtk_target_list_unref (target_list); } +/** + * gtk_drag_source_add_image_targets: + * @widget: a #GtkWidget that's is a drag source + * + * Add the writable image targets supported by #GtkSelection to + * the target list of the drag source. + * + * Since: 2.6 + **/ +void +gtk_drag_source_add_image_targets (GtkWidget *widget) +{ + GtkTargetList *target_list; + + target_list = gtk_drag_source_get_target_list (widget); + if (target_list) + gtk_target_list_ref (target_list); + else + target_list = gtk_target_list_new (NULL, 0); + gtk_target_list_add_image_targets (target_list, TRUE); + gtk_drag_source_set_target_list (widget, target_list); + gtk_target_list_unref (target_list); +} + static void gtk_drag_source_unset_icon (GtkDragSourceSite *site) { diff --git a/gtk/gtkdnd.h b/gtk/gtkdnd.h index bfcbb50c37..1932340290 100644 --- a/gtk/gtkdnd.h +++ b/gtk/gtkdnd.h @@ -86,6 +86,7 @@ GtkTargetList* gtk_drag_dest_get_target_list (GtkWidget *widget); void gtk_drag_dest_set_target_list (GtkWidget *widget, GtkTargetList *target_list); void gtk_drag_dest_add_text_targets (GtkWidget *widget); +void gtk_drag_dest_add_image_targets (GtkWidget *widget); /* Source side */ @@ -101,6 +102,7 @@ GtkTargetList* gtk_drag_source_get_target_list (GtkWidget *widget); void gtk_drag_source_set_target_list (GtkWidget *widget, GtkTargetList *target_list); void gtk_drag_source_add_text_targets (GtkWidget *widget); +void gtk_drag_source_add_image_targets (GtkWidget *widget); void gtk_drag_source_set_icon (GtkWidget *widget, GdkColormap *colormap, diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index e9fab86014..44f39e3b2b 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -59,6 +59,7 @@ #include "gtkalias.h" #include "gtkmain.h" #include "gtkselection.h" +#include "gdk-pixbuf/gdk-pixbuf.h" #ifdef GDK_WINDOWING_X11 #include "x11/gdkx.h" @@ -294,6 +295,49 @@ gtk_target_list_add_text_targets (GtkTargetList *list) gtk_target_list_add (list, text_plain_atom, 0, 0); } +/** + * gtk_target_list_add_image_targets: + * @list: a #GtkTargetList + * @writable: whether to add only targets for which GTK+ knows + * how to convert a pixbuf into the format + * + * Adds the image targets supported by #GtkSelection to + * the target list. The targets are added with both flags + * and info being zero. + * + * Since: 2.6 + **/ +void +gtk_target_list_add_image_targets (GtkTargetList *list, + gboolean writable) +{ + GSList *formats, *f; + gchar **mimes, **m; + GdkAtom atom; + + g_return_if_fail (list != NULL); + + formats = gdk_pixbuf_get_formats (); + + 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, 0); + } + g_strfreev (mimes); + } + + g_slist_free (formats); +} + void gtk_target_list_add_table (GtkTargetList *list, const GtkTargetEntry *targets, @@ -1158,6 +1202,107 @@ gtk_selection_data_get_text (GtkSelectionData *selection_data) } /** + * 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; + + 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); + 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; + + loader = gdk_pixbuf_loader_new (); + + if (gdk_pixbuf_loader_write (loader, + selection_data->data, + selection_data->length, + NULL)) + result = gdk_pixbuf_loader_get_pixbuf (loader); + + if (result) + g_object_ref (result); + + gdk_pixbuf_loader_close (loader, NULL); + g_object_unref (loader); + + return result; +} + + +/** * gtk_selection_data_get_targets: * @selection_data: a #GtkSelectionData object * @targets: location to store an array of targets. The result diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h index 9e398a8e6d..02bbd8a0f0 100644 --- a/gtk/gtkselection.h +++ b/gtk/gtkselection.h @@ -96,6 +96,8 @@ void gtk_target_list_add (GtkTargetList *list, guint flags, guint info); void gtk_target_list_add_text_targets (GtkTargetList *list); +void gtk_target_list_add_image_targets (GtkTargetList *list, + gboolean writable); void gtk_target_list_add_table (GtkTargetList *list, const GtkTargetEntry *targets, guint ntargets); @@ -138,6 +140,9 @@ gboolean gtk_selection_data_set_text (GtkSelectionData *selection_data, const gchar *str, gint len); guchar * gtk_selection_data_get_text (GtkSelectionData *selection_data); +gboolean gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data, + GdkPixbuf *pixbuf); +GdkPixbuf *gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data); gboolean gtk_selection_data_get_targets (GtkSelectionData *selection_data, GdkAtom **targets, |