[gtk/wip/otte/listview: 36/46] listitemfactory: vfuncify
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 36/46] listitemfactory: vfuncify
- Date: Mon, 7 Oct 2019 05:49:39 +0000 (UTC)
commit 53686caa3d0d348d6c52200763a2bae233a112ff
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 | 127 +++++++++++++++++++++++++++++-----------
gtk/gtklistitemfactoryprivate.h | 28 +++++++++
2 files changed, 120 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtklistitemfactory.c b/gtk/gtklistitemfactory.c
index cd93b46716..771b6c376d 100644
--- a/gtk/gtklistitemfactory.c
+++ b/gtk/gtklistitemfactory.c
@@ -25,6 +25,77 @@
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)
+{
+ GtkWidget *child;
+
+ child = gtk_bin_get_child (GTK_BIN (list_item));
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (list_item), child);
+
+ 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)
{
@@ -42,6 +113,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
@@ -76,8 +154,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
@@ -92,12 +178,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));
}
@@ -114,12 +195,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));
}
@@ -135,8 +211,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));
}
@@ -150,25 +225,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)
-{
- GtkWidget *child;
-
- g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
-
- child = gtk_bin_get_child (GTK_BIN (list_item));
- if (child)
- gtk_container_remove (GTK_CONTAINER (list_item), child);
-
- 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]