Provide default implementation for atk_component_get_accessible_at_point().
[platform/upstream/atk.git] / atk / atkcomponent.c
1 /* ATK -  Accessibility 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
21 #include "atkcomponent.h"
22
23 static AtkObject* atk_component_real_get_accessible_at_point (AtkComponent *component,
24                                                               gint         x,
25                                                               gint         y);
26
27 GType
28 atk_component_get_type ()
29 {
30   static GType type = 0;
31
32   if (!type) {
33     static const GTypeInfo tinfo =
34     {
35       sizeof (AtkComponentIface),
36       NULL,
37       NULL,
38
39     };
40
41     type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
42   }
43
44   return type;
45 }
46
47 /**
48  *
49  **/
50 guint
51 atk_component_add_focus_handler (AtkComponent    *component,
52                                  AtkFocusHandler handler)
53 {
54   AtkComponentIface *iface = NULL;
55   g_return_val_if_fail (component != NULL, 0);
56   g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
57
58   iface = ATK_COMPONENT_GET_IFACE (component);
59
60   if (iface->add_focus_handler)
61     return (iface->add_focus_handler) (component, handler);
62   else
63     return 0;
64 }
65
66 /**
67  *
68  **/
69 void
70 atk_component_remove_focus_handler (AtkComponent    *component,
71                                     guint           handler_id)
72 {
73   AtkComponentIface *iface = NULL;
74   g_return_if_fail (component != NULL);
75   g_return_if_fail (ATK_IS_COMPONENT (component));
76
77   iface = ATK_COMPONENT_GET_IFACE (component);
78
79   if (iface->remove_focus_handler)
80     (iface->remove_focus_handler) (component, handler_id);
81 }
82
83 gboolean
84 atk_component_contains (AtkComponent    *component,
85                         gint            x,
86                         gint            y)
87 {
88   AtkComponentIface *iface = NULL;
89   g_return_val_if_fail (component != NULL, FALSE);
90   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
91
92   iface = ATK_COMPONENT_GET_IFACE (component);
93
94   if (iface->contains)
95     return (iface->contains) (component, x, y);
96   else
97     return FALSE;
98 }
99
100 AtkObject*
101 atk_component_get_accessible_at_point (AtkComponent    *component,
102                                        gint            x,
103                                        gint            y)
104 {
105   AtkComponentIface *iface = NULL;
106   g_return_val_if_fail (component != NULL, NULL);
107   g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
108
109   iface = ATK_COMPONENT_GET_IFACE (component);
110
111   if (iface->get_accessible_at_point)
112     return (iface->get_accessible_at_point) (component, x, y);
113   else
114   {
115     /*
116      * if this method is not overridden use the default implementation.
117      */
118     return atk_component_real_get_accessible_at_point (component, x, y);
119   }
120 }
121
122 void
123 atk_component_get_extents    (AtkComponent    *component,
124                               gint            *x,
125                               gint            *y,
126                               gint            *width,
127                               gint            *height)
128 {
129   AtkComponentIface *iface = NULL;
130   g_return_if_fail (component != NULL);
131   g_return_if_fail (ATK_IS_COMPONENT (component));
132
133   iface = ATK_COMPONENT_GET_IFACE (component);
134
135   if (iface->get_extents)
136     (iface->get_extents) (component, x, y, width, height);
137 }
138
139 void
140 atk_component_get_position   (AtkComponent    *component,
141                               gint            *x,
142                               gint            *y)
143 {
144   AtkComponentIface *iface = NULL;
145   g_return_if_fail (component != NULL);
146   g_return_if_fail (ATK_IS_COMPONENT (component));
147
148   iface = ATK_COMPONENT_GET_IFACE (component);
149
150   if (iface->get_position)
151     (iface->get_position) (component, x, y);
152 }
153
154 void
155 atk_component_get_position_on_screen (AtkComponent    *component,
156                                       gint            *x,
157                                       gint            *y)
158 {
159   AtkComponentIface *iface = NULL;
160   g_return_if_fail (component != NULL);
161   g_return_if_fail (ATK_IS_COMPONENT (component));
162
163   iface = ATK_COMPONENT_GET_IFACE (component);
164
165   if (iface->get_position_on_screen)
166     return (iface->get_position_on_screen) (component, x, y);
167 }
168
169 void
170 atk_component_get_size       (AtkComponent    *component,
171                               gint            *x,
172                               gint            *y)
173 {
174   AtkComponentIface *iface = NULL;
175   g_return_if_fail (component != NULL);
176   g_return_if_fail (ATK_IS_COMPONENT (component));
177
178   iface = ATK_COMPONENT_GET_IFACE (component);
179
180   if (iface->get_size)
181     (iface->get_size) (component, x, y);
182 }
183
184 void
185 atk_component_grab_focus (AtkComponent    *component)
186 {
187   AtkComponentIface *iface = NULL;
188   g_return_if_fail (component != NULL);
189   g_return_if_fail (ATK_IS_COMPONENT (component));
190
191   iface = ATK_COMPONENT_GET_IFACE (component);
192
193   if (iface->grab_focus)
194     (iface->grab_focus) (component);
195 }
196
197 void
198 atk_component_set_extents   (AtkComponent    *component,
199                              gint            x,
200                              gint            y,
201                              gint            width,
202                              gint            height)
203 {
204   AtkComponentIface *iface = NULL;
205   g_return_if_fail (component != NULL);
206   g_return_if_fail (ATK_IS_COMPONENT (component));
207
208   iface = ATK_COMPONENT_GET_IFACE (component);
209
210   if (iface->set_extents)
211     (iface->set_extents) (component, x, y, width, height);
212 }
213
214 void
215 atk_component_set_position   (AtkComponent    *component,
216                               gint            x,
217                               gint            y)
218 {
219   AtkComponentIface *iface = NULL;
220   g_return_if_fail (component != NULL);
221   g_return_if_fail (ATK_IS_COMPONENT (component));
222
223   iface = ATK_COMPONENT_GET_IFACE (component);
224
225   if (iface->set_position)
226     (iface->set_position) (component, x, y);
227 }
228
229 void
230 atk_component_set_size       (AtkComponent    *component,
231                               gint            x,
232                               gint            y)
233 {
234   AtkComponentIface *iface = NULL;
235   g_return_if_fail (component != NULL);
236   g_return_if_fail (ATK_IS_COMPONENT (component));
237
238   iface = ATK_COMPONENT_GET_IFACE (component);
239
240   if (iface->set_size)
241     (iface->set_size) (component, x, y);
242 }
243
244 static AtkObject* 
245 atk_component_real_get_accessible_at_point (AtkComponent *component,
246                                             gint         x,
247                                             gint         y)
248 {
249   gint count, i;
250
251   count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
252
253   g_return_val_if_fail (count != 0, NULL);
254
255   for (i = 0; i < count; i++)
256   {
257     AtkObject *obj;
258
259     obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
260
261     if (obj != NULL)
262     {
263       if (atk_component_contains (ATK_COMPONENT (obj), x, y))
264       {
265         g_object_unref (obj);
266         return obj;
267       }
268       else
269       {
270         g_object_unref (obj);
271       }
272     }
273   }
274   return NULL;
275 }