X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkaccessible.c;h=27d88ca00ea35b178118fdd8dd0cf5eefba11e27;hb=6767541ead7cc150d1dd066d3b84d85559500c28;hp=eb7697f403fcfc464b8cb6dc6dda1a3e9348626a;hpb=c7514e8f0d19a833257497caff413bb4dfae6eb4;p=~andy%2Fgtk diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c index eb7697f40..27d88ca00 100644 --- a/gtk/gtkaccessible.c +++ b/gtk/gtkaccessible.c @@ -12,9 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ #include "config.h" @@ -28,22 +26,73 @@ * SECTION:gtkaccessible * @Short_description: Accessibility support for widgets * @Title: GtkAccessible + * + * The #GtkAccessible class is the base class for accessible + * implementations for #GtkWidget subclasses. It is a thin + * wrapper around #AtkObject, which adds facilities for associating + * a widget with its accessible object. + * + * An accessible implementation for a third-party widget should + * derive from #GtkAccessible and implement the suitable interfaces + * from ATK, such as #AtkText or #AtkSelection. To establish + * the connection between the widget class and its corresponding + * acccessible implementation, override the get_accessible vfunc + * in #GtkWidgetClass. */ -/* - * GtkAccessiblePriv: - * @widget: The GtkWidget whose properties and features are exported via this - * accessible instance - */ struct _GtkAccessiblePrivate { GtkWidget *widget; }; +enum { + PROP_0, + PROP_WIDGET +}; + static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible); G_DEFINE_TYPE (GtkAccessible, gtk_accessible, ATK_TYPE_OBJECT) +static void +gtk_accessible_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkAccessible *accessible = GTK_ACCESSIBLE (object); + + switch (prop_id) + { + case PROP_WIDGET: + gtk_accessible_set_widget (accessible, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_accessible_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkAccessible *accessible = GTK_ACCESSIBLE (object); + GtkAccessiblePrivate *priv = accessible->priv; + + switch (prop_id) + { + case PROP_WIDGET: + g_value_set_object (value, priv->widget); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void gtk_accessible_init (GtkAccessible *accessible) { @@ -52,10 +101,64 @@ gtk_accessible_init (GtkAccessible *accessible) GtkAccessiblePrivate); } +static AtkStateSet * +gtk_accessible_ref_state_set (AtkObject *object) +{ + GtkAccessible *accessible = GTK_ACCESSIBLE (object); + AtkStateSet *state_set; + + state_set = ATK_OBJECT_CLASS (gtk_accessible_parent_class)->ref_state_set (object); + + if (accessible->priv->widget == NULL) + atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT); + + return state_set; +} + +static void +gtk_accessible_real_widget_set (GtkAccessible *accessible) +{ + atk_object_notify_state_change (ATK_OBJECT (accessible), ATK_STATE_DEFUNCT, FALSE); +} + +static void +gtk_accessible_real_widget_unset (GtkAccessible *accessible) +{ + atk_object_notify_state_change (ATK_OBJECT (accessible), ATK_STATE_DEFUNCT, TRUE); +} + +static void +gtk_accessible_dispose (GObject *object) +{ + GtkAccessible *accessible = GTK_ACCESSIBLE (object); + + gtk_accessible_set_widget (accessible, NULL); + + G_OBJECT_CLASS (gtk_accessible_parent_class)->dispose (object); +} + static void gtk_accessible_class_init (GtkAccessibleClass *klass) { + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + AtkObjectClass *atkobject_class = ATK_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; + + atkobject_class->ref_state_set = gtk_accessible_ref_state_set; + gobject_class->get_property = gtk_accessible_get_property; + gobject_class->set_property = gtk_accessible_set_property; + gobject_class->dispose = gtk_accessible_dispose; + + g_object_class_install_property (gobject_class, + PROP_WIDGET, + g_param_spec_object ("widget", + P_("Widget"), + P_("The widget referenced by this accessible."), + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); g_type_class_add_private (klass, sizeof (GtkAccessiblePrivate)); } @@ -63,33 +166,55 @@ gtk_accessible_class_init (GtkAccessibleClass *klass) /** * gtk_accessible_set_widget: * @accessible: a #GtkAccessible - * @widget: a #GtkWidget + * @widget: (allow-none): a #GtkWidget or %NULL to unset * * Sets the #GtkWidget corresponding to the #GtkAccessible. * + * @accessible will not hold a reference to @widget. + * It is the caller's responsibility to ensure that when @widget + * is destroyed, the widget is unset by calling this function + * again with @widget set to %NULL. * Since: 2.22 - **/ + */ void gtk_accessible_set_widget (GtkAccessible *accessible, GtkWidget *widget) { + GtkAccessiblePrivate *priv; + GtkAccessibleClass *klass; + g_return_if_fail (GTK_IS_ACCESSIBLE (accessible)); - accessible->priv->widget = widget; + 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"); } /** * gtk_accessible_get_widget: * @accessible: a #GtkAccessible * - * Gets the #GtkWidget corresponding to the #GtkAccessible. The returned widget - * does not have a reference added, so you do not need to unref it. + * Gets the #GtkWidget corresponding to the #GtkAccessible. + * The returned widget does not have a reference added, so + * you do not need to unref it. * - * Returns: (transfer none): pointer to the #GtkWidget corresponding to - * the #GtkAccessible, or %NULL. + * Returns: (transfer none): pointer to the #GtkWidget + * corresponding to the #GtkAccessible, or %NULL. * * Since: 2.22 - **/ + */ GtkWidget* gtk_accessible_get_widget (GtkAccessible *accessible) { @@ -99,11 +224,13 @@ gtk_accessible_get_widget (GtkAccessible *accessible) } /** - * gtk_accessible_connect_widget_destroyed + * gtk_accessible_connect_widget_destroyed: * @accessible: a #GtkAccessible * - * This function specifies the callback function to be called when the widget - * corresponding to a GtkAccessible is destroyed. + * This function specifies the callback function to be called + * when the widget corresponding to a GtkAccessible is destroyed. + * + * Deprecated: 3.4: Use gtk_accessible_set_widget() and its vfuncs. */ void gtk_accessible_connect_widget_destroyed (GtkAccessible *accessible) @@ -118,47 +245,19 @@ gtk_accessible_connect_widget_destroyed (GtkAccessible *accessible) class->connect_widget_destroyed (accessible); } +static void +gtk_accessible_widget_destroyed (GtkWidget *widget, + GtkAccessible *accessible) +{ + gtk_accessible_set_widget (accessible, NULL); +} + static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible) { GtkAccessiblePrivate *priv = accessible->priv; if (priv->widget) - { - g_signal_connect (priv->widget, - "destroy", - G_CALLBACK (gtk_widget_destroyed), - &priv->widget); - } + g_signal_connect (priv->widget, "destroy", + G_CALLBACK (gtk_accessible_widget_destroyed), accessible); } - -/* - * _gtk_accessible_set_factory_type: - * @widget_type: a #GtkWidget subtype - * @factory_type: a #AtkObjectFactory subtype - * - * A wrapper around atk_registry_set_factory_type(). - * - * Only installs the factory if accessibility is - * enabled. - */ -void -_gtk_accessible_set_factory_type (GType widget_type, - GType factory_type) -{ - AtkObjectFactory *factory; - AtkRegistry *registry; - GType accessible_type; - - /* - * Figure out whether accessibility is enabled by looking - * at the type of the accessible object which would be created - * for GtkWidget. - */ - registry = atk_get_default_registry (); - factory = atk_registry_get_factory (registry, GTK_TYPE_WIDGET); - accessible_type = atk_object_factory_get_accessible_type (factory); - if (g_type_is_a (accessible_type, GTK_TYPE_ACCESSIBLE)) - atk_registry_set_factory_type (registry, widget_type, factory_type); -} -