diff options
author | Benjamin Otte <otte@redhat.com> | 2019-11-03 02:23:46 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-30 19:26:46 -0400 |
commit | 1af004361c60d43fdcc00576c0a6fd118723575e (patch) | |
tree | 543d452aea4d9d0820a93d56b40c6aa2300724e8 /gtk/gtklistitemwidget.c | |
parent | b33c56819b312aa61fc21fca566e1859c822cedf (diff) | |
download | gtk+-1af004361c60d43fdcc00576c0a6fd118723575e.tar.gz |
listitemfactory: Simplify
Instead of 6 vfuncs, we now have 3 and rely on the factory keeping track
of what it needs to do.
We're doing lots of dancing from one object to another here, but this
will hopefully get simpler with further commits.
Diffstat (limited to 'gtk/gtklistitemwidget.c')
-rw-r--r-- | gtk/gtklistitemwidget.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c index dcd0e2f3cf..8481054e72 100644 --- a/gtk/gtklistitemwidget.c +++ b/gtk/gtklistitemwidget.c @@ -106,9 +106,8 @@ gtk_list_item_widget_dispose (GObject *object) if (self->item) { - gtk_list_item_factory_teardown (self->factory, self->item); - self->item->owner = NULL; - g_clear_object (&self->item); + gtk_list_item_factory_teardown (self->factory, self); + g_assert (self->item == NULL); } g_clear_object (&self->factory); @@ -313,8 +312,6 @@ gtk_list_item_widget_init (GtkListItemWidget *self) controller = gtk_event_controller_focus_new (); g_signal_connect (controller, "enter", G_CALLBACK (gtk_list_item_widget_enter_cb), self); gtk_widget_add_controller (GTK_WIDGET (self), controller); - - self->item = gtk_list_item_new (self); } GtkWidget * @@ -332,7 +329,8 @@ gtk_list_item_widget_new (GtkListItemFactory *factory, { result->factory = g_object_ref (factory); - gtk_list_item_factory_setup (factory, result->item); + gtk_list_item_factory_setup (factory, result); + g_assert (result->item != NULL); } return GTK_WIDGET (result); @@ -344,7 +342,8 @@ gtk_list_item_widget_update (GtkListItemWidget *self, gpointer item, gboolean selected) { - gtk_list_item_factory_update (self->factory, self->item, position, item, selected); + if (self->factory) + gtk_list_item_factory_update (self->factory, self, position, item, selected); if (selected) gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE); @@ -353,6 +352,42 @@ gtk_list_item_widget_update (GtkListItemWidget *self, } void +gtk_list_item_widget_default_setup (GtkListItemWidget *self, + GtkListItem *list_item) +{ + self->item = list_item; + list_item->owner = self; + + if (list_item->child) + gtk_list_item_widget_add_child (self, list_item->child); +} + +void +gtk_list_item_widget_default_teardown (GtkListItemWidget *self, + GtkListItem *list_item) +{ + g_assert (self->item == list_item); + + self->item = NULL; + list_item->owner = NULL; + + if (list_item->child) + gtk_list_item_widget_remove_child (self, list_item->child); +} + +void +gtk_list_item_widget_default_update (GtkListItemWidget *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); +} + +void gtk_list_item_widget_add_child (GtkListItemWidget *self, GtkWidget *child) { @@ -366,6 +401,12 @@ gtk_list_item_widget_remove_child (GtkListItemWidget *self, gtk_widget_unparent (child); } +GtkListItem * +gtk_list_item_widget_get_list_item (GtkListItemWidget *self) +{ + return self->item; +} + guint gtk_list_item_widget_get_position (GtkListItemWidget *self) { |