summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2017-02-10 16:58:17 +0100
committerTimm Bäder <mail@baedert.org>2017-03-31 09:50:40 +0200
commit6e9d8577147de7856e7b937cb633088db2193164 (patch)
tree051066f95be7f6c68f9c66464d91dfeb4f0272bc
parent9b70d9897d52fc5612c0059e088e8ad6e1cfe8e4 (diff)
downloadgtk+-6e9d8577147de7856e7b937cb633088db2193164.tar.gz
Widget: Shuffle focus code around
-rw-r--r--gtk/gtkwidget.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f01ebdd9ee..ee67492c8a 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7310,44 +7310,47 @@ static gboolean
gtk_widget_real_focus (GtkWidget *widget,
GtkDirectionType direction)
{
- if (!gtk_widget_get_can_focus (widget))
+ if (gtk_widget_get_can_focus (widget))
+ {
+ if (!gtk_widget_is_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ return TRUE;
+ }
+ }
+ else
{
/* @widget can't be focused, but maybe one of its child widgets. */
GtkWidget *focus_child = gtk_widget_get_focus_child (widget);
GtkWidget *child;
- for (child = _gtk_widget_get_first_child (widget);
+ if (focus_child != NULL)
+ {
+ if (gtk_widget_child_focus (focus_child, direction))
+ return TRUE;
+
+ child = focus_child;
+ }
+ else
+ {
+ child = _gtk_widget_get_first_child (widget);
+ }
+
+ /* The current focus child didn't handle the focus, so lets'
+ try all its siblings. If none of them accepts it, we simply
+ have to return FALSE since we couldn't handle it either. */
+ for (;
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
- if (focus_child)
- {
- if (focus_child == child)
- {
- focus_child = NULL;
- if (gtk_widget_child_focus (child, direction))
- return TRUE;
- }
- }
- else if (_gtk_widget_is_drawable (child) &&
- gtk_widget_is_ancestor (child, widget))
- {
- if (gtk_widget_child_focus (child, direction))
- return TRUE;
- }
+ if (_gtk_widget_is_drawable (child) &&
+ gtk_widget_child_focus (child, direction))
+ return TRUE;
}
-
- return FALSE;
}
- if (!gtk_widget_is_focus (widget))
- {
- gtk_widget_grab_focus (widget);
- return TRUE;
- }
- else
- return FALSE;
+ return FALSE;
}
static void