forked from AuroraMiddleware/gtk
gtkspinbutton: Use GtkEventControllerKey
And drop the ::event vfunc implementation with it.
This commit is contained in:
parent
3eb1b22651
commit
c5586f85fb
@ -258,8 +258,6 @@ static void gtk_spin_button_measure (GtkWidget *widget,
|
|||||||
static void gtk_spin_button_size_allocate (GtkWidget *widget,
|
static void gtk_spin_button_size_allocate (GtkWidget *widget,
|
||||||
const GtkAllocation *allocation,
|
const GtkAllocation *allocation,
|
||||||
int baseline);
|
int baseline);
|
||||||
static gboolean gtk_spin_button_event (GtkWidget *widget,
|
|
||||||
GdkEvent *event);
|
|
||||||
static void gtk_spin_button_grab_notify (GtkWidget *widget,
|
static void gtk_spin_button_grab_notify (GtkWidget *widget,
|
||||||
gboolean was_grabbed);
|
gboolean was_grabbed);
|
||||||
static void gtk_spin_button_state_flags_changed (GtkWidget *widget,
|
static void gtk_spin_button_state_flags_changed (GtkWidget *widget,
|
||||||
@ -318,7 +316,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->event = gtk_spin_button_event;
|
|
||||||
widget_class->grab_notify = gtk_spin_button_grab_notify;
|
widget_class->grab_notify = gtk_spin_button_grab_notify;
|
||||||
widget_class->state_flags_changed = gtk_spin_button_state_flags_changed;
|
widget_class->state_flags_changed = gtk_spin_button_state_flags_changed;
|
||||||
|
|
||||||
@ -819,6 +816,29 @@ button_released_cb (GtkGestureMultiPress *gesture,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
key_controller_key_released (GtkEventControllerKey *key,
|
||||||
|
guint keyval,
|
||||||
|
guint keycode,
|
||||||
|
GdkModifierType modifiers,
|
||||||
|
GtkSpinButton *spin_button)
|
||||||
|
{
|
||||||
|
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
|
||||||
|
|
||||||
|
priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
|
||||||
|
priv->timer_calls = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
key_controller_focus_out (GtkEventControllerKey *key,
|
||||||
|
GtkSpinButton *spin_button)
|
||||||
|
{
|
||||||
|
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
|
||||||
|
|
||||||
|
if (gtk_editable_get_editable (GTK_EDITABLE (priv->entry)))
|
||||||
|
gtk_spin_button_update (spin_button);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_spin_button_init (GtkSpinButton *spin_button)
|
gtk_spin_button_init (GtkSpinButton *spin_button)
|
||||||
{
|
{
|
||||||
@ -901,6 +921,13 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
|
|||||||
g_signal_connect (controller, "scroll",
|
g_signal_connect (controller, "scroll",
|
||||||
G_CALLBACK (scroll_controller_scroll), spin_button);
|
G_CALLBACK (scroll_controller_scroll), spin_button);
|
||||||
gtk_widget_add_controller (GTK_WIDGET (spin_button), controller);
|
gtk_widget_add_controller (GTK_WIDGET (spin_button), controller);
|
||||||
|
|
||||||
|
controller = gtk_event_controller_key_new ();
|
||||||
|
g_signal_connect (controller, "key-released",
|
||||||
|
G_CALLBACK (key_controller_key_released), spin_button);
|
||||||
|
g_signal_connect (controller, "focus-out",
|
||||||
|
G_CALLBACK (key_controller_focus_out), spin_button);
|
||||||
|
gtk_widget_add_controller (GTK_WIDGET (spin_button), controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1079,38 +1106,6 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
|
|||||||
gtk_widget_size_allocate (priv->box, allocation, baseline);
|
gtk_widget_size_allocate (priv->box, allocation, baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gtk_spin_button_event (GtkWidget *widget,
|
|
||||||
GdkEvent *event)
|
|
||||||
{
|
|
||||||
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
|
|
||||||
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
|
|
||||||
|
|
||||||
if (gdk_event_get_event_type (event) == GDK_KEY_RELEASE)
|
|
||||||
{
|
|
||||||
/* We only get a release at the end of a key repeat run, so reset the timer_step */
|
|
||||||
priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
|
|
||||||
priv->timer_calls = 0;
|
|
||||||
|
|
||||||
return GDK_EVENT_STOP;
|
|
||||||
}
|
|
||||||
if (gdk_event_get_event_type (event) == GDK_FOCUS_CHANGE)
|
|
||||||
{
|
|
||||||
gboolean focus_in;
|
|
||||||
|
|
||||||
gdk_event_get_focus_in (event, &focus_in);
|
|
||||||
if (!focus_in)
|
|
||||||
{
|
|
||||||
if (gtk_editable_get_editable (GTK_EDITABLE (priv->entry)))
|
|
||||||
gtk_spin_button_update (spin_button);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_spin_button_grab_notify (GtkWidget *widget,
|
gtk_spin_button_grab_notify (GtkWidget *widget,
|
||||||
gboolean was_grabbed)
|
gboolean was_grabbed)
|
||||||
|
Loading…
Reference in New Issue
Block a user