[gtk/wip/otte/dnd: 9/9] dragdest: Make gtk_drop_target_new() args be transfer full



commit 1ef8932ce9f0a05be4e4143a26f7cf1004780b81
Author: Benjamin Otte <otte redhat com>
Date:   Sun Feb 16 19:52:17 2020 +0100

    dragdest: Make gtk_drop_target_new() args be transfer full
    
    Saves tons of code.

 demos/gtk-demo/clipboard.c |  9 ++-------
 gtk/gtkcalendar.c          |  6 ++----
 gtk/gtkcolorbutton.c       |  6 ++----
 gtk/gtkcolorswatch.c       |  6 ++----
 gtk/gtkdragdest.c          | 16 +++++++++++-----
 gtk/gtkexpander.c          |  5 +----
 gtk/gtkfilechooserbutton.c |  6 ++----
 gtk/gtkfilechooserwidget.c |  8 +++-----
 gtk/gtkiconview.c          |  2 +-
 gtk/gtknotebook.c          |  5 +----
 gtk/gtkplacessidebar.c     |  6 ++----
 gtk/gtkstackswitcher.c     |  5 +----
 gtk/gtktext.c              |  6 ++----
 gtk/gtktextview.c          |  5 +----
 gtk/gtktreeview.c          |  2 +-
 gtk/gtkwindow.c            |  5 +----
 tests/testdnd.c            |  8 ++------
 tests/testdnd2.c           |  2 --
 tests/testdnd3.c           |  5 +----
 tests/testlist3.c          |  6 +-----
 tests/testnotebookdnd.c    |  5 +----
 tests/testtreednd.c        |  5 +----
 22 files changed, 41 insertions(+), 88 deletions(-)
---
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index 7acc83093d..68e9695619 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -273,7 +273,6 @@ do_clipboard (GtkWidget *do_widget)
       GActionGroup *actions;
       GtkDragSource *source;
       GtkDropTarget *dest;
-      GdkContentFormats *formats;
 
       window = gtk_window_new ();
       gtk_window_set_display (GTK_WINDOW (window),
@@ -342,9 +341,7 @@ do_clipboard (GtkWidget *do_widget)
       gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
 
       /* accept drops on image */
-      formats = gdk_content_formats_new_for_gtype (GDK_TYPE_TEXTURE);
-      dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
-      gdk_content_formats_unref (formats);
+      dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GDK_TYPE_TEXTURE), GDK_ACTION_COPY);
       g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), image);
       gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
 
@@ -373,9 +370,7 @@ do_clipboard (GtkWidget *do_widget)
       gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
 
       /* accept drops on image */
-      formats = gdk_content_formats_new_for_gtype (GDK_TYPE_TEXTURE);
-      dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
-      gdk_content_formats_unref (formats);
+      dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GDK_TYPE_TEXTURE), GDK_ACTION_COPY);
       g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), image);
       gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
 
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 769d85f68d..1c97018c2d 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -536,7 +536,6 @@ gtk_calendar_init (GtkCalendar *calendar)
 #else
   gchar *week_start;
 #endif
-  GdkContentFormats *formats;
   GtkDropTarget *dest;
   int min_year_width;
   GDateTime *now;
@@ -718,9 +717,8 @@ gtk_calendar_init (GtkCalendar *calendar)
 
   priv->in_drag = 0;
 
-  formats = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
-  gdk_content_formats_unref (formats);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (G_TYPE_STRING),
+                              GDK_ACTION_COPY);
 
   g_signal_connect (dest, "accept", G_CALLBACK (gtk_calendar_drag_accept), calendar);
   g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_calendar_drag_leave), calendar);
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 91a96301c6..86c81830f5 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -295,7 +295,6 @@ gtk_color_button_init (GtkColorButton *button)
   GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
   PangoLayout *layout;
   PangoRectangle rect;
-  GdkContentFormats *formats;
   GtkDragSource *source;
   GtkDropTarget *dest;
 
@@ -321,11 +320,10 @@ gtk_color_button_init (GtkColorButton *button)
   priv->rgba.alpha = 1;
   priv->use_alpha = FALSE;
 
-  formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA),
+                              GDK_ACTION_COPY);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_color_button_drag_drop), button);
   gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (formats);
 
   source = gtk_drag_source_new ();
   g_signal_connect (source, "prepare", G_CALLBACK (gtk_color_button_drag_prepare), button);
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index b59c49862b..ac40dfae8c 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -661,10 +661,8 @@ gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
 
   if (can_drop && !priv->dest)
     {
-      GdkContentFormats *formats;
-
-      formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
-      priv->dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
+      priv->dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA),
+                                        GDK_ACTION_COPY);
       g_signal_connect (priv->dest, "drag-drop", G_CALLBACK (swatch_drag_drop), swatch);
       gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
     }
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index 65d6faad75..26cdc6eb53 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -392,7 +392,7 @@ gtk_drop_target_class_init (GtkDropTargetClass *class)
 
 /**
  * gtk_drop_target_new:
- * @formats: (nullable): the supported data formats
+ * @formats: (nullable) (transfer full): the supported data formats
  * @actions: the supported actions
  *
  * Creates a new #GtkDropTarget object.
@@ -403,10 +403,16 @@ GtkDropTarget *
 gtk_drop_target_new (GdkContentFormats *formats,
                      GdkDragAction      actions)
 {
-  return g_object_new (GTK_TYPE_DROP_TARGET,
-                       "formats", formats,
-                       "actions", actions,
-                       NULL);
+  GtkDropTarget *result;
+
+  result = g_object_new (GTK_TYPE_DROP_TARGET,
+                         "formats", formats,
+                         "actions", actions,
+                         NULL);
+
+  g_clear_pointer (&formats, gdk_content_formats_unref);
+
+  return result;
 }
 
 /**
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 720c167051..c8300240ab 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -348,7 +348,6 @@ gtk_expander_init (GtkExpander *expander)
   GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
   GtkGesture *gesture;
   GtkDropTarget *dest;
-  GdkContentFormats *formats;
 
   gtk_widget_set_can_focus (GTK_WIDGET (expander), TRUE);
 
@@ -373,9 +372,7 @@ gtk_expander_init (GtkExpander *expander)
   gtk_widget_add_css_class (priv->arrow_widget, GTK_STYLE_CLASS_HORIZONTAL);
   gtk_container_add (GTK_CONTAINER (priv->title_widget), priv->arrow_widget);
 
-  formats = gdk_content_formats_new (NULL, 0);
-  dest = gtk_drop_target_new (formats, 0);
-  gdk_content_formats_unref (formats);
+  dest = gtk_drop_target_new (NULL, 0);
   g_signal_connect (dest, "accept", G_CALLBACK (gtk_expander_drag_accept), expander);
   g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_expander_drag_leave), expander);
   gtk_widget_add_controller (GTK_WIDGET (expander), GTK_EVENT_CONTROLLER (dest));
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index 95b366753f..ff6dd9bbf3 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -446,7 +446,6 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
   GtkWidget *box;
   GtkWidget *icon;
   GdkContentFormatsBuilder *builder;
-  GdkContentFormats *target_list;
   GtkDropTarget *dest;
 
   priv->button = gtk_button_new ();
@@ -502,11 +501,10 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
   builder = gdk_content_formats_builder_new ();
   gdk_content_formats_builder_add_gtype (builder, G_TYPE_STRING);
   gdk_content_formats_builder_add_gtype (builder, GDK_TYPE_FILE_LIST);
-  target_list = gdk_content_formats_builder_free_to_formats (builder);
-  dest = gtk_drop_target_new (target_list, GDK_ACTION_COPY);
+  dest = gtk_drop_target_new (gdk_content_formats_builder_free_to_formats (builder),
+                              GDK_ACTION_COPY);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_file_chooser_button_drag_drop), button);
   gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (target_list);
 }
 
 
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index f561e8d293..0b960d9c33 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -8362,24 +8362,22 @@ post_process_ui (GtkFileChooserWidget *impl)
   GList            *cells;
   GFile            *file;
   GtkDropTarget *dest;
-  GdkContentFormats *formats;
 
   /* Setup file list treeview */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
   gtk_tree_selection_set_select_function (selection,
                                           list_select_func,
                                           impl, NULL);
-  formats = gdk_content_formats_new_for_gtype (GDK_TYPE_FILE_LIST);
   gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (priv->browse_files_tree_view),
                                           GDK_BUTTON1_MASK,
-                                          formats,
+                                          gdk_content_formats_new_for_gtype (GDK_TYPE_FILE_LIST),
                                           GDK_ACTION_COPY | GDK_ACTION_MOVE);
   
-  dest = gtk_drop_target_new (formats, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GDK_TYPE_FILE_LIST),
+                              GDK_ACTION_COPY | GDK_ACTION_MOVE);
   g_signal_connect (dest, "accept", G_CALLBACK (file_list_drag_accept_cb), impl);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (file_list_drag_drop_cb), impl);
   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,
    * so we don't set cell renderer attributes in GtkBuilder, but rather keep that
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 1cd7b1c3a7..10b86fa642 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -6453,7 +6453,7 @@ gtk_icon_view_enable_model_drag_dest (GtkIconView       *icon_view,
   g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
   GtkCssNode *widget_node;
 
-  icon_view->priv->dest = gtk_drop_target_new (formats, actions);
+  icon_view->priv->dest = gtk_drop_target_new (gdk_content_formats_ref (formats), actions);
   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);
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 6f7894defe..01f0d01773 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1292,7 +1292,6 @@ static void
 gtk_notebook_init (GtkNotebook *notebook)
 {
   GtkNotebookPrivate *priv;
-  GdkContentFormats *targets;
   GtkEventController *controller;
   GtkGesture *gesture;
   GtkLayoutManager *layout;
@@ -1348,13 +1347,11 @@ gtk_notebook_init (GtkNotebook *notebook)
   gtk_widget_set_vexpand (priv->stack_widget, TRUE);
   gtk_widget_set_parent (priv->stack_widget, GTK_WIDGET (notebook));
 
-  targets = gdk_content_formats_new (dst_notebook_targets, G_N_ELEMENTS (dst_notebook_targets));
-  dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new (dst_notebook_targets, G_N_ELEMENTS 
(dst_notebook_targets)), GDK_ACTION_MOVE);
   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_widget_add_controller (GTK_WIDGET (priv->tabs_widget), GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (targets);
 
   gesture = gtk_gesture_click_new ();
   gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 92bee5066f..4607dde431 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -4018,7 +4018,6 @@ shell_shows_desktop_changed (GtkSettings *settings,
 static void
 gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
 {
-  GdkContentFormats *formats;
   GtkDropTarget *dest;
   gboolean show_desktop;
   GtkEventController *controller;
@@ -4082,9 +4081,8 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
   builder = gdk_content_formats_builder_new ();
   gdk_content_formats_builder_add_mime_type (builder, "DND_GTK_SIDEBAR_ROW");
   gdk_content_formats_builder_add_gtype (builder, GDK_TYPE_FILE_LIST);
-  formats = gdk_content_formats_builder_free_to_formats (builder);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
-  gdk_content_formats_unref (formats);
+  dest = gtk_drop_target_new (gdk_content_formats_builder_free_to_formats (builder),
+                              GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
   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);
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 54e0aaef99..699904627f 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -113,16 +113,13 @@ static void
 gtk_stack_switcher_init (GtkStackSwitcher *switcher)
 {
   GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (switcher);
-  GdkContentFormats *formats;
   GtkDropTarget *dest;
 
   priv->buttons = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
 
   gtk_widget_add_css_class (GTK_WIDGET (switcher), "linked");
 
-  formats = gdk_content_formats_new (NULL, 0);
-  dest = gtk_drop_target_new (formats, 0);
-  gdk_content_formats_unref (formats);
+  dest = gtk_drop_target_new (NULL, 0);
   g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_stack_switcher_drag_leave), switcher);
   g_signal_connect (dest, "accept", G_CALLBACK (gtk_stack_switcher_drag_accept), switcher);
   g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_stack_switcher_drag_motion), switcher);
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index c7ca23be88..c5f6142c5b 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -1712,7 +1712,6 @@ gtk_text_init (GtkText *self)
   GtkEventController *controller;
   int i;
   GtkDropTarget *dest;
-  GdkContentFormats *formats;
 
   gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
   gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
@@ -1734,13 +1733,12 @@ gtk_text_init (GtkText *self)
   priv->selection_content = g_object_new (GTK_TYPE_TEXT_CONTENT, NULL);
   GTK_TEXT_CONTENT (priv->selection_content)->self = self;
 
-  formats = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (G_TYPE_STRING),
+                              GDK_ACTION_COPY | GDK_ACTION_MOVE);
   g_signal_connect (dest, "accept", G_CALLBACK (gtk_text_drag_accept), self);
   g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_text_drag_motion), 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_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (dest));
 
   /* This object is completely private. No external entity can gain a reference
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 5f677847a1..d176abe2e1 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -1611,7 +1611,6 @@ static void
 gtk_text_view_init (GtkTextView *text_view)
 {
   GtkWidget *widget = GTK_WIDGET (text_view);
-  GdkContentFormats *formats;
   GtkDropTarget *dest;
   GtkTextViewPrivate *priv;
   GtkEventController *controller;
@@ -1640,9 +1639,7 @@ gtk_text_view_init (GtkTextView *text_view)
 
   priv->scroll_after_paste = FALSE;
 
-  formats = gdk_content_formats_new_for_gtype (GTK_TYPE_TEXT_BUFFER);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_COPY | GDK_ACTION_MOVE);
-  gdk_content_formats_unref (formats);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GTK_TYPE_TEXT_BUFFER), GDK_ACTION_COPY | 
GDK_ACTION_MOVE);
   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);
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 27b0576477..8ce1a0ef14 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -12907,7 +12907,7 @@ gtk_tree_view_enable_model_drag_dest (GtkTreeView       *tree_view,
   di = ensure_info (tree_view);
   di->dest_set = TRUE;
 
-  di->dest = gtk_drop_target_new (formats, actions);
+  di->dest = gtk_drop_target_new (gdk_content_formats_ref (formats), actions);
   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);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 37836d360f..3e771c6c8c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1774,7 +1774,6 @@ gtk_window_init (GtkWindow *window)
   GdkSeat *seat;
   GtkEventController *motion_controller;
 #ifdef GDK_WINDOWING_X11
-  GdkContentFormats *targets;
   GtkDropTarget *dest;
 #endif
 
@@ -1828,9 +1827,7 @@ gtk_window_init (GtkWindow *window)
   priv->scale = gtk_widget_get_scale_factor (widget);
 
 #ifdef GDK_WINDOWING_X11
-  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);
+  dest = gtk_drop_target_new (gdk_content_formats_new (dnd_dest_targets, G_N_ELEMENTS (dnd_dest_targets)), 
GDK_ACTION_MOVE);
   gtk_widget_add_controller (GTK_WIDGET (window), GTK_EVENT_CONTROLLER (dest));
 #endif
 
diff --git a/tests/testdnd.c b/tests/testdnd.c
index 40ec72d60c..f48a55b6af 100644
--- a/tests/testdnd.c
+++ b/tests/testdnd.c
@@ -631,7 +631,7 @@ main (int argc, char **argv)
   label = gtk_label_new ("Drop Here\n");
 
   targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */
-  dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_ref (targets), GDK_ACTION_COPY | GDK_ACTION_MOVE);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (label_drag_drop), NULL);
   gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
 
@@ -651,16 +651,12 @@ main (int argc, char **argv)
   gtk_widget_set_vexpand (label, TRUE);
   gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
 
-  gdk_content_formats_unref (targets);
-  
   pixmap = gtk_image_new_from_pixbuf (trashcan_closed);
-  targets = gdk_content_formats_new (NULL, 0);
-  dest = gtk_drop_target_new (targets, 0);
+  dest = gtk_drop_target_new (NULL, 0);
   g_signal_connect (dest, "drag-leave", G_CALLBACK (target_drag_leave), pixmap);
   g_signal_connect (dest, "accept", G_CALLBACK (target_drag_motion), pixmap);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (target_drag_drop), pixmap);
   gtk_widget_add_controller (pixmap, GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (targets);
 
   gtk_widget_set_hexpand (pixmap, TRUE);
   gtk_widget_set_vexpand (pixmap, TRUE);
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index cfb0da65c5..0c170be28a 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -416,8 +416,6 @@ make_image (const gchar *icon_name, int hotspot)
   g_signal_connect (dest, "drag-drop", G_CALLBACK (image_drag_drop), image);
   gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
 
-  gdk_content_formats_unref (formats);
-
   return image;
 }
 
diff --git a/tests/testdnd3.c b/tests/testdnd3.c
index b1c4a47dc8..4b58ad136b 100644
--- a/tests/testdnd3.c
+++ b/tests/testdnd3.c
@@ -139,7 +139,6 @@ canvas_new (void)
   GtkWidget *canvas;
   GtkDragSource *source;
   GtkDropTarget *dest;
-  GdkContentFormats *formats;
 
   canvas = gtk_fixed_new ();
   gtk_widget_set_hexpand (canvas, TRUE);
@@ -154,11 +153,9 @@ canvas_new (void)
   g_signal_connect (source, "drag-cancel", G_CALLBACK (drag_cancel), NULL);
   gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (source));
 
-  formats = gdk_content_formats_new_for_gtype (GTK_TYPE_WIDGET);
-  dest = gtk_drop_target_new (formats, GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GTK_TYPE_WIDGET), GDK_ACTION_MOVE);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), NULL);
   gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (formats);
 
   return canvas;
 }
diff --git a/tests/testlist3.c b/tests/testlist3.c
index fb5fd1addd..72dcc2db28 100644
--- a/tests/testlist3.c
+++ b/tests/testlist3.c
@@ -77,7 +77,6 @@ static GtkWidget *
 create_row (const gchar *text)
 {
   GtkWidget *row, *box, *label, *image;
-  GdkContentFormats *targets;
   GtkDragSource *source;
   GtkDropTarget *dest;
 
@@ -97,13 +96,10 @@ create_row (const gchar *text)
   g_signal_connect (source, "prepare", G_CALLBACK (prepare), row);
   gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
 
-  targets = gdk_content_formats_new_for_gtype (GTK_TYPE_LIST_BOX_ROW);
-  dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new_for_gtype (GTK_TYPE_LIST_BOX_ROW), GDK_ACTION_MOVE);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), row);
   gtk_widget_add_controller (GTK_WIDGET (row), GTK_EVENT_CONTROLLER (dest));
 
-  gdk_content_formats_unref (targets);
-
   return row;
 }
 
diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c
index 042a6a4ce3..f7050f04a9 100644
--- a/tests/testnotebookdnd.c
+++ b/tests/testnotebookdnd.c
@@ -293,17 +293,14 @@ create_notebook_with_notebooks (gchar           **labels,
 static GtkWidget*
 create_trash_button (void)
 {
-  GdkContentFormats *targets;
   GtkWidget *button;
   GtkDropTarget *dest;
 
   button = gtk_button_new_with_mnemonic ("_Delete");
 
-  targets = gdk_content_formats_new (button_targets, G_N_ELEMENTS (button_targets));
-  dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
+  dest = gtk_drop_target_new (gdk_content_formats_new (button_targets, G_N_ELEMENTS (button_targets)), 
GDK_ACTION_MOVE);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (on_button_drag_drop), NULL);
   gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (targets);
 
   return button;
 }
diff --git a/tests/testtreednd.c b/tests/testtreednd.c
index 89e72bf202..16efa7e302 100644
--- a/tests/testtreednd.c
+++ b/tests/testtreednd.c
@@ -121,15 +121,12 @@ static GtkWidget *
 get_droptarget (void)
 {
   GtkWidget *label;
-  GdkContentFormats *targets;
   GtkDropTarget *dest;
 
   label = gtk_label_new ("Drop here");
-  targets = gdk_content_formats_new (entries, G_N_ELEMENTS (entries));
-  dest = gtk_drop_target_new (targets, GDK_ACTION_COPY);
+  dest = gtk_drop_target_new (gdk_content_formats_new (entries, G_N_ELEMENTS (entries)), GDK_ACTION_COPY);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (drag_drop), NULL);
   gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (dest));
-  gdk_content_formats_unref (targets);
 
   return label;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]