From 7ee4ea8719283be67608bcfe7372e800c38fc2a9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 30 Aug 2005 05:42:37 +0000 Subject: [PATCH] Add functions which look for text, image or uri targets in an array of 2005-08-30 Matthias Clasen * gtk/gtk.symbols: * gtk/gtkselection.h: * gtk/gtkselection.c: Add functions which look for text, image or uri targets in an array of atoms. (#314089, Mark Wielaard) --- ChangeLog | 5 + ChangeLog.pre-2-10 | 5 + docs/reference/ChangeLog | 1 + docs/reference/gtk/gtk-sections.txt | 3 + gtk/gtk.symbols | 3 + gtk/gtkselection.c | 168 ++++++++++++++++++++-------- gtk/gtkselection.h | 7 ++ 7 files changed, 145 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10040aaac6..7bdfbd12c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-08-30 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtkselection.h: + * gtk/gtkselection.c: Add functions which look for text, image + or uri targets in an array of atoms. (#314089, Mark Wielaard) + * gtk/gtk.symbols: * gtk/gtkselection.h: * gtk/gtkselection.c (gtk_selection_data_targets_include_uri): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 10040aaac6..7bdfbd12c2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,10 @@ 2005-08-30 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtkselection.h: + * gtk/gtkselection.c: Add functions which look for text, image + or uri targets in an array of atoms. (#314089, Mark Wielaard) + * gtk/gtk.symbols: * gtk/gtkselection.h: * gtk/gtkselection.c (gtk_selection_data_targets_include_uri): diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f8cec45e74..a88aeffe1c 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -2,6 +2,7 @@ * gtk/gtk-sections.txt: Add gtk_window_[sg]et_deletable. Add gtk_selection_data_targets_include_uri. + Add gtk_targets_include... functions. 2005-08-29 Matthias Clasen diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 26b4e4a441..ed4d89ed25 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -5147,6 +5147,9 @@ gtk_selection_data_get_targets gtk_selection_data_targets_include_image gtk_selection_data_targets_include_text gtk_selection_data_targets_include_uri +gtk_targets_include_image +gtk_targets_include_text +gtk_targets_include_uri gtk_selection_remove_all gtk_selection_clear gtk_selection_data_copy diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 5e31af30f4..1c1a24fbff 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2612,6 +2612,9 @@ gtk_selection_data_set_uris gtk_selection_data_targets_include_image gtk_selection_data_targets_include_text gtk_selection_data_targets_include_uri +gtk_targets_include_image +gtk_targets_include_text +gtk_targets_include_uri gtk_selection_owner_set gtk_selection_owner_set_for_display gtk_selection_remove_all diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index 57294758fa..067409c949 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -1568,6 +1568,46 @@ gtk_selection_data_get_targets (GtkSelectionData *selection_data, } } +/** + * gtk_targets_include_text: + * @targets: an array of #GdkAtoms + * @n_targets: the length of @targets + * + * Determines if any of the targets in @targets can be used to + * provide text. + * + * Return value: %TRUE if @targets include a suitable target for text, + * otherwise %FALSE. + * + * Since: 2.10 + **/ +gboolean +gtk_targets_include_text (GdkAtom *targets, + gint n_targets) +{ + gint i; + gboolean result = FALSE; + + /* Keep in sync with gtk_target_list_add_text_targets() + */ + for (i = 0; i < n_targets; i++) + { + if (targets[i] == utf8_atom || + targets[i] == text_atom || + targets[i] == GDK_TARGET_STRING || + targets[i] == ctext_atom || + targets[i] == text_plain_atom || + targets[i] == text_plain_utf8_atom || + targets[i] == text_plain_locale_atom) + { + result = TRUE; + break; + } + } + + return result; +} + /** * gtk_selection_data_targets_include_text: * @selection_data: a #GtkSelectionData object @@ -1584,36 +1624,63 @@ gtk_selection_data_targets_include_text (GtkSelectionData *selection_data) { GdkAtom *targets; gint n_targets; - gint i; gboolean result = FALSE; - /* Keep in sync with gtk_target_list_add_text_targets() - */ init_atoms (); if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) { - for (i=0; i < n_targets; i++) - { - if (targets[i] == utf8_atom || - targets[i] == text_atom || - targets[i] == GDK_TARGET_STRING || - targets[i] == ctext_atom || - targets[i] == text_plain_atom || - targets[i] == text_plain_utf8_atom || - targets[i] == text_plain_locale_atom) - { - result = TRUE; - break; - } - } - + result = gtk_targets_include_text (targets, n_targets); g_free (targets); } return result; } +/** + * gtk_targets_include_image: + * @targets: an array of #GdkAtoms + * @n_targets: the length of @targets + * @writable: whether to accept only targets for which GTK+ knows + * how to convert a pixbuf into the format + * + * Determines if any of the targets in @targets can be used to + * provide a #GdkPixbuf. + * + * Return value: %TRUE if @targets include a suitable target for images, + * otherwise %FALSE. + * + * Since: 2.10 + **/ +gboolean +gtk_targets_include_image (GdkAtom *targets, + gint n_targets, + gboolean writable) +{ + GtkTargetList *list; + GList *l; + gint i; + gboolean result = FALSE; + + list = gtk_target_list_new (NULL, 0); + gtk_target_list_add_image_targets (list, 0, writable); + for (i = 0; i < n_targets && !result; i++) + { + for (l = list->list; l; l = l->next) + { + GtkTargetPair *pair = (GtkTargetPair *)l->data; + if (pair->target == targets[i]) + { + result = TRUE; + break; + } + } + } + gtk_target_list_unref (list); + + return result; +} + /** * gtk_selection_data_targets_include_image: * @selection_data: a #GtkSelectionData object @@ -1635,35 +1702,53 @@ gtk_selection_data_targets_include_image (GtkSelectionData *selection_data, { GdkAtom *targets; gint n_targets; - gint i; gboolean result = FALSE; - GtkTargetList *list; - GList *l; - /* Keep in sync with gtk_target_list_add_image_targets() - */ init_atoms (); if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) { - list = gtk_target_list_new (NULL, 0); - gtk_target_list_add_image_targets (list, 0, writable); - for (i=0; i < n_targets && !result; i++) - { - for (l = list->list; l && !result; l = l->next) - { - GtkTargetPair *pair = (GtkTargetPair *)l->data; - if (pair->target == targets[i]) - result = TRUE; - } - } - gtk_target_list_unref (list); + result = gtk_targets_include_image (targets, n_targets, writable); g_free (targets); } return result; } +/** + * gtk_targets_include_uri: + * @targets: an array of #GdkAtoms + * @n_targets: the length of @targets + * + * Determines if any of the targets in @targets can be used to + * provide an uri list. + * + * Return value: %TRUE if @targets include a suitable target for uri lists, + * otherwise %FALSE. + * + * Since: 2.10 + **/ +gboolean +gtk_targets_include_uri (GdkAtom *targets, + gint n_targets) +{ + gint i; + gboolean result = FALSE; + + /* Keep in sync with gtk_target_list_add_uri_targets() + */ + for (i = 0; i < n_targets; i++) + { + if (targets[i] == text_uri_list_atom) + { + result = TRUE; + break; + } + } + + return result; +} + /** * gtk_selection_data_targets_include_uri: * @selection_data: a #GtkSelectionData object @@ -1682,24 +1767,13 @@ gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data) { GdkAtom *targets; gint n_targets; - gint i; gboolean result = FALSE; - /* Keep in sync with gtk_target_list_add_uri_targets() - */ init_atoms (); if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) { - for (i=0; i < n_targets; i++) - { - if (targets[i] == text_uri_list_atom) - { - result = TRUE; - break; - } - } - + result = gtk_targets_include_uri (targets, n_targets); g_free (targets); } diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h index a37b3f35af..038a16a972 100644 --- a/gtk/gtkselection.h +++ b/gtk/gtkselection.h @@ -156,6 +156,13 @@ gboolean gtk_selection_data_targets_include_text (GtkSelectionData *selection_d gboolean gtk_selection_data_targets_include_image (GtkSelectionData *selection_data, gboolean writable); gboolean gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data); +gboolean gtk_targets_include_text (GdkAtom *targets, + gint n_targets); +gboolean gtk_targets_include_image (GdkAtom *targets, + gint n_targets, + gboolean writable); +gboolean gtk_targets_include_uri (GdkAtom *targets, + gint n_targets); /* Called when a widget is destroyed */