[gtk/wip/matthiasc/focus2: 46/91] window: Check for child-focusable



commit 1ce4fee9cde847bb1e197627214fc5a8e3aeef41
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 3 00:49:45 2019 -0500

    window: Check for child-focusable
    
    Don't allow gtk_window_set_focus to focus a widget
    that is !can-focus or has an ancestor that is !child-focusable.

 gtk/gtkwindow.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0083802361..fa97dcf03e 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -7263,11 +7263,30 @@ set_focus_widget (GtkWindow *window,
     do_focus_change (priv->focus_widget, TRUE);
 }
 
+static gboolean
+can_focus_widget (GtkWidget *widget)
+{
+  GtkWidget *w;
+
+  if (!gtk_widget_is_sensitive (widget) ||
+      !gtk_widget_get_can_focus (widget))
+    return FALSE;
+
+  w = widget;
+  do {
+    if (!gtk_widget_get_child_focusable (w))
+      return FALSE;
+    w = gtk_widget_get_parent (w);
+  } while (w != NULL);
+
+  return TRUE;
+}
+
 static void
 gtk_window_real_set_focus (GtkWindow *window,
                           GtkWidget *focus)
 {
-  if (focus && !gtk_widget_is_sensitive (focus))
+  if (focus && !can_focus_widget (focus))
     return;
 
   unset_focus_widget (window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]