Port simple cases to GtkDropControllerMotion

This commit is contained in:
Benjamin Otte 2020-02-22 04:09:02 +01:00
parent 2a8fd25a4b
commit d680e2e344
2 changed files with 57 additions and 62 deletions

View File

@ -115,7 +115,7 @@
#include "gtkbox.h"
#include "gtkbuildable.h"
#include "gtkcontainerprivate.h"
#include "gtkdragdest.h"
#include "gtkdropcontrollermotion.h"
#include "gtkbuiltiniconprivate.h"
#include "gtkgestureclick.h"
#include "gtkgesturesingle.h"
@ -192,12 +192,6 @@ static void gtk_expander_size_allocate (GtkWidget *widget,
int baseline);
static gboolean gtk_expander_focus (GtkWidget *widget,
GtkDirectionType direction);
static gboolean gtk_expander_drag_accept (GtkDropTarget *dest,
GdkDrop *drop,
GtkExpander *expander);
static void gtk_expander_drag_leave (GtkDropTarget *dest,
GdkDrop *drop,
GtkExpander *expander);
static void gtk_expander_add (GtkContainer *container,
GtkWidget *widget);
@ -236,6 +230,48 @@ G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_expander_buildable_init))
static gboolean
expand_timeout (gpointer data)
{
GtkExpander *expander = GTK_EXPANDER (data);
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
priv->expand_timer = 0;
gtk_expander_set_expanded (expander, TRUE);
return FALSE;
}
static gboolean
gtk_expander_drag_enter (GtkDropControllerMotion *motion,
double x,
double y,
GtkExpander *expander)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
if (!priv->expanded && !priv->expand_timer)
{
priv->expand_timer = g_timeout_add (TIMEOUT_EXPAND, (GSourceFunc) expand_timeout, expander);
g_source_set_name_by_id (priv->expand_timer, "[gtk] expand_timeout");
}
return TRUE;
}
static void
gtk_expander_drag_leave (GtkDropControllerMotion *motion,
GtkExpander *expander)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
if (priv->expand_timer)
{
g_source_remove (priv->expand_timer);
priv->expand_timer = 0;
}
}
static void
gtk_expander_forall (GtkContainer *container,
GtkCallback callback,
@ -347,7 +383,7 @@ gtk_expander_init (GtkExpander *expander)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
GtkGesture *gesture;
GtkDropTarget *dest;
GtkEventController *controller;
gtk_widget_set_can_focus (GTK_WIDGET (expander), TRUE);
@ -372,10 +408,10 @@ 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);
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));
controller = gtk_drop_controller_motion_new ();
g_signal_connect (controller, "enter", G_CALLBACK (gtk_expander_drag_enter), expander);
g_signal_connect (controller, "leave", G_CALLBACK (gtk_expander_drag_leave), expander);
gtk_widget_add_controller (GTK_WIDGET (expander), controller);
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture),
@ -530,48 +566,6 @@ gesture_click_released_cb (GtkGestureClick *gesture,
gtk_widget_activate (GTK_WIDGET (expander));
}
static gboolean
expand_timeout (gpointer data)
{
GtkExpander *expander = GTK_EXPANDER (data);
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
priv->expand_timer = 0;
gtk_expander_set_expanded (expander, TRUE);
return FALSE;
}
static gboolean
gtk_expander_drag_accept (GtkDropTarget *dest,
GdkDrop *drop,
GtkExpander *expander)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
if (!priv->expanded && !priv->expand_timer)
{
priv->expand_timer = g_timeout_add (TIMEOUT_EXPAND, (GSourceFunc) expand_timeout, expander);
g_source_set_name_by_id (priv->expand_timer, "[gtk] expand_timeout");
}
return TRUE;
}
static void
gtk_expander_drag_leave (GtkDropTarget *dest,
GdkDrop *drop,
GtkExpander *expander)
{
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
if (priv->expand_timer)
{
g_source_remove (priv->expand_timer);
priv->expand_timer = 0;
}
}
typedef enum
{
FOCUS_NONE,

View File

@ -35,6 +35,7 @@
#include "gtkcssstylepropertyprivate.h"
#include "gtkdragdest.h"
#include "gtkdragicon.h"
#include "gtkdropcontrollermotion.h"
#include "gtkeventcontrollermotion.h"
#include "gtkgestureclick.h"
#include "gtkgizmoprivate.h"
@ -3081,12 +3082,13 @@ gtk_notebook_state_flags_changed (GtkWidget *widget,
}
static void
gtk_notebook_arrow_drag_enter (GtkDropTarget *target,
GdkDrop *drop,
GtkNotebook *notebook)
gtk_notebook_arrow_drag_enter (GtkDropControllerMotion *motion,
double x,
double y,
GtkNotebook *notebook)
{
GtkNotebookPrivate *priv = notebook->priv;
GtkWidget *arrow_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (target));
GtkWidget *arrow_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
guint arrow;
for (arrow = 0; arrow < 4; arrow++)
@ -3099,7 +3101,6 @@ gtk_notebook_arrow_drag_enter (GtkDropTarget *target,
priv->click_child = arrow;
gtk_notebook_set_scroll_timer (notebook);
gdk_drop_status (drop, 0);
}
static void
@ -3192,9 +3193,9 @@ update_arrow_nodes (GtkNotebook *notebook)
priv->arrow_widget[i] = g_object_new (GTK_TYPE_BUTTON,
"css-name", "arrow",
NULL);
controller = GTK_EVENT_CONTROLLER (gtk_drop_target_new (NULL, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK));
g_signal_connect (controller, "drag-enter", G_CALLBACK (gtk_notebook_arrow_drag_enter), notebook);
g_signal_connect (controller, "drag-leave", G_CALLBACK (gtk_notebook_arrow_drag_leave), notebook);
controller = gtk_drop_controller_motion_new ();
g_signal_connect (controller, "enter", G_CALLBACK (gtk_notebook_arrow_drag_enter), notebook);
g_signal_connect (controller, "leave", G_CALLBACK (gtk_notebook_arrow_drag_leave), notebook);
gtk_widget_add_controller (priv->arrow_widget[i], controller);
if (i == ARROW_LEFT_BEFORE || i == ARROW_LEFT_AFTER)