common/date-chooser: Make arrow left/right move focus across grid
This also notifies the user when out of bound with arrow buttons. Related: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1036 Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/608>
This commit is contained in:
@@ -841,11 +841,14 @@ gcal_date_chooser_child_focus (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GcalDateChooser *self = GCAL_DATE_CHOOSER (widget);
|
GcalDateChooser *self = GCAL_DATE_CHOOSER (widget);
|
||||||
GtkRoot *root;
|
GtkRoot *root;
|
||||||
gboolean is_tab;
|
GtkWidget *focus_widget, *new_focus;
|
||||||
|
gboolean is_tab, is_rtl, left_or_right;
|
||||||
|
|
||||||
is_tab = direction == GTK_DIR_TAB_FORWARD || direction == GTK_DIR_TAB_BACKWARD;
|
is_tab = direction == GTK_DIR_TAB_FORWARD || direction == GTK_DIR_TAB_BACKWARD;
|
||||||
|
|
||||||
if (gtk_widget_get_focus_child (self->grid) && is_tab)
|
if (gtk_widget_get_focus_child (self->grid))
|
||||||
|
{
|
||||||
|
if (is_tab)
|
||||||
{
|
{
|
||||||
root = gtk_widget_get_root (self->grid);
|
root = gtk_widget_get_root (self->grid);
|
||||||
|
|
||||||
@@ -862,6 +865,32 @@ gcal_date_chooser_child_focus (GtkWidget *widget,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gtk_widget_child_focus (self->grid, direction))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
left_or_right = direction == GTK_DIR_LEFT || direction == GTK_DIR_RIGHT;
|
||||||
|
|
||||||
|
if (left_or_right)
|
||||||
|
{
|
||||||
|
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||||
|
root = gtk_widget_get_root (self->grid);
|
||||||
|
focus_widget = gtk_root_get_focus (root);
|
||||||
|
|
||||||
|
g_assert (GCAL_IS_DATE_CHOOSER_DAY (focus_widget));
|
||||||
|
|
||||||
|
if (direction == (is_rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
|
||||||
|
new_focus = gtk_widget_get_next_sibling (focus_widget);
|
||||||
|
else
|
||||||
|
new_focus = gtk_widget_get_prev_sibling (focus_widget);
|
||||||
|
|
||||||
|
if (new_focus)
|
||||||
|
return gtk_widget_grab_focus (new_focus);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_error_bell (self->grid);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return GTK_WIDGET_CLASS (gcal_date_chooser_parent_class)->focus (widget, direction);
|
return GTK_WIDGET_CLASS (gcal_date_chooser_parent_class)->focus (widget, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user