[gtk/wip/otte/listview: 55/152] listitemfactory: vfuncify
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 55/152] listitemfactory: vfuncify
- Date: Sun, 24 May 2020 18:46:42 +0000 (UTC)
commit cd48ae390d3c6dbacce40e691d54bffc0e1ca632
Author: Benjamin Otte <otte redhat com>
Date: Mon Jun 10 00:17:44 2019 +0200
listitemfactory: vfuncify
No functional changes other than a new indirection.
gtk/gtklistitemfactory.c | 118 +++++++++++++++++++++++++++++-----------
gtk/gtklistitemfactoryprivate.h | 28 ++++++++++
2 files changed, 115 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtklistitemfactory.c b/gtk/gtklistitemfactory.c
index 510c04889b..1025173bd8 100644
--- a/gtk/gtklistitemfactory.c
+++ b/gtk/gtklistitemfactory.c
@@ -73,6 +73,72 @@
G_DEFINE_TYPE (GtkListItemFactory, gtk_list_item_factory, G_TYPE_OBJECT)
+static void
+gtk_list_item_factory_default_setup (GtkListItemFactory *self,
+ GtkListItem *list_item)
+{
+ if (self->setup_func)
+ self->setup_func (list_item, self->user_data);
+}
+
+static void
+gtk_list_item_factory_default_teardown (GtkListItemFactory *self,
+ GtkListItem *list_item)
+{
+ gtk_list_item_set_child (list_item, NULL);
+ gtk_list_item_set_selectable (list_item, TRUE);
+
+}
+
+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);
+
+ if (self->bind_func)
+ self->bind_func (list_item, self->user_data);
+}
+
+static void
+gtk_list_item_factory_default_rebind (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);
+
+ if (self->bind_func)
+ self->bind_func (list_item, self->user_data);
+}
+
+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_finalize (GObject *object)
{
@@ -90,6 +156,13 @@ gtk_list_item_factory_class_init (GtkListItemFactoryClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_list_item_factory_finalize;
+
+ 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
@@ -124,8 +197,16 @@ gtk_list_item_factory_setup (GtkListItemFactory *self,
{
g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
- if (self->setup_func)
- self->setup_func (list_item, self->user_data);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->setup (self, list_item);
+}
+
+void
+gtk_list_item_factory_teardown (GtkListItemFactory *self,
+ GtkListItem *list_item)
+{
+ g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
+
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->teardown (self, list_item);
}
void
@@ -140,12 +221,7 @@ gtk_list_item_factory_bind (GtkListItemFactory *self,
g_object_freeze_notify (G_OBJECT (list_item));
- gtk_list_item_set_item (list_item, item);
- gtk_list_item_set_position (list_item, position);
- gtk_list_item_set_selected (list_item, selected);
-
- if (self->bind_func)
- self->bind_func (list_item, self->user_data);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->bind (self, list_item, position, item, selected);
g_object_thaw_notify (G_OBJECT (list_item));
}
@@ -162,12 +238,7 @@ gtk_list_item_factory_rebind (GtkListItemFactory *self,
g_object_freeze_notify (G_OBJECT (list_item));
- gtk_list_item_set_item (list_item, item);
- gtk_list_item_set_position (list_item, position);
- gtk_list_item_set_selected (list_item, selected);
-
- if (self->bind_func)
- self->bind_func (list_item, self->user_data);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->rebind (self, list_item, position, item, selected);
g_object_thaw_notify (G_OBJECT (list_item));
}
@@ -183,8 +254,7 @@ gtk_list_item_factory_update (GtkListItemFactory *self,
g_object_freeze_notify (G_OBJECT (list_item));
- gtk_list_item_set_position (list_item, position);
- gtk_list_item_set_selected (list_item, selected);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->update (self, list_item, position, selected);
g_object_thaw_notify (G_OBJECT (list_item));
}
@@ -198,21 +268,7 @@ gtk_list_item_factory_unbind (GtkListItemFactory *self,
g_object_freeze_notify (G_OBJECT (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);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->unbind (self, list_item);
g_object_thaw_notify (G_OBJECT (list_item));
}
-
-void
-gtk_list_item_factory_teardown (GtkListItemFactory *self,
- GtkListItem *list_item)
-{
- g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
-
- gtk_list_item_set_child (list_item, NULL);
-
- gtk_list_item_set_selectable (list_item, TRUE);
-}
-
diff --git a/gtk/gtklistitemfactoryprivate.h b/gtk/gtklistitemfactoryprivate.h
index 34582257bc..98ca4b350e 100644
--- a/gtk/gtklistitemfactoryprivate.h
+++ b/gtk/gtklistitemfactoryprivate.h
@@ -49,6 +49,34 @@ struct _GtkListItemFactory
struct _GtkListItemFactoryClass
{
GObjectClass parent_class;
+
+ /* setup @list_item so it can be bound */
+ void (* setup) (GtkListItemFactory *self,
+ GtkListItem *list_item);
+ /* undo the effects of GtkListItemFactoryClass::setup() */
+ 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 */
+ void (* update) (GtkListItemFactory *self,
+ GtkListItem *list_item,
+ guint position,
+ gboolean selected);
+ /* undo the effects of GtkListItemFactoryClass::bind() */
+ void (* unbind) (GtkListItemFactory *self,
+ GtkListItem *list_item);
};
GType gtk_list_item_factory_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]