[gtk+/wip/baedert/children: 37/44] widget: Add focus_child pointer



commit 982031fbd68025570bf85c116b86537338974886
Author: Timm Bäder <mail baedert org>
Date:   Thu Nov 24 16:59:53 2016 +0100

    widget: Add focus_child pointer

 gtk/gtkcontainer.c     |   43 ++++++++++++-------------------------------
 gtk/gtkwidget.c        |   26 ++++++++++++++++++++++++++
 gtk/gtkwidgetprivate.h |    5 +++++
 3 files changed, 43 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 4f074c8..a289ce5 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -276,8 +276,6 @@
 
 struct _GtkContainerPrivate
 {
-  GtkWidget *focus_child;
-
   GdkFrameClock *resize_clock;
   guint resize_handler;
 
@@ -1590,12 +1588,7 @@ gtk_container_remove_unimplemented (GtkContainer     *container,
 static void
 gtk_container_init (GtkContainer *container)
 {
-  GtkContainerPrivate *priv;
-
   container->priv = gtk_container_get_instance_private (container);
-  priv = container->priv;
-
-  priv->focus_child = NULL;
 }
 
 static void
@@ -1607,8 +1600,6 @@ gtk_container_destroy (GtkWidget *widget)
   if (priv->restyle_pending)
     priv->restyle_pending = FALSE;
 
-  g_clear_object (&priv->focus_child);
-
   /* do this before walking child widgets, to avoid
    * removing children from focus chain one by one.
    */
@@ -2004,9 +1995,7 @@ gtk_container_set_focus_child (GtkContainer *container,
 GtkWidget *
 gtk_container_get_focus_child (GtkContainer *container)
 {
-  g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
-
-  return container->priv->focus_child;
+  return gtk_widget_get_focus_child (GTK_WIDGET (container));
 }
 
 /**
@@ -2081,26 +2070,18 @@ static void
 gtk_container_real_set_focus_child (GtkContainer     *container,
                                     GtkWidget        *child)
 {
-  GtkContainerPrivate *priv;
+  GtkWidget *container_focus_child;
 
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
 
-  priv = container->priv;
-
-  if (child != priv->focus_child)
-    {
-      if (priv->focus_child)
-        g_object_unref (priv->focus_child);
-      priv->focus_child = child;
-      if (priv->focus_child)
-        g_object_ref (priv->focus_child);
-    }
+  gtk_widget_set_focus_child (GTK_WIDGET (container), child);
 
 
+  container_focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
   /* check for h/v adjustments
    */
-  if (priv->focus_child)
+  if (container_focus_child)
     {
       GtkAdjustment *hadj;
       GtkAdjustment *vadj;
@@ -2113,16 +2094,17 @@ gtk_container_real_set_focus_child (GtkContainer     *container,
       if (hadj || vadj)
         {
 
-          focus_child = priv->focus_child;
-          while (GTK_IS_CONTAINER (focus_child) && gtk_container_get_focus_child (GTK_CONTAINER 
(focus_child)))
+          focus_child = container_focus_child;
+          while (GTK_IS_CONTAINER (focus_child) && 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,
+          gtk_widget_translate_coordinates (focus_child,
+                                            container_focus_child,
                                             0, 0, &x, &y);
 
-          _gtk_widget_get_allocation (priv->focus_child, &allocation);
+          _gtk_widget_get_allocation (container_focus_child, &allocation);
           x += allocation.x;
           y += allocation.y;
 
@@ -2670,11 +2652,10 @@ gtk_container_focus_move (GtkContainer     *container,
                           GList            *children,
                           GtkDirectionType  direction)
 {
-  GtkContainerPrivate *priv = container->priv;
   GtkWidget *focus_child;
   GtkWidget *child;
 
-  focus_child = priv->focus_child;
+  focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
 
   while (children)
     {
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 548c405..d63c7dd 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3803,6 +3803,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   priv->last_child = NULL;
   priv->prev_sibling = NULL;
   priv->next_sibling = NULL;
+  priv->focus_child = NULL;
 
   priv->sensitive = TRUE;
   priv->redraw_on_alloc = TRUE;
@@ -15895,3 +15896,28 @@ gtk_widget_get_children_clip (GtkWidget     *widget,
         gdk_rectangle_union (&widget_clip, out_clip, out_clip);
     }
 }
+
+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));
+  g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
+
+  if (child != priv->focus_child)
+    {
+      if (priv->focus_child)
+        g_object_unref (priv->focus_child);
+      priv->focus_child = child;
+      if (priv->focus_child)
+        g_object_ref (priv->focus_child);
+    }
+}
+
+GtkWidget *
+gtk_widget_get_focus_child (GtkWidget *widget)
+{
+  return widget->priv->focus_child;
+}
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index b2d0e6a..3615736 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -159,6 +159,8 @@ struct _GtkWidgetPrivate
   GtkWidget *next_sibling;
   GtkWidget *first_child;
   GtkWidget *last_child;
+
+  GtkWidget *focus_child;
 };
 
 GtkCssNode *  gtk_widget_get_css_node       (GtkWidget *widget);
@@ -302,6 +304,9 @@ void              gtk_widget_adjust_baseline_request       (GtkWidget *widget,
                                                             gint      *natural_baseline);
 void              gtk_widget_get_children_clip             (GtkWidget     *container,
                                                             GtkAllocation *out_clip);
+void              gtk_widget_set_focus_child               (GtkWidget *widget,
+                                                            GtkWidget *child);
+GtkWidget *       gtk_widget_get_focus_child               (GtkWidget *widget);
 
 
 


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