[gtk] treeview: Stop using set_focus_child



commit fda4546de522008de734d26e9d3a583e724c8671
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 27 22:42:27 2019 -0500

    treeview: Stop using set_focus_child
    
    Do this with an event controller on the buttons instead.

 gtk/gtktreeview.c       | 23 -----------------------
 gtk/gtktreeviewcolumn.c | 12 ++++++++++++
 2 files changed, 12 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 77de04413c..2573371a99 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -603,8 +603,6 @@ 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,
-                                                   GtkWidget        *child);
 static gboolean gtk_tree_view_key_controller_key_pressed  (GtkEventControllerKey *key,
                                                            guint                  keyval,
                                                            guint                  keycode,
@@ -994,7 +992,6 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
   /* 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;
@@ -8018,26 +8015,6 @@ gtk_tree_view_style_updated (GtkWidget *widget)
   priv->expander_size = -1;
 }
 
-
-static void
-gtk_tree_view_set_focus_child (GtkContainer *container,
-                              GtkWidget    *child)
-{
-  GtkTreeView *tree_view = GTK_TREE_VIEW (container);
-  GList *list;
-
-  for (list = tree_view->priv->columns; list; list = list->next)
-    {
-      if (gtk_tree_view_column_get_button (GTK_TREE_VIEW_COLUMN (list->data)) == child)
-       {
-          _gtk_tree_view_set_focus_column (tree_view, GTK_TREE_VIEW_COLUMN (list->data));
-         break;
-       }
-    }
-
-  GTK_CONTAINER_CLASS (gtk_tree_view_parent_class)->set_focus_child (container, child);
-}
-
 static gboolean
 gtk_tree_view_real_move_cursor (GtkTreeView       *tree_view,
                                GtkMovementStep    step,
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index 674cb7696b..5817a5f2f8 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -35,6 +35,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkwidgetprivate.h"
 #include "gtkgesturedrag.h"
+#include "gtkeventcontrollerkey.h"
 
 #include "a11y/gtktreeviewaccessibleprivate.h"
 
@@ -811,6 +812,13 @@ gtk_tree_view_column_cell_layout_get_area (GtkCellLayout   *cell_layout)
   return priv->cell_area;
 }
 
+static void
+focus_in (GtkEventControllerKey *controller,
+          GtkTreeViewColumn     *column)
+{
+  _gtk_tree_view_set_focus_column (GTK_TREE_VIEW (column->priv->tree_view), column);
+}
+
 /* Button handling code
  */
 static void
@@ -838,6 +846,10 @@ gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
   gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
   gtk_widget_add_controller (priv->button, controller);
 
+  controller = gtk_event_controller_key_new ();
+  g_signal_connect (controller, "focus-in", G_CALLBACK (focus_in), tree_column);
+  gtk_widget_add_controller (priv->button, controller);
+
   priv->frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
   gtk_widget_set_hexpand (priv->frame, TRUE);


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