Replace gtk_drop_target_attach/detach

Since drop targets are now just event controller,
gtk_widget_add/remove_controller works just fine
for them.
This commit is contained in:
Matthias Clasen 2020-01-06 00:12:21 -05:00
parent f898bee032
commit e9067ae2db
23 changed files with 38 additions and 77 deletions

View File

@ -342,7 +342,7 @@ do_clipboard (GtkWidget *do_widget)
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
gdk_content_formats_unref (formats);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), image);
gtk_drop_target_attach (dest, image);
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
/* context menu on image */
gesture = gtk_gesture_click_new ();
@ -375,7 +375,7 @@ do_clipboard (GtkWidget *do_widget)
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
gdk_content_formats_unref (formats);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), image);
gtk_drop_target_attach (dest, image);
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
/* context menu on image */
gesture = gtk_gesture_click_new ();

View File

@ -791,7 +791,7 @@ gtk_calendar_init (GtkCalendar *calendar)
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_calendar_drag_leave), calendar);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_calendar_drag_drop), calendar);
gtk_drop_target_attach (dest, widget);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
priv->year_before = 0;

View File

@ -46,6 +46,7 @@
#include "gtkstylecontext.h"
#include "gtkdragsource.h"
#include "gtkdragdest.h"
#include "gtkeventcontroller.h"
/**
@ -328,7 +329,7 @@ gtk_color_button_init (GtkColorButton *button)
targets = gdk_content_formats_new (drop_types, G_N_ELEMENTS (drop_types));
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_color_button_drag_drop), button);
gtk_drop_target_attach (dest, GTK_WIDGET (button));
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
content = gdk_content_provider_new_with_callback (GDK_TYPE_RGBA, get_rgba_value, button);

View File

@ -473,7 +473,6 @@ swatch_finalize (GObject *object)
g_free (priv->icon);
gtk_widget_unparent (priv->overlay_widget);
g_clear_pointer (&priv->dest, gtk_drop_target_detach);
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
}
@ -678,12 +677,13 @@ gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
targets = gdk_content_formats_new (dnd_targets, G_N_ELEMENTS (dnd_targets));
priv->dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
g_signal_connect (priv->dest, "drag-drop", G_CALLBACK (swatch_drag_drop), swatch);
gtk_drop_target_attach (priv->dest, GTK_WIDGET (swatch));
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
gdk_content_formats_unref (targets);
}
if (!can_drop && priv->dest)
{
g_clear_pointer (&priv->dest, gtk_drop_target_detach);
gtk_widget_remove_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
priv->dest = NULL;
}
g_object_notify (G_OBJECT (swatch), "can-drop");

View File

@ -46,7 +46,7 @@
*
* To use a GtkDropTarget to receive drops on a widget, you create
* a GtkDropTarget object, connect to its signals, and then attach
* it to the widget with gtk_drop_target_attach().
* it to the widget with gtk_widget_add_controller().
*/
struct _GtkDropTarget
@ -445,44 +445,6 @@ gtk_drop_target_get (GtkWidget *widget)
return g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest"));
}
/**
* gtk_drop_target_attach:
* @dest: (transfer full): a #GtkDropTarget
* @widget the widget to attach @dest to
*
* Attaches the @dest to widget and makes it accept drops
* on the widgets.
*
* To undo the effect of this call, use gtk_drop_target_detach().
*/
void
gtk_drop_target_attach (GtkDropTarget *dest,
GtkWidget *widget)
{
g_return_if_fail (GTK_IS_DROP_TARGET (dest));
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (dest), GTK_PHASE_BUBBLE);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
}
/**
* gtk_drop_target_detach:
* @dest: a #GtkDropTarget
*
* Undoes the effect of a prior gtk_drop_target_attach() call.
*/
void
gtk_drop_target_detach (GtkDropTarget *dest)
{
GtkWidget *widget;
g_return_if_fail (GTK_IS_DROP_TARGET (dest));
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
gtk_widget_remove_controller (widget, GTK_EVENT_CONTROLLER (dest));
}
/**
* gtk_drop_target_get_target:
* @dest: a #GtkDropTarget

View File

@ -68,12 +68,6 @@ void gtk_drop_target_set_actions (GtkDropTarget *dest,
GDK_AVAILABLE_IN_ALL
GdkDragAction gtk_drop_target_get_actions (GtkDropTarget *dest);
GDK_AVAILABLE_IN_ALL
void gtk_drop_target_attach (GtkDropTarget *dest,
GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_drop_target_detach (GtkDropTarget *dest);
GDK_AVAILABLE_IN_ALL
GdkDrop *gtk_drop_target_get_drop (GtkDropTarget *dest);

View File

@ -379,7 +379,7 @@ gtk_expander_init (GtkExpander *expander)
gdk_content_formats_unref (formats);
g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_expander_drag_motion), expander);
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_expander_drag_leave), expander);
gtk_drop_target_attach (dest, GTK_WIDGET (expander));
gtk_widget_add_controller (GTK_WIDGET (expander), GTK_EVENT_CONTROLLER (dest));
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture),

View File

@ -60,6 +60,7 @@
#include "gtksettings.h"
#include "gtkstylecontextprivate.h"
#include "gtkbitmaskprivate.h"
#include "gtkeventcontroller.h"
/**
* SECTION:gtkfilechooserbutton
@ -500,7 +501,7 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
target_list = gtk_content_formats_add_text_targets (target_list);
dest = gtk_drop_target_new (target_list, GDK_ACTION_COPY);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_file_chooser_button_drag_drop), button);
gtk_drop_target_attach (dest, GTK_WIDGET (button));
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (target_list);
}

View File

@ -8522,7 +8522,7 @@ post_process_ui (GtkFileChooserWidget *impl)
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-motion", G_CALLBACK (file_list_drag_motion_cb), impl);
g_signal_connect (dest, "drag-drop", G_CALLBACK (file_list_drag_drop_cb), impl);
gtk_drop_target_attach (dest, priv->browse_files_tree_view);
gtk_widget_add_controller (priv->browse_files_tree_view, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (formats);
/* File browser treemodel columns are shared between GtkFileChooser implementations,

View File

@ -1025,7 +1025,6 @@ gtk_icon_view_dispose (GObject *object)
g_clear_object (&priv->key_controller);
g_clear_object (&priv->source);
g_clear_pointer (&priv->dest, gtk_drop_target_detach);
G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
}
@ -6499,7 +6498,7 @@ gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
g_signal_connect (icon_view->priv->dest, "drag-leave", G_CALLBACK (gtk_icon_view_drag_leave), icon_view);
g_signal_connect (icon_view->priv->dest, "drag-motion", G_CALLBACK (gtk_icon_view_drag_motion), icon_view);
g_signal_connect (icon_view->priv->dest, "drag-drop", G_CALLBACK (gtk_icon_view_drag_drop), icon_view);
gtk_drop_target_attach (icon_view->priv->dest, GTK_WIDGET (icon_view));
gtk_widget_add_controller (GTK_WIDGET (icon_view), GTK_EVENT_CONTROLLER (icon_view->priv->dest));
icon_view->priv->dest_actions = actions;
@ -6545,7 +6544,7 @@ gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
if (icon_view->priv->dest_set)
{
gtk_drop_target_detach (icon_view->priv->dest);
gtk_widget_remove_controller (GTK_WIDGET (icon_view), GTK_EVENT_CONTROLLER (icon_view->priv->dest));
icon_view->priv->dest = NULL;
icon_view->priv->dest_set = FALSE;
}

View File

@ -1329,7 +1329,8 @@ gtk_notebook_init (GtkNotebook *notebook)
g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_notebook_drag_motion), NULL);
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_notebook_drag_leave), NULL);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_notebook_drag_drop), NULL);
gtk_drop_target_attach (dest, GTK_WIDGET (notebook));
gtk_widget_add_controller (GTK_WIDGET (notebook), GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
priv->header_widget = g_object_new (GTK_TYPE_BOX,

View File

@ -4099,7 +4099,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
g_signal_connect (dest, "drag-motion", G_CALLBACK (drag_motion_callback), sidebar);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop_callback), sidebar);
g_signal_connect (dest, "drag-leave", G_CALLBACK (drag_leave_callback), sidebar);
gtk_drop_target_attach (dest, sidebar->list_box);
gtk_widget_add_controller (sidebar->list_box, GTK_EVENT_CONTROLLER (dest));
sidebar->source_targets = gdk_content_formats_new (dnd_source_targets, G_N_ELEMENTS (dnd_source_targets));
sidebar->source_targets = gtk_content_formats_add_text_targets (sidebar->source_targets);

View File

@ -120,7 +120,7 @@ gtk_stack_switcher_init (GtkStackSwitcher *switcher)
gdk_content_formats_unref (formats);
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_stack_switcher_drag_leave), switcher);
g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_stack_switcher_drag_motion), switcher);
gtk_drop_target_attach (dest, GTK_WIDGET (switcher));
gtk_widget_add_controller (GTK_WIDGET (switcher), GTK_EVENT_CONTROLLER (dest));
}
static void

View File

@ -1732,7 +1732,7 @@ gtk_text_init (GtkText *self)
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_text_drag_leave), self);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_text_drag_drop), self);
gdk_content_formats_unref (formats);
gtk_drop_target_attach (dest, GTK_WIDGET (self));
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (dest));
/* This object is completely private. No external entity can gain a reference
* to it; so we create it here and destroy it in finalize().

View File

@ -1635,7 +1635,7 @@ gtk_text_view_init (GtkTextView *text_view)
g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_text_view_drag_leave), text_view);
g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_text_view_drag_motion), text_view);
g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_text_view_drag_drop), text_view);
gtk_drop_target_attach (dest, GTK_WIDGET (text_view));
gtk_widget_add_controller (GTK_WIDGET (text_view), GTK_EVENT_CONTROLLER (dest));
priv->virtual_cursor_x = -1;
priv->virtual_cursor_y = -1;

View File

@ -6743,8 +6743,6 @@ static void
destroy_info (TreeViewDragInfo *di)
{
g_clear_object (&di->source);
if (di->dest)
gtk_drop_target_detach (di->dest);
g_clear_object (&di->dest);
g_slice_free (TreeViewDragInfo, di);
@ -6773,6 +6771,11 @@ ensure_info (GtkTreeView *tree_view)
static void
remove_info (GtkTreeView *tree_view)
{
TreeViewDragInfo *di;
di = get_info (tree_view);
if (di && di->dest)
gtk_widget_remove_controller (GTK_WIDGET (tree_view), GTK_EVENT_CONTROLLER (di->dest));
g_object_set_data (G_OBJECT (tree_view), I_("gtk-tree-view-drag-info"), NULL);
}
@ -12968,7 +12971,7 @@ gtk_tree_view_enable_model_drag_dest (GtkTreeView *tree_view,
g_signal_connect (di->dest, "drag-leave", G_CALLBACK (gtk_tree_view_drag_leave), tree_view);
g_signal_connect (di->dest, "drag-motion", G_CALLBACK (gtk_tree_view_drag_motion), tree_view);
g_signal_connect (di->dest, "drag-drop", G_CALLBACK (gtk_tree_view_drag_drop), tree_view);
gtk_drop_target_attach (di->dest, GTK_WIDGET (tree_view));
gtk_widget_add_controller (GTK_WIDGET (tree_view), GTK_EVENT_CONTROLLER (di->dest));
g_object_ref (di->dest);
unset_reorderable (tree_view);
@ -13029,7 +13032,7 @@ gtk_tree_view_unset_rows_drag_dest (GtkTreeView *tree_view)
{
if (di->dest_set)
{
gtk_drop_target_detach (di->dest);
gtk_widget_remove_controller (GTK_WIDGET (tree_view), GTK_EVENT_CONTROLLER (di->dest));
di->dest = NULL;
di->dest_set = FALSE;
}

View File

@ -1841,7 +1841,7 @@ gtk_window_init (GtkWindow *window)
targets = gdk_content_formats_new (dnd_dest_targets, G_N_ELEMENTS (dnd_dest_targets));
dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
gdk_content_formats_unref (targets);
gtk_drop_target_attach (dest, GTK_WIDGET (window));
gtk_widget_add_controller (GTK_WIDGET (window), GTK_EVENT_CONTROLLER (dest));
#endif
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));

View File

@ -504,7 +504,7 @@ popup_cb (gpointer data)
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-motion", G_CALLBACK (popup_motion), NULL);
g_signal_connect (dest, "drag-leave", G_CALLBACK (popup_leave), NULL);
gtk_drop_target_attach (dest, button);
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
}
gtk_container_add (GTK_CONTAINER (popup_window), grid);
gdk_content_formats_unref (targets);
@ -597,7 +597,7 @@ main (int argc, char **argv)
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-drop", G_CALLBACK (label_drag_drop), NULL);
gtk_drop_target_attach (dest, label);
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
gtk_widget_set_hexpand (label, TRUE);
gtk_widget_set_vexpand (label, TRUE);
@ -608,7 +608,7 @@ main (int argc, char **argv)
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-motion", G_CALLBACK (popsite_motion), NULL);
g_signal_connect (dest, "drag-leave", G_CALLBACK (popsite_leave), NULL);
gtk_drop_target_attach (dest, label);
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
gtk_widget_set_hexpand (label, TRUE);
gtk_widget_set_vexpand (label, TRUE);
@ -622,7 +622,7 @@ main (int argc, char **argv)
g_signal_connect (dest, "drag-leave", G_CALLBACK (target_drag_leave), pixmap);
g_signal_connect (dest, "drag-motion", G_CALLBACK (target_drag_motion), pixmap);
g_signal_connect (dest, "drag-drop", G_CALLBACK (target_drag_drop), pixmap);
gtk_drop_target_attach (dest, pixmap);
gtk_widget_add_controller (pixmap, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
gtk_widget_set_hexpand (pixmap, TRUE);

View File

@ -307,7 +307,7 @@ make_image (const gchar *icon_name, int hotspot)
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_ASK);
g_signal_connect (dest, "drag-drop", G_CALLBACK (image_drag_drop), image);
gtk_drop_target_attach (dest, image);
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (formats);

View File

@ -90,7 +90,7 @@ create_row (const gchar *text)
targets = gdk_content_formats_new (entries, 1);
dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), row);
gtk_drop_target_attach (dest, row);
gtk_widget_add_controller (GTK_WIDGET (row), GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);

View File

@ -303,7 +303,7 @@ create_trash_button (void)
targets = gdk_content_formats_new (button_targets, G_N_ELEMENTS (button_targets));
dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
g_signal_connect (dest, "drag-drop", G_CALLBACK (on_button_drag_drop), NULL);
gtk_drop_target_attach (dest, button);
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
return button;

View File

@ -625,7 +625,7 @@ main (gint argc, gchar **argv)
g_signal_connect (dest, "drag_motion", G_CALLBACK (toolbar_drag_motion), toolbar);
g_signal_connect (dest, "drag_leave", G_CALLBACK (toolbar_drag_leave), toolbar);
g_signal_connect (dest, "drag_drop", G_CALLBACK (toolbar_drag_drop), label);
gtk_drop_target_attach (dest, toolbar);
gtk_widget_add_controller (toolbar, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
gtk_widget_show (window);

View File

@ -127,7 +127,7 @@ get_droptarget (void)
targets = gdk_content_formats_new (entries, G_N_ELEMENTS (entries));
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), NULL);
gtk_drop_target_attach (dest, label);
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (targets);
return label;