1 /* object.c : Glue for overriding vms of AtkObject
2  *
3  * Author: Andres G. Aragoneses  <aaragoneses@novell.com>
4  *
5  * Copyright (c) 2008 Novell, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the Lesser GNU General
9  * Public License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include <atk/atk.h>
23 
24 static const gchar *__prefix = "__gtksharp_";
25 
26 #define HAS_PREFIX(a) (*((guint64 *)(a)) == *((guint64 *) __prefix))
27 
28 static GObjectClass *
get_threshold_class(GObject * obj)29 get_threshold_class (GObject *obj)
30 {
31 	GType gtype = G_TYPE_FROM_INSTANCE (obj);
32 	while (HAS_PREFIX (g_type_name (gtype)))
33 		gtype = g_type_parent (gtype);
34 	GObjectClass *klass = g_type_class_peek (gtype);
35 	if (klass == NULL) klass = g_type_class_ref (gtype);
36 	return klass;
37 }
38 
39 
40 void atksharp_object_override_get_n_children (GType gtype, gpointer cb);
41 
42 int atksharp_object_base_get_n_children (AtkObject *base);
43 
44 void atksharp_object_override_ref_child (GType gtype, gpointer cb);
45 
46 AtkObject *atksharp_object_base_ref_child (AtkObject *base, gint i);
47 
48 void atksharp_object_override_ref_state_set (GType gtype, gpointer cb);
49 
50 AtkStateSet* atksharp_object_base_ref_state_set (AtkObject *base);
51 
52 void atksharp_object_override_get_index_in_parent (GType gtype, gpointer cb);
53 
54 gint atksharp_object_base_get_index_in_parent (AtkObject *base);
55 
56 void atksharp_object_override_ref_relation_set (GType gtype, gpointer cb);
57 
58 AtkRelationSet* atksharp_object_base_ref_relation_set (AtkObject *base);
59 
60 void atksharp_object_override_get_attributes(GType gtype, gpointer cb);
61 
62 AtkAttributeSet* atksharp_object_base_get_attributes (AtkObject *base);
63 
64 void
atksharp_object_override_get_n_children(GType gtype,gpointer cb)65 atksharp_object_override_get_n_children (GType gtype, gpointer cb)
66 {
67 	AtkObjectClass *klass = g_type_class_peek (gtype);
68 	if (!klass)
69 		klass = g_type_class_ref (gtype);
70 	((AtkObjectClass *) klass)->get_n_children = cb;
71 }
72 
73 int
atksharp_object_base_get_n_children(AtkObject * base)74 atksharp_object_base_get_n_children (AtkObject *base)
75 {
76 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (base));
77 	if (parent->get_n_children)
78 		return (*parent->get_n_children) (base);
79 	return 0;
80 }
81 
82 void
atksharp_object_override_ref_child(GType gtype,gpointer cb)83 atksharp_object_override_ref_child (GType gtype, gpointer cb)
84 {
85 	AtkObjectClass *klass = g_type_class_peek (gtype);
86 	if (!klass)
87 		klass = g_type_class_ref (gtype);
88 	((AtkObjectClass *) klass)->ref_child = cb;
89 }
90 
91 AtkObject *
atksharp_object_base_ref_child(AtkObject * base,gint i)92 atksharp_object_base_ref_child (AtkObject *base, gint i)
93 {
94 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (base));
95 	if (parent->ref_child)
96 		return (*parent->ref_child) (base, i);
97 	return NULL;
98 }
99 
100 void
atksharp_object_override_ref_state_set(GType gtype,gpointer cb)101 atksharp_object_override_ref_state_set (GType gtype, gpointer cb)
102 {
103 	AtkObjectClass *klass = g_type_class_peek (gtype);
104 	if (!klass)
105 		klass = g_type_class_ref (gtype);
106 	((AtkObjectClass *) klass)->ref_state_set = cb;
107 }
108 
109 AtkStateSet*
atksharp_object_base_ref_state_set(AtkObject * atk_obj)110 atksharp_object_base_ref_state_set (AtkObject *atk_obj)
111 {
112 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (atk_obj));
113 	if (parent->ref_state_set)
114 		return (*parent->ref_state_set) (atk_obj);
115 	return NULL;
116 }
117 
118 void
atksharp_object_override_get_index_in_parent(GType gtype,gpointer cb)119 atksharp_object_override_get_index_in_parent (GType gtype, gpointer cb)
120 {
121 	AtkObjectClass *klass = g_type_class_peek (gtype);
122 	if (!klass)
123 		klass = g_type_class_ref (gtype);
124 	((AtkObjectClass *) klass)->get_index_in_parent = cb;
125 }
126 
127 gint
atksharp_object_base_get_index_in_parent(AtkObject * atk_obj)128 atksharp_object_base_get_index_in_parent (AtkObject *atk_obj)
129 {
130 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (atk_obj));
131 	if (parent->get_index_in_parent)
132 		return (*parent->get_index_in_parent) (atk_obj);
133 	return -1;
134 }
135 
136 void
atksharp_object_override_ref_relation_set(GType gtype,gpointer cb)137 atksharp_object_override_ref_relation_set (GType gtype, gpointer cb)
138 {
139 	AtkObjectClass *klass = g_type_class_peek (gtype);
140 	if (!klass)
141 		klass = g_type_class_ref (gtype);
142 	((AtkObjectClass *) klass)->ref_relation_set = cb;
143 }
144 
145 AtkRelationSet*
atksharp_object_base_ref_relation_set(AtkObject * atk_obj)146 atksharp_object_base_ref_relation_set (AtkObject *atk_obj)
147 {
148 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (atk_obj));
149 	if (parent->ref_relation_set)
150 		return (*parent->ref_relation_set) (atk_obj);
151 	return NULL;
152 }
153 
154 
155 void
atksharp_object_override_get_attributes(GType gtype,gpointer cb)156 atksharp_object_override_get_attributes (GType gtype, gpointer cb)
157 {
158 	AtkObjectClass *klass = g_type_class_peek (gtype);
159 	if (!klass)
160 		klass = g_type_class_ref (gtype);
161 	((AtkObjectClass *) klass)->get_attributes = cb;
162 }
163 
164 AtkAttributeSet*
atksharp_object_base_get_attributes(AtkObject * base)165 atksharp_object_base_get_attributes (AtkObject *base)
166 {
167 	AtkObjectClass *parent = (AtkObjectClass *)get_threshold_class (G_OBJECT (base));
168 	if (parent->get_attributes)
169 		return (*parent->get_attributes) (base);
170 	return NULL;
171 }
172