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.
This commit is contained in:
committed by
Matthias Clasen
parent
30f09ea10b
commit
b33c56819b
@@ -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
|
||||
|
||||
@@ -89,19 +89,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,
|
||||
@@ -112,34 +100,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
|
||||
@@ -166,24 +132,7 @@ gtk_list_item_factory_teardown (GtkListItemFactory *self,
|
||||
}
|
||||
|
||||
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,
|
||||
gtk_list_item_factory_update (GtkListItemFactory *self,
|
||||
GtkListItem *list_item,
|
||||
guint position,
|
||||
gpointer item,
|
||||
@@ -194,37 +143,8 @@ gtk_list_item_factory_rebind (GtkListItemFactory *self,
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (list_item));
|
||||
|
||||
GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->rebind (self, list_item, position, item, 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_update (GtkListItemFactory *self,
|
||||
GtkListItem *list_item,
|
||||
guint position,
|
||||
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)->update (self, list_item, position, 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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -934,7 +934,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);
|
||||
|
||||
@@ -972,7 +972,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);
|
||||
@@ -1010,7 +1014,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);
|
||||
}
|
||||
@@ -1029,13 +1036,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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -106,8 +106,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);
|
||||
@@ -341,61 +339,17 @@ gtk_list_item_widget_new (GtkListItemFactory *factory,
|
||||
}
|
||||
|
||||
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,
|
||||
gtk_list_item_widget_update (GtkListItemWidget *self,
|
||||
guint position,
|
||||
gpointer item,
|
||||
gboolean selected)
|
||||
{
|
||||
if (self->factory)
|
||||
gtk_list_item_factory_rebind (self->factory, self->item, position, item, 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);
|
||||
|
||||
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,
|
||||
gboolean selected)
|
||||
{
|
||||
if (self->factory)
|
||||
gtk_list_item_factory_update (self->factory, self->item, position, 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
|
||||
@@ -424,3 +378,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user