diff options
author | Benjamin Otte <otte@redhat.com> | 2017-11-20 03:54:42 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2017-11-20 23:13:10 +0100 |
commit | fc2ce5a9254c7678eaadde35297b8fd90c869bd4 (patch) | |
tree | 40472431d75245904fa9576b534c38b19824eb55 | |
parent | 1a482ad2760b2f078605f807a13aed2877e95ef0 (diff) | |
download | gtk+-fc2ce5a9254c7678eaadde35297b8fd90c869bd4.tar.gz |
gdk: Make GdkContentFormats immutable
-rw-r--r-- | demos/icon-browser/iconbrowserwin.c | 2 | ||||
-rw-r--r-- | docs/reference/gdk/gdk4-sections.txt | 1 | ||||
-rw-r--r-- | gdk/gdkcontentformats.c | 43 | ||||
-rw-r--r-- | gdk/gdkcontentformats.h | 9 | ||||
-rw-r--r-- | gdk/wayland/gdkselection-wayland.c | 14 | ||||
-rw-r--r-- | gtk/gtkcalendar.c | 2 | ||||
-rw-r--r-- | gtk/gtkclipboard.c | 4 | ||||
-rw-r--r-- | gtk/gtkdragdest.c | 6 | ||||
-rw-r--r-- | gtk/gtkdragsource.c | 6 | ||||
-rw-r--r-- | gtk/gtkentry.c | 4 | ||||
-rw-r--r-- | gtk/gtkfilechooserbutton.c | 4 | ||||
-rw-r--r-- | gtk/gtkfilechooserwidget.c | 4 | ||||
-rw-r--r-- | gtk/gtklabel.c | 4 | ||||
-rw-r--r-- | gtk/gtkplacessidebar.c | 4 | ||||
-rw-r--r-- | gtk/gtkselection.c | 118 | ||||
-rw-r--r-- | gtk/gtkselection.h | 14 | ||||
-rw-r--r-- | gtk/gtktextbuffer.c | 17 | ||||
-rw-r--r-- | tests/testdnd2.c | 8 | ||||
-rw-r--r-- | tests/testentryicons.c | 2 |
19 files changed, 163 insertions, 103 deletions
diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c index 96800481fa..7034f237dd 100644 --- a/demos/icon-browser/iconbrowserwin.c +++ b/demos/icon-browser/iconbrowserwin.c @@ -459,7 +459,7 @@ icon_browser_window_init (IconBrowserWindow *win) gtk_widget_init_template (GTK_WIDGET (win)); list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (list); + list = gtk_content_formats_add_text_targets (list); gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (win->list), GDK_BUTTON1_MASK, list, diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 1746f1983b..ca179679ee 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -376,7 +376,6 @@ gdk_content_formats_ref gdk_content_formats_unref gdk_content_formats_print gdk_content_formats_to_string -gdk_content_formats_add gdk_content_formats_union gdk_content_formats_intersects gdk_content_formats_remove diff --git a/gdk/gdkcontentformats.c b/gdk/gdkcontentformats.c index bb1496426c..afb6a021e3 100644 --- a/gdk/gdkcontentformats.c +++ b/gdk/gdkcontentformats.c @@ -207,42 +207,31 @@ gdk_content_formats_to_string (GdkContentFormats *formats) } /** - * gdk_content_formats_add: - * @formats: a #GdkContentFormats - * @mime_type: the mime type to add - * - * Appends another mime_type to a #GdkContentFormats. - **/ -void -gdk_content_formats_add (GdkContentFormats *formats, - const char *mime_type) -{ - g_return_if_fail (formats != NULL); - - formats->formats = g_list_append (formats->formats, (gpointer) gdk_atom_intern (mime_type, FALSE)); -} - -/** * gdk_content_formats_union: - * @first: the #GdkContentFormats to merge into - * @second: the #GtkTargeList to merge from + * @first: (transfer full): the #GdkContentFormats to merge into + * @second: (transfer none): the #GdkContentFormats to merge from * * Append all missing types from @second to @first, in the order * they had in @second. + * + * Returns: a new #GdkContentFormats */ -void +GdkContentFormats * gdk_content_formats_union (GdkContentFormats *first, const GdkContentFormats *second) { - GList *l; + GdkContentFormatsBuilder *builder; - g_return_if_fail (first != NULL); - g_return_if_fail (second != NULL); + g_return_val_if_fail (first != NULL, NULL); + g_return_val_if_fail (second != NULL, NULL); - for (l = second->formats; l; l = l->next) - { - first->formats = g_list_append (first->formats, l->data); - } + builder = gdk_content_formats_builder_new (); + + gdk_content_formats_builder_add_formats (builder, first); + gdk_content_formats_unref (first); + gdk_content_formats_builder_add_formats (builder, second); + + return gdk_content_formats_builder_free (builder); } /** @@ -384,7 +373,7 @@ gdk_content_formats_builder_free (GdkContentFormatsBuilder *builder) **/ void gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder, - GdkContentFormats *formats) + const GdkContentFormats *formats) { GList *l; diff --git a/gdk/gdkcontentformats.h b/gdk/gdkcontentformats.h index 5b27a47654..1172bdca06 100644 --- a/gdk/gdkcontentformats.h +++ b/gdk/gdkcontentformats.h @@ -47,15 +47,12 @@ GDK_AVAILABLE_IN_3_94 char * gdk_content_formats_to_string (GdkContentFormats *formats); GDK_AVAILABLE_IN_3_94 -void gdk_content_formats_union (GdkContentFormats *first, - const GdkContentFormats *second); +GdkContentFormats * gdk_content_formats_union (GdkContentFormats *first, + const GdkContentFormats *second) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_3_94 GdkAtom gdk_content_formats_intersects (const GdkContentFormats *first, const GdkContentFormats *second); GDK_AVAILABLE_IN_3_94 -void gdk_content_formats_add (GdkContentFormats *formats, - const char *mime_type); -GDK_AVAILABLE_IN_3_94 gboolean gdk_content_formats_contains (const GdkContentFormats *formats, const char *mime_type); @@ -67,7 +64,7 @@ GDK_AVAILABLE_IN_3_94 GdkContentFormats * gdk_content_formats_builder_free (GdkContentFormatsBuilder *builder) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_3_94 void gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder, - GdkContentFormats *formats); + const GdkContentFormats *formats); GDK_AVAILABLE_IN_3_94 void gdk_content_formats_builder_add_mime_type(GdkContentFormatsBuilder *builder, const char *mime_type); diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c index 4b2acf8bc0..da0d1145bb 100644 --- a/gdk/wayland/gdkselection-wayland.c +++ b/gdk/wayland/gdkselection-wayland.c @@ -374,6 +374,7 @@ data_offer_offer (void *data, const char *type) { GdkWaylandSelection *selection = data; + GdkContentFormatsBuilder *builder; DataOfferData *info; info = g_hash_table_lookup (selection->offers, wl_data_offer); @@ -384,7 +385,11 @@ data_offer_offer (void *data, GDK_NOTE (EVENTS, g_message ("data offer offer, offer %p, type = %s", wl_data_offer, type)); - gdk_content_formats_add (info->targets, type); + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, info->targets); + gdk_content_formats_builder_add_mime_type (builder, type); + gdk_content_formats_unref (info->targets); + info->targets = gdk_content_formats_builder_free (builder); } static inline GdkDragAction @@ -461,6 +466,7 @@ primary_offer_offer (void *data, const char *type) { GdkWaylandSelection *selection = data; + GdkContentFormatsBuilder *builder; DataOfferData *info; info = g_hash_table_lookup (selection->offers, gtk_offer); @@ -471,7 +477,11 @@ primary_offer_offer (void *data, GDK_NOTE (EVENTS, g_message ("primary offer offer, offer %p, type = %s", gtk_offer, type)); - gdk_content_formats_add (info->targets, type); + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, info->targets); + gdk_content_formats_builder_add_mime_type (builder, type); + gdk_content_formats_unref (info->targets); + info->targets = gdk_content_formats_builder_free (builder); } static const struct gtk_primary_selection_offer_listener primary_offer_listener = { diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index 08fd646c66..1932ebfe70 100644 --- a/gtk/gtkcalendar.c +++ b/gtk/gtkcalendar.c @@ -2648,7 +2648,7 @@ gtk_calendar_motion_notify (GtkWidget *widget, { GdkDragContext *context; GdkContentFormats *target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); context = gtk_drag_begin_with_coordinates (widget, target_list, GDK_ACTION_COPY, 1, (GdkEvent *)event, priv->drag_start_x, priv->drag_start_y); diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c index 03151e3f0e..68d8b15c73 100644 --- a/gtk/gtkclipboard.c +++ b/gtk/gtkclipboard.c @@ -802,7 +802,7 @@ gtk_clipboard_set_text (GtkClipboard *clipboard, g_return_if_fail (text != NULL); formats = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (formats); + formats = gtk_content_formats_add_text_targets (formats); if (len < 0) len = strlen (text); @@ -853,7 +853,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard, g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); formats = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (formats, TRUE); + formats = gtk_content_formats_add_image_targets (formats, TRUE); gtk_clipboard_set_with_data (clipboard, formats, diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c index 91afffba79..fabbe27a4e 100644 --- a/gtk/gtkdragdest.c +++ b/gtk/gtkdragdest.c @@ -273,7 +273,7 @@ gtk_drag_dest_add_text_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_drag_dest_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } @@ -300,7 +300,7 @@ gtk_drag_dest_add_image_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (target_list, FALSE); + target_list = gtk_content_formats_add_image_targets (target_list, FALSE); gtk_drag_dest_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } @@ -327,7 +327,7 @@ gtk_drag_dest_add_uri_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_uri_targets (target_list); + target_list = gtk_content_formats_add_uri_targets (target_list); gtk_drag_dest_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c index cab952cbc5..ff61520e0c 100644 --- a/gtk/gtkdragsource.c +++ b/gtk/gtkdragsource.c @@ -290,7 +290,7 @@ gtk_drag_source_add_text_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_drag_source_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } @@ -317,7 +317,7 @@ gtk_drag_source_add_image_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (target_list, TRUE); + target_list = gtk_content_formats_add_image_targets (target_list, TRUE); gtk_drag_source_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } @@ -344,7 +344,7 @@ gtk_drag_source_add_uri_targets (GtkWidget *widget) gdk_content_formats_ref (target_list); else target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_uri_targets (target_list); + target_list = gtk_content_formats_add_uri_targets (target_list); gtk_drag_source_set_target_list (widget, target_list); gdk_content_formats_unref (target_list); } diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index d1dd6548ee..67841e778b 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3908,7 +3908,7 @@ gtk_entry_drag_gesture_update (GtkGestureDrag *gesture, guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY; guint button; - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges); @@ -6589,7 +6589,7 @@ gtk_entry_update_primary_selection (GtkEntry *entry) return; list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (list); + list = gtk_content_formats_add_text_targets (list); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY); diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 095352a01b..e3b26a7f68 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -539,8 +539,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button) /* DnD */ target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_uri_targets (target_list); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_uri_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_drag_dest_set (GTK_WIDGET (button), (GTK_DEST_DEFAULT_ALL), target_list, diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 6b0da2ac68..c788f50073 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -1729,8 +1729,8 @@ copy_file_location_cb (GSimpleAction *action, clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD); target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (target_list); - gtk_content_formats_add_uri_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_uri_targets (target_list); gtk_clipboard_set_with_data (clipboard, target_list, copy_file_get_cb, diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index af3a08b2a9..882ab1e702 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -4778,7 +4778,7 @@ gtk_label_drag_gesture_update (GtkGestureDrag *gesture, const GdkEvent *event; event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); g_signal_connect (widget, "drag-begin", G_CALLBACK (drag_begin_cb), NULL); @@ -5229,7 +5229,7 @@ gtk_label_select_region_index (GtkLabel *label, GdkContentFormats *list; list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (list); + list = gtk_content_formats_add_text_targets (list); if (clipboard) gtk_clipboard_set_with_owner (clipboard, diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 2faf2f000f..2d818e9f74 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -4074,11 +4074,11 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar) NULL, GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK); target_list = gdk_content_formats_new (dnd_drop_targets, G_N_ELEMENTS (dnd_drop_targets)); - gtk_content_formats_add_uri_targets (target_list); + target_list = gtk_content_formats_add_uri_targets (target_list); gtk_drag_dest_set_target_list (sidebar->list_box, target_list); gdk_content_formats_unref (target_list); sidebar->source_targets = gdk_content_formats_new (dnd_source_targets, G_N_ELEMENTS (dnd_source_targets)); - gtk_content_formats_add_text_targets (sidebar->source_targets); + sidebar->source_targets = gtk_content_formats_add_text_targets (sidebar->source_targets); g_signal_connect (sidebar->list_box, "motion-notify-event", G_CALLBACK (on_motion_notify_event), sidebar); diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index 159c4dc214..8d6c1ec4ec 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -259,23 +259,31 @@ init_atoms (void) * * Since: 2.6 **/ -void +GdkContentFormats * gtk_content_formats_add_text_targets (GdkContentFormats *list) { - g_return_if_fail (list != NULL); + GdkContentFormatsBuilder *builder; + + g_return_val_if_fail (list != NULL, NULL); init_atoms (); + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, list); + gdk_content_formats_unref (list); + /* Keep in sync with gtk_selection_data_targets_include_text() */ - gdk_content_formats_add (list, utf8_atom); - gdk_content_formats_add (list, ctext_atom); - gdk_content_formats_add (list, text_atom); - gdk_content_formats_add (list, GDK_TARGET_STRING); - gdk_content_formats_add (list, text_plain_utf8_atom); + gdk_content_formats_builder_add_mime_type (builder, utf8_atom); + gdk_content_formats_builder_add_mime_type (builder, ctext_atom); + gdk_content_formats_builder_add_mime_type (builder, text_atom); + gdk_content_formats_builder_add_mime_type (builder, GDK_TARGET_STRING); + gdk_content_formats_builder_add_mime_type (builder, text_plain_utf8_atom); if (!g_get_charset (NULL)) - gdk_content_formats_add (list, text_plain_locale_atom); - gdk_content_formats_add (list, text_plain_atom); + gdk_content_formats_builder_add_mime_type (builder, text_plain_locale_atom); + gdk_content_formats_builder_add_mime_type (builder, text_plain_atom); + + return gdk_content_formats_builder_free (builder); } /** @@ -292,17 +300,22 @@ gtk_content_formats_add_text_targets (GdkContentFormats *list) * * Since: 2.10 **/ -void +GdkContentFormats * gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, gboolean deserializable, GtkTextBuffer *buffer) { + GdkContentFormatsBuilder *builder; GdkAtom *atoms; gint n_atoms; gint i; - g_return_if_fail (list != NULL); - g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); + g_return_val_if_fail (list != NULL, NULL); + g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL); + + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, list); + gdk_content_formats_unref (list); if (deserializable) atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms); @@ -310,9 +323,11 @@ gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, atoms = gtk_text_buffer_get_serialize_formats (buffer, &n_atoms); for (i = 0; i < n_atoms; i++) - gdk_content_formats_add (list, atoms[i]); + gdk_content_formats_builder_add_mime_type (builder, atoms[i]); g_free (atoms); + + return gdk_content_formats_builder_free (builder); } /** @@ -326,14 +341,19 @@ gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, * * Since: 2.6 **/ -void +GdkContentFormats * gtk_content_formats_add_image_targets (GdkContentFormats *list, gboolean writable) { + GdkContentFormatsBuilder *builder; GSList *formats, *f; gchar **mimes, **m; - g_return_if_fail (list != NULL); + g_return_val_if_fail (list != NULL, NULL); + + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, list); + gdk_content_formats_unref (list); formats = gdk_pixbuf_get_formats (); @@ -367,12 +387,14 @@ gtk_content_formats_add_image_targets (GdkContentFormats *list, mimes = gdk_pixbuf_format_get_mime_types (fmt); for (m = mimes; *m; m++) { - gdk_content_formats_add (list, *m); + gdk_content_formats_builder_add_mime_type (builder, *m); } g_strfreev (mimes); } g_slist_free (formats); + + return gdk_content_formats_builder_free (builder); } /** @@ -385,14 +407,22 @@ gtk_content_formats_add_image_targets (GdkContentFormats *list, * * Since: 2.6 **/ -void +GdkContentFormats * gtk_content_formats_add_uri_targets (GdkContentFormats *list) { - g_return_if_fail (list != NULL); + GdkContentFormatsBuilder *builder; + + g_return_val_if_fail (list != NULL, NULL); init_atoms (); - gdk_content_formats_add (list, text_uri_list_atom); + builder = gdk_content_formats_builder_new (); + gdk_content_formats_builder_add_formats (builder, list); + gdk_content_formats_unref (list); + + gdk_content_formats_builder_add_mime_type (builder, text_uri_list_atom); + + return gdk_content_formats_builder_free (builder); } /** @@ -567,6 +597,40 @@ gtk_selection_target_list_get (GtkWidget *widget, } static void +gtk_selection_target_list_add (GtkWidget *widget, + GdkAtom selection, + GdkContentFormats *formats) +{ + GtkSelectionTargetList *sellist; + GList *tmp_list; + GList *lists; + + lists = g_object_get_data (G_OBJECT (widget), gtk_selection_handler_key); + + tmp_list = lists; + while (tmp_list) + { + sellist = tmp_list->data; + if (sellist->selection == selection) + { + sellist->list = gdk_content_formats_union (sellist->list, formats); + return; + } + tmp_list = tmp_list->next; + } + + if (tmp_list == NULL) + { + sellist = g_slice_new (GtkSelectionTargetList); + sellist->selection = selection; + sellist->list = gdk_content_formats_ref (formats); + } + + lists = g_list_prepend (lists, sellist); + g_object_set_data (G_OBJECT (widget), I_(gtk_selection_handler_key), lists); +} + +static void gtk_selection_target_list_remove (GtkWidget *widget) { GtkSelectionTargetList *sellist; @@ -651,9 +715,9 @@ gtk_selection_add_target (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (selection != NULL); - list = gtk_selection_target_list_get (widget, selection); - gdk_content_formats_add (list, target); - gdk_selection_add_targets (gtk_widget_get_window (widget), selection, &target, 1); + list = gdk_content_formats_new (&target, 1); + gtk_selection_add_targets (widget, selection, list); + gdk_content_formats_unref (list); } /** @@ -666,11 +730,10 @@ gtk_selection_add_target (GtkWidget *widget, * for a given widget and selection. **/ void -gtk_selection_add_targets (GtkWidget *widget, - GdkAtom selection, +gtk_selection_add_targets (GtkWidget *widget, + GdkAtom selection, GdkContentFormats *targets) { - GdkContentFormats *list; GdkAtom *atoms; guint n_targets; @@ -678,8 +741,7 @@ gtk_selection_add_targets (GtkWidget *widget, g_return_if_fail (selection != NULL); g_return_if_fail (targets != NULL); - list = gtk_selection_target_list_get (widget, selection); - gdk_content_formats_union (list, targets); + gtk_selection_target_list_add (widget, selection, targets); atoms = gdk_content_formats_get_atoms (targets, &n_targets); gdk_selection_add_targets (gtk_widget_get_window (widget), selection, atoms, n_targets); @@ -1867,7 +1929,7 @@ gtk_targets_include_image (GdkAtom *targets, g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE); list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (list, writable); + list = gtk_content_formats_add_image_targets (list, writable); for (i = 0; i < n_targets && !result; i++) { if (gdk_content_formats_contains (list, targets[i])) diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h index 3d24f0105c..d597871964 100644 --- a/gtk/gtkselection.h +++ b/gtk/gtkselection.h @@ -37,16 +37,16 @@ G_BEGIN_DECLS #define GTK_TYPE_SELECTION_DATA (gtk_selection_data_get_type ()) GDK_AVAILABLE_IN_ALL -void gtk_content_formats_add_text_targets (GdkContentFormats *list); +GdkContentFormats * gtk_content_formats_add_text_targets (GdkContentFormats *list) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_ALL -void gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, - gboolean deserializable, - GtkTextBuffer *buffer); +GdkContentFormats * gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, + gboolean deserializable, + GtkTextBuffer *buffer) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_ALL -void gtk_content_formats_add_image_targets (GdkContentFormats *list, - gboolean writable); +GdkContentFormats * gtk_content_formats_add_image_targets (GdkContentFormats *list, + gboolean writable) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_ALL -void gtk_content_formats_add_uri_targets (GdkContentFormats *list); +GdkContentFormats * gtk_content_formats_add_uri_targets (GdkContentFormats *list) G_GNUC_WARN_UNUSED_RESULT; GDK_AVAILABLE_IN_ALL gboolean gtk_selection_owner_set (GtkWidget *widget, diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index 67d7c0e053..010219452a 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -4007,17 +4007,20 @@ gtk_text_buffer_get_target_list (GtkTextBuffer *buffer, { GdkContentFormats *target_list; - target_list = gdk_content_formats_new (NULL, 0); if (include_local) - gdk_content_formats_add (target_list, - gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS")); + target_list = gdk_content_formats_new ((const char *[2]) { + "GTK_TEXT_BUFFER_CONTENTS", + NULL + }, 1); + else + target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_rich_text_targets (target_list, - deserializable, - buffer); + target_list = gtk_content_formats_add_rich_text_targets (target_list, + deserializable, + buffer); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); return target_list; } diff --git a/tests/testdnd2.c b/tests/testdnd2.c index 489ade05cf..bcd028d86c 100644 --- a/tests/testdnd2.c +++ b/tests/testdnd2.c @@ -124,9 +124,9 @@ update_source_target_list (GtkWidget *image) target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (target_list, FALSE); + target_list = gtk_content_formats_add_image_targets (target_list, FALSE); if (gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME) - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_drag_source_set_target_list (image, target_list); @@ -140,8 +140,8 @@ update_dest_target_list (GtkWidget *image) target_list = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_image_targets (target_list, FALSE); - gtk_content_formats_add_text_targets (target_list); + target_list = gtk_content_formats_add_image_targets (target_list, FALSE); + target_list = gtk_content_formats_add_text_targets (target_list); gtk_drag_dest_set_target_list (image, target_list); diff --git a/tests/testentryicons.c b/tests/testentryicons.c index a3667c08e6..acfa8f4847 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -167,7 +167,7 @@ main (int argc, char **argv) GTK_ENTRY_ICON_PRIMARY, "Save a file"); tlist = gdk_content_formats_new (NULL, 0); - gtk_content_formats_add_text_targets (tlist); + tlist = gtk_content_formats_add_text_targets (tlist); gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, tlist, GDK_ACTION_COPY); |