[gtk+/wip/csoriano/pathbar-bin-view-window] f



commit 6e8c5aeabe1c7b0eb87545f8cf9b3e7e91503d73
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Jun 23 18:13:36 2016 +0200

    f

 gtk/gtkpathbarbox.c        |  131 +++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkpathbarboxprivate.h |    7 +-
 2 files changed, 134 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkpathbarbox.c b/gtk/gtkpathbarbox.c
index 4226ba4..324931a 100644
--- a/gtk/gtkpathbarbox.c
+++ b/gtk/gtkpathbarbox.c
@@ -30,7 +30,65 @@
 #include "gtkbuildable.h"
 #include "gtkrevealer.h"
 
-G_DEFINE_TYPE (GtkPathBarBox, gtk_path_bar_box, GTK_TYPE_BOX)
+struct _GtkPathBarBoxPrivate
+{
+  GList *children;
+};
+
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+buildable_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+}
+
+G_DEFINE_TYPE_WITH_CODE (GtkPathBarBox, gtk_path_bar_box, GTK_TYPE_CONTAINER,
+                         G_ADD_PRIVATE (GtkPathBarBox)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_init))
+static void
+gtk_path_bar_box_forall (GtkContainer *container,
+                  gboolean      include_internals,
+                  GtkCallback   callback,
+                  gpointer      callback_data)
+{
+  GtkPathBarBox *self = GTK_PATH_BAR_BOX (container);
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+  GList *child;
+
+  for (child = priv->children; child != NULL; child = child->next)
+      (* callback) (child->data, callback_data);
+}
+
+static void
+gtk_path_bar_box_add (GtkContainer *container,
+               GtkWidget    *widget)
+{
+  GtkPathBarBox *self = GTK_PATH_BAR_BOX (container);
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+
+  priv->children = g_list_append (priv->children, widget);
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+static void
+gtk_path_bar_box_remove (GtkContainer *container,
+                  GtkWidget    *widget)
+{
+  GtkPathBarBox *self = GTK_PATH_BAR_BOX (container);
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+
+  priv->children = g_list_remove (priv->children, widget);
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+static GtkSizeRequestMode
+get_request_mode (GtkWidget *self)
+{
+  return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
 
 static void
 gtk_path_bar_box_size_allocate (GtkWidget     *widget,
@@ -51,6 +109,7 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
 
   gtk_widget_get_preferred_size (widget, &minimum_size, &natural_size);
 
+#if 0
   if (natural_size.width <= allocation->width)
     {
       GTK_WIDGET_CLASS (gtk_path_bar_box_parent_class)->size_allocate (widget, allocation);
@@ -58,6 +117,8 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
       return;
     }
 
+#endif
+
   gtk_widget_set_allocation (widget, allocation);
 
   available_size = allocation->width;
@@ -120,16 +181,84 @@ gtk_path_bar_box_size_allocate (GtkWidget     *widget,
 }
 
 static void
+gtk_path_bar_box_get_preferred_width (GtkWidget *widget,
+                                      gint      *minimum_width,
+                                      gint      *natural_width)
+{
+  GtkPathBarBox *self = GTK_PATH_BAR_BOX (widget);
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+  gint child_minimum_width;
+  gint child_natural_width;
+  GList *child;
+
+  for (child = priv->children; child != NULL; child = child->next)
+    {
+      if (!gtk_widget_is_visible (child->data))
+        continue;
+
+      gtk_widget_get_preferred_width (GTK_WIDGET (child->data),
+                                     &child_minimum_width,
+                                     &child_natural_width);
+
+      *minimum_width = MAX (*minimum_width, child_minimum_width);
+      *natural_width = MAX (*natural_width, child_natural_width);
+    }
+}
+
+static void
+gtk_path_bar_box_get_preferred_width_for_height (GtkWidget *widget,
+                                                 gint       height,
+                                                 gint      *minimum_width_out,
+                                                 gint      *natural_width_out)
+{
+  gtk_path_bar_box_get_preferred_width (widget, minimum_width_out, natural_width_out);
+}
+
+static void
+gtk_path_bar_box_get_preferred_height (GtkWidget *widget,
+                                       gint      *minimum_height,
+                                       gint      *natural_height)
+{
+  GtkPathBarBox *self = GTK_PATH_BAR_BOX (widget);
+  GtkPathBarBoxPrivate *priv = gtk_path_bar_box_get_instance_private (self);
+  gint child_minimum_height;
+  gint child_natural_height;
+  GList *child;
+
+  for (child = priv->children; child != NULL; child = child->next)
+    {
+      if (!gtk_widget_is_visible (child->data))
+        continue;
+
+      gtk_widget_get_preferred_height (child->data,
+                                       &child_minimum_height,
+                                       &child_natural_height);
+      *minimum_height = MAX (*minimum_height, child_minimum_height);
+      *natural_height = MAX (*natural_height, child_natural_height);
+    }
+}
+
+static void
 gtk_path_bar_box_init (GtkPathBarBox *self)
 {
+  gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
 }
 
 static void
 gtk_path_bar_box_class_init (GtkPathBarBoxClass *class)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
 
   widget_class->size_allocate = gtk_path_bar_box_size_allocate;
+  widget_class->get_request_mode = get_request_mode;
+  widget_class->get_preferred_width = gtk_path_bar_box_get_preferred_width;
+  widget_class->get_preferred_height = gtk_path_bar_box_get_preferred_height;
+  widget_class->get_preferred_width_for_height = gtk_path_bar_box_get_preferred_width_for_height;
+
+  container_class->forall = gtk_path_bar_box_forall;
+  container_class->add = gtk_path_bar_box_add;
+  container_class->remove = gtk_path_bar_box_remove;
 }
 
 GtkWidget *
diff --git a/gtk/gtkpathbarboxprivate.h b/gtk/gtkpathbarboxprivate.h
index fe98aa7..d2a4cc1 100644
--- a/gtk/gtkpathbarboxprivate.h
+++ b/gtk/gtkpathbarboxprivate.h
@@ -23,7 +23,7 @@
 #endif
 
 #include "gtkwidget.h"
-#include <gtk/gtkbox.h>
+#include <gtk/gtkcontainer.h>
 
 G_BEGIN_DECLS
 
@@ -36,10 +36,11 @@ G_BEGIN_DECLS
 
 typedef struct _GtkPathBarBox GtkPathBarBox;
 typedef struct _GtkPathBarBoxClass GtkPathBarBoxClass;
+typedef struct _GtkPathBarBoxPrivate GtkPathBarBoxPrivate;
 
 struct _GtkPathBarBoxClass
 {
-  GtkBoxClass parent_class;
+  GtkContainerClass parent_class;
 
   /* Padding for future expansion */
   gpointer reserved[10];
@@ -47,7 +48,7 @@ struct _GtkPathBarBoxClass
 
 struct _GtkPathBarBox
 {
-  GtkBox parent_instance;
+  GtkContainer parent_instance;
 };
 
 GType             gtk_path_bar_box_get_type                (void) G_GNUC_CONST;


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