diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-01-06 00:21:41 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-01-08 18:48:21 -0500 |
commit | f3be49838fcd1c3e9bc0f4f988aa78e024f2555d (patch) | |
tree | 257c90671766212a785dcc827edc78c304e8d926 | |
parent | e9067ae2db95a30a714efdec22de07debe5ca12d (diff) | |
download | gtk+-f3be49838fcd1c3e9bc0f4f988aa78e024f2555d.tar.gz |
Move code over
Move remaining code from gtkdnd.c to gtkdragdest.c
and nuke gtkdnd.c and gtkdndprivate.h.
-rw-r--r-- | docs/reference/gtk/meson.build | 1 | ||||
-rw-r--r-- | gtk/gtkdnd.c | 141 | ||||
-rw-r--r-- | gtk/gtkdndprivate.h | 37 | ||||
-rw-r--r-- | gtk/gtkdragdest.c | 94 | ||||
-rw-r--r-- | gtk/gtkdragdestprivate.h | 24 | ||||
-rw-r--r-- | gtk/gtkdragsource.c | 1 | ||||
-rw-r--r-- | gtk/gtkentry.c | 1 | ||||
-rw-r--r-- | gtk/gtkmain.c | 2 | ||||
-rw-r--r-- | gtk/gtktext.c | 1 | ||||
-rw-r--r-- | 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/gtkdnd.c b/gtk/gtkdnd.c deleted file mode 100644 index 5bb5b45190..0000000000 --- a/gtk/gtkdnd.c +++ /dev/null @@ -1,141 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include "gtkdndprivate.h" - -#include "gtkdragdestprivate.h" -#include "gtkimageprivate.h" -#include "gtkintl.h" -#include "gtkmain.h" -#include "gtkpicture.h" -#include "gtkselectionprivate.h" -#include "gtksettingsprivate.h" -#include "gtkstylecontext.h" -#include "gtktooltipprivate.h" -#include "gtkwidgetprivate.h" -#include "gtkwindowgroup.h" -#include "gtkwindowprivate.h" -#include "gtknative.h" -#include "gtkdragiconprivate.h" - -#include "gdk/gdkcontentformatsprivate.h" -#include "gdk/gdktextureprivate.h" - -#include <math.h> -#include <stdlib.h> -#include <string.h> - - -/** - * SECTION:gtkdnd - * @Short_description: Functions for controlling drag and drop handling - * @Title: Drag and Drop - * - * GTK+ has a rich set of functions for doing inter-process communication - * via the drag-and-drop metaphor. - * - * As well as the functions listed here, applications may need to use some - * facilities provided for [Selections][gtk3-Selections]. Also, the Drag and - * Drop API makes use of signals in the #GtkWidget class. - */ - -/* - * gtk_drag_dest_handle_event: - * @toplevel: Toplevel widget that received the event - * @event: the event to handle - * - * Called from widget event handling code on Drag events - * for destinations. For drag-motion and drop-start events, - * this function is only called if no event handler has - * handled the 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); - - /* Find the widget for the 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 -clear_current_dest (gpointer data, GObject *former_object) -{ - g_object_set_data (G_OBJECT (data), "current-dest", NULL); -} - -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); -} - -GtkDropTarget * -gtk_drop_get_current_dest (GdkDrop *drop) -{ - return g_object_get_data (G_OBJECT (drop), "current-dest"); -} diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h deleted file mode 100644 index 4de9a173d5..0000000000 --- a/gtk/gtkdndprivate.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */ -/* GTK - The GIMP Toolkit - * Copyright (C) 2015 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __GTK_DND_PRIVATE_H__ -#define __GTK_DND_PRIVATE_H__ - -#include "gtkwidget.h" -#include "gtkdragdest.h" - - -G_BEGIN_DECLS - -void gtk_drag_dest_handle_event (GtkWidget *toplevel, - GdkEvent *event); - -void gtk_drop_set_current_dest (GdkDrop *drop, - GtkDropTarget *dest); -GtkDropTarget *gtk_drop_get_current_dest (GdkDrop *drop); - -G_END_DECLS - -#endif /* __GTK_DND_PRIVATE_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', |