[gtk/wip/matthiasc/focus: 3/3] Move set_focus_child to GtkWidget



commit 62bc807e1d3878f58a65e5de2fd1bba198843955
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 26 00:21:03 2019 -0500

    Move set_focus_child to GtkWidget
    
    Maybe we can get rid of this vfunc altogether.
    But it still has some users, so just move it to
    GtkWidget for now.

 gtk/gtkcontainer.c        | 35 +++++------------------------------
 gtk/gtkcontainer.h        |  3 ---
 gtk/gtkcontainerprivate.h |  2 --
 gtk/gtknotebook.c         | 18 +++++++++---------
 gtk/gtkpaned.c            | 18 +++++++++---------
 gtk/gtktreeview.c         | 12 ++++++------
 gtk/gtkwidget.c           | 19 +++++++++++++------
 gtk/gtkwidget.h           |  5 ++++-
 8 files changed, 46 insertions(+), 66 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 9fb6d81d9e..c7218b155e 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -148,8 +148,8 @@ static void     gtk_container_remove_unimplemented (GtkContainer      *container
 static void     gtk_container_compute_expand       (GtkWidget         *widget,
                                                     gboolean          *hexpand_p,
                                                     gboolean          *vexpand_p);
-static void     gtk_container_real_set_focus_child (GtkContainer      *container,
-                                                    GtkWidget         *widget);
+static void     gtk_container_set_focus_child      (GtkWidget         *widget,
+                                                    GtkWidget         *focus_child);
 
 static void     gtk_container_children_callback    (GtkWidget         *widget,
                                                     gpointer           client_data);
@@ -277,11 +277,11 @@ gtk_container_class_init (GtkContainerClass *class)
   widget_class->destroy = gtk_container_destroy;
   widget_class->compute_expand = gtk_container_compute_expand;
   widget_class->get_request_mode = gtk_container_get_request_mode;
+  widget_class->set_focus_child = gtk_container_set_focus_child;
 
   class->add = gtk_container_add_unimplemented;
   class->remove = gtk_container_remove_unimplemented;
   class->forall = NULL;
-  class->set_focus_child = gtk_container_real_set_focus_child;
   class->child_type = NULL;
   class->get_path_for_child = gtk_container_real_get_path_for_child;
 
@@ -1537,31 +1537,6 @@ gtk_container_foreach (GtkContainer *container,
     class->forall (container, callback, callback_data);
 }
 
-/**
- * gtk_container_set_focus_child:
- * @container: a #GtkContainer
- * @child: (allow-none): a #GtkWidget, or %NULL
- *
- * Sets, or unsets if @child is %NULL, the focused child of @container.
- *
- * This function emits the GtkContainer::set_focus_child signal of
- * @container. Implementations of #GtkContainer can override the
- * default behaviour by overriding the class closure of this signal.
- *
- * This is function is mostly meant to be used by widgets. Applications can use
- * gtk_widget_grab_focus() to manually set the focus to a specific widget.
- */
-void
-gtk_container_set_focus_child (GtkContainer *container,
-                               GtkWidget    *child)
-{
-  g_return_if_fail (GTK_IS_CONTAINER (container));
-  if (child)
-    g_return_if_fail (GTK_IS_WIDGET (child));
-
-  GTK_CONTAINER_GET_CLASS (container)->set_focus_child (container, child);
-}
-
 /**
  * gtk_container_get_children:
  * @container: a #GtkContainer
@@ -1616,8 +1591,8 @@ gtk_container_compute_expand (GtkWidget *widget,
 }
 
 static void
-gtk_container_real_set_focus_child (GtkContainer *container,
-                                    GtkWidget    *focus_child)
+gtk_container_set_focus_child (GtkWidget *container,
+                               GtkWidget *focus_child)
 {
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (focus_child == NULL || GTK_IS_WIDGET (focus_child));
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index 4e2aa50aec..a384715f29 100644
--- a/gtk/gtkcontainer.h
+++ b/gtk/gtkcontainer.h
@@ -58,7 +58,6 @@ struct _GtkContainer
  * @remove: Signal emitted when a widget is removed from container.
  * @forall: Invokes callback on each child of container. The callback handler
  *    may remove the child.
- * @set_focus_child: Sets the focused child of container.
  * @child_type: Returns the type of the children supported by the container.
  * @set_child_property: Set a property on a child of container.
  * @get_child_property: Get a property from a child of container.
@@ -80,8 +79,6 @@ struct _GtkContainerClass
   void    (*forall)                    (GtkContainer    *container,
                                 GtkCallback      callback,
                                 gpointer         callback_data);
-  void    (*set_focus_child)   (GtkContainer    *container,
-                                GtkWidget       *child);
   GType   (*child_type)                (GtkContainer    *container);
   void    (*set_child_property) (GtkContainer    *container,
                                 GtkWidget       *child,
diff --git a/gtk/gtkcontainerprivate.h b/gtk/gtkcontainerprivate.h
index 74f24ddc90..0ff622b7d1 100644
--- a/gtk/gtkcontainerprivate.h
+++ b/gtk/gtkcontainerprivate.h
@@ -29,8 +29,6 @@ G_BEGIN_DECLS
 void     _gtk_container_queue_restyle          (GtkContainer *container);
 void      gtk_container_stop_idle_sizer         (GtkContainer     *container);
 void      gtk_container_start_idle_sizer        (GtkContainer     *container);
-void      gtk_container_set_focus_child         (GtkContainer     *container,
-                                                 GtkWidget        *child);
 
 
 G_END_DECLS
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 8f32b457d0..886ff55dad 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -678,7 +678,7 @@ static void gtk_notebook_add                 (GtkContainer     *container,
                                               GtkWidget        *widget);
 static void gtk_notebook_remove              (GtkContainer     *container,
                                               GtkWidget        *widget);
-static void gtk_notebook_set_focus_child     (GtkContainer     *container,
+static void gtk_notebook_set_focus_child     (GtkWidget        *widget,
                                               GtkWidget        *child);
 static GType gtk_notebook_child_type       (GtkContainer     *container);
 static void gtk_notebook_forall              (GtkContainer     *container,
@@ -933,11 +933,11 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->drag_data_received = gtk_notebook_drag_data_received;
   widget_class->drag_failed = gtk_notebook_drag_failed;
   widget_class->compute_expand = gtk_notebook_compute_expand;
+  widget_class->set_focus_child = gtk_notebook_set_focus_child;
 
   container_class->add = gtk_notebook_add;
   container_class->remove = gtk_notebook_remove;
   container_class->forall = gtk_notebook_forall;
-  container_class->set_focus_child = gtk_notebook_set_focus_child;
   container_class->child_type = gtk_notebook_child_type;
 
   class->switch_page = gtk_notebook_real_switch_page;
@@ -3546,7 +3546,7 @@ focus_tabs_in (GtkNotebook *notebook)
   if (priv->show_tabs && gtk_notebook_has_current_page (notebook))
     {
       gtk_widget_grab_focus (GTK_WIDGET (notebook));
-      gtk_notebook_set_focus_child (GTK_CONTAINER (notebook), NULL);
+      gtk_notebook_set_focus_child (GTK_WIDGET (notebook), NULL);
       gtk_notebook_switch_focus_tab (notebook,
                                      g_list_find (priv->children,
                                                   priv->cur_page));
@@ -3790,10 +3790,10 @@ gtk_notebook_focus (GtkWidget        *widget,
 }
 
 static void
-gtk_notebook_set_focus_child (GtkContainer *container,
-                              GtkWidget    *child)
+gtk_notebook_set_focus_child (GtkWidget *widget,
+                              GtkWidget *child)
 {
-  GtkNotebook *notebook = GTK_NOTEBOOK (container);
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
   GtkWidget *page_child;
   GtkWidget *toplevel;
@@ -3803,13 +3803,13 @@ gtk_notebook_set_focus_child (GtkContainer *container,
    * for future use if we switch to the page with a mnemonic.
    */
 
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
+  toplevel = gtk_widget_get_toplevel (widget);
   if (toplevel && gtk_widget_is_toplevel (toplevel))
     {
       page_child = gtk_window_get_focus (GTK_WINDOW (toplevel));
       while (page_child)
         {
-          if (gtk_widget_get_parent (page_child) == GTK_WIDGET (container))
+          if (gtk_widget_get_parent (page_child) == widget)
             {
               GList *list = gtk_notebook_find_child (notebook, page_child);
               if (list != NULL)
@@ -3853,7 +3853,7 @@ gtk_notebook_set_focus_child (GtkContainer *container,
   else
     priv->child_has_focus = FALSE;
 
-  GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
+  GTK_WIDGET_CLASS (gtk_notebook_parent_class)->set_focus_child (widget, child);
 }
 
 static void
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 9fc18c9667..e6ed70fe7d 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -231,7 +231,7 @@ static void     gtk_paned_calc_position         (GtkPaned         *paned,
                                                  gint              allocation,
                                                  gint              child1_req,
                                                  gint              child2_req);
-static void     gtk_paned_set_focus_child       (GtkContainer     *container,
+static void     gtk_paned_set_focus_child       (GtkWidget        *widget,
                                                 GtkWidget        *child);
 static void     gtk_paned_set_saved_focus       (GtkPaned         *paned,
                                                 GtkWidget        *widget);
@@ -367,12 +367,12 @@ gtk_paned_class_init (GtkPanedClass *class)
   widget_class->unrealize = gtk_paned_unrealize;
   widget_class->focus = gtk_paned_focus;
   widget_class->pick = gtk_paned_pick;
+  widget_class->set_focus_child = gtk_paned_set_focus_child;
 
   container_class->add = gtk_paned_add;
   container_class->remove = gtk_paned_remove;
   container_class->forall = gtk_paned_forall;
   container_class->child_type = gtk_paned_child_type;
-  container_class->set_focus_child = gtk_paned_set_focus_child;
   container_class->set_child_property = gtk_paned_set_child_property;
   container_class->get_child_property = gtk_paned_get_child_property;
 
@@ -1905,14 +1905,14 @@ paned_get_focus_widget (GtkPaned *paned)
 }
 
 static void
-gtk_paned_set_focus_child (GtkContainer *container,
-                          GtkWidget    *focus_child)
+gtk_paned_set_focus_child (GtkWidget *widget,
+                          GtkWidget *focus_child)
 {
-  GtkPaned *paned = GTK_PANED (container);
+  GtkPaned *paned = GTK_PANED (widget);
   GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
   GtkWidget *container_focus_child;
 
-  g_return_if_fail (GTK_IS_PANED (container));
+  g_return_if_fail (GTK_IS_PANED (widget));
 
   if (focus_child == NULL)
     {
@@ -1930,7 +1930,7 @@ gtk_paned_set_focus_child (GtkContainer *container,
            if (GTK_IS_PANED (w))
              last_focus = w;
 
-          container_focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
+          container_focus_child = gtk_widget_get_focus_child (widget);
           if (container_focus_child == priv->child1)
            gtk_paned_set_last_child1_focus (paned, last_focus);
          else if (container_focus_child == priv->child2)
@@ -1938,8 +1938,8 @@ gtk_paned_set_focus_child (GtkContainer *container,
        }
     }
 
-  if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
-    GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
+  if (GTK_WIDGET_CLASS (gtk_paned_parent_class)->set_focus_child)
+    GTK_WIDGET_CLASS (gtk_paned_parent_class)->set_focus_child (widget, focus_child);
 }
 
 static void
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 77de04413c..aefa0ce785 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -603,7 +603,7 @@ static void     gtk_tree_view_size_allocate        (GtkWidget      *widget,
 static void     gtk_tree_view_snapshot             (GtkWidget        *widget,
                                                     GtkSnapshot      *snapshot);
 
-static void     gtk_tree_view_set_focus_child      (GtkContainer     *container,
+static void     gtk_tree_view_set_focus_child      (GtkWidget        *widget,
                                                    GtkWidget        *child);
 static gboolean gtk_tree_view_key_controller_key_pressed  (GtkEventControllerKey *key,
                                                            guint                  keyval,
@@ -990,11 +990,11 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
   widget_class->focus = gtk_tree_view_focus;
   widget_class->grab_focus = gtk_tree_view_grab_focus;
   widget_class->style_updated = gtk_tree_view_style_updated;
+  widget_class->set_focus_child = gtk_tree_view_set_focus_child;
 
   /* GtkContainer signals */
   container_class->remove = gtk_tree_view_remove;
   container_class->forall = gtk_tree_view_forall;
-  container_class->set_focus_child = gtk_tree_view_set_focus_child;
 
   class->move_cursor = gtk_tree_view_real_move_cursor;
   class->select_all = gtk_tree_view_real_select_all;
@@ -8020,10 +8020,10 @@ gtk_tree_view_style_updated (GtkWidget *widget)
 
 
 static void
-gtk_tree_view_set_focus_child (GtkContainer *container,
-                              GtkWidget    *child)
+gtk_tree_view_set_focus_child (GtkWidget *widget,
+                              GtkWidget *child)
 {
-  GtkTreeView *tree_view = GTK_TREE_VIEW (container);
+  GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
   GList *list;
 
   for (list = tree_view->priv->columns; list; list = list->next)
@@ -8035,7 +8035,7 @@ gtk_tree_view_set_focus_child (GtkContainer *container,
        }
     }
 
-  GTK_CONTAINER_CLASS (gtk_tree_view_parent_class)->set_focus_child (container, child);
+  GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->set_focus_child (widget, child);
 }
 
 static gboolean
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 80f8dcc099..0839228d5d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -602,6 +602,8 @@ static void gtk_widget_dispatch_child_properties_changed    (GtkWidget        *obje
                                                                 GParamSpec      **pspecs);
 static gboolean                gtk_widget_real_focus                   (GtkWidget        *widget,
                                                                 GtkDirectionType  direction);
+static void             gtk_widget_real_set_focus_child         (GtkWidget        *widget,
+                                                                 GtkWidget        *focus_child);
 static void             gtk_widget_real_move_focus              (GtkWidget        *widget,
                                                                  GtkDirectionType  direction);
 static gboolean                gtk_widget_real_keynav_failed           (GtkWidget        *widget,
@@ -932,6 +934,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
   klass->grab_focus = gtk_widget_real_grab_focus;
   klass->focus = gtk_widget_real_focus;
+  klass->set_focus_child = gtk_widget_real_set_focus_child;
   klass->move_focus = gtk_widget_real_move_focus;
   klass->keynav_failed = gtk_widget_real_keynav_failed;
   klass->drag_begin = NULL;
@@ -13442,16 +13445,23 @@ void
 gtk_widget_set_focus_child (GtkWidget *widget,
                             GtkWidget *child)
 {
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-
   g_return_if_fail (GTK_IS_WIDGET (widget));
-
   if (child != NULL)
     {
       g_return_if_fail (GTK_IS_WIDGET (child));
       g_return_if_fail (gtk_widget_get_parent (child) == widget);
     }
 
+
+  GTK_WIDGET_GET_CLASS (widget)->set_focus_child (widget, child);
+}
+
+static void
+gtk_widget_real_set_focus_child (GtkWidget *widget,
+                                 GtkWidget *child)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
   if (priv->focus_child)
     gtk_widget_unset_state_flags (priv->focus_child,
                                   GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_VISIBLE);
@@ -13469,9 +13479,6 @@ gtk_widget_set_focus_child (GtkWidget *widget,
     }
 
   g_set_object (&priv->focus_child, child);
-
-  if (GTK_IS_CONTAINER (widget))
-    gtk_container_set_focus_child (GTK_CONTAINER (widget), child);
 }
 
 /**
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index db4a81272c..885c0c3e6a 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -185,7 +185,8 @@ struct _GtkWidget
  *   %FALSE, and just grabs the focus if @group_cycling is %TRUE.
  * @grab_focus: Causes @widget to have the keyboard focus for the
  *   #GtkWindow it’s inside.
- * @focus:
+ * @focus: Move the focus among @widget's children
+ * @set_focus_child: Sets the focused child of widget
  * @move_focus: Signal emitted when a change of focus is requested
  * @keynav_failed: Signal emitted if keyboard navigation fails.
  * @drag_begin: Signal emitted on the drag source when a drag is
@@ -280,6 +281,8 @@ struct _GtkWidgetClass
   void     (* grab_focus)               (GtkWidget           *widget);
   gboolean (* focus)                    (GtkWidget           *widget,
                                          GtkDirectionType     direction);
+  void     (* set_focus_child)          (GtkWidget           *widget,
+                                         GtkWidget           *focus_child);
 
   /* keyboard navigation */
   void     (* move_focus)               (GtkWidget           *widget,


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