forked from AuroraMiddleware/gtk
gtktreeviewcolumn: Implement column dragging through GtkGestureDrag
And remove ::event signal handler.
This commit is contained in:
parent
b3e91b7111
commit
9df5171962
@ -34,6 +34,7 @@
|
|||||||
#include "gtktreeview.h"
|
#include "gtktreeview.h"
|
||||||
#include "gtktypebuiltins.h"
|
#include "gtktypebuiltins.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkgesturedrag.h"
|
||||||
|
|
||||||
#include "a11y/gtktreeviewaccessibleprivate.h"
|
#include "a11y/gtktreeviewaccessibleprivate.h"
|
||||||
|
|
||||||
@ -86,9 +87,15 @@ static void gtk_tree_view_column_create_button (GtkTreeViewColum
|
|||||||
static void gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column);
|
static void gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column);
|
||||||
|
|
||||||
/* Button signal handlers */
|
/* Button signal handlers */
|
||||||
static gint gtk_tree_view_column_button_event (GtkWidget *widget,
|
static void column_button_drag_begin (GtkGestureDrag *gesture,
|
||||||
GdkEvent *event,
|
gdouble x,
|
||||||
gpointer data);
|
gdouble y,
|
||||||
|
GtkTreeViewColumn *column);
|
||||||
|
static void column_button_drag_update (GtkGestureDrag *gesture,
|
||||||
|
gdouble offset_x,
|
||||||
|
gdouble offset_y,
|
||||||
|
GtkTreeViewColumn *column);
|
||||||
|
|
||||||
static void gtk_tree_view_column_button_clicked (GtkWidget *widget,
|
static void gtk_tree_view_column_button_clicked (GtkWidget *widget,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean gtk_tree_view_column_mnemonic_activate (GtkWidget *widget,
|
static gboolean gtk_tree_view_column_mnemonic_activate (GtkWidget *widget,
|
||||||
@ -810,6 +817,7 @@ static void
|
|||||||
gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
|
gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
|
||||||
{
|
{
|
||||||
GtkTreeViewColumnPrivate *priv = tree_column->priv;
|
GtkTreeViewColumnPrivate *priv = tree_column->priv;
|
||||||
|
GtkEventController *controller;
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
|
|
||||||
@ -818,13 +826,18 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
|
|||||||
priv->button = gtk_button_new ();
|
priv->button = gtk_button_new ();
|
||||||
g_object_ref_sink (priv->button);
|
g_object_ref_sink (priv->button);
|
||||||
|
|
||||||
g_signal_connect (priv->button, "event",
|
|
||||||
G_CALLBACK (gtk_tree_view_column_button_event),
|
|
||||||
tree_column);
|
|
||||||
g_signal_connect (priv->button, "clicked",
|
g_signal_connect (priv->button, "clicked",
|
||||||
G_CALLBACK (gtk_tree_view_column_button_clicked),
|
G_CALLBACK (gtk_tree_view_column_button_clicked),
|
||||||
tree_column);
|
tree_column);
|
||||||
|
|
||||||
|
controller = GTK_EVENT_CONTROLLER (gtk_gesture_drag_new ());
|
||||||
|
g_signal_connect (controller, "drag-begin",
|
||||||
|
G_CALLBACK (column_button_drag_begin), tree_column);
|
||||||
|
g_signal_connect (controller, "drag-update",
|
||||||
|
G_CALLBACK (column_button_drag_update), tree_column);
|
||||||
|
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
|
||||||
|
gtk_widget_add_controller (priv->button, controller);
|
||||||
|
|
||||||
priv->frame = gtk_frame_new (NULL);
|
priv->frame = gtk_frame_new (NULL);
|
||||||
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
|
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
|
||||||
gtk_widget_set_hexpand (priv->frame, TRUE);
|
gtk_widget_set_hexpand (priv->frame, TRUE);
|
||||||
@ -1008,62 +1021,41 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
|
|||||||
/* Button signal handlers
|
/* Button signal handlers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static gint
|
static void
|
||||||
gtk_tree_view_column_button_event (GtkWidget *widget,
|
column_button_drag_begin (GtkGestureDrag *gesture,
|
||||||
GdkEvent *event,
|
gdouble x,
|
||||||
gpointer data)
|
gdouble y,
|
||||||
|
GtkTreeViewColumn *column)
|
||||||
{
|
{
|
||||||
GtkTreeViewColumn *column = (GtkTreeViewColumn *) data;
|
GtkTreeViewColumnPrivate *priv = column->priv;
|
||||||
GtkTreeViewColumnPrivate *priv = column->priv;
|
|
||||||
GdkEventType event_type;
|
|
||||||
guint button;
|
|
||||||
gdouble x, y;
|
|
||||||
|
|
||||||
g_return_val_if_fail (event != NULL, FALSE);
|
if (!priv->reorderable)
|
||||||
|
|
||||||
event_type = gdk_event_get_event_type (event);
|
|
||||||
gdk_event_get_button (event, &button);
|
|
||||||
gdk_event_get_coords (event, &x, &y);
|
|
||||||
|
|
||||||
if (event_type == GDK_BUTTON_PRESS &&
|
|
||||||
priv->reorderable &&
|
|
||||||
button == GDK_BUTTON_PRIMARY)
|
|
||||||
{
|
{
|
||||||
priv->maybe_reordered = TRUE;
|
gtk_gesture_set_state (GTK_GESTURE (gesture),
|
||||||
priv->drag_x = x;
|
GTK_EVENT_SEQUENCE_DENIED);
|
||||||
priv->drag_y = y;
|
return;
|
||||||
gtk_widget_grab_focus (widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_type == GDK_BUTTON_RELEASE ||
|
priv->drag_x = x;
|
||||||
event_type == GDK_LEAVE_NOTIFY)
|
priv->drag_y = y;
|
||||||
priv->maybe_reordered = FALSE;
|
gtk_widget_grab_focus (priv->button);
|
||||||
|
|
||||||
if (event_type == GDK_MOTION_NOTIFY &&
|
|
||||||
priv->maybe_reordered &&
|
|
||||||
gtk_drag_check_threshold (widget, priv->drag_x, priv->drag_y, (gint) x, (gint) y))
|
|
||||||
{
|
|
||||||
priv->maybe_reordered = FALSE;
|
|
||||||
_gtk_tree_view_column_start_drag (GTK_TREE_VIEW (priv->tree_view), column,
|
|
||||||
gdk_event_get_device (event));
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->clickable == FALSE)
|
|
||||||
{
|
|
||||||
switch ((guint) event_type)
|
|
||||||
{
|
|
||||||
case GDK_BUTTON_PRESS:
|
|
||||||
case GDK_BUTTON_RELEASE:
|
|
||||||
return GDK_EVENT_STOP;
|
|
||||||
default:
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
column_button_drag_update (GtkGestureDrag *gesture,
|
||||||
|
gdouble offset_x,
|
||||||
|
gdouble offset_y,
|
||||||
|
GtkTreeViewColumn *column)
|
||||||
|
{
|
||||||
|
GtkTreeViewColumnPrivate *priv = column->priv;
|
||||||
|
|
||||||
|
if (gtk_drag_check_threshold (priv->button, 0, 0, offset_x, offset_y))
|
||||||
|
{
|
||||||
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
||||||
|
_gtk_tree_view_column_start_drag (GTK_TREE_VIEW (priv->tree_view), column,
|
||||||
|
gtk_gesture_get_device (GTK_GESTURE (gesture)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data)
|
gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data)
|
||||||
|
Loading…
Reference in New Issue
Block a user