[gtk/container-focus-cleanup] Move set_focus_child to GtkWidget



commit 581cad9ed967dc8b752b9e5fa515e31e625ac20b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Apr 19 11:18:02 2020 -0400

    Move set_focus_child to GtkWidget
    
    Move the set_focus_child vfunc from GtkContainer
    to GtkWidget. This removes the last focus functionality
    from GtkContainer.
    
    Update the two users.

 gtk/gtkcontainer.c | 34 ----------------------------------
 gtk/gtkcontainer.h |  3 ---
 gtk/gtknotebook.c  | 22 +++++++++++-----------
 gtk/gtkpaned.c     | 25 +++++++++++--------------
 gtk/gtkwidget.c    | 14 ++++++++++++--
 gtk/gtkwidget.h    |  3 +++
 6 files changed, 37 insertions(+), 64 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 7383b1bf91..a2cbd1b8b9 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -109,8 +109,6 @@ 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_children_callback    (GtkWidget         *widget,
                                                     gpointer           client_data);
 static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget   *widget);
@@ -141,7 +139,6 @@ gtk_container_class_init (GtkContainerClass *class)
   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;
 
   container_signals[ADD] =
@@ -524,31 +521,6 @@ gtk_container_foreach (GtkContainer *container,
     GTK_CONTAINER_GET_CLASS (container)->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
@@ -602,12 +574,6 @@ gtk_container_compute_expand (GtkWidget *widget,
   *vexpand_p = vexpand;
 }
 
-static void
-gtk_container_real_set_focus_child (GtkContainer *container,
-                                    GtkWidget    *focus_child)
-{
-}
-
 static void
 gtk_container_children_callback (GtkWidget *widget,
                                  gpointer   client_data)
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index f6d2a5c44e..1a16f260c9 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.
@@ -78,8 +77,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);
 
 
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 1faaf5f8ea..3a22d028c8 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -769,7 +769,7 @@ static void gtk_notebook_popup_menu          (GtkWidget        *widget,
                                               const char       *action_name,
                                               GVariant         *parameters);
 static void gtk_notebook_motion              (GtkEventController *controller,
-                                              double              x,
+                                             double              x,
                                               double              y,
                                               gpointer            user_data);
 static void gtk_notebook_grab_notify         (GtkWidget          *widget,
@@ -781,6 +781,8 @@ static void gtk_notebook_direction_changed   (GtkWidget        *widget,
 static gboolean gtk_notebook_focus           (GtkWidget        *widget,
                                               GtkDirectionType  direction);
 static gboolean gtk_notebook_grab_focus      (GtkWidget        *widget);
+static void     gtk_notebook_set_focus_child (GtkWidget        *widget,
+                                              GtkWidget        *child);
 
 /*** Drag and drop Methods ***/
 static void gtk_notebook_dnd_finished_cb     (GdkDrag          *drag,
@@ -803,8 +805,6 @@ 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,
-                                              GtkWidget        *child);
 static GType gtk_notebook_child_type       (GtkContainer     *container);
 static void gtk_notebook_forall              (GtkContainer     *container,
                                               GtkCallback       callback,
@@ -1045,12 +1045,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->direction_changed = gtk_notebook_direction_changed;
   widget_class->focus = gtk_notebook_focus;
   widget_class->grab_focus = gtk_notebook_grab_focus;
+  widget_class->set_focus_child = gtk_notebook_set_focus_child;
   widget_class->compute_expand = gtk_notebook_compute_expand;
 
   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;
@@ -3473,7 +3473,7 @@ focus_tabs_in (GtkNotebook *notebook)
   if (notebook->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 (notebook->children,
                                                   notebook->cur_page));
@@ -3725,10 +3725,10 @@ gtk_notebook_grab_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);
   GtkWidget *page_child;
   GtkWidget *toplevel;
 
@@ -3737,13 +3737,13 @@ gtk_notebook_set_focus_child (GtkContainer *container,
    * for future use if we switch to the page with a mnemonic.
    */
 
-  toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (container)));
+  toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
   if (GTK_IS_WINDOW (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)
@@ -3787,7 +3787,7 @@ gtk_notebook_set_focus_child (GtkContainer *container,
   else
     notebook->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 19ffa164f7..a4f0a5bd24 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -240,7 +240,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);
@@ -351,13 +351,13 @@ gtk_paned_class_init (GtkPanedClass *class)
   widget_class->size_allocate = gtk_paned_size_allocate;
   widget_class->unrealize = gtk_paned_unrealize;
   widget_class->focus = gtk_paned_focus;
+  widget_class->set_focus_child = gtk_paned_set_focus_child;
   widget_class->css_changed = gtk_paned_css_changed;
 
   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;
 
   class->cycle_child_focus = gtk_paned_cycle_child_focus;
   class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
@@ -1870,16 +1870,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 *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));
+  GtkWidget *focus_child;
 
-  if (focus_child == NULL)
+  if (child == NULL)
     {
       GtkWidget *last_focus;
       GtkWidget *w;
@@ -1895,16 +1893,15 @@ 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));
-          if (container_focus_child == priv->child1)
+          focus_child = gtk_widget_get_focus_child (widget);
+          if (focus_child == priv->child1)
            gtk_paned_set_last_child1_focus (paned, last_focus);
-         else if (container_focus_child == priv->child2)
+         else if (focus_child == priv->child2)
            gtk_paned_set_last_child2_focus (paned, last_focus);
        }
     }
 
-  if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
-    GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
+  GTK_WIDGET_CLASS (gtk_paned_parent_class)->set_focus_child (widget, child);
 }
 
 static void
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 307f516f14..cb184f2bd9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -594,6 +594,8 @@ static gboolean gtk_widget_real_query_tooltip    (GtkWidget         *widget,
 static void     gtk_widget_real_css_changed      (GtkWidget         *widget,
                                                   GtkCssStyleChange *change);
 
+static void             gtk_widget_real_set_focus_child         (GtkWidget        *widget,
+                                                                 GtkWidget        *child);
 static void             gtk_widget_real_move_focus              (GtkWidget        *widget,
                                                                  GtkDirectionType  direction);
 static gboolean                gtk_widget_real_keynav_failed           (GtkWidget        *widget,
@@ -905,6 +907,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
   klass->grab_focus = gtk_widget_grab_focus_self;
   klass->focus = gtk_widget_focus_all;
+  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->query_tooltip = gtk_widget_real_query_tooltip;
@@ -12000,8 +12003,6 @@ 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)
@@ -12010,6 +12011,15 @@ gtk_widget_set_focus_child (GtkWidget *widget,
       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);
+
   g_set_object (&priv->focus_child, child);
 }
 
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index f71c2bbd45..7b23ac733d 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -187,6 +187,7 @@ struct _GtkWidget
  * @grab_focus: Causes @widget to have the keyboard focus for the
  *   #GtkWindow it’s inside.
  * @focus:
+ * @set_focus_child: Sets the focused child of a widget. Must chain up
  * @move_focus: Signal emitted when a change of focus is requested
  * @keynav_failed: Signal emitted if keyboard navigation fails.
  * @popup_menu: Signal emitted whenever a widget should pop up a
@@ -255,6 +256,8 @@ struct _GtkWidgetClass
   gboolean (* grab_focus)               (GtkWidget           *widget);
   gboolean (* focus)                    (GtkWidget           *widget,
                                          GtkDirectionType     direction);
+  void     (* set_focus_child)          (GtkWidget           *widget,
+                                         GtkWidget           *child);
 
   /* keyboard navigation */
   void     (* move_focus)               (GtkWidget           *widget,


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