forked from AuroraMiddleware/gtk
gtkspinbutton: Use scroll event controller
This commit is contained in:
parent
9a204921ae
commit
ad05caedd3
@ -198,6 +198,7 @@ struct _GtkSpinButtonPrivate
|
|||||||
GtkOrientation orientation;
|
GtkOrientation orientation;
|
||||||
|
|
||||||
GtkGesture *swipe_gesture;
|
GtkGesture *swipe_gesture;
|
||||||
|
GtkEventController *scroll_controller;
|
||||||
|
|
||||||
guint digits : 10;
|
guint digits : 10;
|
||||||
guint need_timer : 1;
|
guint need_timer : 1;
|
||||||
@ -272,8 +273,6 @@ static gint gtk_spin_button_key_release (GtkWidget *widget,
|
|||||||
static gint gtk_spin_button_motion_notify (GtkWidget *widget,
|
static gint gtk_spin_button_motion_notify (GtkWidget *widget,
|
||||||
GdkEventMotion *event);
|
GdkEventMotion *event);
|
||||||
|
|
||||||
static gint gtk_spin_button_scroll (GtkWidget *widget,
|
|
||||||
GdkEventScroll *event);
|
|
||||||
static void gtk_spin_button_activate (GtkEntry *entry,
|
static void gtk_spin_button_activate (GtkEntry *entry,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static void gtk_spin_button_unset_adjustment (GtkSpinButton *spin_button);
|
static void gtk_spin_button_unset_adjustment (GtkSpinButton *spin_button);
|
||||||
@ -323,7 +322,6 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
|
|||||||
widget_class->realize = gtk_spin_button_realize;
|
widget_class->realize = gtk_spin_button_realize;
|
||||||
widget_class->measure = gtk_spin_button_measure;
|
widget_class->measure = gtk_spin_button_measure;
|
||||||
widget_class->size_allocate = gtk_spin_button_size_allocate;
|
widget_class->size_allocate = gtk_spin_button_size_allocate;
|
||||||
widget_class->scroll_event = gtk_spin_button_scroll;
|
|
||||||
widget_class->motion_notify_event = gtk_spin_button_motion_notify;
|
widget_class->motion_notify_event = gtk_spin_button_motion_notify;
|
||||||
widget_class->key_release_event = gtk_spin_button_key_release;
|
widget_class->key_release_event = gtk_spin_button_key_release;
|
||||||
widget_class->focus_out_event = gtk_spin_button_focus_out;
|
widget_class->focus_out_event = gtk_spin_button_focus_out;
|
||||||
@ -708,6 +706,20 @@ swipe_gesture_update (GtkGesture *gesture,
|
|||||||
gtk_spin_button_real_spin (spin_button, -vel_y / 20);
|
gtk_spin_button_real_spin (spin_button, -vel_y / 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
scroll_controller_scroll (GtkEventControllerScroll *Scroll,
|
||||||
|
gdouble dx,
|
||||||
|
gdouble dy,
|
||||||
|
GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
|
||||||
|
GtkSpinButtonPrivate *priv = spin->priv;
|
||||||
|
|
||||||
|
if (!gtk_widget_has_focus (widget))
|
||||||
|
gtk_widget_grab_focus (widget);
|
||||||
|
gtk_spin_button_real_spin (spin, -dy * gtk_adjustment_get_step_increment (priv->adjustment));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_node_ordering (GtkSpinButton *spin_button)
|
update_node_ordering (GtkSpinButton *spin_button)
|
||||||
{
|
{
|
||||||
@ -911,6 +923,13 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
|
|||||||
G_CALLBACK (swipe_gesture_begin), spin_button);
|
G_CALLBACK (swipe_gesture_begin), spin_button);
|
||||||
g_signal_connect (priv->swipe_gesture, "update",
|
g_signal_connect (priv->swipe_gesture, "update",
|
||||||
G_CALLBACK (swipe_gesture_update), spin_button);
|
G_CALLBACK (swipe_gesture_update), spin_button);
|
||||||
|
|
||||||
|
priv->scroll_controller =
|
||||||
|
gtk_event_controller_scroll_new (GTK_WIDGET (spin_button),
|
||||||
|
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
|
||||||
|
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
|
||||||
|
g_signal_connect (priv->scroll_controller, "scroll",
|
||||||
|
G_CALLBACK (scroll_controller_scroll), spin_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -921,6 +940,7 @@ gtk_spin_button_finalize (GObject *object)
|
|||||||
|
|
||||||
gtk_spin_button_unset_adjustment (spin_button);
|
gtk_spin_button_unset_adjustment (spin_button);
|
||||||
|
|
||||||
|
g_object_unref (priv->scroll_controller);
|
||||||
g_object_unref (priv->swipe_gesture);
|
g_object_unref (priv->swipe_gesture);
|
||||||
g_object_unref (priv->up_click_gesture);
|
g_object_unref (priv->up_click_gesture);
|
||||||
g_object_unref (priv->down_click_gesture);
|
g_object_unref (priv->down_click_gesture);
|
||||||
@ -1109,35 +1129,6 @@ gtk_spin_button_state_flags_changed (GtkWidget *widget,
|
|||||||
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->state_flags_changed (widget, previous_state);
|
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->state_flags_changed (widget, previous_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
|
||||||
gtk_spin_button_scroll (GtkWidget *widget,
|
|
||||||
GdkEventScroll *event)
|
|
||||||
{
|
|
||||||
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
|
|
||||||
GtkSpinButtonPrivate *priv = spin->priv;
|
|
||||||
GdkScrollDirection direction;
|
|
||||||
|
|
||||||
if (!gdk_event_get_scroll_direction ((GdkEvent *) event, &direction))
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
|
|
||||||
if (direction == GDK_SCROLL_UP)
|
|
||||||
{
|
|
||||||
if (!gtk_widget_has_focus (widget))
|
|
||||||
gtk_widget_grab_focus (widget);
|
|
||||||
gtk_spin_button_real_spin (spin, gtk_adjustment_get_step_increment (priv->adjustment));
|
|
||||||
}
|
|
||||||
else if (direction == GDK_SCROLL_DOWN)
|
|
||||||
{
|
|
||||||
if (!gtk_widget_has_focus (widget))
|
|
||||||
gtk_widget_grab_focus (widget);
|
|
||||||
gtk_spin_button_real_spin (spin, -gtk_adjustment_get_step_increment (priv->adjustment));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
gtk_spin_button_motion_notify (GtkWidget *widget,
|
gtk_spin_button_motion_notify (GtkWidget *widget,
|
||||||
GdkEventMotion *event)
|
GdkEventMotion *event)
|
||||||
|
Loading…
Reference in New Issue
Block a user