summaryrefslogtreecommitdiff
path: root/gtk/gtkselection.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-10-22 20:47:01 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-10-22 20:47:01 +0000
commit92d2dc0ba639efbc360a3de34d4a2ae722afa098 (patch)
tree07727da269ec0f3ecac5f8e6973354999342fdcc /gtk/gtkselection.c
parent8fe966936c5b855b27aca8e9b2d07839d14662a4 (diff)
downloadgdk-pixbuf-92d2dc0ba639efbc360a3de34d4a2ae722afa098.tar.gz
Fixing popup menus to have "Paste" sensitized correctly. Original patches
Mon Oct 22 16:25:12 2001 Owen Taylor <otaylor@redhat.com> Fixing popup menus to have "Paste" sensitized correctly. Original patches from Damian Ivereigh, much mangled. * gtk/gtkselection.c: Add functions gtk_selection_data_get_targets(), gtk_selection_data_targets_include_text(). (#60854) * gtk/gtkclipboard.c: Add a simple do-it-all non-async "check if the clipboard has text" function gtk_clipboard_wait_is_text_available. (#60854) * gtk/gtkentry.c: Only enable the paste item if the clipboard contains text. (#60973) * gtk/gtktextview.c: Only enable the paste item if the clipboard contains text. (#60975)
Diffstat (limited to 'gtk/gtkselection.c')
-rw-r--r--gtk/gtkselection.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index 5b7d39160..21bcb510b 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -866,6 +866,84 @@ gtk_selection_data_get_text (GtkSelectionData *selection_data)
return result;
}
+/**
+ * gtk_selection_data_get_targets:
+ * @selection_data: a #GtkSelectionData object
+ * @targets: location to store an array of targets. The result
+ * stored here must be freed with g_free().
+ * @n_atoms: location to store number of items in @targets.
+ *
+ * Get the contents of @selection_data as an array of targets.
+ * This can be used to interpret the results of getting
+ * the standard TARGETS target that is always supplied for
+ * any selection.
+ *
+ * Return value: %TRUE if @selection_data contains a valid
+ * array of targets, otherwise %FALSE.
+ **/
+gboolean
+gtk_selection_data_get_targets (GtkSelectionData *selection_data,
+ GdkAtom **targets,
+ gint *n_atoms)
+{
+ if (selection_data->length >= 0 &&
+ selection_data->format == 32 &&
+ selection_data->type == GDK_SELECTION_TYPE_ATOM)
+ {
+ if (targets)
+ *targets = g_memdup (selection_data->data, selection_data->length);
+ if (n_atoms)
+ *n_atoms = selection_data->length / sizeof (GdkAtom);
+
+ return TRUE;
+ }
+ else
+ {
+ if (targets)
+ *targets = NULL;
+ if (n_atoms)
+ *n_atoms = -1;
+
+ return FALSE;
+ }
+}
+
+/**
+ * gtk_selection_data_targets_include_text:
+ * @selection_data: a #GtkSelectionData object
+ *
+ * Given a #GtkSelectionData object holding a list of targets,
+ * Determines if any of the targets in @targets can be used to
+ * provide text.
+ *
+ * Return value: %TRUE if @selection_data holds a list of targets,
+ * and a suitable target for text is included, otherwise %FALSE.
+ **/
+gboolean
+gtk_selection_data_targets_include_text (GtkSelectionData *selection_data)
+{
+ GdkAtom *targets;
+ gint n_targets;
+ gint i;
+ gboolean result = FALSE;
+
+ if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
+ {
+ for (i=0; i < n_targets; i++)
+ {
+ if (targets[i] == gdk_atom_intern ("STRING", FALSE) ||
+ targets[i] == gdk_atom_intern ("TEXT", FALSE) ||
+ targets[i] == gdk_atom_intern ("COMPOUND_TEXT", FALSE) ||
+ targets[i] == gdk_atom_intern ("UTF8_STRING", FALSE))
+ result = TRUE;
+ }
+
+ g_free (targets);
+ }
+
+ return result;
+}
+
/*************************************************************
* gtk_selection_init:
* Initialize local variables