listitemfactory: vfuncify

No functional changes other than a new indirection.
This commit is contained in:
Benjamin Otte 2019-06-10 00:17:44 +02:00 committed by Matthias Clasen
parent 10b967ae1f
commit 824326a029
2 changed files with 115 additions and 31 deletions

View File

@ -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);
}

View File

@ -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;