]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccessible.c
Merge branch 'bgo593793-filechooser-recent-folders-master'
[~andy/gtk] / gtk / gtkaccessible.c
1 /* GTK - The GIMP Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include <string.h>
22
23 #include "gtkwidget.h"
24 #include "gtkintl.h"
25 #include "gtkaccessible.h"
26
27 /**
28  * SECTION:gtkaccessible
29  * @Short_description: Accessibility support for widgets
30  * @Title: GtkAccessible
31  *
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.
36  *
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
42  * in #GtkWidgetClass.
43  */
44
45 struct _GtkAccessiblePrivate
46 {
47   GtkWidget *widget;
48 };
49
50 static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible);
51
52 G_DEFINE_TYPE (GtkAccessible, gtk_accessible, ATK_TYPE_OBJECT)
53
54 static void
55 gtk_accessible_init (GtkAccessible *accessible)
56 {
57   accessible->priv = G_TYPE_INSTANCE_GET_PRIVATE (accessible,
58                                                   GTK_TYPE_ACCESSIBLE,
59                                                   GtkAccessiblePrivate);
60 }
61
62 static void
63 gtk_accessible_class_init (GtkAccessibleClass *klass)
64 {
65   klass->connect_widget_destroyed = gtk_accessible_real_connect_widget_destroyed;
66
67   g_type_class_add_private (klass, sizeof (GtkAccessiblePrivate));
68 }
69
70 /**
71  * gtk_accessible_set_widget:
72  * @accessible: a #GtkAccessible
73  * @widget: a #GtkWidget
74  *
75  * Sets the #GtkWidget corresponding to the #GtkAccessible.
76  *
77  * Since: 2.22
78  */
79 void
80 gtk_accessible_set_widget (GtkAccessible *accessible,
81                            GtkWidget     *widget)
82 {
83   g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
84
85   accessible->priv->widget = widget;
86 }
87
88 /**
89  * gtk_accessible_get_widget:
90  * @accessible: a #GtkAccessible
91  *
92  * Gets the #GtkWidget corresponding to the #GtkAccessible.
93  * The returned widget does not have a reference added, so
94  * you do not need to unref it.
95  *
96  * Returns: (transfer none): pointer to the #GtkWidget
97  *     corresponding to the #GtkAccessible, or %NULL.
98  *
99  * Since: 2.22
100  */
101 GtkWidget*
102 gtk_accessible_get_widget (GtkAccessible *accessible)
103 {
104   g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), NULL);
105
106   return accessible->priv->widget;
107 }
108
109 /**
110  * gtk_accessible_connect_widget_destroyed:
111  * @accessible: a #GtkAccessible
112  *
113  * This function specifies the callback function to be called
114  * when the widget corresponding to a GtkAccessible is destroyed.
115  */
116 void
117 gtk_accessible_connect_widget_destroyed (GtkAccessible *accessible)
118 {
119   GtkAccessibleClass *class;
120
121   g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
122
123   class = GTK_ACCESSIBLE_GET_CLASS (accessible);
124
125   if (class->connect_widget_destroyed)
126     class->connect_widget_destroyed (accessible);
127 }
128
129 static void
130 gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible)
131 {
132   GtkAccessiblePrivate *priv = accessible->priv;
133
134   if (priv->widget)
135     g_signal_connect (priv->widget, "destroy",
136                       G_CALLBACK (gtk_widget_destroyed), &priv->widget);
137 }