]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccessible.c
Merge bgo593793-filechooser-recent-folders-master branch.
[~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
33 /*
34  * GtkAccessiblePriv:
35  * @widget: The GtkWidget whose properties and features are exported via this
36  *   accessible instance
37  */
38 struct _GtkAccessiblePrivate
39 {
40   GtkWidget *widget;
41 };
42
43 static void gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible);
44
45 G_DEFINE_TYPE (GtkAccessible, gtk_accessible, ATK_TYPE_OBJECT)
46
47 static void
48 gtk_accessible_init (GtkAccessible *accessible)
49 {
50   accessible->priv = G_TYPE_INSTANCE_GET_PRIVATE (accessible,
51                                                   GTK_TYPE_ACCESSIBLE,
52                                                   GtkAccessiblePrivate);
53 }
54
55 static void
56 gtk_accessible_class_init (GtkAccessibleClass *klass)
57 {
58   klass->connect_widget_destroyed = gtk_accessible_real_connect_widget_destroyed;
59
60   g_type_class_add_private (klass, sizeof (GtkAccessiblePrivate));
61 }
62
63 /**
64  * gtk_accessible_set_widget:
65  * @accessible: a #GtkAccessible
66  * @widget: a #GtkWidget
67  *
68  * Sets the #GtkWidget corresponding to the #GtkAccessible.
69  *
70  * Since: 2.22
71  **/
72 void
73 gtk_accessible_set_widget (GtkAccessible *accessible,
74                            GtkWidget     *widget)
75 {
76   g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
77
78   accessible->priv->widget = widget;
79 }
80
81 /**
82  * gtk_accessible_get_widget:
83  * @accessible: a #GtkAccessible
84  *
85  * Gets the #GtkWidget corresponding to the #GtkAccessible. The returned widget
86  * does not have a reference added, so you do not need to unref it.
87  *
88  * Returns: (transfer none): pointer to the #GtkWidget corresponding to
89  *   the #GtkAccessible, or %NULL.
90  *
91  * Since: 2.22
92  **/
93 GtkWidget*
94 gtk_accessible_get_widget (GtkAccessible *accessible)
95 {
96   g_return_val_if_fail (GTK_IS_ACCESSIBLE (accessible), NULL);
97
98   return accessible->priv->widget;
99 }
100
101 /**
102  * gtk_accessible_connect_widget_destroyed
103  * @accessible: a #GtkAccessible
104  *
105  * This function specifies the callback function to be called when the widget
106  * corresponding to a GtkAccessible is destroyed.
107  */
108 void
109 gtk_accessible_connect_widget_destroyed (GtkAccessible *accessible)
110 {
111   GtkAccessibleClass *class;
112
113   g_return_if_fail (GTK_IS_ACCESSIBLE (accessible));
114
115   class = GTK_ACCESSIBLE_GET_CLASS (accessible);
116
117   if (class->connect_widget_destroyed)
118     class->connect_widget_destroyed (accessible);
119 }
120
121 static void
122 gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible)
123 {
124   GtkAccessiblePrivate *priv = accessible->priv;
125
126   if (priv->widget)
127     g_signal_connect (priv->widget, "destroy",
128                       G_CALLBACK (gtk_widget_destroyed), &priv->widget);
129 }
130
131 /*
132  * _gtk_accessible_set_factory_type:
133  * @widget_type: a #GtkWidget subtype
134  * @factory_type: a #AtkObjectFactory subtype
135  *
136  * A wrapper around atk_registry_set_factory_type().
137  *
138  * Only installs the factory if accessibility is
139  * enabled.
140  */
141 void
142 _gtk_accessible_set_factory_type (GType widget_type,
143                                   GType factory_type)
144 {
145   AtkObjectFactory *factory;
146   AtkRegistry *registry;
147   GType accessible_type;
148
149   /*
150    * Figure out whether accessibility is enabled by looking
151    * at the type of the accessible object which would be created
152    * for GtkWidget.
153    */
154   registry = atk_get_default_registry ();
155   factory = atk_registry_get_factory (registry, GTK_TYPE_WIDGET);
156   accessible_type = atk_object_factory_get_accessible_type (factory);
157   if (g_type_is_a (accessible_type, GTK_TYPE_ACCESSIBLE))
158     atk_registry_set_factory_type (registry, widget_type, factory_type);
159 }
160