[gtk/dnd-gestures-2: 64/150] dragdest: Clean up internals
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dnd-gestures-2: 64/150] dragdest: Clean up internals
- Date: Tue, 7 Jan 2020 06:57:18 +0000 (UTC)
commit d99f8d91c586f701641e828527b21fa9a65fe1a2
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 5 09:18:47 2020 -0500
dragdest: Clean up internals
Remove the no-longer needed GtkDragDest struct
and just attach the GtkDropTarget directly.
gtk/gtkdnd.c | 48 +++++++++--------
gtk/gtkdndprivate.h | 10 ----
gtk/gtkdragdest.c | 136 ++++++++++++++++++++---------------------------
gtk/gtkdragdestprivate.h | 5 ++
4 files changed, 88 insertions(+), 111 deletions(-)
---
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 788e46513d..71ae8405b5 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -345,23 +345,25 @@ gtk_drag_dest_leave (GtkWidget *widget,
GdkDrop *drop,
guint time)
{
- GtkDragDestSite *site;
+ GtkDropTarget *dest;
GtkDestDefaults flags;
gboolean track_motion;
+ gboolean armed;
- site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
- g_return_if_fail (site != NULL);
+ dest = gtk_drop_target_get (widget);
+ g_return_if_fail (dest != NULL);
- flags = gtk_drop_target_get_defaults (site->dest);
- track_motion = gtk_drop_target_get_track_motion (site->dest);
+ flags = gtk_drop_target_get_defaults (dest);
+ track_motion = gtk_drop_target_get_track_motion (dest);
+ armed = gtk_drop_target_get_armed (dest);
- if ((flags & GTK_DEST_DEFAULT_HIGHLIGHT) && site->have_drag)
+ if ((flags & GTK_DEST_DEFAULT_HIGHLIGHT) && armed)
gtk_drag_unhighlight (widget);
- if (!(flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag || track_motion)
- gtk_drop_target_emit_drag_leave (site->dest, drop, time);
+ if (!(flags & GTK_DEST_DEFAULT_MOTION) || armed || track_motion)
+ gtk_drop_target_emit_drag_leave (dest, drop, time);
- site->have_drag = FALSE;
+ gtk_drop_target_set_armed (dest, FALSE);
}
static gboolean
@@ -371,18 +373,18 @@ gtk_drag_dest_motion (GtkWidget *widget,
gint y,
guint time)
{
- GtkDragDestSite *site;
+ GtkDropTarget *dest;
GdkDragAction dest_actions;
GtkDestDefaults flags;
gboolean track_motion;
gboolean retval;
- site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
- g_return_val_if_fail (site != NULL, FALSE);
+ dest = gtk_drop_target_get (widget);
+ g_return_val_if_fail (dest != NULL, FALSE);
- dest_actions = gtk_drop_target_get_actions (site->dest);
- flags = gtk_drop_target_get_defaults (site->dest);
- track_motion = gtk_drop_target_get_track_motion (site->dest);
+ dest_actions = gtk_drop_target_get_actions (dest);
+ flags = gtk_drop_target_get_defaults (dest);
+ track_motion = gtk_drop_target_get_track_motion (dest);
if (track_motion || flags & GTK_DEST_DEFAULT_MOTION)
{
@@ -394,13 +396,13 @@ gtk_drag_dest_motion (GtkWidget *widget,
if ((dest_actions & actions) == 0)
actions = 0;
- target = gtk_drop_target_match (site->dest, drop);
+ target = gtk_drop_target_match (dest, drop);
if (actions && target)
{
- if (!site->have_drag)
+ if (!gtk_drop_target_get_armed (dest))
{
- site->have_drag = TRUE;
+ gtk_drop_target_set_armed (dest, TRUE);
if (flags & GTK_DEST_DEFAULT_HIGHLIGHT)
gtk_drag_highlight (widget);
}
@@ -415,7 +417,7 @@ gtk_drag_dest_motion (GtkWidget *widget,
}
}
- retval = gtk_drop_target_emit_drag_motion (site->dest, drop, x, y);
+ retval = gtk_drop_target_emit_drag_motion (dest, drop, x, y);
return (flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
}
@@ -427,14 +429,14 @@ gtk_drag_dest_drop (GtkWidget *widget,
gint y,
guint time)
{
- GtkDragDestSite *site;
+ GtkDropTarget *dest;
GtkDragDestInfo *info;
- site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
- g_return_val_if_fail (site != NULL, FALSE);
+ dest = gtk_drop_target_get (widget);
+ g_return_val_if_fail (dest != NULL, FALSE);
info = gtk_drag_get_dest_info (drop, FALSE);
g_return_val_if_fail (info != NULL, FALSE);
- return gtk_drop_target_emit_drag_drop (site->dest, drop, x, y);
+ return gtk_drop_target_emit_drag_drop (dest, drop, x, y);
}
diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h
index 54826d7b0c..ad829e05b7 100644
--- a/gtk/gtkdndprivate.h
+++ b/gtk/gtkdndprivate.h
@@ -19,18 +19,8 @@
#ifndef __GTK_DND_PRIVATE_H__
#define __GTK_DND_PRIVATE_H__
-#include "gtkdragdest.h"
-#include "gtkimagedefinitionprivate.h"
-#include "gtkselection.h"
#include "gtkwidget.h"
-typedef struct _GtkDragDestSite GtkDragDestSite;
-struct _GtkDragDestSite
-{
- GtkDropTarget *dest;
- GtkDestDefaults flags;
- guint have_drag : 1;
-};
G_BEGIN_DECLS
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index 5a4728f117..b8d66334a0 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -36,77 +36,6 @@
#include "gtkselectionprivate.h"
-static void
-gtk_drag_dest_realized (GtkWidget *widget)
-{
- GtkNative *native = gtk_widget_get_native (widget);
-
- gdk_surface_register_dnd (gtk_native_get_surface (native));
-}
-
-static void
-gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
- GParamSpec *pspec,
- gpointer data)
-{
- GtkNative *native = gtk_widget_get_native (widget);
-
- if (native && gtk_widget_get_realized (GTK_WIDGET (native)))
- gdk_surface_register_dnd (gtk_native_get_surface (native));
-}
-
-static void
-gtk_drag_dest_site_destroy (gpointer data)
-{
- GtkDragDestSite *site = data;
-
- g_clear_object (&site->dest);
-
- g_slice_free (GtkDragDestSite, site);
-}
-
-static void
-gtk_drag_dest_set_internal (GtkWidget *widget,
- GtkDragDestSite *site)
-{
- GtkDragDestSite *old_site;
-
- old_site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest"));
- if (old_site)
- {
- g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_realized, old_site);
- g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_hierarchy_changed, old_site);
- gtk_drop_target_set_track_motion (site->dest, gtk_drop_target_get_track_motion (old_site->dest));
- }
-
- if (gtk_widget_get_realized (widget))
- gtk_drag_dest_realized (widget);
-
- g_signal_connect (widget, "realize", G_CALLBACK (gtk_drag_dest_realized), site);
- g_signal_connect (widget, "notify::root", G_CALLBACK (gtk_drag_dest_hierarchy_changed), site);
-
- g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"),
- site, gtk_drag_dest_site_destroy);
-}
-
-static void
-gtk_drag_dest_unset (GtkWidget *widget)
-{
- GtkDragDestSite *old_site;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
-
- old_site = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest"));
- if (old_site)
- {
- g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_realized, old_site);
- g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_hierarchy_changed, old_site);
- }
-
- g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL);
-}
-
-
/**
* SECTION:gtkdroptarget
* @Short_description: An object to receive DND drops
@@ -131,6 +60,7 @@ struct _GtkDropTarget
GtkWidget *widget;
GdkDrop *drop;
+ gboolean armed;
};
struct _GtkDropTargetClass
@@ -573,6 +503,31 @@ gtk_drop_target_get_track_motion (GtkDropTarget *dest)
return dest->track_motion;
}
+static void
+gtk_drag_dest_realized (GtkWidget *widget)
+{
+ GtkNative *native = gtk_widget_get_native (widget);
+
+ gdk_surface_register_dnd (gtk_native_get_surface (native));
+}
+
+static void
+gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ GtkNative *native = gtk_widget_get_native (widget);
+
+ if (native && gtk_widget_get_realized (GTK_WIDGET (native)))
+ gdk_surface_register_dnd (gtk_native_get_surface (native));
+}
+
+GtkDropTarget *
+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
@@ -587,20 +542,28 @@ void
gtk_drop_target_attach (GtkDropTarget *dest,
GtkWidget *widget)
{
- GtkDragDestSite *site;
+ GtkDropTarget *old_dest;
g_return_if_fail (GTK_IS_DROP_TARGET (dest));
g_return_if_fail (dest->widget == NULL);
g_return_if_fail (GTK_IS_WIDGET (widget));
- dest->widget = widget;
+ old_dest = g_object_get_data (G_OBJECT (widget), I_("gtk-drag-dest"));
+ if (old_dest)
+ {
+ g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_realized, old_dest);
+ g_signal_handlers_disconnect_by_func (widget, gtk_drag_dest_hierarchy_changed, old_dest);
+ }
+
+ if (gtk_widget_get_realized (widget))
+ gtk_drag_dest_realized (widget);
- site = g_slice_new0 (GtkDragDestSite);
+ dest->widget = widget;
- site->dest = dest;
- site->have_drag = FALSE;
+ g_signal_connect (widget, "realize", G_CALLBACK (gtk_drag_dest_realized), dest);
+ g_signal_connect (widget, "notify::root", G_CALLBACK (gtk_drag_dest_hierarchy_changed), dest);
- gtk_drag_dest_set_internal (widget, site);
+ g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"), dest, g_object_unref);
}
/**
@@ -616,7 +579,11 @@ gtk_drop_target_detach (GtkDropTarget *dest)
if (dest->widget)
{
- gtk_drag_dest_unset (dest->widget);
+ g_signal_handlers_disconnect_by_func (dest->widget, gtk_drag_dest_realized, dest);
+ g_signal_handlers_disconnect_by_func (dest->widget, gtk_drag_dest_hierarchy_changed, dest);
+
+ g_object_set_data (G_OBJECT (dest->widget), I_("gtk-drag-dest"), NULL);
+
dest->widget = NULL;
}
}
@@ -742,6 +709,19 @@ gtk_drop_target_emit_drag_drop (GtkDropTarget *dest,
return result;
}
+void
+gtk_drop_target_set_armed (GtkDropTarget *target,
+ gboolean armed)
+{
+ target->armed = armed;
+}
+
+gboolean
+gtk_drop_target_get_armed (GtkDropTarget *target)
+{
+ return target->armed;
+}
+
/**
* gtk_drag_highlight: (method)
* @widget: a widget to highlight
diff --git a/gtk/gtkdragdestprivate.h b/gtk/gtkdragdestprivate.h
index deb772763f..6341ac579a 100644
--- a/gtk/gtkdragdestprivate.h
+++ b/gtk/gtkdragdestprivate.h
@@ -40,6 +40,11 @@ gboolean gtk_drop_target_emit_drag_drop (GtkDropTarget *dest,
const char * gtk_drop_target_match (GtkDropTarget *dest,
GdkDrop *drop);
+void gtk_drop_target_set_armed (GtkDropTarget *dest,
+ gboolean armed);
+gboolean gtk_drop_target_get_armed (GtkDropTarget *dest);
+
+GtkDropTarget *gtk_drop_target_get (GtkWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]