[gtk/kill-containers: 40/48] flowbox: Derive from GtkWidget



commit 44cbcce1016c62a68ce25af97b4962673cbaf68c
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 7 23:47:14 2020 -0400

    flowbox: Derive from GtkWidget

 gtk/a11y/gtkflowboxaccessible.c |   2 +-
 gtk/a11y/gtkflowboxaccessible.h |   6 +--
 gtk/gtkflowbox.c                | 111 ++++++++++++++++++++++------------------
 3 files changed, 66 insertions(+), 53 deletions(-)
---
diff --git a/gtk/a11y/gtkflowboxaccessible.c b/gtk/a11y/gtkflowboxaccessible.c
index d32a7f2db0..ac3b91a597 100644
--- a/gtk/a11y/gtkflowboxaccessible.c
+++ b/gtk/a11y/gtkflowboxaccessible.c
@@ -23,7 +23,7 @@
 
 static void atk_selection_interface_init (AtkSelectionIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GtkFlowBoxAccessible, gtk_flow_box_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
+G_DEFINE_TYPE_WITH_CODE (GtkFlowBoxAccessible, gtk_flow_box_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
 
 static void
diff --git a/gtk/a11y/gtkflowboxaccessible.h b/gtk/a11y/gtkflowboxaccessible.h
index 3447315f50..8a5f8376c1 100644
--- a/gtk/a11y/gtkflowboxaccessible.h
+++ b/gtk/a11y/gtkflowboxaccessible.h
@@ -22,7 +22,7 @@
 #error "Only <gtk/gtk-a11y.h> can be included directly."
 #endif
 
-#include <gtk/a11y/gtkcontaineraccessible.h>
+#include <gtk/a11y/gtkwidgetaccessible.h>
 
 G_BEGIN_DECLS
 
@@ -39,14 +39,14 @@ typedef struct _GtkFlowBoxAccessiblePrivate GtkFlowBoxAccessiblePrivate;
 
 struct _GtkFlowBoxAccessible
 {
-  GtkContainerAccessible parent;
+  GtkWidgetAccessible parent;
 
   GtkFlowBoxAccessiblePrivate *priv;
 };
 
 struct _GtkFlowBoxAccessibleClass
 {
-  GtkContainerAccessibleClass parent_class;
+  GtkWidgetAccessibleClass parent_class;
 };
 
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index b5e7f50026..f778feb219 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -726,12 +726,12 @@ typedef struct _GtkFlowBoxClass       GtkFlowBoxClass;
 
 struct _GtkFlowBox
 {
-  GtkContainer container;
+  GtkWidget container;
 };
 
 struct _GtkFlowBoxClass
 {
-  GtkContainerClass parent_class;
+  GtkWidgetClass parent_class;
 
   void (*child_activated)            (GtkFlowBox        *box,
                                       GtkFlowBoxChild   *child);
@@ -803,11 +803,15 @@ struct _GtkFlowBoxPrivate {
 
 #define BOX_PRIV(box) ((GtkFlowBoxPrivate*)gtk_flow_box_get_instance_private ((GtkFlowBox*)(box)))
 
-G_DEFINE_TYPE_WITH_CODE (GtkFlowBox, gtk_flow_box, GTK_TYPE_CONTAINER,
+static void gtk_flow_box_buildable_iface_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkFlowBox, gtk_flow_box, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkFlowBox)
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                                gtk_flow_box_buildable_iface_init))
 
-/*  Internal API, utilities {{{2 */
+/*  Internal API, utilities {{{2 */ 
 
 #define ORIENTATION_ALIGN(box)                              \
   (BOX_PRIV(box)->orientation == GTK_ORIENTATION_HORIZONTAL \
@@ -892,7 +896,7 @@ gtk_flow_box_apply_sort (GtkFlowBox      *box,
     }
 }
 
-/* Selection utilities {{{3 */
+/* Sel ection utilities {{{3 */
 
 static gboolean
 gtk_flow_box_child_set_selected (GtkFlowBoxChild *child,
@@ -2978,15 +2982,6 @@ gtk_flow_box_unmap (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_flow_box_parent_class)->unmap (widget);
 }
 
-/* GtkContainer implementation {{{2 */
-
-static void
-gtk_flow_box_add (GtkContainer *container,
-                  GtkWidget    *child)
-{
-  gtk_flow_box_insert (GTK_FLOW_BOX (container), child, -1);
-}
-
 /**
  * gtk_flow_box_remove:
  * @box: a #GtkFlowBox
@@ -3038,29 +3033,6 @@ gtk_flow_box_remove (GtkFlowBox *box,
     g_signal_emit (box, signals[SELECTED_CHILDREN_CHANGED], 0);
 }
 
-static void
-gtk_flow_box_forall (GtkContainer *container,
-                     GtkCallback   callback,
-                     gpointer      callback_target)
-{
-  GSequenceIter *iter;
-  GtkWidget *child;
-
-  iter = g_sequence_get_begin_iter (BOX_PRIV (container)->children);
-  while (!g_sequence_iter_is_end (iter))
-    {
-      child = g_sequence_get (iter);
-      iter = g_sequence_iter_next (iter);
-      callback (child, callback_target);
-    }
-}
-
-static GType
-gtk_flow_box_child_type (GtkContainer *container)
-{
-  return GTK_TYPE_FLOW_BOX_CHILD;
-}
-
 /* Keynav {{{2 */
 
 static gboolean
@@ -3486,7 +3458,7 @@ gtk_flow_box_set_property (GObject      *object,
 }
 
 static void
-gtk_flow_box_finalize (GObject *obj)
+gtk_flow_box_dispose (GObject *obj)
 {
   GtkFlowBoxPrivate *priv = BOX_PRIV (obj);
 
@@ -3508,7 +3480,28 @@ gtk_flow_box_finalize (GObject *obj)
       g_clear_object (&priv->bound_model);
     }
 
-  G_OBJECT_CLASS (gtk_flow_box_parent_class)->finalize (obj);
+  G_OBJECT_CLASS (gtk_flow_box_parent_class)->dispose (obj);
+}
+
+static void
+gtk_flow_box_compute_expand (GtkWidget *widget,
+                             gboolean  *hexpand_p,
+                             gboolean  *vexpand_p)
+{
+  GtkWidget *w;
+  gboolean hexpand = FALSE;
+  gboolean vexpand = FALSE;
+
+  for (w = gtk_widget_get_first_child (widget);
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
+    {
+      hexpand = hexpand || gtk_widget_compute_expand (w, GTK_ORIENTATION_HORIZONTAL);
+      vexpand = vexpand || gtk_widget_compute_expand (w, GTK_ORIENTATION_VERTICAL);
+    }
+
+  *hexpand_p = hexpand;
+  *vexpand_p = vexpand;
 }
 
 static void
@@ -3516,9 +3509,8 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
 {
   GObjectClass      *object_class = G_OBJECT_CLASS (class);
   GtkWidgetClass    *widget_class = GTK_WIDGET_CLASS (class);
-  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
 
-  object_class->finalize = gtk_flow_box_finalize;
+  object_class->dispose = gtk_flow_box_dispose;
   object_class->get_property = gtk_flow_box_get_property;
   object_class->set_property = gtk_flow_box_set_property;
 
@@ -3527,13 +3519,9 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
   widget_class->focus = gtk_flow_box_focus;
   widget_class->snapshot = gtk_flow_box_snapshot;
   widget_class->get_request_mode = gtk_flow_box_get_request_mode;
+  widget_class->compute_expand = gtk_flow_box_compute_expand;
   widget_class->measure = gtk_flow_box_measure;
 
-  container_class->add = gtk_flow_box_add;
-  container_class->remove = gtk_flow_box_remove;
-  container_class->forall = gtk_flow_box_forall;
-  container_class->child_type = gtk_flow_box_child_type;
-
   class->activate_cursor_child = gtk_flow_box_activate_cursor_child;
   class->toggle_cursor_child = gtk_flow_box_toggle_cursor_child;
   class->move_cursor = gtk_flow_box_move_cursor;
@@ -3953,7 +3941,30 @@ gtk_flow_box_bound_model_changed (GListModel *list,
     }
 }
 
- /* Public API {{{2 */
+/* Buildable implemenation {{{3 */
+
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gtk_flow_box_buildable_add_child (GtkBuildable *buildable,
+                                  GtkBuilder   *builder,
+                                  GObject      *child,
+                                  const gchar  *type)
+{
+  if (GTK_IS_WIDGET (child))
+    gtk_flow_box_insert (GTK_FLOW_BOX (buildable), GTK_WIDGET (child), -1);
+  else
+    parent_buildable_iface->add_child (buildable, builder, child, type);
+}
+
+static void
+gtk_flow_box_buildable_iface_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+  iface->add_child = gtk_flow_box_buildable_add_child;
+}
+  /* Public API {{{2 */
 
 /**
  * gtk_flow_box_new:
@@ -4208,6 +4219,7 @@ gtk_flow_box_bind_model (GtkFlowBox                 *box,
                          GDestroyNotify              user_data_free_func)
 {
   GtkFlowBoxPrivate *priv = BOX_PRIV (box);
+  GtkWidget *child;
 
   g_return_if_fail (GTK_IS_FLOW_BOX (box));
   g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
@@ -4222,7 +4234,8 @@ gtk_flow_box_bind_model (GtkFlowBox                 *box,
       g_clear_object (&priv->bound_model);
     }
 
-  gtk_flow_box_forall (GTK_CONTAINER (box), (GtkCallback) gtk_widget_destroy, NULL);
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (box))))
+    gtk_flow_box_remove (box, child);
 
   if (model == NULL)
     return;


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