gdk: Make GdkContentFormats immutable

This commit is contained in:
Benjamin Otte 2017-11-20 03:54:42 +01:00
parent 1a482ad276
commit fc2ce5a925
19 changed files with 163 additions and 103 deletions

View File

@ -459,7 +459,7 @@ icon_browser_window_init (IconBrowserWindow *win)
gtk_widget_init_template (GTK_WIDGET (win)); gtk_widget_init_template (GTK_WIDGET (win));
list = gdk_content_formats_new (NULL, 0); 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), gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (win->list),
GDK_BUTTON1_MASK, GDK_BUTTON1_MASK,
list, list,

View File

@ -376,7 +376,6 @@ gdk_content_formats_ref
gdk_content_formats_unref gdk_content_formats_unref
gdk_content_formats_print gdk_content_formats_print
gdk_content_formats_to_string gdk_content_formats_to_string
gdk_content_formats_add
gdk_content_formats_union gdk_content_formats_union
gdk_content_formats_intersects gdk_content_formats_intersects
gdk_content_formats_remove gdk_content_formats_remove

View File

@ -206,43 +206,32 @@ gdk_content_formats_to_string (GdkContentFormats *formats)
return g_string_free (string, FALSE); return g_string_free (string, FALSE);
} }
/**
* 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: * gdk_content_formats_union:
* @first: the #GdkContentFormats to merge into * @first: (transfer full): the #GdkContentFormats to merge into
* @second: the #GtkTargeList to merge from * @second: (transfer none): the #GdkContentFormats to merge from
* *
* Append all missing types from @second to @first, in the order * Append all missing types from @second to @first, in the order
* they had in @second. * they had in @second.
*
* Returns: a new #GdkContentFormats
*/ */
void GdkContentFormats *
gdk_content_formats_union (GdkContentFormats *first, gdk_content_formats_union (GdkContentFormats *first,
const GdkContentFormats *second) const GdkContentFormats *second)
{ {
GList *l; GdkContentFormatsBuilder *builder;
g_return_if_fail (first != NULL); g_return_val_if_fail (first != NULL, NULL);
g_return_if_fail (second != NULL); g_return_val_if_fail (second != NULL, NULL);
for (l = second->formats; l; l = l->next) builder = gdk_content_formats_builder_new ();
{
first->formats = g_list_append (first->formats, l->data); 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 void
gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder, gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder,
GdkContentFormats *formats) const GdkContentFormats *formats)
{ {
GList *l; GList *l;

View File

@ -47,15 +47,12 @@ GDK_AVAILABLE_IN_3_94
char * gdk_content_formats_to_string (GdkContentFormats *formats); char * gdk_content_formats_to_string (GdkContentFormats *formats);
GDK_AVAILABLE_IN_3_94 GDK_AVAILABLE_IN_3_94
void gdk_content_formats_union (GdkContentFormats *first, GdkContentFormats * gdk_content_formats_union (GdkContentFormats *first,
const GdkContentFormats *second); const GdkContentFormats *second) G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_3_94 GDK_AVAILABLE_IN_3_94
GdkAtom gdk_content_formats_intersects (const GdkContentFormats *first, GdkAtom gdk_content_formats_intersects (const GdkContentFormats *first,
const GdkContentFormats *second); const GdkContentFormats *second);
GDK_AVAILABLE_IN_3_94 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, gboolean gdk_content_formats_contains (const GdkContentFormats *formats,
const char *mime_type); 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; GdkContentFormats * gdk_content_formats_builder_free (GdkContentFormatsBuilder *builder) G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_3_94 GDK_AVAILABLE_IN_3_94
void gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder, void gdk_content_formats_builder_add_formats (GdkContentFormatsBuilder *builder,
GdkContentFormats *formats); const GdkContentFormats *formats);
GDK_AVAILABLE_IN_3_94 GDK_AVAILABLE_IN_3_94
void gdk_content_formats_builder_add_mime_type(GdkContentFormatsBuilder *builder, void gdk_content_formats_builder_add_mime_type(GdkContentFormatsBuilder *builder,
const char *mime_type); const char *mime_type);

View File

@ -374,6 +374,7 @@ data_offer_offer (void *data,
const char *type) const char *type)
{ {
GdkWaylandSelection *selection = data; GdkWaylandSelection *selection = data;
GdkContentFormatsBuilder *builder;
DataOfferData *info; DataOfferData *info;
info = g_hash_table_lookup (selection->offers, wl_data_offer); info = g_hash_table_lookup (selection->offers, wl_data_offer);
@ -384,7 +385,11 @@ data_offer_offer (void *data,
GDK_NOTE (EVENTS, GDK_NOTE (EVENTS,
g_message ("data offer offer, offer %p, type = %s", wl_data_offer, type)); 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 static inline GdkDragAction
@ -461,6 +466,7 @@ primary_offer_offer (void *data,
const char *type) const char *type)
{ {
GdkWaylandSelection *selection = data; GdkWaylandSelection *selection = data;
GdkContentFormatsBuilder *builder;
DataOfferData *info; DataOfferData *info;
info = g_hash_table_lookup (selection->offers, gtk_offer); info = g_hash_table_lookup (selection->offers, gtk_offer);
@ -471,7 +477,11 @@ primary_offer_offer (void *data,
GDK_NOTE (EVENTS, GDK_NOTE (EVENTS,
g_message ("primary offer offer, offer %p, type = %s", gtk_offer, type)); 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 = { static const struct gtk_primary_selection_offer_listener primary_offer_listener = {

View File

@ -2648,7 +2648,7 @@ gtk_calendar_motion_notify (GtkWidget *widget,
{ {
GdkDragContext *context; GdkDragContext *context;
GdkContentFormats *target_list = gdk_content_formats_new (NULL, 0); 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, context = gtk_drag_begin_with_coordinates (widget, target_list, GDK_ACTION_COPY,
1, (GdkEvent *)event, 1, (GdkEvent *)event,
priv->drag_start_x, priv->drag_start_y); priv->drag_start_x, priv->drag_start_y);

View File

@ -802,7 +802,7 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
g_return_if_fail (text != NULL); g_return_if_fail (text != NULL);
formats = gdk_content_formats_new (NULL, 0); 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) if (len < 0)
len = strlen (text); len = strlen (text);
@ -853,7 +853,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
formats = gdk_content_formats_new (NULL, 0); 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, gtk_clipboard_set_with_data (clipboard,
formats, formats,

View File

@ -273,7 +273,7 @@ gtk_drag_dest_add_text_targets (GtkWidget *widget)
gdk_content_formats_ref (target_list); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_dest_set_target_list (widget, target_list);
gdk_content_formats_unref (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); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_dest_set_target_list (widget, target_list);
gdk_content_formats_unref (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); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_dest_set_target_list (widget, target_list);
gdk_content_formats_unref (target_list); gdk_content_formats_unref (target_list);
} }

View File

@ -290,7 +290,7 @@ gtk_drag_source_add_text_targets (GtkWidget *widget)
gdk_content_formats_ref (target_list); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_source_set_target_list (widget, target_list);
gdk_content_formats_unref (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); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_source_set_target_list (widget, target_list);
gdk_content_formats_unref (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); gdk_content_formats_ref (target_list);
else else
target_list = gdk_content_formats_new (NULL, 0); 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); gtk_drag_source_set_target_list (widget, target_list);
gdk_content_formats_unref (target_list); gdk_content_formats_unref (target_list);
} }

View File

@ -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 actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
guint button; 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); gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
@ -6589,7 +6589,7 @@ gtk_entry_update_primary_selection (GtkEntry *entry)
return; return;
list = gdk_content_formats_new (NULL, 0); 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); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);

View File

@ -539,8 +539,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
/* DnD */ /* DnD */
target_list = gdk_content_formats_new (NULL, 0); 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_content_formats_add_text_targets (target_list); target_list = gtk_content_formats_add_text_targets (target_list);
gtk_drag_dest_set (GTK_WIDGET (button), gtk_drag_dest_set (GTK_WIDGET (button),
(GTK_DEST_DEFAULT_ALL), (GTK_DEST_DEFAULT_ALL),
target_list, target_list,

View File

@ -1729,8 +1729,8 @@ copy_file_location_cb (GSimpleAction *action,
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD);
target_list = gdk_content_formats_new (NULL, 0); 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_content_formats_add_uri_targets (target_list); target_list = gtk_content_formats_add_uri_targets (target_list);
gtk_clipboard_set_with_data (clipboard, target_list, gtk_clipboard_set_with_data (clipboard, target_list,
copy_file_get_cb, copy_file_get_cb,

View File

@ -4778,7 +4778,7 @@ gtk_label_drag_gesture_update (GtkGestureDrag *gesture,
const GdkEvent *event; const GdkEvent *event;
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence); 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_signal_connect (widget, "drag-begin",
G_CALLBACK (drag_begin_cb), NULL); G_CALLBACK (drag_begin_cb), NULL);
@ -5229,7 +5229,7 @@ gtk_label_select_region_index (GtkLabel *label,
GdkContentFormats *list; GdkContentFormats *list;
list = gdk_content_formats_new (NULL, 0); list = gdk_content_formats_new (NULL, 0);
gtk_content_formats_add_text_targets (list); list = gtk_content_formats_add_text_targets (list);
if (clipboard) if (clipboard)
gtk_clipboard_set_with_owner (clipboard, gtk_clipboard_set_with_owner (clipboard,

View File

@ -4074,11 +4074,11 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
NULL, NULL,
GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK); GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
target_list = gdk_content_formats_new (dnd_drop_targets, G_N_ELEMENTS (dnd_drop_targets)); 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); gtk_drag_dest_set_target_list (sidebar->list_box, target_list);
gdk_content_formats_unref (target_list); gdk_content_formats_unref (target_list);
sidebar->source_targets = gdk_content_formats_new (dnd_source_targets, G_N_ELEMENTS (dnd_source_targets)); 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_signal_connect (sidebar->list_box, "motion-notify-event",
G_CALLBACK (on_motion_notify_event), sidebar); G_CALLBACK (on_motion_notify_event), sidebar);

View File

@ -259,23 +259,31 @@ init_atoms (void)
* *
* Since: 2.6 * Since: 2.6
**/ **/
void GdkContentFormats *
gtk_content_formats_add_text_targets (GdkContentFormats *list) 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 (); 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() /* Keep in sync with gtk_selection_data_targets_include_text()
*/ */
gdk_content_formats_add (list, utf8_atom); gdk_content_formats_builder_add_mime_type (builder, utf8_atom);
gdk_content_formats_add (list, ctext_atom); gdk_content_formats_builder_add_mime_type (builder, ctext_atom);
gdk_content_formats_add (list, text_atom); gdk_content_formats_builder_add_mime_type (builder, text_atom);
gdk_content_formats_add (list, GDK_TARGET_STRING); gdk_content_formats_builder_add_mime_type (builder, GDK_TARGET_STRING);
gdk_content_formats_add (list, text_plain_utf8_atom); gdk_content_formats_builder_add_mime_type (builder, text_plain_utf8_atom);
if (!g_get_charset (NULL)) if (!g_get_charset (NULL))
gdk_content_formats_add (list, text_plain_locale_atom); gdk_content_formats_builder_add_mime_type (builder, text_plain_locale_atom);
gdk_content_formats_add (list, text_plain_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 * Since: 2.10
**/ **/
void GdkContentFormats *
gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, gtk_content_formats_add_rich_text_targets (GdkContentFormats *list,
gboolean deserializable, gboolean deserializable,
GtkTextBuffer *buffer) GtkTextBuffer *buffer)
{ {
GdkContentFormatsBuilder *builder;
GdkAtom *atoms; GdkAtom *atoms;
gint n_atoms; gint n_atoms;
gint i; gint i;
g_return_if_fail (list != NULL); g_return_val_if_fail (list != NULL, NULL);
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); 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) if (deserializable)
atoms = gtk_text_buffer_get_deserialize_formats (buffer, &n_atoms); 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); atoms = gtk_text_buffer_get_serialize_formats (buffer, &n_atoms);
for (i = 0; i < n_atoms; i++) 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); 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 * Since: 2.6
**/ **/
void GdkContentFormats *
gtk_content_formats_add_image_targets (GdkContentFormats *list, gtk_content_formats_add_image_targets (GdkContentFormats *list,
gboolean writable) gboolean writable)
{ {
GdkContentFormatsBuilder *builder;
GSList *formats, *f; GSList *formats, *f;
gchar **mimes, **m; 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 (); 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); mimes = gdk_pixbuf_format_get_mime_types (fmt);
for (m = mimes; *m; m++) for (m = mimes; *m; m++)
{ {
gdk_content_formats_add (list, *m); gdk_content_formats_builder_add_mime_type (builder, *m);
} }
g_strfreev (mimes); g_strfreev (mimes);
} }
g_slist_free (formats); 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 * Since: 2.6
**/ **/
void GdkContentFormats *
gtk_content_formats_add_uri_targets (GdkContentFormats *list) 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 (); 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);
} }
/** /**
@ -566,6 +596,40 @@ gtk_selection_target_list_get (GtkWidget *widget,
return sellist->list; return sellist->list;
} }
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 static void
gtk_selection_target_list_remove (GtkWidget *widget) gtk_selection_target_list_remove (GtkWidget *widget)
{ {
@ -651,9 +715,9 @@ gtk_selection_add_target (GtkWidget *widget,
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (selection != NULL); g_return_if_fail (selection != NULL);
list = gtk_selection_target_list_get (widget, selection); list = gdk_content_formats_new (&target, 1);
gdk_content_formats_add (list, target); gtk_selection_add_targets (widget, selection, list);
gdk_selection_add_targets (gtk_widget_get_window (widget), selection, &target, 1); gdk_content_formats_unref (list);
} }
/** /**
@ -666,11 +730,10 @@ gtk_selection_add_target (GtkWidget *widget,
* for a given widget and selection. * for a given widget and selection.
**/ **/
void void
gtk_selection_add_targets (GtkWidget *widget, gtk_selection_add_targets (GtkWidget *widget,
GdkAtom selection, GdkAtom selection,
GdkContentFormats *targets) GdkContentFormats *targets)
{ {
GdkContentFormats *list;
GdkAtom *atoms; GdkAtom *atoms;
guint n_targets; guint n_targets;
@ -678,8 +741,7 @@ gtk_selection_add_targets (GtkWidget *widget,
g_return_if_fail (selection != NULL); g_return_if_fail (selection != NULL);
g_return_if_fail (targets != NULL); g_return_if_fail (targets != NULL);
list = gtk_selection_target_list_get (widget, selection); gtk_selection_target_list_add (widget, selection, targets);
gdk_content_formats_union (list, targets);
atoms = gdk_content_formats_get_atoms (targets, &n_targets); atoms = gdk_content_formats_get_atoms (targets, &n_targets);
gdk_selection_add_targets (gtk_widget_get_window (widget), selection, atoms, 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); g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
list = gdk_content_formats_new (NULL, 0); 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++) for (i = 0; i < n_targets && !result; i++)
{ {
if (gdk_content_formats_contains (list, targets[i])) if (gdk_content_formats_contains (list, targets[i]))

View File

@ -37,16 +37,16 @@ G_BEGIN_DECLS
#define GTK_TYPE_SELECTION_DATA (gtk_selection_data_get_type ()) #define GTK_TYPE_SELECTION_DATA (gtk_selection_data_get_type ())
GDK_AVAILABLE_IN_ALL 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 GDK_AVAILABLE_IN_ALL
void gtk_content_formats_add_rich_text_targets (GdkContentFormats *list, GdkContentFormats * gtk_content_formats_add_rich_text_targets (GdkContentFormats *list,
gboolean deserializable, gboolean deserializable,
GtkTextBuffer *buffer); GtkTextBuffer *buffer) G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_content_formats_add_image_targets (GdkContentFormats *list, GdkContentFormats * gtk_content_formats_add_image_targets (GdkContentFormats *list,
gboolean writable); gboolean writable) G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_ALL 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 GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_owner_set (GtkWidget *widget, gboolean gtk_selection_owner_set (GtkWidget *widget,

View File

@ -4007,17 +4007,20 @@ gtk_text_buffer_get_target_list (GtkTextBuffer *buffer,
{ {
GdkContentFormats *target_list; GdkContentFormats *target_list;
target_list = gdk_content_formats_new (NULL, 0);
if (include_local) if (include_local)
gdk_content_formats_add (target_list, target_list = gdk_content_formats_new ((const char *[2]) {
gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS")); "GTK_TEXT_BUFFER_CONTENTS",
NULL
}, 1);
else
target_list = gdk_content_formats_new (NULL, 0);
gtk_content_formats_add_rich_text_targets (target_list, target_list = gtk_content_formats_add_rich_text_targets (target_list,
deserializable, deserializable,
buffer); buffer);
gtk_content_formats_add_text_targets (target_list); target_list = gtk_content_formats_add_text_targets (target_list);
return target_list; return target_list;
} }

View File

@ -124,9 +124,9 @@ update_source_target_list (GtkWidget *image)
target_list = gdk_content_formats_new (NULL, 0); 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) 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); 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); 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_content_formats_add_text_targets (target_list); target_list = gtk_content_formats_add_text_targets (target_list);
gtk_drag_dest_set_target_list (image, target_list); gtk_drag_dest_set_target_list (image, target_list);

View File

@ -167,7 +167,7 @@ main (int argc, char **argv)
GTK_ENTRY_ICON_PRIMARY, GTK_ENTRY_ICON_PRIMARY,
"Save a file"); "Save a file");
tlist = gdk_content_formats_new (NULL, 0); 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_set_icon_drag_source (GTK_ENTRY (entry),
GTK_ENTRY_ICON_PRIMARY, GTK_ENTRY_ICON_PRIMARY,
tlist, GDK_ACTION_COPY); tlist, GDK_ACTION_COPY);