1 /* GTK - The GIMP Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "gtkwidget.h"
25 #include "gtkaccessible.h"
28 * SECTION:gtkaccessible
29 * @Short_description: Accessibility support for widgets
30 * @Title: GtkAccessible
32 * The #GtkAccessible class is the base class for accessible
33 * implementations for #GtkWidget subclasses. It is a thin
34 * wrapper around #AtkObject, which adds facilities for associating
35 * a widget with its accessible object.
37 * An accessible implementation for a third-party widget should
38 * derive from #GtkAccessible and implement the suitable interfaces
39 * from ATK, such as #AtkText or #AtkSelection. To establish
40 * the connection between the widget class and its corresponding
41 * acccessible implementation, override the get_accessible vfunc
45 struct _GtkAccessiblePrivate
55 static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible);
57 G_DEFINE_TYPE (GtkAccessible, gtk_accessible, ATK_TYPE_OBJECT)
60 gtk_accessible_set_property (GObject *object,
65 GtkAccessible *accessible = GTK_ACCESSIBLE (object);
70 gtk_accessible_set_widget (accessible, g_value_get_object (value));
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
79 gtk_accessible_get_property (GObject *object,
84 GtkAccessible *accessible = GTK_ACCESSIBLE (object);
85 GtkAccessiblePrivate *priv = accessible->priv;
90 g_value_set_object (value, priv->widget);
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
99 gtk_accessible_init (GtkAccessible *accessible)
101 accessible->priv = G_TYPE_INSTANCE_GET_PRIVATE (accessible,
103 GtkAccessiblePrivate);
107 gtk_accessible_real_widget_set (GtkAccessible *accessible)
112 gtk_accessible_real_widget_unset (GtkAccessible *accessible)
117 gtk_accessible_class_init (GtkAccessibleClass *klass)
119 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
121 klass->connect_widget_destroyed = gtk_accessible_real_connect_widget_destroyed;
122 klass->widget_set = gtk_accessible_real_widget_set;
123 klass->widget_unset = gtk_accessible_real_widget_unset;
125 gobject_class->get_property = gtk_accessible_get_property;
126 gobject_class->set_property = gtk_accessible_set_property;
128 g_object_class_install_property (gobject_class,
130 g_param_spec_object ("widget",
132 P_("The widget referenced by this accessible."),
136 g_type_class_add_private (klass, sizeof (GtkAccessiblePrivate));
140 * gtk_accessible_set_widget:
141 * @accessible: a #GtkAccessible
142 * @widget: (allow-none): a #GtkWidget or %NULL to unset
144 * Sets the #GtkWidget corresponding to the #GtkAccessible.
146 * <note><para>@accessible will not hold a reference to @widget.
147 * It is the caller's responsibility to ensure that when @widget
148 * is destroyed, the widget is unset by calling this function
149 * again with @widget set to %NULL.</para></note>
153 gtk_accessible_set_widget (GtkAccessible *accessible,
156 GtkAccessiblePrivate *priv;
157 GtkAccessibleClass *klass;
159 g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
161 priv = accessible->priv;
162 klass = GTK_ACCESSIBLE_GET_CLASS (accessible);
164 if (priv->widget == widget)
168 klass->widget_unset (accessible);
170 priv->widget = widget;
173 klass->widget_set (accessible);
175 g_object_notify (G_OBJECT (accessible), "widget");
179 * gtk_accessible_get_widget:
180 * @accessible: a #GtkAccessible
182 * Gets the #GtkWidget corresponding to the #GtkAccessible.
183 * The returned widget does not have a reference added, so
184 * you do not need to unref it.
186 * Returns: (transfer none): pointer to the #GtkWidget
187 * corresponding to the #GtkAccessible, or %NULL.
192 gtk_accessible_get_widget (GtkAccessible *accessible)
194 g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), NULL);
196 return accessible->priv->widget;
200 * gtk_accessible_connect_widget_destroyed:
201 * @accessible: a #GtkAccessible
203 * This function specifies the callback function to be called
204 * when the widget corresponding to a GtkAccessible is destroyed.
207 gtk_accessible_connect_widget_destroyed (GtkAccessible *accessible)
209 GtkAccessibleClass *class;
211 g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
213 class = GTK_ACCESSIBLE_GET_CLASS (accessible);
215 if (class->connect_widget_destroyed)
216 class->connect_widget_destroyed (accessible);
220 gtk_accessible_widget_destroyed (GtkWidget *widget,
221 GtkAccessible *accessible)
223 gtk_accessible_set_widget (accessible, NULL);
227 gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible)
229 GtkAccessiblePrivate *priv = accessible->priv;
232 g_signal_connect (priv->widget, "destroy",
233 G_CALLBACK (gtk_accessible_widget_destroyed), accessible);