[gtk/wip/otte/listview: 103/113] listitemfactory: Reorganize vfuncs



commit b309ca8df628bf47df43f37edec595aced4d2273
Author: Benjamin Otte <otte redhat com>
Date:   Sat Nov 2 18:56:36 2019 +0100

    listitemfactory: Reorganize vfuncs
    
    Instead of bind/rebind/update/unbind, we now just have update, and the
    factories get to interpret that in the way they want.

 gtk/gtkfunctionslistitemfactory.c | 24 ++---------
 gtk/gtklistitemfactory.c          | 86 ++-------------------------------------
 gtk/gtklistitemfactoryprivate.h   | 32 ++-------------
 gtk/gtklistitemmanager.c          | 19 +++++++--
 gtk/gtklistitemwidget.c           | 56 ++++---------------------
 gtk/gtklistitemwidgetprivate.h    | 11 +----
 gtk/gtksignallistitemfactory.c    | 38 +++++------------
 7 files changed, 46 insertions(+), 220 deletions(-)
---
diff --git a/gtk/gtkfunctionslistitemfactory.c b/gtk/gtkfunctionslistitemfactory.c
index 6b7c2814b9..41b708e36e 100644
--- a/gtk/gtkfunctionslistitemfactory.c
+++ b/gtk/gtkfunctionslistitemfactory.c
@@ -54,22 +54,7 @@ gtk_functions_list_item_factory_setup (GtkListItemFactory *factory,
 }
 
 static void                  
-gtk_functions_list_item_factory_bind (GtkListItemFactory *factory,
-                                      GtkListItem        *list_item,
-                                      guint               position,
-                                      gpointer            item,
-                                      gboolean            selected)
-{
-  GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
-
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item, 
position, item, selected);
-
-  if (self->bind_func)  
-    self->bind_func (list_item, self->user_data);
-}
-
-static void
-gtk_functions_list_item_factory_rebind (GtkListItemFactory *factory,
+gtk_functions_list_item_factory_update (GtkListItemFactory *factory,
                                         GtkListItem        *list_item,
                                         guint               position,
                                         gpointer            item,
@@ -77,9 +62,9 @@ gtk_functions_list_item_factory_rebind (GtkListItemFactory *factory,
 {
   GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
 
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item, 
position, item, selected);
+  GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->update (factory, list_item, 
position, item, selected);
 
-  if (self->bind_func)  
+  if (item != NULL && self->bind_func)  
     self->bind_func (list_item, self->user_data);
 }
 
@@ -103,8 +88,7 @@ gtk_functions_list_item_factory_class_init (GtkFunctionsListItemFactoryClass *kl
   object_class->finalize = gtk_functions_list_item_factory_finalize;
 
   factory_class->setup = gtk_functions_list_item_factory_setup;
-  factory_class->bind = gtk_functions_list_item_factory_bind;
-  factory_class->rebind = gtk_functions_list_item_factory_rebind;
+  factory_class->update = gtk_functions_list_item_factory_update;
 }
 
 static void
diff --git a/gtk/gtklistitemfactory.c b/gtk/gtklistitemfactory.c
index 43d65d0af0..c9f8b5d443 100644
--- a/gtk/gtklistitemfactory.c
+++ b/gtk/gtklistitemfactory.c
@@ -42,19 +42,7 @@ gtk_list_item_factory_default_teardown (GtkListItemFactory *self,
 }
 
 static void                  
-gtk_list_item_factory_default_bind (GtkListItemFactory *self,
-                                    GtkListItem        *list_item,
-                                    guint               position,
-                                    gpointer            item,
-                                    gboolean            selected)
-{
-  gtk_list_item_set_item (list_item, item);
-  gtk_list_item_set_position (list_item, position);
-  gtk_list_item_set_selected (list_item, selected);
-}
-
-static void
-gtk_list_item_factory_default_rebind (GtkListItemFactory *self,
+gtk_list_item_factory_default_update (GtkListItemFactory *self,
                                       GtkListItem        *list_item,
                                       guint               position,
                                       gpointer            item,
@@ -65,34 +53,12 @@ gtk_list_item_factory_default_rebind (GtkListItemFactory *self,
   gtk_list_item_set_selected (list_item, selected);
 }
 
-static void
-gtk_list_item_factory_default_update (GtkListItemFactory *self,
-                                      GtkListItem        *list_item,
-                                      guint               position,
-                                      gboolean            selected)
-{
-  gtk_list_item_set_position (list_item, position);
-  gtk_list_item_set_selected (list_item, selected);
-}
-
-static void
-gtk_list_item_factory_default_unbind (GtkListItemFactory *self,
-                                      GtkListItem        *list_item)
-{
-  gtk_list_item_set_item (list_item, NULL);
-  gtk_list_item_set_position (list_item, 0);
-  gtk_list_item_set_selected (list_item, FALSE);
-}
-
 static void
 gtk_list_item_factory_class_init (GtkListItemFactoryClass *klass)
 {
   klass->setup = gtk_list_item_factory_default_setup;
   klass->teardown = gtk_list_item_factory_default_teardown;
-  klass->bind = gtk_list_item_factory_default_bind;
-  klass->rebind = gtk_list_item_factory_default_rebind;
   klass->update = gtk_list_item_factory_default_update;
-  klass->unbind = gtk_list_item_factory_default_unbind;
 }
 
 static void
@@ -118,44 +84,11 @@ gtk_list_item_factory_teardown (GtkListItemFactory *self,
   GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->teardown (self, list_item);
 }
 
-void
-gtk_list_item_factory_bind (GtkListItemFactory *self,
-                            GtkListItem        *list_item,
-                            guint               position,
-                            gpointer            item,
-                            gboolean            selected)
-{
-  g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
-  g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
-  g_object_freeze_notify (G_OBJECT (list_item));
-
-  GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->bind (self, list_item, position, item, selected);
-
-  g_object_thaw_notify (G_OBJECT (list_item));
-}
-
-void
-gtk_list_item_factory_rebind (GtkListItemFactory *self,
-                              GtkListItem        *list_item,
-                              guint               position,
-                              gpointer            item,
-                              gboolean            selected)
-{
-  g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
-  g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
-  g_object_freeze_notify (G_OBJECT (list_item));
-
-  GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->rebind (self, list_item, position, item, selected);
-
-  g_object_thaw_notify (G_OBJECT (list_item));
-}
-
 void
 gtk_list_item_factory_update (GtkListItemFactory *self,
                               GtkListItem        *list_item,
                               guint               position,
+                              gpointer            item,
                               gboolean            selected)
 {
   g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
@@ -163,21 +96,8 @@ gtk_list_item_factory_update (GtkListItemFactory *self,
 
   g_object_freeze_notify (G_OBJECT (list_item));
 
-  GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->update (self, list_item, position, selected);
+  GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->update (self, list_item, position, item, selected);
 
   g_object_thaw_notify (G_OBJECT (list_item));
 }
 
-void
-gtk_list_item_factory_unbind (GtkListItemFactory *self,
-                              GtkListItem        *list_item)
-{
-  g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
-  g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
-  g_object_freeze_notify (G_OBJECT (list_item));
-
-  GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->unbind (self, list_item);
-
-  g_object_thaw_notify (G_OBJECT (list_item));
-}
diff --git a/gtk/gtklistitemfactoryprivate.h b/gtk/gtklistitemfactoryprivate.h
index d948db5ede..4cb49e8821 100644
--- a/gtk/gtklistitemfactoryprivate.h
+++ b/gtk/gtklistitemfactoryprivate.h
@@ -43,26 +43,13 @@ struct _GtkListItemFactoryClass
   void                  (* teardown)                            (GtkListItemFactory     *self,
                                                                  GtkListItem            *list_item);
 
-  /* bind @list_item to the given @item, which is in @position and @selected state */
-  void                  (* bind)                                (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
-  /* unbind the current item and bind a new one */
-  void                  (* rebind)                              (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
-  /* like GtkListItemFactoryClass::rebind(), but the item didn't change */
+  /* Update properties on @list_item to the given @item, which is in @position and @selected state.
+   * One or more of those properties might be unchanged. */
   void                  (* update)                              (GtkListItemFactory     *self,
                                                                  GtkListItem            *list_item,
                                                                  guint                   position,
+                                                                 gpointer                item,
                                                                  gboolean                selected);
-  /* undo the effects of GtkListItemFactoryClass::bind() */
-  void                  (* unbind)                              (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item);
 };
 
 void                    gtk_list_item_factory_setup             (GtkListItemFactory     *self,
@@ -70,22 +57,11 @@ void                    gtk_list_item_factory_setup             (GtkListItemFact
 void                    gtk_list_item_factory_teardown          (GtkListItemFactory     *self,
                                                                  GtkListItem            *list_item);
 
-void                    gtk_list_item_factory_bind              (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
-void                    gtk_list_item_factory_rebind            (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
 void                    gtk_list_item_factory_update            (GtkListItemFactory     *self,
                                                                  GtkListItem            *list_item,
                                                                  guint                   position,
+                                                                 gpointer                item,
                                                                  gboolean                selected);
-void                    gtk_list_item_factory_unbind            (GtkListItemFactory     *self,
-                                                                 GtkListItem            *list_item);
 
 
 G_END_DECLS
diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c
index 75303fb27b..148fb2bdb9 100644
--- a/gtk/gtklistitemmanager.c
+++ b/gtk/gtklistitemmanager.c
@@ -931,7 +931,7 @@ gtk_list_item_manager_acquire_list_item (GtkListItemManager *self,
 
   item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
   selected = gtk_selection_model_is_selected (self->model, position);
-  gtk_list_item_widget_bind (GTK_LIST_ITEM_WIDGET (result), position, item, selected);
+  gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (result), position, item, selected);
   g_object_unref (item);
   gtk_widget_insert_after (result, self->widget, prev_sibling);
 
@@ -969,7 +969,11 @@ gtk_list_item_manager_try_reacquire_list_item (GtkListItemManager *self,
   item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
   if (g_hash_table_steal_extended (change, item, NULL, (gpointer *) &result))
     {
-      gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (result), position, FALSE);
+      GtkListItemWidget *list_item = GTK_LIST_ITEM_WIDGET (result);
+      gtk_list_item_widget_update (list_item,
+                                   position,
+                                   gtk_list_item_widget_get_item (list_item),
+                                   gtk_list_item_widget_get_selected (list_item));
       gtk_widget_insert_after (result, self->widget, prev_sibling);
       /* XXX: Should we let the listview do this? */
       gtk_widget_queue_resize (result);
@@ -1007,7 +1011,10 @@ gtk_list_item_manager_move_list_item (GtkListItemManager     *self,
 
   item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
   selected = gtk_selection_model_is_selected (self->model, position);
-  gtk_list_item_widget_rebind (GTK_LIST_ITEM_WIDGET (list_item), position, item, selected);
+  gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (list_item),
+                               position,
+                               item,
+                               selected);
   gtk_widget_insert_after (list_item, _gtk_widget_get_parent (list_item), prev_sibling);
   g_object_unref (item);
 }
@@ -1026,13 +1033,17 @@ gtk_list_item_manager_update_list_item (GtkListItemManager *self,
                                         GtkWidget          *item,
                                         guint               position)
 {
+  GtkListItemWidget *list_item = GTK_LIST_ITEM_WIDGET (item);
   gboolean selected;
 
   g_return_if_fail (GTK_IS_LIST_ITEM_MANAGER (self));
   g_return_if_fail (GTK_IS_LIST_ITEM_WIDGET (item));
 
   selected = gtk_selection_model_is_selected (self->model, position);
-  gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (item), position, selected);
+  gtk_list_item_widget_update (list_item,
+                               position,
+                               gtk_list_item_widget_get_item (list_item),
+                               selected);
 }
 
 /*
diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c
index a4b8815b89..c989731d60 100644
--- a/gtk/gtklistitemwidget.c
+++ b/gtk/gtklistitemwidget.c
@@ -107,8 +107,6 @@ gtk_list_item_widget_dispose (GObject *object)
 
   if (self->item)
     {
-      if (self->item->item)
-        gtk_list_item_factory_unbind (self->factory, self->item);
       gtk_list_item_factory_teardown (self->factory, self->item);
       self->item->owner = NULL;
       g_clear_object (&self->item);
@@ -352,62 +350,18 @@ gtk_list_item_widget_new (GtkListItemFactory *factory,
   return GTK_WIDGET (result);
 }
 
-void
-gtk_list_item_widget_bind (GtkListItemWidget *self,
-                           guint              position,
-                           gpointer           item,
-                           gboolean           selected)
-{
-  if (self->factory)
-    gtk_list_item_factory_bind (self->factory, self->item, position, item, selected);
-
-  if (selected)
-    gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
-  else
-    gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-}
-
-void
-gtk_list_item_widget_rebind (GtkListItemWidget *self,
-                             guint              position,
-                             gpointer           item,
-                             gboolean           selected)
-{
-  if (self->factory)
-    gtk_list_item_factory_rebind (self->factory, self->item, position, item, selected);
-
-  if (selected)
-    gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
-  else
-    gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
-  gtk_css_node_invalidate (gtk_widget_get_css_node (GTK_WIDGET (self)), GTK_CSS_CHANGE_ANIMATIONS);
-}
-
 void
 gtk_list_item_widget_update (GtkListItemWidget *self,
                              guint              position,
+                             gpointer           item,
                              gboolean           selected)
 {
-  if (self->factory)
-    gtk_list_item_factory_update (self->factory, self->item, position, selected);
+  gtk_list_item_factory_update (self->factory, self->item, position, item, selected);
 
   if (selected)
     gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
   else
     gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
-}
-
-void
-gtk_list_item_widget_unbind (GtkListItemWidget *self)
-{
-  if (self->factory)
-    gtk_list_item_factory_unbind (self->factory, self->item);
-
-  gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
-  gtk_css_node_invalidate (gtk_widget_get_css_node (GTK_WIDGET (self)), GTK_CSS_CHANGE_ANIMATIONS);
 }
 
 void
@@ -436,3 +390,9 @@ gtk_list_item_widget_get_item (GtkListItemWidget *self)
   return self->item->item;
 }
 
+gboolean
+gtk_list_item_widget_get_selected (GtkListItemWidget *self)
+{
+  return self->item->selected;
+}
+
diff --git a/gtk/gtklistitemwidgetprivate.h b/gtk/gtklistitemwidgetprivate.h
index 77db256cb0..b3289b139e 100644
--- a/gtk/gtklistitemwidgetprivate.h
+++ b/gtk/gtklistitemwidgetprivate.h
@@ -55,18 +55,10 @@ GType                   gtk_list_item_widget_get_type           (void) G_GNUC_CO
 GtkWidget *             gtk_list_item_widget_new                (GtkListItemFactory     *factory,
                                                                  const char             *css_name);
 
-void                    gtk_list_item_widget_bind               (GtkListItemWidget      *self,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
-void                    gtk_list_item_widget_rebind             (GtkListItemWidget      *self,
-                                                                 guint                   position,
-                                                                 gpointer                item,
-                                                                 gboolean                selected);
 void                    gtk_list_item_widget_update             (GtkListItemWidget      *self,
                                                                  guint                   position,
+                                                                 gpointer                item,
                                                                  gboolean                selected);
-void                    gtk_list_item_widget_unbind             (GtkListItemWidget      *self);
 
 void                    gtk_list_item_widget_add_child          (GtkListItemWidget      *self,
                                                                  GtkWidget              *child);
@@ -75,6 +67,7 @@ void                    gtk_list_item_widget_remove_child       (GtkListItemWidg
 
 guint                   gtk_list_item_widget_get_position       (GtkListItemWidget      *self);
 gpointer                gtk_list_item_widget_get_item           (GtkListItemWidget      *self);
+gboolean                gtk_list_item_widget_get_selected       (GtkListItemWidget      *self);
 
 G_END_DECLS
 
diff --git a/gtk/gtksignallistitemfactory.c b/gtk/gtksignallistitemfactory.c
index 0665b2a603..d26ee013a8 100644
--- a/gtk/gtksignallistitemfactory.c
+++ b/gtk/gtksignallistitemfactory.c
@@ -117,44 +117,28 @@ gtk_signal_list_item_factory_setup (GtkListItemFactory *factory,
 }
 
 static void                  
-gtk_signal_list_item_factory_bind (GtkListItemFactory *factory,
-                                   GtkListItem        *list_item,
-                                   guint               position,
-                                   gpointer            item,
-                                   gboolean            selected)
-{
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->bind (factory, list_item, 
position, item, selected);
-
-  g_signal_emit (factory, signals[BIND], 0, list_item);
-}
-
-static void
-gtk_signal_list_item_factory_rebind (GtkListItemFactory *factory,
+gtk_signal_list_item_factory_update (GtkListItemFactory *factory,
                                      GtkListItem        *list_item,
                                      guint               position,
                                      gpointer            item,
                                      gboolean            selected)
 {
-  g_signal_emit (factory, signals[UNBIND], 0, list_item);
+  if (gtk_list_item_get_item (list_item))
+    g_signal_emit (factory, signals[UNBIND], 0, list_item);
 
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->bind (factory, list_item, 
position, item, selected);
+  GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->update (factory, list_item, 
position, item, selected);
 
-  g_signal_emit (factory, signals[BIND], 0, list_item);
-}
-
-static void
-gtk_signal_list_item_factory_unbind (GtkListItemFactory *factory,
-                                     GtkListItem        *list_item)
-{
-  g_signal_emit (factory, signals[UNBIND], 0, list_item);
-
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->unbind (factory, list_item);
+  if (item)
+    g_signal_emit (factory, signals[BIND], 0, list_item);
 }
 
 static void
 gtk_signal_list_item_factory_teardown (GtkListItemFactory *factory,
                                        GtkListItem        *list_item)
 {
+  if (gtk_list_item_get_item (list_item))
+    g_signal_emit (factory, signals[UNBIND], 0, list_item);
+
   g_signal_emit (factory, signals[TEARDOWN], 0, list_item);
 
   GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->teardown (factory, list_item);
@@ -166,10 +150,8 @@ gtk_signal_list_item_factory_class_init (GtkSignalListItemFactoryClass *klass)
   GtkListItemFactoryClass *factory_class = GTK_LIST_ITEM_FACTORY_CLASS (klass);
 
   factory_class->setup = gtk_signal_list_item_factory_setup;
-  factory_class->bind = gtk_signal_list_item_factory_bind;
-  factory_class->rebind = gtk_signal_list_item_factory_rebind;
-  factory_class->unbind = gtk_signal_list_item_factory_unbind;
   factory_class->teardown = gtk_signal_list_item_factory_teardown;
+  factory_class->update = gtk_signal_list_item_factory_update;
 
   /**
    * GtkSignalListItemFactory::setup:


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