[gtk+] headerbar: Get rid of get_path_for_child()



commit 3d2ead0fce07d571b56d0118a3419d658457afde
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jul 16 03:22:40 2015 +0200

    headerbar: Get rid of get_path_for_child()
    
    Instead, reorder CSS nodes.

 gtk/gtkcontainer.c        |    4 +-
 gtk/gtkcontainerprivate.h |    1 -
 gtk/gtkheaderbar.c        |  108 +++++++++++++++++++++++----------------------
 3 files changed, 57 insertions(+), 56 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 1c06579..2f51045 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -2636,7 +2636,7 @@ get_focus_chain (GtkContainer *container)
 /* same as gtk_container_get_children, except it includes internals
  */
 GList *
-_gtk_container_get_all_children (GtkContainer *container)
+gtk_container_get_all_children (GtkContainer *container)
 {
   GList *children = NULL;
 
@@ -2710,7 +2710,7 @@ gtk_container_focus (GtkWidget        *widget,
       if (priv->has_focus_chain)
         children = g_list_copy (get_focus_chain (container));
       else
-        children = _gtk_container_get_all_children (container);
+        children = gtk_container_get_all_children (container);
 
       if (priv->has_focus_chain &&
           (direction == GTK_DIR_TAB_FORWARD ||
diff --git a/gtk/gtkcontainerprivate.h b/gtk/gtkcontainerprivate.h
index 79ed0b8..ec81720 100644
--- a/gtk/gtkcontainerprivate.h
+++ b/gtk/gtkcontainerprivate.h
@@ -25,7 +25,6 @@
 G_BEGIN_DECLS
 
 
-GList *  _gtk_container_get_all_children       (GtkContainer *container);
 void     _gtk_container_queue_resize           (GtkContainer *container);
 void     _gtk_container_queue_restyle          (GtkContainer *container);
 void     _gtk_container_resize_invalidate      (GtkContainer *container);
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 22bda73..deca8bb 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -25,7 +25,7 @@
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkwidgetprivate.h"
-#include "gtkcontainerprivate.h"
+#include "gtkcssnodeprivate.h"
 #include "gtkwindowprivate.h"
 #include "a11y/gtkcontaineraccessible.h"
 
@@ -464,9 +464,19 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
 
           if ((direction == GTK_TEXT_DIR_LTR && i == 0) ||
               (direction == GTK_TEXT_DIR_RTL && i == 1))
-            gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LEFT);
+            {
+              gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LEFT);
+              gtk_css_node_insert_after (gtk_widget_get_css_node (GTK_WIDGET (bar)),
+                                         gtk_widget_get_css_node (box),
+                                         NULL);
+            }
           else
-            gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RIGHT);
+            {
+              gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RIGHT);
+              gtk_css_node_insert_before (gtk_widget_get_css_node (GTK_WIDGET (bar)),
+                                          gtk_widget_get_css_node (box),
+                                          NULL);
+            }
 
           gtk_widget_show (box);
           gtk_widget_set_parent (box, GTK_WIDGET (bar));
@@ -504,6 +514,44 @@ _gtk_header_bar_shows_app_menu (GtkHeaderBar *bar)
   return ret;
 }
 
+/* As an intended side effect, this function allows @child
+ * to be the title/label box */
+static void
+gtk_header_bar_reorder_css_node (GtkHeaderBar *bar,
+                                 GtkPackType   pack_type,
+                                 GtkWidget    *widget)
+{
+  GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
+  GtkWidget *previous_widget;
+  GList *l;
+  
+  if (pack_type == GTK_PACK_START)
+    previous_widget = priv->titlebar_start_box;
+  else
+    previous_widget = priv->titlebar_end_box;
+
+  for (l = priv->children; l; l = l->next)
+    {
+      Child *iter = l->data;
+
+      if (iter->widget == widget)
+        break;
+
+      if (iter->pack_type == pack_type)
+        previous_widget = iter->widget;
+    }
+
+  if ((pack_type == GTK_PACK_START)
+      ^ (gtk_widget_get_direction (GTK_WIDGET (bar)) == GTK_TEXT_DIR_LTR))
+    gtk_css_node_insert_after (gtk_widget_get_css_node (GTK_WIDGET (bar)),
+                               gtk_widget_get_css_node (widget),
+                               previous_widget ? gtk_widget_get_css_node (previous_widget) : NULL);
+  else
+    gtk_css_node_insert_before (gtk_widget_get_css_node (GTK_WIDGET (bar)),
+                                gtk_widget_get_css_node (widget),
+                                previous_widget ? gtk_widget_get_css_node (previous_widget) : NULL);
+}
+
 static void
 construct_label_box (GtkHeaderBar *bar)
 {
@@ -515,6 +563,7 @@ construct_label_box (GtkHeaderBar *bar)
                                       priv->subtitle,
                                       &priv->title_label,
                                       &priv->subtitle_label);
+  gtk_header_bar_reorder_css_node (bar, GTK_PACK_START, priv->label_box);
   gtk_widget_set_parent (priv->label_box, GTK_WIDGET (bar));
 }
 
@@ -1279,6 +1328,7 @@ gtk_header_bar_set_custom_title (GtkHeaderBar *bar,
     {
       priv->custom_title = title_widget;
 
+      gtk_header_bar_reorder_css_node (bar, GTK_PACK_START, priv->custom_title);
       gtk_widget_set_parent (priv->custom_title, GTK_WIDGET (bar));
       gtk_widget_set_valign (priv->custom_title, GTK_ALIGN_CENTER);
 
@@ -1466,6 +1516,7 @@ gtk_header_bar_pack (GtkHeaderBar *bar,
   priv->children = g_list_append (priv->children, child);
 
   gtk_widget_freeze_child_notify (widget);
+  gtk_header_bar_reorder_css_node (bar, GTK_PACK_START, widget);
   gtk_widget_set_parent (widget, GTK_WIDGET (bar));
   g_signal_connect (widget, "notify::visible", G_CALLBACK (notify_child_cb), bar);
   gtk_widget_child_notify (widget, "pack-type");
@@ -1597,6 +1648,7 @@ gtk_header_bar_reorder_child (GtkHeaderBar *bar,
     l = g_list_nth (priv->children, position);
 
   priv->children = g_list_insert_before (priv->children, l, child);
+  gtk_header_bar_reorder_css_node (bar, child->pack_type, widget);
   gtk_widget_child_notify (widget, "position");
   gtk_widget_queue_resize (widget);
 }
@@ -1679,55 +1731,6 @@ gtk_header_bar_set_child_property (GtkContainer *container,
     }
 }
 
-static GtkWidgetPath *
-gtk_header_bar_get_path_for_child (GtkContainer *container,
-                                   GtkWidget    *child)
-{
-  GtkHeaderBar *bar = GTK_HEADER_BAR (container);
-  GtkWidgetPath *path, *sibling_path;
-  GList *list, *children;
-
-  path = _gtk_widget_create_path (GTK_WIDGET (container));
-
-  if (gtk_widget_get_visible (child))
-    {
-      gint i, position;
-
-      sibling_path = gtk_widget_path_new ();
-
-      /* get_all_children works in reverse (!) visible order */
-      children = _gtk_container_get_all_children (container);
-      if (gtk_widget_get_direction (GTK_WIDGET (bar)) == GTK_TEXT_DIR_LTR)
-        children = g_list_reverse (children);
-
-      position = -1;
-      i = 0;
-      for (list = children; list; list = list->next)
-        {
-          if (!gtk_widget_get_visible (list->data))
-            continue;
-
-          gtk_widget_path_append_for_widget (sibling_path, list->data);
-
-          if (list->data == child)
-            position = i;
-          i++;
-        }
-      g_list_free (children);
-
-      if (position >= 0)
-        gtk_widget_path_append_with_siblings (path, sibling_path, position);
-      else
-        gtk_widget_path_append_for_widget (path, child);
-
-      gtk_widget_path_unref (sibling_path);
-    }
-  else
-    gtk_widget_path_append_for_widget (path, child);
-
-  return path;
-}
-
 static gint
 gtk_header_bar_draw (GtkWidget *widget,
                      cairo_t   *cr)
@@ -1833,7 +1836,6 @@ gtk_header_bar_class_init (GtkHeaderBarClass *class)
   container_class->child_type = gtk_header_bar_child_type;
   container_class->set_child_property = gtk_header_bar_set_child_property;
   container_class->get_child_property = gtk_header_bar_get_child_property;
-  container_class->get_path_for_child = gtk_header_bar_get_path_for_child;
   gtk_container_class_handle_border_width (container_class);
 
   gtk_container_class_install_child_property (container_class,


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