[gtk+/wip/baedert/children: 22/22] Add and use gtk_widget_get_focus_child



commit d710da77ee5cfecf981c174d0ed065f68e248085
Author: Timm Bäder <mail baedert org>
Date:   Wed Nov 23 11:23:38 2016 +0100

    Add and use gtk_widget_get_focus_child

 gtk/gtkcontainer.c      |   28 +++-------------------------
 gtk/gtkcontainer.h      |    3 ---
 gtk/gtkexpander.c       |    4 ++--
 gtk/gtkflowbox.c        |    4 ++--
 gtk/gtklistbox.c        |    4 ++--
 gtk/gtknotebook.c       |    7 ++-----
 gtk/gtkpaned.c          |    8 +++-----
 gtk/gtkscrolledwindow.c |    2 +-
 gtk/gtktextview.c       |    5 +----
 gtk/gtktoolbar.c        |    7 +++----
 gtk/gtktreeview.c       |    5 ++---
 gtk/gtkwidget.c         |   15 ++++++++++-----
 gtk/gtkwidget.h         |    2 ++
 gtk/gtkwindow.c         |    6 +++---
 14 files changed, 36 insertions(+), 64 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 55cb6e3..4524593 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -1950,28 +1950,6 @@ gtk_container_foreach (GtkContainer *container,
 }
 
 /**
- * gtk_container_get_focus_child:
- * @container: a #GtkContainer
- *
- * Returns the current focus child widget inside @container. This is not the
- * currently focused widget. That can be obtained by calling
- * gtk_window_get_focus().
- *
- * Returns: (nullable) (transfer none): The child widget which will receive the
- *          focus inside @container when the @container is focused,
- *          or %NULL if none is set.
- *
- * Since: 2.14
- **/
-GtkWidget *
-gtk_container_get_focus_child (GtkContainer *container)
-{
-  g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
-
-  return container->priv->focus_child;
-}
-
-/**
  * gtk_container_get_children:
  * @container: a #GtkContainer
  *
@@ -2076,9 +2054,9 @@ gtk_container_real_set_focus_child (GtkContainer     *container,
         {
 
           focus_child = priv->focus_child;
-          while (GTK_IS_CONTAINER (focus_child) && gtk_container_get_focus_child (GTK_CONTAINER 
(focus_child)))
+          while (gtk_widget_get_focus_child (focus_child))
             {
-              focus_child = gtk_container_get_focus_child (GTK_CONTAINER (focus_child));
+              focus_child = gtk_widget_get_focus_child (focus_child);
             }
 
           gtk_widget_translate_coordinates (focus_child, priv->focus_child,
@@ -2272,7 +2250,7 @@ find_old_focus (GtkContainer *container,
 
           parent = _gtk_widget_get_parent (widget);
 
-          if (parent && (gtk_container_get_focus_child (GTK_CONTAINER (parent)) != widget))
+          if (parent && (gtk_widget_get_focus_child (parent) != widget))
             goto next;
 
           widget = parent;
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index 42ad410..907bf81 100644
--- a/gtk/gtkcontainer.h
+++ b/gtk/gtkcontainer.h
@@ -153,9 +153,6 @@ GDK_AVAILABLE_IN_ALL
 void   gtk_container_set_focus_child      (GtkContainer     *container,
                                            GtkWidget        *child);
 GDK_AVAILABLE_IN_ALL
-GtkWidget *
-       gtk_container_get_focus_child      (GtkContainer     *container);
-GDK_AVAILABLE_IN_ALL
 void   gtk_container_set_focus_vadjustment (GtkContainer     *container,
                                            GtkAdjustment    *adjustment);
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index ecadd02..ad595e1 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -798,7 +798,7 @@ focus_current_site (GtkExpander      *expander,
 {
   GtkWidget *current_focus;
 
-  current_focus = gtk_container_get_focus_child (GTK_CONTAINER (expander));
+  current_focus = gtk_widget_get_focus_child (GTK_WIDGET (expander));
 
   if (!current_focus)
     return FALSE;
@@ -963,7 +963,7 @@ gtk_expander_focus (GtkWidget        *widget,
       FocusSite site = FOCUS_NONE;
 
       widget_is_focus = gtk_widget_is_focus (widget);
-      old_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget));
+      old_focus_child = gtk_widget_get_focus_child (widget);
 
       if (old_focus_child && old_focus_child == expander->priv->label_widget)
         site = FOCUS_LABEL;
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index d543d54..e7c927b 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -342,7 +342,7 @@ gtk_flow_box_child_focus (GtkWidget        *widget,
 
       return FALSE;
     }
-  else if (gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL)
+  else if (gtk_widget_get_focus_child (widget) != NULL)
     {
       /* Child has focus, always navigate inside it first */
       if (gtk_widget_child_focus (child, direction))
@@ -3275,7 +3275,7 @@ gtk_flow_box_focus (GtkWidget        *widget,
       return GTK_WIDGET_CLASS (gtk_flow_box_parent_class)->focus (widget, direction);
     }
 
-  focus_child = gtk_container_get_focus_child (GTK_CONTAINER (box));
+  focus_child = gtk_widget_get_focus_child (widget);
   next_focus_child = NULL;
 
   if (focus_child != NULL)
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index db3a9a5..4f06ba6 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -2017,7 +2017,7 @@ gtk_list_box_focus (GtkWidget        *widget,
   GtkWidget *row;
   GtkWidget *header;
 
-  focus_child = gtk_container_get_focus_child ((GtkContainer *)box);
+  focus_child = gtk_widget_get_focus_child (widget);
 
   next_focus_row = NULL;
   if (focus_child != NULL)
@@ -3214,7 +3214,7 @@ gtk_list_box_row_focus (GtkWidget        *widget,
 
       return FALSE;
     }
-  else if (gtk_container_get_focus_child (GTK_CONTAINER (row)) != NULL)
+  else if (gtk_widget_get_focus_child (widget) != NULL)
     {
       /* Child has focus, always navigate inside it first */
       if (gtk_widget_child_focus (child, direction))
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 1b0f295..ea3d199 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1438,7 +1438,7 @@ gtk_notebook_move_focus_out (GtkNotebook      *notebook,
   GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
   GtkWidget *toplevel;
 
-  if (gtk_container_get_focus_child (GTK_CONTAINER (notebook)) && effective_direction == GTK_DIR_UP)
+  if (gtk_widget_get_focus_child (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_UP)
     if (focus_tabs_in (notebook))
       return;
   if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
@@ -4182,9 +4182,6 @@ gtk_notebook_focus (GtkWidget        *widget,
   gint last_action;
 
   gboolean widget_is_focus;
-  GtkContainer *container;
-
-  container = GTK_CONTAINER (widget);
 
   if (priv->tab_pos == GTK_POS_TOP ||
       priv->tab_pos == GTK_POS_LEFT)
@@ -4205,7 +4202,7 @@ gtk_notebook_focus (GtkWidget        *widget,
     }
 
   widget_is_focus = gtk_widget_is_focus (widget);
-  old_focus_child = gtk_container_get_focus_child (container);
+  old_focus_child = gtk_widget_get_focus_child (widget);
 
   effective_direction = get_effective_direction (notebook, direction);
 
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index c040c60..7f3c749 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -2445,7 +2445,7 @@ gtk_paned_set_focus_child (GtkContainer *container,
            if (GTK_IS_PANED (w))
              last_focus = w;
 
-          container_focus_child = gtk_container_get_focus_child (container);
+          container_focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
           if (container_focus_child == priv->child1)
            gtk_paned_set_last_child1_focus (paned, last_focus);
          else if (container_focus_child == priv->child2)
@@ -2463,7 +2463,6 @@ gtk_paned_get_cycle_chain (GtkPaned          *paned,
                           GList            **widgets)
 {
   GtkPanedPrivate *priv = paned->priv;
-  GtkContainer *container = GTK_CONTAINER (paned);
   GtkWidget *ancestor = NULL;
   GtkWidget *focus_child;
   GtkWidget *parent;
@@ -2500,7 +2499,7 @@ gtk_paned_get_cycle_chain (GtkPaned          *paned,
    * priv->last_child?_focus before priv->child?, both when we
    * are going forward and backward.
    */
-  focus_child = gtk_container_get_focus_child (container);
+  focus_child = gtk_widget_get_focus_child (GTK_WIDGET (paned));
   if (direction == GTK_DIR_TAB_FORWARD)
     {
       if (focus_child == priv->child1)
@@ -2876,14 +2875,13 @@ gtk_paned_cycle_handle_focus (GtkPaned *paned,
     }
   else
     {
-      GtkContainer *container = GTK_CONTAINER (paned);
       GtkPaned *focus;
       GtkPaned *first;
       GtkWidget *toplevel;
       GtkWidget *focus_child;
 
       gtk_paned_find_neighbours (paned, &next, &prev);
-      focus_child = gtk_container_get_focus_child (container);
+      focus_child = gtk_widget_get_focus_child (GTK_WIDGET (paned));
 
       if (focus_child == priv->child1)
        {
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index bc5f459..9739872 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -3662,7 +3662,7 @@ gtk_scrolled_window_focus (GtkWidget        *widget,
   GtkWidget *child;
   gboolean had_focus_child;
 
-  had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
+  had_focus_child = gtk_widget_get_focus_child (widget) != NULL;
 
   if (priv->focus_out)
     {
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 9af3eed..37ac949 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -5964,13 +5964,10 @@ static gboolean
 gtk_text_view_focus (GtkWidget        *widget,
                      GtkDirectionType  direction)
 {
-  GtkContainer *container;
   gboolean result;
 
-  container = GTK_CONTAINER (widget);
-
   if (!gtk_widget_is_focus (widget) &&
-      gtk_container_get_focus_child (container) == NULL)
+      gtk_widget_get_focus_child (widget) == NULL)
     {
       if (gtk_widget_get_can_focus (widget))
         {
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 439e216..eea13e3 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -1831,7 +1831,7 @@ gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
     {
       GtkWidget *child = list->data;
 
-      if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
+      if (gtk_widget_get_focus_child (GTK_WIDGET (toolbar)) == child)
        break;
       
       if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
@@ -1851,13 +1851,12 @@ gtk_toolbar_move_focus (GtkWidget        *widget,
                        GtkDirectionType  dir)
 {
   GtkToolbar *toolbar = GTK_TOOLBAR (widget);
-  GtkContainer *container = GTK_CONTAINER (toolbar);
   GtkWidget *focus_child;
   GList *list;
   gboolean try_focus = FALSE;
   GList *children;
 
-  focus_child = gtk_container_get_focus_child (container);
+  focus_child = gtk_widget_get_focus_child (widget);
 
   if (focus_child && gtk_widget_child_focus (focus_child, dir))
     return;
@@ -1894,7 +1893,7 @@ gtk_toolbar_focus (GtkWidget        *widget,
    * arrow keys or Ctrl TAB (both of which are handled by the
    * gtk_toolbar_move_focus() keybinding function.
    */
-  if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
+  if (gtk_widget_get_focus_child (widget))
     return FALSE;
 
   children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 9107863..5b4fb69 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -8272,7 +8272,7 @@ gtk_tree_view_header_focus (GtkTreeView      *tree_view,
   if (! tree_view->priv->headers_visible)
     return FALSE;
 
-  focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
+  focus_child = gtk_widget_get_focus_child (GTK_WIDGET (tree_view));
 
   first_column = tree_view->priv->columns;
   while (first_column)
@@ -8469,13 +8469,12 @@ gtk_tree_view_focus (GtkWidget        *widget,
                     GtkDirectionType  direction)
 {
   GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
-  GtkContainer *container = GTK_CONTAINER (widget);
   GtkWidget *focus_child;
 
   if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
     return FALSE;
 
-  focus_child = gtk_container_get_focus_child (container);
+  focus_child = gtk_widget_get_focus_child (widget);
 
   gtk_tree_view_stop_editing (GTK_TREE_VIEW (widget), FALSE);
   /* Case 1.  Headers currently have focus. */
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 270b930..6050c8c 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4027,11 +4027,8 @@ gtk_widget_unparent (GtkWidget *widget)
   if (_gtk_widget_is_toplevel (toplevel))
     _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
 
-  if (GTK_IS_CONTAINER (priv->parent))
-    {
-      if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
-        gtk_widget_set_focus_child (priv->parent, NULL);
-    }
+  if (gtk_widget_get_focus_child (priv->parent) == widget)
+    gtk_widget_set_focus_child (priv->parent, NULL);
 
   if (_gtk_widget_is_drawable (priv->parent))
     gtk_widget_queue_draw_area (priv->parent,
@@ -16015,3 +16012,11 @@ gtk_widget_set_focus_child (GtkWidget *widget,
 
 
 }
+
+GtkWidget *             
+gtk_widget_get_focus_child (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return widget->priv->focus_child;
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 6235936..acac62b 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -1328,6 +1328,8 @@ void                    gtk_widget_propagate_draw       (GtkWidget *widget,
 GDK_AVAILABLE_IN_3_90
 void                    gtk_widget_set_focus_child (GtkWidget *widget,
                                                     GtkWidget *child);
+GDK_AVAILABLE_IN_3_90
+GtkWidget *             gtk_widget_get_focus_child (GtkWidget *widget);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0ecd6bd..abf002f 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -7981,7 +7981,7 @@ gtk_window_focus (GtkWidget        *widget,
   priv = window->priv;
   bin = GTK_BIN (widget);
 
-  old_focus_child = gtk_container_get_focus_child (container);
+  old_focus_child = gtk_widget_get_focus_child (widget);
 
   /* We need a special implementation here to deal properly with wrapping
    * around in the tab chain without the danger of going into an
@@ -8046,7 +8046,7 @@ gtk_window_move_focus (GtkWidget        *widget,
 
   gtk_widget_child_focus (widget, dir);
 
-  if (! gtk_container_get_focus_child (GTK_CONTAINER (widget)))
+  if (!gtk_widget_get_focus_child (widget))
     gtk_window_set_focus (GTK_WINDOW (widget), NULL);
 }
 
@@ -8212,7 +8212,7 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
   g_object_ref (widget);
 
   parent = _gtk_widget_get_parent (widget);
-  if (gtk_container_get_focus_child (GTK_CONTAINER (parent)) == widget)
+  if (gtk_widget_get_focus_child (parent) == widget)
     {
       child = priv->focus_widget;
       


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