forked from AuroraMiddleware/gtk
iconview: Use a motion event controller
This can replace ::motion-notify-event and ::leave-notify-event.
This commit is contained in:
parent
ab4f4fb045
commit
118424bd93
@ -156,10 +156,12 @@ static void gtk_icon_view_size_allocate (GtkWidget
|
|||||||
GtkAllocation *out_clip);
|
GtkAllocation *out_clip);
|
||||||
static void gtk_icon_view_snapshot (GtkWidget *widget,
|
static void gtk_icon_view_snapshot (GtkWidget *widget,
|
||||||
GtkSnapshot *snapshot);
|
GtkSnapshot *snapshot);
|
||||||
static gboolean gtk_icon_view_motion (GtkWidget *widget,
|
static void gtk_icon_view_motion (GtkEventController *controller,
|
||||||
GdkEventMotion *event);
|
double x,
|
||||||
static gboolean gtk_icon_view_leave (GtkWidget *widget,
|
double y,
|
||||||
GdkEventCrossing *event);
|
gpointer user_data);
|
||||||
|
static void gtk_icon_view_leave (GtkEventController *controller,
|
||||||
|
gpointer user_data);
|
||||||
static void gtk_icon_view_button_press (GtkGestureMultiPress *gesture,
|
static void gtk_icon_view_button_press (GtkGestureMultiPress *gesture,
|
||||||
int n_press,
|
int n_press,
|
||||||
double x,
|
double x,
|
||||||
@ -301,8 +303,10 @@ static void gtk_icon_view_drag_data_received (GtkWidget *widget,
|
|||||||
GdkDragContext *context,
|
GdkDragContext *context,
|
||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
guint time);
|
guint time);
|
||||||
static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
||||||
GdkEventMotion *event);
|
double x,
|
||||||
|
double y,
|
||||||
|
GdkDevice *device);
|
||||||
|
|
||||||
static void remove_scroll_timeout (GtkIconView *icon_view);
|
static void remove_scroll_timeout (GtkIconView *icon_view);
|
||||||
|
|
||||||
@ -355,8 +359,6 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
|
|||||||
widget_class->measure = gtk_icon_view_measure;
|
widget_class->measure = gtk_icon_view_measure;
|
||||||
widget_class->size_allocate = gtk_icon_view_size_allocate;
|
widget_class->size_allocate = gtk_icon_view_size_allocate;
|
||||||
widget_class->snapshot = gtk_icon_view_snapshot;
|
widget_class->snapshot = gtk_icon_view_snapshot;
|
||||||
widget_class->motion_notify_event = gtk_icon_view_motion;
|
|
||||||
widget_class->leave_notify_event = gtk_icon_view_leave;
|
|
||||||
widget_class->key_press_event = gtk_icon_view_key_press;
|
widget_class->key_press_event = gtk_icon_view_key_press;
|
||||||
widget_class->key_release_event = gtk_icon_view_key_release;
|
widget_class->key_release_event = gtk_icon_view_key_release;
|
||||||
widget_class->drag_begin = gtk_icon_view_drag_begin;
|
widget_class->drag_begin = gtk_icon_view_drag_begin;
|
||||||
@ -978,6 +980,12 @@ gtk_icon_view_init (GtkIconView *icon_view)
|
|||||||
icon_view);
|
icon_view);
|
||||||
g_signal_connect (icon_view->priv->press_gesture, "released", G_CALLBACK (gtk_icon_view_button_release),
|
g_signal_connect (icon_view->priv->press_gesture, "released", G_CALLBACK (gtk_icon_view_button_release),
|
||||||
icon_view);
|
icon_view);
|
||||||
|
|
||||||
|
icon_view->priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (icon_view));
|
||||||
|
g_signal_connect (icon_view->priv->motion_controller, "leave", G_CALLBACK (gtk_icon_view_leave),
|
||||||
|
icon_view);
|
||||||
|
g_signal_connect (icon_view->priv->motion_controller, "motion", G_CALLBACK (gtk_icon_view_motion),
|
||||||
|
icon_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GObject methods */
|
/* GObject methods */
|
||||||
@ -1027,6 +1035,7 @@ gtk_icon_view_dispose (GObject *object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_object (&priv->press_gesture);
|
g_clear_object (&priv->press_gesture);
|
||||||
|
g_clear_object (&priv->motion_controller);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
|
G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
@ -1800,30 +1809,35 @@ _gtk_icon_view_get_item_at_widget_coords (GtkIconView *icon_view,
|
|||||||
only_in_cell, cell_at_pos);
|
only_in_cell, cell_at_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_icon_view_motion (GtkWidget *widget,
|
gtk_icon_view_motion (GtkEventController *controller,
|
||||||
GdkEventMotion *event)
|
double x,
|
||||||
|
double y,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkIconView *icon_view;
|
GtkIconView *icon_view;
|
||||||
gint abs_y;
|
gint abs_y;
|
||||||
|
GdkDevice *device;
|
||||||
icon_view = GTK_ICON_VIEW (widget);
|
|
||||||
|
|
||||||
gdk_event_get_coords ((const GdkEvent *)event, &icon_view->priv->mouse_x, &icon_view->priv->mouse_y);
|
icon_view = GTK_ICON_VIEW (user_data);
|
||||||
|
|
||||||
gtk_icon_view_maybe_begin_drag (icon_view, event);
|
icon_view->priv->mouse_x = x;
|
||||||
|
icon_view->priv->mouse_y = y;
|
||||||
|
|
||||||
|
device = gtk_get_current_event_device (); /* FIXME: controller device */
|
||||||
|
gtk_icon_view_maybe_begin_drag (icon_view, x, y, device);
|
||||||
|
|
||||||
if (icon_view->priv->doing_rubberband)
|
if (icon_view->priv->doing_rubberband)
|
||||||
{
|
{
|
||||||
int height;
|
int height;
|
||||||
gtk_icon_view_update_rubberband (icon_view);
|
gtk_icon_view_update_rubberband (icon_view);
|
||||||
|
|
||||||
abs_y = icon_view->priv->mouse_y - icon_view->priv->height *
|
abs_y = icon_view->priv->mouse_y - icon_view->priv->height *
|
||||||
(gtk_adjustment_get_value (icon_view->priv->vadjustment) /
|
(gtk_adjustment_get_value (icon_view->priv->vadjustment) /
|
||||||
(gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
|
(gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
|
||||||
gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
|
gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
|
||||||
|
|
||||||
height = gtk_widget_get_height (widget);
|
height = gtk_widget_get_height (GTK_WIDGET (icon_view));
|
||||||
|
|
||||||
|
|
||||||
if (abs_y < 0 || abs_y > height)
|
if (abs_y < 0 || abs_y > height)
|
||||||
@ -1842,7 +1856,7 @@ gtk_icon_view_motion (GtkWidget *widget,
|
|||||||
g_source_set_name_by_id (icon_view->priv->scroll_timeout_id, "[gtk+] rubberband_scroll_timeout");
|
g_source_set_name_by_id (icon_view->priv->scroll_timeout_id, "[gtk+] rubberband_scroll_timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
remove_scroll_timeout (icon_view);
|
remove_scroll_timeout (icon_view);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1873,18 +1887,16 @@ gtk_icon_view_motion (GtkWidget *widget,
|
|||||||
icon_view->priv->last_prelight = item;
|
icon_view->priv->last_prelight = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gtk_icon_view_leave (GtkWidget *widget,
|
gtk_icon_view_leave (GtkEventController *controller,
|
||||||
GdkEventCrossing *event)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkIconView *icon_view;
|
GtkIconView *icon_view;
|
||||||
GtkIconViewPrivate *priv;
|
GtkIconViewPrivate *priv;
|
||||||
|
|
||||||
icon_view = GTK_ICON_VIEW (widget);
|
icon_view = GTK_ICON_VIEW (user_data);
|
||||||
priv = icon_view->priv;
|
priv = icon_view->priv;
|
||||||
|
|
||||||
if (priv->last_prelight)
|
if (priv->last_prelight)
|
||||||
@ -1892,8 +1904,6 @@ gtk_icon_view_leave (GtkWidget *widget,
|
|||||||
gtk_icon_view_queue_draw_item (icon_view, priv->last_prelight);
|
gtk_icon_view_queue_draw_item (icon_view, priv->last_prelight);
|
||||||
priv->last_prelight = NULL;
|
priv->last_prelight = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -6140,21 +6150,21 @@ get_logical_destination (GtkIconView *icon_view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
||||||
GdkEventMotion *event)
|
double x,
|
||||||
|
double y,
|
||||||
|
GdkDevice *device)
|
||||||
{
|
{
|
||||||
GtkWidget *widget = GTK_WIDGET (icon_view);
|
GtkWidget *widget = GTK_WIDGET (icon_view);
|
||||||
GdkDragContext *context;
|
GdkDragContext *context;
|
||||||
GtkTreePath *path = NULL;
|
GtkTreePath *path = NULL;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
gboolean retval = FALSE;
|
gboolean retval = FALSE;
|
||||||
gdouble x, y;
|
|
||||||
|
|
||||||
if (!icon_view->priv->source_set)
|
if (!icon_view->priv->source_set)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (icon_view->priv->pressed_button < 0 ||
|
if (icon_view->priv->pressed_button < 0)
|
||||||
!gdk_event_get_coords ((GdkEvent *) event, &x, &y))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
|
if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
|
||||||
@ -6187,18 +6197,18 @@ gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Now we can begin the drag */
|
/* Now we can begin the drag */
|
||||||
|
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
|
|
||||||
context = gtk_drag_begin_with_coordinates (widget,
|
context = gtk_drag_begin_with_coordinates (widget,
|
||||||
gdk_event_get_device ((GdkEvent*) event),
|
device,
|
||||||
gtk_drag_source_get_target_list (widget),
|
gtk_drag_source_get_target_list (widget),
|
||||||
icon_view->priv->source_actions,
|
icon_view->priv->source_actions,
|
||||||
icon_view->priv->press_start_x,
|
icon_view->priv->press_start_x,
|
||||||
icon_view->priv->press_start_y);
|
icon_view->priv->press_start_y);
|
||||||
|
|
||||||
set_source_row (context, model, path);
|
set_source_row (context, model, path);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (path)
|
if (path)
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (path);
|
||||||
@ -6207,7 +6217,7 @@ gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Source side drag signals */
|
/* Source side drag signals */
|
||||||
static void
|
static void
|
||||||
gtk_icon_view_drag_begin (GtkWidget *widget,
|
gtk_icon_view_drag_begin (GtkWidget *widget,
|
||||||
GdkDragContext *context)
|
GdkDragContext *context)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "gtk/gtkiconview.h"
|
#include "gtk/gtkiconview.h"
|
||||||
#include "gtk/gtkcssnodeprivate.h"
|
#include "gtk/gtkcssnodeprivate.h"
|
||||||
#include "gtk/gtkgesturemultipress.h"
|
#include "gtk/gtkgesturemultipress.h"
|
||||||
|
#include "gtk/gtkeventcontrollermotion.h"
|
||||||
|
|
||||||
#ifndef __GTK_ICON_VIEW_PRIVATE_H__
|
#ifndef __GTK_ICON_VIEW_PRIVATE_H__
|
||||||
#define __GTK_ICON_VIEW_PRIVATE_H__
|
#define __GTK_ICON_VIEW_PRIVATE_H__
|
||||||
@ -60,6 +61,7 @@ struct _GtkIconViewPrivate
|
|||||||
GList *items;
|
GList *items;
|
||||||
|
|
||||||
GtkGesture *press_gesture;
|
GtkGesture *press_gesture;
|
||||||
|
GtkEventController *motion_controller;
|
||||||
|
|
||||||
GtkAdjustment *hadjustment;
|
GtkAdjustment *hadjustment;
|
||||||
GtkAdjustment *vadjustment;
|
GtkAdjustment *vadjustment;
|
||||||
|
Loading…
Reference in New Issue
Block a user