[gtk/wip/otte/listview: 88/113] listbase: Move item manager here



commit 05e5ee014cb85451bba9881ebc52789712b59a8f
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 23 02:34:28 2019 +0200

    listbase: Move item manager here
    
    Nothing really changes, because both ListView and GridView still keep
    self->item_manager around, but it's set up to point at the base's item
    manager.
    
    This way we can slowly move things to GtkListBase that need the item
    manager (like trackers).

 gtk/gtkgridview.c        | 66 +++++++++++++++++++++++++-----------------------
 gtk/gtklistbase.c        | 26 ++++++++++++++++++-
 gtk/gtklistbaseprivate.h |  8 ++++++
 gtk/gtklistview.c        | 19 +++++---------
 4 files changed, 74 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index c0515f641c..96856ae716 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -149,6 +149,35 @@ dump (GtkGridView *self)
   g_print ("  => %u widgets in %u list rows\n", n_widgets, n_list_rows);
 }
 
+static void
+cell_augment (GtkRbTree *tree,
+              gpointer   node_augment,
+              gpointer   node,
+              gpointer   left,
+              gpointer   right)
+{
+  Cell *cell = node;
+  CellAugment *aug = node_augment;
+
+  gtk_list_item_manager_augment_node (tree, node_augment, node, left, right);
+
+  aug->size = cell->size;
+
+  if (left)
+    {
+      CellAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
+
+      aug->size += left_aug->size;
+    }
+
+  if (right)
+    {
+      CellAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
+
+      aug->size += right_aug->size;
+    }
+}
+
 /*<private>
  * gtk_grid_view_get_cell_at_y:
  * @self: a #GtkGridView
@@ -1036,7 +1065,7 @@ gtk_grid_view_dispose (GObject *object)
       gtk_list_item_tracker_free (self->item_manager, self->focus);
       self->focus = NULL;
     }
-  g_clear_object (&self->item_manager);
+  self->item_manager = NULL;
 
   G_OBJECT_CLASS (gtk_grid_view_parent_class)->dispose (object);
 }
@@ -1576,6 +1605,10 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkBindingSet *binding_set;
 
+  list_base_class->list_item_name = "flowboxchild";
+  list_base_class->list_item_size = sizeof (Cell);
+  list_base_class->list_item_augment_size = sizeof (CellAugment);
+  list_base_class->list_item_augment_func = cell_augment;
   list_base_class->adjustment_value_changed = gtk_grid_view_adjustment_value_changed;
 
   widget_class->focus = gtk_grid_view_focus;
@@ -1777,39 +1810,10 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
 
 }
 
-static void
-cell_augment (GtkRbTree *tree,
-              gpointer   node_augment,
-              gpointer   node,
-              gpointer   left,
-              gpointer   right)
-{
-  Cell *cell = node;
-  CellAugment *aug = node_augment;
-
-  gtk_list_item_manager_augment_node (tree, node_augment, node, left, right);
-
-  aug->size = cell->size;
-
-  if (left)
-    {
-      CellAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
-
-      aug->size += left_aug->size;
-    }
-
-  if (right)
-    {
-      CellAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
-
-      aug->size += right_aug->size;
-    }
-}
-
 static void
 gtk_grid_view_init (GtkGridView *self)
 {
-  self->item_manager = gtk_list_item_manager_new (GTK_WIDGET (self), "flowboxchild", Cell, CellAugment, 
cell_augment);
+  self->item_manager = gtk_list_base_get_manager (GTK_LIST_BASE (self));
   self->anchor = gtk_list_item_tracker_new (self->item_manager);
   self->anchor_xstart = TRUE;
   self->anchor_ystart = TRUE;
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
index 880b259d93..199d1519e5 100644
--- a/gtk/gtklistbase.c
+++ b/gtk/gtklistbase.c
@@ -28,6 +28,7 @@ typedef struct _GtkListBasePrivate GtkListBasePrivate;
 
 struct _GtkListBasePrivate
 {
+  GtkListItemManager *item_manager;
   GtkAdjustment *adjustment[2];
   GtkScrollablePolicy scroll_policy[2];
 };
@@ -43,9 +44,14 @@ enum
   N_PROPS
 };
 
+/* HACK: We want the g_class argument in our instance init func and G_DEFINE_TYPE() won't let us */
+static void gtk_list_base_init_real (GtkListBase *self, GtkListBaseClass *g_class);
+#define g_type_register_static_simple(a,b,c,d,e,evil,f) g_type_register_static_simple(a,b,c,d,e, 
(GInstanceInitFunc) gtk_list_base_init_real, f);
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkListBase, gtk_list_base, GTK_TYPE_WIDGET,
                                                               G_ADD_PRIVATE (GtkListBase)
                                                               G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, 
NULL))
+#undef g_type_register_static_simple
+G_GNUC_UNUSED static void gtk_list_base_init (GtkListBase *self) { }
 
 static GParamSpec *properties[N_PROPS] = { NULL, };
 
@@ -82,10 +88,13 @@ static void
 gtk_list_base_dispose (GObject *object)
 {
   GtkListBase *self = GTK_LIST_BASE (object);
+  GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
 
   gtk_list_base_clear_adjustment (self, GTK_ORIENTATION_HORIZONTAL);
   gtk_list_base_clear_adjustment (self, GTK_ORIENTATION_VERTICAL);
 
+  g_clear_object (&priv->item_manager);
+
   G_OBJECT_CLASS (gtk_list_base_parent_class)->dispose (object);
 }
 
@@ -228,10 +237,17 @@ gtk_list_base_class_init (GtkListBaseClass *klass)
 }
 
 static void
-gtk_list_base_init (GtkListBase *self)
+gtk_list_base_init_real (GtkListBase      *self,
+                         GtkListBaseClass *g_class)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
 
+  priv->item_manager = gtk_list_item_manager_new_for_size (GTK_WIDGET (self),
+                                                           g_class->list_item_name,
+                                                           g_class->list_item_size,
+                                                           g_class->list_item_augment_size,
+                                                           g_class->list_item_augment_func);
+
   priv->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   priv->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
 
@@ -313,3 +329,11 @@ gtk_list_base_get_scroll_policy (GtkListBase    *self,
   return priv->scroll_policy[orientation];
 }
 
+GtkListItemManager *
+gtk_list_base_get_manager (GtkListBase *self)
+{
+  GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
+
+  return priv->item_manager;
+}
+
diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h
index 39acd980e4..4d0c668291 100644
--- a/gtk/gtklistbaseprivate.h
+++ b/gtk/gtklistbaseprivate.h
@@ -22,6 +22,8 @@
 
 #include "gtklistbase.h"
 
+#include "gtklistitemmanagerprivate.h"
+
 struct _GtkListBase
 {
   GtkWidget parent_instance;
@@ -31,10 +33,16 @@ struct _GtkListBaseClass
 {
   GtkWidgetClass parent_class;
 
+  const char *         list_item_name;
+  gsize                list_item_size;
+  gsize                list_item_augment_size;
+  GtkRbTreeAugmentFunc list_item_augment_func;
+
   void                 (* adjustment_value_changed)             (GtkListBase            *self,
                                                                  GtkOrientation          orientation);
 };
 
+GtkListItemManager *   gtk_list_base_get_manager                (GtkListBase            *self);
 GtkScrollablePolicy    gtk_list_base_get_scroll_policy          (GtkListBase            *self,
                                                                  GtkOrientation          orientation);
 void                   gtk_list_base_get_adjustment_values      (GtkListBase            *self,
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 3affde8d10..411bca0e70 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -792,21 +792,11 @@ gtk_list_view_dispose (GObject *object)
       gtk_list_item_tracker_free (self->item_manager, self->focus);
       self->focus = NULL;
     }
-  g_clear_object (&self->item_manager);
+  self->item_manager = NULL;
 
   G_OBJECT_CLASS (gtk_list_view_parent_class)->dispose (object);
 }
 
-static void
-gtk_list_view_finalize (GObject *object)
-{
-  GtkListView *self = GTK_LIST_VIEW (object);
-
-  g_clear_object (&self->item_manager);
-
-  G_OBJECT_CLASS (gtk_list_view_parent_class)->finalize (object);
-}
-
 static void
 gtk_list_view_get_property (GObject    *object,
                             guint       property_id,
@@ -1322,6 +1312,10 @@ gtk_list_view_class_init (GtkListViewClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkBindingSet *binding_set;
 
+  list_base_class->list_item_name = "row";
+  list_base_class->list_item_size = sizeof (ListRow);
+  list_base_class->list_item_augment_size = sizeof (ListRowAugment);
+  list_base_class->list_item_augment_func = list_row_augment;
   list_base_class->adjustment_value_changed = gtk_list_view_adjustment_value_changed;
 
   widget_class->measure = gtk_list_view_measure;
@@ -1329,7 +1323,6 @@ gtk_list_view_class_init (GtkListViewClass *klass)
   widget_class->focus = gtk_list_view_focus;
 
   gobject_class->dispose = gtk_list_view_dispose;
-  gobject_class->finalize = gtk_list_view_finalize;
   gobject_class->get_property = gtk_list_view_get_property;
   gobject_class->set_property = gtk_list_view_set_property;
 
@@ -1510,7 +1503,7 @@ gtk_list_view_class_init (GtkListViewClass *klass)
 static void
 gtk_list_view_init (GtkListView *self)
 {
-  self->item_manager = gtk_list_item_manager_new (GTK_WIDGET (self), "row", ListRow, ListRowAugment, 
list_row_augment);
+  self->item_manager = gtk_list_base_get_manager (GTK_LIST_BASE (self));
   self->focus = gtk_list_item_tracker_new (self->item_manager);
   self->anchor = gtk_list_item_tracker_new (self->item_manager);
   self->selected = gtk_list_item_tracker_new (self->item_manager);


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