1 /* ATK - Accessibility Toolkit
2 * Copyright 2001, 2002, 2003 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.
20 #include <atk/atkgobjectaccessible.h>
21 #include <atk/atkregistry.h>
22 #include <atk/atkutil.h>
24 static void atk_gobject_accessible_class_init (AtkGObjectAccessibleClass
*klass
);
25 static void atk_real_gobject_accessible_initialize (AtkObject
*atk_obj
,
27 static void atk_gobject_accessible_dispose (gpointer data
);
29 static GQuark quark_accessible_object
= 0;
30 static GQuark quark_object
= 0;
31 static gpointer parent_class
= NULL
;
34 atk_gobject_accessible_get_type (void)
36 static GType type
= 0;
40 static const GTypeInfo tinfo
=
42 sizeof (AtkGObjectAccessibleClass
),
43 (GBaseInitFunc
) NULL
, /* base init */
44 (GBaseFinalizeFunc
) NULL
, /* base finalize */
45 (GClassInitFunc
) atk_gobject_accessible_class_init
,
46 (GClassFinalizeFunc
) NULL
, /* class finalize */
47 NULL
, /* class data */
48 sizeof (AtkGObjectAccessible
),
50 (GInstanceInitFunc
) NULL
, /* instance init */
51 NULL
/* value table */
54 type
= g_type_register_static (ATK_TYPE_OBJECT
,
55 "AtkGObjectAccessible", &tinfo
, 0);
62 * atk_gobject_accessible_for_object:
65 * Gets the accessible object for the specified @obj.
67 * Returns: (transfer none): a #AtkObject which is the accessible object for
71 atk_gobject_accessible_for_object (GObject
*obj
)
73 AtkObject
* accessible
;
75 g_return_val_if_fail (G_IS_OBJECT (obj
), NULL
);
76 /* See if we have a cached accessible for this object */
78 accessible
= g_object_get_qdata (obj
,
79 quark_accessible_object
);
83 AtkObjectFactory
*factory
;
84 AtkRegistry
*default_registry
;
86 default_registry
= atk_get_default_registry ();
87 factory
= atk_registry_get_factory (default_registry
,
89 accessible
= atk_object_factory_create_accessible (factory
,
91 if (!ATK_IS_GOBJECT_ACCESSIBLE (accessible
))
94 * The AtkObject which was created was not a AtkGObjectAccessible
96 g_object_weak_ref (obj
,
97 (GWeakNotify
) g_object_unref
,
99 if (!quark_accessible_object
)
100 quark_accessible_object
= g_quark_from_static_string ("accessible-object");
102 g_object_set_qdata (obj
, quark_accessible_object
, accessible
);
108 * atk_gobject_accessible_get_object:
109 * @obj: a #AtkGObjectAccessible
111 * Gets the GObject for which @obj is the accessible object.
113 * Returns: (transfer none): a #GObject which is the object for which @obj is
114 * the accessible object
117 atk_gobject_accessible_get_object (AtkGObjectAccessible
*obj
)
119 g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (obj
), NULL
);
121 return g_object_get_qdata (G_OBJECT (obj
), quark_object
);
125 atk_real_gobject_accessible_initialize (AtkObject
*atk_obj
,
128 AtkGObjectAccessible
*atk_gobj
;
130 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (atk_obj
);
132 g_object_set_qdata (G_OBJECT (atk_gobj
), quark_object
, data
);
133 atk_obj
->layer
= ATK_LAYER_WIDGET
;
135 g_object_weak_ref (data
,
136 (GWeakNotify
) atk_gobject_accessible_dispose
,
141 atk_gobject_accessible_dispose (gpointer data
)
145 g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (data
));
147 object
= atk_gobject_accessible_get_object (data
);
149 g_object_set_qdata (object
, quark_accessible_object
, NULL
);
151 g_object_set_qdata (G_OBJECT (data
), quark_object
, NULL
);
152 atk_object_notify_state_change (ATK_OBJECT (data
), ATK_STATE_DEFUNCT
,
154 g_object_unref (data
);
158 atk_gobject_accessible_class_init (AtkGObjectAccessibleClass
*klass
)
160 AtkObjectClass
*class;
162 class = ATK_OBJECT_CLASS (klass
);
164 parent_class
= g_type_class_peek_parent (klass
);
166 class->initialize
= atk_real_gobject_accessible_initialize
;
168 if (!quark_accessible_object
)
169 quark_accessible_object
= g_quark_from_static_string ("accessible-object");
170 quark_object
= g_quark_from_static_string ("object-for-accessible");