[gtk/dnd-gestures-2: 81/173] Move code over



commit f3be49838fcd1c3e9bc0f4f988aa78e024f2555d
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 6 00:21:41 2020 -0500

    Move code over
    
    Move remaining code from gtkdnd.c to gtkdragdest.c
    and nuke gtkdnd.c and gtkdndprivate.h.

 docs/reference/gtk/meson.build |   1 -
 gtk/gtkdnd.c                   | 141 -----------------------------------------
 gtk/gtkdndprivate.h            |  37 -----------
 gtk/gtkdragdest.c              |  94 +++++++++++++++++++++++----
 gtk/gtkdragdestprivate.h       |  24 +------
 gtk/gtkdragsource.c            |   1 -
 gtk/gtkentry.c                 |   1 -
 gtk/gtkmain.c                  |   2 +-
 gtk/gtktext.c                  |   1 -
 gtk/meson.build                |   1 -
 10 files changed, 85 insertions(+), 218 deletions(-)
---
diff --git a/docs/reference/gtk/meson.build b/docs/reference/gtk/meson.build
index 0ee718a1c5..4091c704e3 100644
--- a/docs/reference/gtk/meson.build
+++ b/docs/reference/gtk/meson.build
@@ -97,7 +97,6 @@ private_headers = [
   'gtkcsswidgetnodeprivate.h',
   'gtkcsswin32sizevalueprivate.h',
   'gtkdialogprivate.h',
-  'gtkdndprivate.h',
   'gtkentryprivate.h',
   'gtkeventcontrollerlegacyprivate.h',
   'gtkeventcontrollerprivate.h',
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index 9c2e802076..adf7edfa16 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -27,7 +27,6 @@
 #include "gtkdragdest.h"
 #include "gtkdragdestprivate.h"
 
-#include "gtkdndprivate.h"
 #include "gtkintl.h"
 #include "gtknative.h"
 #include "gtktypebuiltins.h"
@@ -102,6 +101,10 @@ static void     gtk_drop_target_set_widget   (GtkEventController *controller,
                                               GtkWidget          *widget);
 static void     gtk_drop_target_unset_widget (GtkEventController *controller);
 
+static gboolean gtk_drop_target_get_armed    (GtkDropTarget *dest);
+static void     gtk_drop_target_set_armed    (GtkDropTarget *dest,
+                                              gboolean       armed);
+
 G_DEFINE_TYPE (GtkDropTarget, gtk_drop_target, GTK_TYPE_EVENT_CONTROLLER);
 
 static void
@@ -439,12 +442,6 @@ gtk_drag_dest_hierarchy_changed (GtkWidget  *widget,
     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_get_target:
  * @dest: a #GtkDropTarget
@@ -477,7 +474,7 @@ gtk_drop_target_get_drop (GtkDropTarget *dest)
   return dest->drop;
 }
 
-const char *
+static const char *
 gtk_drop_target_match (GtkDropTarget *dest,
                        GdkDrop       *drop)
 {
@@ -557,7 +554,7 @@ set_drop (GtkDropTarget *dest,
     g_object_add_weak_pointer (G_OBJECT (dest->drop), (gpointer *)&dest->drop);
 }
 
-void
+static void
 gtk_drop_target_emit_drag_leave (GtkDropTarget    *dest,
                                  GdkDrop          *drop)
 {
@@ -567,7 +564,7 @@ gtk_drop_target_emit_drag_leave (GtkDropTarget    *dest,
   gtk_drop_target_set_armed (dest, FALSE);
 }
 
-gboolean
+static gboolean
 gtk_drop_target_emit_drag_motion (GtkDropTarget    *dest,
                                   GdkDrop          *drop,
                                   int               x,
@@ -586,7 +583,7 @@ gtk_drop_target_emit_drag_motion (GtkDropTarget    *dest,
   return result;
 }
 
-gboolean
+static gboolean
 gtk_drop_target_emit_drag_drop (GtkDropTarget    *dest,
                                 GdkDrop          *drop,
                                 int               x,
@@ -600,7 +597,7 @@ gtk_drop_target_emit_drag_drop (GtkDropTarget    *dest,
   return result;
 }
 
-void
+static void
 gtk_drop_target_set_armed (GtkDropTarget *dest,
                            gboolean       armed)
 {
@@ -623,7 +620,7 @@ gtk_drop_target_set_armed (GtkDropTarget *dest,
   g_object_notify_by_pspec (G_OBJECT (dest), properties[PROP_ARMED]);
 }
 
-gboolean
+static gboolean
 gtk_drop_target_get_armed (GtkDropTarget *dest)
 {
   return dest->armed;
@@ -647,6 +644,35 @@ gtk_drop_target_filter_event (GtkEventController *controller,
   return TRUE;
 }
 
+static void
+clear_current_dest (gpointer data, GObject *former_object)
+{
+  g_object_set_data (G_OBJECT (data), "current-dest", NULL);
+}
+
+static void
+gtk_drop_set_current_dest (GdkDrop       *drop,
+                           GtkDropTarget *dest)
+{
+  GtkDropTarget *old_dest;
+
+  old_dest = g_object_get_data (G_OBJECT (drop), "current-dest");
+
+  if (old_dest)
+    g_object_weak_unref (G_OBJECT (old_dest), clear_current_dest, drop);
+
+  g_object_set_data (G_OBJECT (drop), "current-dest", dest);
+
+  if (dest)
+    g_object_weak_ref (G_OBJECT (dest), clear_current_dest, drop);
+}
+
+static GtkDropTarget *
+gtk_drop_get_current_dest (GdkDrop *drop)
+{
+  return g_object_get_data (G_OBJECT (drop), "current-dest");
+}
+
 static gboolean
 gtk_drop_target_handle_event (GtkEventController *controller,
                               const GdkEvent     *event)
@@ -699,6 +725,48 @@ gtk_drop_target_handle_event (GtkEventController *controller,
   return found;
 }
 
+/*
+ * This function is called if none of the event
+ * controllers has handled a drag event.
+ */
+void
+gtk_drag_dest_handle_event (GtkWidget *toplevel,
+                            GdkEvent  *event)
+{
+  GtkDropTarget *dest;
+  GdkDrop *drop;
+  GdkEventType event_type;
+
+  g_return_if_fail (toplevel != NULL);
+  g_return_if_fail (event != NULL);
+
+  event_type = gdk_event_get_event_type (event);
+  drop = gdk_event_get_drop (event);
+
+  switch ((guint) event_type)
+    {
+    case GDK_DRAG_ENTER:
+      break;
+
+    case GDK_DRAG_LEAVE:
+      dest = gtk_drop_get_current_dest (drop);
+      if (dest)
+        {
+          gtk_drop_target_emit_drag_leave (dest, drop);
+          gtk_drop_set_current_dest (drop, NULL);
+        }
+      break;
+
+    case GDK_DRAG_MOTION:
+    case GDK_DROP_START:
+      gdk_drop_status (drop, 0);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+}
+
 static void
 gtk_drop_target_set_widget (GtkEventController *controller,
                             GtkWidget          *widget)
diff --git a/gtk/gtkdragdestprivate.h b/gtk/gtkdragdestprivate.h
index cb1c031208..0113f98709 100644
--- a/gtk/gtkdragdestprivate.h
+++ b/gtk/gtkdragdestprivate.h
@@ -23,27 +23,9 @@
 
 G_BEGIN_DECLS
 
-void gtk_drop_target_emit_drag_data_received (GtkDropTarget    *dest,
-                                              GdkDrop          *drop,
-                                              GtkSelectionData *sdata);
-void gtk_drop_target_emit_drag_leave         (GtkDropTarget    *dest,
-                                              GdkDrop          *drop);
-gboolean gtk_drop_target_emit_drag_motion    (GtkDropTarget    *dest,
-                                              GdkDrop          *drop,
-                                              int               x,
-                                              int               y);
-gboolean gtk_drop_target_emit_drag_drop      (GtkDropTarget    *dest,
-                                              GdkDrop          *drop,
-                                              int               x,
-                                              int               y);
-
-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);
+
+void           gtk_drag_dest_handle_event (GtkWidget     *toplevel,
+                                           GdkEvent      *event);
 
 G_END_DECLS
 
diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c
index 7c3b249a33..53c80774d3 100644
--- a/gtk/gtkdragsource.c
+++ b/gtk/gtkdragsource.c
@@ -26,7 +26,6 @@
 
 #include "gtkdragsource.h"
 
-#include "gtkdndprivate.h"
 #include "gtkgesturedrag.h"
 #include "gtkgesturesingleprivate.h"
 #include "gtkimagedefinitionprivate.h"
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index db33c193aa..1b249b2fb6 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -38,7 +38,6 @@
 #include "gtkcelllayout.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkdebug.h"
-#include "gtkdndprivate.h"
 #include "gtkeditable.h"
 #include "gtkemojichooser.h"
 #include "gtkemojicompletion.h"
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 504fe53382..3cfaf57396 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -116,7 +116,7 @@
 #include "gtkaccelmapprivate.h"
 #include "gtkbox.h"
 #include "gtkdebug.h"
-#include "gtkdndprivate.h"
+#include "gtkdragdestprivate.h"
 #include "gtkmain.h"
 #include "gtkmediafileprivate.h"
 #include "gtkmodulesprivate.h"
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 27916ada67..72cf662fc6 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -30,7 +30,6 @@
 #include "gtkbutton.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkdebug.h"
-#include "gtkdndprivate.h"
 #include "gtkeditable.h"
 #include "gtkemojichooser.h"
 #include "gtkemojicompletion.h"
diff --git a/gtk/meson.build b/gtk/meson.build
index 40ae032cfd..cf032943ad 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -214,7 +214,6 @@ gtk_public_sources = files([
   'gtkcontainer.c',
   'gtkcssprovider.c',
   'gtkdialog.c',
-  'gtkdnd.c',
   'gtkdragdest.c',
   'gtkdragsource.c',
   'gtkdrawingarea.c',


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