API: accessible: Add widget_set and widget_unset vfuncs

I expect them to be used a lot, so this approach seems better than
requiring signals that connect to "notify::widget". Also, we can't use
regular functions (like dispose or constructed), becaiuse those assume
that (un)setting of the widget only happens once and with the current
design (a puble set_widget() function) we can't really guarantee that.

Also, I split them into two separate functions as one function is part
of construction and the other part of destruction of the object. And it
doesn't sound like a good idea to have that both be part of one
function.
This commit is contained in:
Benjamin Otte
2011-12-18 12:55:41 +01:00
parent 50431be274
commit bac73e48db
2 changed files with 22 additions and 2 deletions

View File

@ -103,12 +103,24 @@ gtk_accessible_init (GtkAccessible *accessible)
GtkAccessiblePrivate);
}
static void
gtk_accessible_real_widget_set (GtkAccessible *accessible)
{
}
static void
gtk_accessible_real_widget_unset (GtkAccessible *accessible)
{
}
static void
gtk_accessible_class_init (GtkAccessibleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
klass->connect_widget_destroyed = gtk_accessible_real_connect_widget_destroyed;
klass->widget_set = gtk_accessible_real_widget_set;
klass->widget_unset = gtk_accessible_real_widget_unset;
gobject_class->get_property = gtk_accessible_get_property;
gobject_class->set_property = gtk_accessible_set_property;
@ -142,16 +154,24 @@ gtk_accessible_set_widget (GtkAccessible *accessible,
GtkWidget *widget)
{
GtkAccessiblePrivate *priv;
GtkAccessibleClass *klass;
g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
priv = accessible->priv;
klass = GTK_ACCESSIBLE_GET_CLASS (accessible);
if (priv->widget == widget)
return;
if (priv->widget)
klass->widget_unset (accessible);
priv->widget = widget;
if (widget);
klass->widget_set (accessible);
g_object_notify (G_OBJECT (accessible), "widget");
}