summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-11-14 05:34:15 +0100
committerBenjamin Otte <otte@redhat.com>2017-11-15 19:07:16 +0100
commit7efc5a1558449194caedaae5f27e4c9c48d88ab7 (patch)
tree09b7c0e0de23b1d24dc14b083bdccc84616d8986
parentfb94f79094745a0e3fc64d5d56cea1637a8fdb73 (diff)
downloadgtk+-7efc5a1558449194caedaae5f27e4c9c48d88ab7.tar.gz
clipboard: Consistently use GtkTargetList
Some code was using GtkTargetList, some used GtkTargetEntry and some GtkTargetPair.
-rw-r--r--demos/gtk-demo/clipboard.c2
-rw-r--r--docs/reference/gtk/gtk4-sections.txt1
-rw-r--r--gtk/gtkclipboard.c113
-rw-r--r--gtk/gtkclipboard.h9
-rw-r--r--gtk/gtkclipboardprivate.h6
-rw-r--r--gtk/gtkentry.c7
-rw-r--r--gtk/gtkfilechooserwidget.c9
-rw-r--r--gtk/gtklabel.c6
-rw-r--r--gtk/gtkselection.c62
-rw-r--r--gtk/gtkselection.h6
-rw-r--r--gtk/gtkselectionprivate.h3
-rw-r--r--gtk/gtktextbuffer.c124
-rw-r--r--tests/testselection.c6
-rw-r--r--testsuite/gtk/clipboard.c5
14 files changed, 173 insertions, 186 deletions
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index f0b4154803..de9ffd80c8 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -320,7 +320,7 @@ do_clipboard (GtkWidget *do_widget)
/* tell the clipboard manager to make the data persistent */
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_can_store (clipboard, NULL, 0);
+ gtk_clipboard_set_can_store (clipboard, NULL);
}
if (!gtk_widget_get_visible (window))
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 6aa7b283bb..683a878f09 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5227,6 +5227,7 @@ gtk_target_list_ref
gtk_target_list_unref
gtk_target_list_add
gtk_target_list_add_table
+gtk_target_list_merge
gtk_target_list_add_text_targets
gtk_target_list_add_image_targets
gtk_target_list_add_uri_targets
diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c
index b066546c02..5379be87da 100644
--- a/gtk/gtkclipboard.c
+++ b/gtk/gtkclipboard.c
@@ -26,6 +26,7 @@
#include "gtkinvisible.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
+#include "gtkselectionprivate.h"
#include "gtktextbufferrichtext.h"
#include "gtkintl.h"
@@ -163,8 +164,7 @@ static void gtk_clipboard_finalize (GObject *object);
static void gtk_clipboard_owner_change (GtkClipboard *clipboard,
GdkEventOwnerChange *event);
static gboolean gtk_clipboard_set_contents (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
gpointer user_data,
@@ -175,8 +175,7 @@ static void gtk_clipboard_real_request_contents (GtkClipboard
GtkClipboardReceivedFunc callback,
gpointer user_data);
static void gtk_clipboard_real_set_can_store (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- gint n_targets);
+ GtkTargetList *targets);
static void gtk_clipboard_real_store (GtkClipboard *clipboard);
@@ -593,8 +592,7 @@ clipboard_remove_owner_notify (GtkClipboard *clipboard)
static gboolean
gtk_clipboard_set_contents (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
gpointer user_data,
@@ -631,8 +629,7 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard,
clipboard->clear_func = clear_func;
gtk_selection_clear_targets (clipboard_widget, clipboard->selection);
- gtk_selection_add_targets (clipboard_widget, clipboard->selection,
- targets, n_targets);
+ gtk_selection_add_targets (clipboard_widget, clipboard->selection, targets);
return TRUE;
}
@@ -643,9 +640,8 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard,
/**
* gtk_clipboard_set_with_data: (skip)
* @clipboard: a #GtkClipboard
- * @targets: (array length=n_targets): array containing information
- * about the available forms for the clipboard data
- * @n_targets: number of elements in @targets
+ * @targets: The targets (data formats) in which the
+ * functions can provide the data
* @get_func: (scope async): function to call to get the actual clipboard data
* @clear_func: (scope async): when the clipboard contents are set again,
* this function will be called, and @get_func will not be subsequently
@@ -662,8 +658,7 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard,
**/
gboolean
gtk_clipboard_set_with_data (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
gpointer user_data)
@@ -674,7 +669,6 @@ gtk_clipboard_set_with_data (GtkClipboard *clipboard,
return GTK_CLIPBOARD_GET_CLASS (clipboard)->set_contents (clipboard,
targets,
- n_targets,
get_func,
clear_func,
user_data,
@@ -684,9 +678,8 @@ gtk_clipboard_set_with_data (GtkClipboard *clipboard,
/**
* gtk_clipboard_set_with_owner: (skip)
* @clipboard: a #GtkClipboard
- * @targets: (array length=n_targets): array containing information
- * about the available forms for the clipboard data
- * @n_targets: number of elements in @targets
+ * @targets: The targets (data formats) in which the
+ * functions can provide the data
* @get_func: (scope async): function to call to get the actual clipboard data
* @clear_func: (scope async): when the clipboard contents are set again,
* this function will be called, and @get_func will not be subsequently
@@ -708,8 +701,7 @@ gtk_clipboard_set_with_data (GtkClipboard *clipboard,
**/
gboolean
gtk_clipboard_set_with_owner (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
GObject *owner)
@@ -721,7 +713,6 @@ gtk_clipboard_set_with_owner (GtkClipboard *clipboard,
return GTK_CLIPBOARD_GET_CLASS (clipboard)->set_contents (clipboard,
targets,
- n_targets,
get_func,
clear_func,
owner,
@@ -851,29 +842,24 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
const gchar *text,
gint len)
{
- GtkTargetList *list;
- GtkTargetEntry *targets;
- gint n_targets;
+ GtkTargetList *targets;
g_return_if_fail (clipboard != NULL);
g_return_if_fail (text != NULL);
- list = gtk_target_list_new (NULL, 0);
- gtk_target_list_add_text_targets (list, 0);
+ targets = gtk_target_list_new (NULL, 0);
+ gtk_target_list_add_text_targets (targets, 0);
- targets = gtk_target_table_new_from_list (list, &n_targets);
-
if (len < 0)
len = strlen (text);
gtk_clipboard_set_with_data (clipboard,
- targets, n_targets,
+ targets,
text_get_func, text_clear_func,
g_strndup (text, len));
- gtk_clipboard_set_can_store (clipboard, NULL, 0);
+ gtk_clipboard_set_can_store (clipboard, NULL);
- gtk_target_table_free (targets, n_targets);
- gtk_target_list_unref (list);
+ gtk_target_list_unref (targets);
}
static void
@@ -908,26 +894,21 @@ void
gtk_clipboard_set_image (GtkClipboard *clipboard,
GdkPixbuf *pixbuf)
{
- GtkTargetList *list;
- GtkTargetEntry *targets;
- gint n_targets;
+ GtkTargetList *targets;
g_return_if_fail (clipboard != NULL);
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
- list = gtk_target_list_new (NULL, 0);
- gtk_target_list_add_image_targets (list, 0, TRUE);
-
- targets = gtk_target_table_new_from_list (list, &n_targets);
+ targets = gtk_target_list_new (NULL, 0);
+ gtk_target_list_add_image_targets (targets, 0, TRUE);
gtk_clipboard_set_with_data (clipboard,
- targets, n_targets,
+ targets,
pixbuf_get_func, pixbuf_clear_func,
g_object_ref (pixbuf));
- gtk_clipboard_set_can_store (clipboard, NULL, 0);
+ gtk_clipboard_set_can_store (clipboard, NULL);
- gtk_target_table_free (targets, n_targets);
- gtk_target_list_unref (list);
+ gtk_target_list_unref (targets);
}
/**
@@ -2128,9 +2109,9 @@ gtk_clipboard_store_timeout (GtkClipboard *clipboard)
/**
* gtk_clipboard_set_can_store:
* @clipboard: a #GtkClipboard
- * @targets: (allow-none) (array length=n_targets): array containing
- * information about which forms should be stored or %NULL
- * to indicate that all forms should be stored.
+ * @targets: (allow-none): The targets (data formats) in which the
+ * functions can provide the data or %NULL
+ * to indicate that all forms should be stored.
* @n_targets: number of elements in @targets
*
* Hints that the clipboard data should be stored somewhere when the
@@ -2143,29 +2124,21 @@ gtk_clipboard_store_timeout (GtkClipboard *clipboard)
* Since: 2.6
*/
void
-gtk_clipboard_set_can_store (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- gint n_targets)
+gtk_clipboard_set_can_store (GtkClipboard *clipboard,
+ GtkTargetList *targets)
{
g_return_if_fail (GTK_IS_CLIPBOARD (clipboard));
- g_return_if_fail (n_targets >= 0);
- GTK_CLIPBOARD_GET_CLASS (clipboard)->set_can_store (clipboard,
- targets,
- n_targets);
+ GTK_CLIPBOARD_GET_CLASS (clipboard)->set_can_store (clipboard, targets);
}
static void
-gtk_clipboard_real_set_can_store (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- gint n_targets)
+gtk_clipboard_real_set_can_store (GtkClipboard *clipboard,
+ GtkTargetList *targets)
{
GtkWidget *clipboard_widget;
- int i;
- static const GtkTargetEntry save_targets[] = {
- { (char *) "SAVE_TARGETS", 0, TARGET_SAVE_TARGETS }
- };
-
+ guint n_atoms;
+
if (clipboard->selection != GDK_SELECTION_CLIPBOARD)
return;
@@ -2180,18 +2153,26 @@ gtk_clipboard_real_set_can_store (GtkClipboard *clipboard,
*/
if (clipboard->n_storable_targets == -1)
{
- gtk_selection_add_targets (clipboard_widget, clipboard->selection,
- save_targets, 1);
+ gtk_selection_add_target (clipboard_widget,
+ clipboard->selection,
+ gdk_atom_intern_static_string ("SAVE_TARGETS"),
+ TARGET_SAVE_TARGETS);
/* Ref the owner so it won't go away */
if (clipboard->have_owner)
g_object_ref (clipboard->user_data);
}
- clipboard->n_storable_targets = n_targets;
- clipboard->storable_targets = g_new (GdkAtom, n_targets);
- for (i = 0; i < n_targets; i++)
- clipboard->storable_targets[i] = gdk_atom_intern (targets[i].target, FALSE);
+ if (targets)
+ {
+ clipboard->storable_targets = gtk_target_list_get_atoms (targets, &n_atoms);
+ clipboard->n_storable_targets = n_atoms;
+ }
+ else
+ {
+ clipboard->storable_targets = NULL;
+ clipboard->n_storable_targets = 0;
+ }
}
static gboolean
diff --git a/gtk/gtkclipboard.h b/gtk/gtkclipboard.h
index 68a68a6229..29ea58581a 100644
--- a/gtk/gtkclipboard.h
+++ b/gtk/gtkclipboard.h
@@ -198,15 +198,13 @@ GdkDisplay *gtk_clipboard_get_display (GtkClipboard *clipboard);
GDK_AVAILABLE_IN_ALL
gboolean gtk_clipboard_set_with_data (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
gpointer user_data);
GDK_AVAILABLE_IN_ALL
gboolean gtk_clipboard_set_with_owner (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
GObject *owner);
@@ -289,8 +287,7 @@ gboolean gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
GDK_AVAILABLE_IN_ALL
void gtk_clipboard_set_can_store (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- gint n_targets);
+ GtkTargetList *targets);
GDK_AVAILABLE_IN_ALL
void gtk_clipboard_store (GtkClipboard *clipboard);
diff --git a/gtk/gtkclipboardprivate.h b/gtk/gtkclipboardprivate.h
index 8792239596..d4c0b1857d 100644
--- a/gtk/gtkclipboardprivate.h
+++ b/gtk/gtkclipboardprivate.h
@@ -63,8 +63,7 @@ struct _GtkClipboardClass
/* vfuncs */
gboolean (* set_contents) (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- guint n_targets,
+ GtkTargetList *targets,
GtkClipboardGetFunc get_func,
GtkClipboardClearFunc clear_func,
gpointer user_data,
@@ -75,8 +74,7 @@ struct _GtkClipboardClass
GtkClipboardReceivedFunc callback,
gpointer user_data);
void (* set_can_store) (GtkClipboard *clipboard,
- const GtkTargetEntry *targets,
- gint n_targets);
+ GtkTargetList *targets);
void (* store) (GtkClipboard *clipboard);
/* signals */
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 7056b82556..185450da66 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -6557,10 +6557,8 @@ static void
gtk_entry_update_primary_selection (GtkEntry *entry)
{
GtkTargetList *list;
- GtkTargetEntry *targets;
GtkClipboard *clipboard;
gint start, end;
- gint n_targets;
if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
return;
@@ -6568,13 +6566,11 @@ gtk_entry_update_primary_selection (GtkEntry *entry)
list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_text_targets (list, 0);
- targets = gtk_target_table_new_from_list (list, &n_targets);
-
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
{
- gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
+ gtk_clipboard_set_with_owner (clipboard, list,
primary_get_cb, primary_clear_cb, G_OBJECT (entry));
}
else
@@ -6583,7 +6579,6 @@ gtk_entry_update_primary_selection (GtkEntry *entry)
gtk_clipboard_clear (clipboard);
}
- gtk_target_table_free (targets, n_targets);
gtk_target_list_unref (list);
}
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index d2f9d5fa5d..4176457d57 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -1733,8 +1733,6 @@ copy_file_location_cb (GSimpleAction *action,
{
GtkClipboard *clipboard;
GtkTargetList *target_list;
- GtkTargetEntry *targets;
- int n_targets;
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD);
@@ -1742,15 +1740,12 @@ copy_file_location_cb (GSimpleAction *action,
gtk_target_list_add_text_targets (target_list, SELECTION_TEXT);
gtk_target_list_add_uri_targets (target_list, SELECTION_URI);
- targets = gtk_target_table_new_from_list (target_list, &n_targets);
- gtk_target_list_unref (target_list);
-
- gtk_clipboard_set_with_data (clipboard, targets, n_targets,
+ gtk_clipboard_set_with_data (clipboard, target_list,
copy_file_get_cb,
copy_file_clear_cb,
selected_files);
- gtk_target_table_free (targets, n_targets);
+ gtk_target_list_unref (target_list);
}
}
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 9f7a7d6e89..ba0d7db3d6 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -5230,21 +5230,17 @@ gtk_label_select_region_index (GtkLabel *label,
if (anchor_index != end_index)
{
GtkTargetList *list;
- GtkTargetEntry *targets;
- gint n_targets;
list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_text_targets (list, 0);
- targets = gtk_target_table_new_from_list (list, &n_targets);
if (clipboard)
gtk_clipboard_set_with_owner (clipboard,
- targets, n_targets,
+ list,
get_text_callback,
clear_text_callback,
G_OBJECT (label));
- gtk_target_table_free (targets, n_targets);
gtk_target_list_unref (list);
if (!priv->select_info->selection_node)
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index 2ab9dc7b40..c72f695dc0 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -502,6 +502,28 @@ gtk_target_list_add_uri_targets (GtkTargetList *list,
}
/**
+ * gtk_target_list_merge:
+ * @target: the #GtkTargetList to merge into
+ * @source: the #GtkTargeList to merge from
+ *
+ * Merges all targets from @source into @target.
+ */
+void
+gtk_target_list_merge (GtkTargetList *target,
+ const GtkTargetList *source)
+{
+ GList *l;
+
+ g_return_if_fail (target != NULL);
+ g_return_if_fail (source != NULL);
+
+ for (l = source->list; l; l = l->next)
+ {
+ target->list = g_list_prepend (target->list, g_slice_dup (GtkTargetPair, l->data));
+ }
+}
+
+/**
* gtk_target_list_add_table:
* @list: a #GtkTargetList
* @targets: (array length=ntargets): the table of #GtkTargetEntry
@@ -600,6 +622,27 @@ gtk_target_list_find (GtkTargetList *list,
return FALSE;
}
+GdkAtom *
+gtk_target_list_get_atoms (GtkTargetList *list,
+ guint *n_atoms)
+{
+ GdkAtom *atoms;
+ GList *l;
+ guint i, n;
+
+ n = g_list_length (list->list);
+ atoms = g_new (GdkAtom, n);
+
+ i = 0;
+ for (l = list->list; l; l = l->next)
+ atoms[i++] = ((GtkTargetPair *) l->data)->target;
+
+ if (n_atoms)
+ *n_atoms = n;
+
+ return atoms;
+}
+
/**
* gtk_target_table_new_from_list:
* @list: a #GtkTargetList
@@ -938,26 +981,23 @@ gtk_selection_add_target (GtkWidget *widget,
* for a given widget and selection.
**/
void
-gtk_selection_add_targets (GtkWidget *widget,
- GdkAtom selection,
- const GtkTargetEntry *targets,
- guint ntargets)
+gtk_selection_add_targets (GtkWidget *widget,
+ GdkAtom selection,
+ GtkTargetList *targets)
{
GtkTargetList *list;
- GdkAtom *atoms = g_new (GdkAtom, ntargets);
- guint i;
+ GdkAtom *atoms;
+ guint n_targets;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (selection != GDK_NONE);
g_return_if_fail (targets != NULL);
list = gtk_selection_target_list_get (widget, selection);
- gtk_target_list_add_table (list, targets, ntargets);
-
- for (i = 0; i < ntargets; i++)
- atoms[i] = gdk_atom_intern (targets[i].target, FALSE);
+ gtk_target_list_merge (list, targets);
- gdk_selection_add_targets (gtk_widget_get_window (widget), selection, atoms, ntargets);
+ atoms = gtk_target_list_get_atoms (targets, &n_targets);
+ gdk_selection_add_targets (gtk_widget_get_window (widget), selection, atoms, n_targets);
g_free (atoms);
}
diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h
index 200272c0b1..04f706764e 100644
--- a/gtk/gtkselection.h
+++ b/gtk/gtkselection.h
@@ -119,6 +119,9 @@ GDK_AVAILABLE_IN_ALL
GtkTargetList *gtk_target_list_ref (GtkTargetList *list);
GDK_AVAILABLE_IN_ALL
void gtk_target_list_unref (GtkTargetList *list);
+GDK_AVAILABLE_IN_3_94
+void gtk_target_list_merge (GtkTargetList *target,
+ const GtkTargetList *source);
GDK_AVAILABLE_IN_ALL
void gtk_target_list_add (GtkTargetList *list,
GdkAtom target,
@@ -176,8 +179,7 @@ void gtk_selection_add_target (GtkWidget *widget,
GDK_AVAILABLE_IN_ALL
void gtk_selection_add_targets (GtkWidget *widget,
GdkAtom selection,
- const GtkTargetEntry *targets,
- guint ntargets);
+ GtkTargetList *targets);
GDK_AVAILABLE_IN_ALL
void gtk_selection_clear_targets (GtkWidget *widget,
GdkAtom selection);
diff --git a/gtk/gtkselectionprivate.h b/gtk/gtkselectionprivate.h
index d77432f9f7..49c1f5f71a 100644
--- a/gtk/gtkselectionprivate.h
+++ b/gtk/gtkselectionprivate.h
@@ -54,6 +54,9 @@ struct _GtkTargetList
guint ref_count;
};
+GdkAtom *gtk_target_list_get_atoms (GtkTargetList *targets,
+ guint *n_atoms);
+
gboolean _gtk_selection_clear (GtkWidget *widget,
GdkEventSelection *event);
gboolean _gtk_selection_request (GtkWidget *widget,
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c
index 77d735227f..1636b09206 100644
--- a/gtk/gtktextbuffer.c
+++ b/gtk/gtktextbuffer.c
@@ -57,12 +57,7 @@ typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
struct _GtkTextBufferPrivate
{
GtkTargetList *copy_target_list;
- GtkTargetEntry *copy_target_entries;
GtkTargetList *paste_target_list;
- GtkTargetEntry *paste_target_entries;
-
- gint n_copy_target_entries;
- gint n_paste_target_entries;
GtkTextTagTable *tag_table;
GtkTextBTree *btree;
@@ -3704,8 +3699,7 @@ update_selection_clipboards (GtkTextBuffer *buffer)
* timestamp.
*/
gtk_clipboard_set_with_owner (clipboard,
- priv->copy_target_entries,
- priv->n_copy_target_entries,
+ priv->copy_target_list,
clipboard_get_selection_cb,
clipboard_clear_selection_cb,
G_OBJECT (buffer));
@@ -4000,6 +3994,41 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
}
static void
+gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer)
+{
+ GtkTextBufferPrivate *priv = buffer->priv;
+
+ g_clear_pointer (&priv->copy_target_list, gtk_target_list_unref);
+ g_clear_pointer (&priv->paste_target_list, gtk_target_list_unref);
+}
+
+static GtkTargetList *
+gtk_text_buffer_get_target_list (GtkTextBuffer *buffer,
+ gboolean deserializable,
+ gboolean include_local)
+{
+ GtkTargetList *target_list;
+
+ target_list = gtk_target_list_new (NULL, 0);
+
+ if (include_local)
+ gtk_target_list_add (target_list,
+ gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
+ GTK_TARGET_SAME_APP,
+ GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS);
+
+ gtk_target_list_add_rich_text_targets (target_list,
+ GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT,
+ deserializable,
+ buffer);
+
+ gtk_target_list_add_text_targets (target_list,
+ GTK_TEXT_BUFFER_TARGET_INFO_TEXT);
+
+ return target_list;
+}
+
+static void
cut_or_copy (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gboolean delete_region_after,
@@ -4048,16 +4077,21 @@ cut_or_copy (GtkTextBuffer *buffer,
gtk_text_buffer_insert_range (contents, &ins, &start, &end);
if (!gtk_clipboard_set_with_data (clipboard,
- priv->copy_target_entries,
- priv->n_copy_target_entries,
+ priv->copy_target_list,
clipboard_get_contents_cb,
clipboard_clear_contents_cb,
contents))
- g_object_unref (contents);
+ {
+ g_object_unref (contents);
+ }
else
- gtk_clipboard_set_can_store (clipboard,
- priv->copy_target_entries + 1,
- priv->n_copy_target_entries - 1);
+ {
+ GtkTargetList *list;
+
+ list = gtk_text_buffer_get_target_list (buffer, FALSE, FALSE);
+ gtk_clipboard_set_can_store (clipboard, list);
+ gtk_target_list_unref (list);
+ }
if (delete_region_after)
{
@@ -4186,62 +4220,6 @@ gtk_text_buffer_end_user_action (GtkTextBuffer *buffer)
}
}
-static void
-gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer)
-{
- GtkTextBufferPrivate *priv = buffer->priv;
-
- if (priv->copy_target_list)
- {
- gtk_target_list_unref (priv->copy_target_list);
- priv->copy_target_list = NULL;
-
- gtk_target_table_free (priv->copy_target_entries,
- priv->n_copy_target_entries);
- priv->copy_target_entries = NULL;
- priv->n_copy_target_entries = 0;
- }
-
- if (priv->paste_target_list)
- {
- gtk_target_list_unref (priv->paste_target_list);
- priv->paste_target_list = NULL;
-
- gtk_target_table_free (priv->paste_target_entries,
- priv->n_paste_target_entries);
- priv->paste_target_entries = NULL;
- priv->n_paste_target_entries = 0;
- }
-}
-
-static GtkTargetList *
-gtk_text_buffer_get_target_list (GtkTextBuffer *buffer,
- gboolean deserializable,
- GtkTargetEntry **entries,
- gint *n_entries)
-{
- GtkTargetList *target_list;
-
- target_list = gtk_target_list_new (NULL, 0);
-
- gtk_target_list_add (target_list,
- gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
- GTK_TARGET_SAME_APP,
- GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS);
-
- gtk_target_list_add_rich_text_targets (target_list,
- GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT,
- deserializable,
- buffer);
-
- gtk_target_list_add_text_targets (target_list,
- GTK_TEXT_BUFFER_TARGET_INFO_TEXT);
-
- *entries = gtk_target_table_new_from_list (target_list, n_entries);
-
- return target_list;
-}
-
/**
* gtk_text_buffer_get_copy_target_list:
* @buffer: a #GtkTextBuffer
@@ -4267,9 +4245,7 @@ gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer)
if (! priv->copy_target_list)
priv->copy_target_list =
- gtk_text_buffer_get_target_list (buffer, FALSE,
- &priv->copy_target_entries,
- &priv->n_copy_target_entries);
+ gtk_text_buffer_get_target_list (buffer, FALSE, TRUE);
return priv->copy_target_list;
}
@@ -4299,9 +4275,7 @@ gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer)
if (! priv->paste_target_list)
priv->paste_target_list =
- gtk_text_buffer_get_target_list (buffer, TRUE,
- &priv->paste_target_entries,
- &priv->n_paste_target_entries);
+ gtk_text_buffer_get_target_list (buffer, TRUE, TRUE);
return priv->paste_target_list;
}
diff --git a/tests/testselection.c b/tests/testselection.c
index e6d029ac94..c6a8e41d8a 100644
--- a/tests/testselection.c
+++ b/tests/testselection.c
@@ -401,6 +401,7 @@ main (int argc, char *argv[])
{ "COMPOUND_TEXT", 0, COMPOUND_TEXT }
};
static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
+ GtkTargetList *list;
gtk_init ();
@@ -432,8 +433,9 @@ main (int argc, char *argv[])
g_signal_connect (selection_widget, "selection_received",
G_CALLBACK (selection_received), NULL);
- gtk_selection_add_targets (selection_widget, GDK_SELECTION_PRIMARY,
- targetlist, ntargets);
+ list = gtk_target_list_new (targetlist, ntargets);
+ gtk_selection_add_targets (selection_widget, GDK_SELECTION_PRIMARY, list);
+ gtk_target_list_unref (list);
g_signal_connect (selection_widget, "selection_get",
G_CALLBACK (selection_get), NULL);
diff --git a/testsuite/gtk/clipboard.c b/testsuite/gtk/clipboard.c
index e665ff7bfb..dee58b9417 100644
--- a/testsuite/gtk/clipboard.c
+++ b/testsuite/gtk/clipboard.c
@@ -70,8 +70,11 @@ test_with_data (void)
{
GtkClipboard *clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD);
GtkTargetEntry entries[] = { { .target = TARGET_TEXT, .info = 42 } };
+ GtkTargetList *targets;
- gtk_clipboard_set_with_data (clipboard, entries, G_N_ELEMENTS(entries), test_with_data_get, NULL, NULL);
+ targets = gtk_target_list_new (entries, G_N_ELEMENTS(entries));
+ gtk_clipboard_set_with_data (clipboard, targets, test_with_data_get, NULL, NULL);
+ gtk_target_list_unref (targets);
gtk_clipboard_request_contents (clipboard, gdk_atom_intern (TARGET_TEXT, FALSE), test_with_data_got, NULL);
}