1 /*
2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4 *
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <atk/atk.h>
26
27 #include "my-atk-object.h"
28 #include "my-atk-component.h"
29
30 typedef struct _MyAtkComponentInfo MyAtkComponentInfo;
31
32 static void atk_component_interface_init (AtkComponentIface *iface);
33
34 G_DEFINE_TYPE_WITH_CODE (MyAtkComponent,
35 my_atk_component,
36 MY_TYPE_ATK_OBJECT,
37 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
38 atk_component_interface_init));
39
40 void
my_atk_component_set_layer(AtkComponent * component,AtkLayer layer)41 my_atk_component_set_layer (AtkComponent *component,
42 AtkLayer layer)
43 {
44 g_return_if_fail (MY_IS_ATK_COMPONENT (component));
45
46 MyAtkComponent *self = MY_ATK_COMPONENT (component);
47 self->layer = layer;
48 }
49
50 void
my_atk_component_set_mdi_zorder(AtkComponent * component,gint mdi_zorder)51 my_atk_component_set_mdi_zorder (AtkComponent *component,
52 gint mdi_zorder)
53 {
54 g_return_if_fail (MY_IS_ATK_COMPONENT (component));
55
56 MyAtkComponent *self = MY_ATK_COMPONENT (component);
57 self->zorder = mdi_zorder;
58 }
59
60 void
my_atk_component_set_alpha(AtkComponent * component,gdouble alpha)61 my_atk_component_set_alpha (AtkComponent *component,
62 gdouble alpha)
63 {
64
65 g_return_if_fail (MY_IS_ATK_COMPONENT (component));
66
67 MyAtkComponent *self = MY_ATK_COMPONENT (component);
68 self->alpha = alpha;
69 }
70
71 static void
my_atk_component_get_extents(AtkComponent * component,gint * width,gint * height,gint * x,gint * y,AtkCoordType coord_type)72 my_atk_component_get_extents (AtkComponent *component,
73 gint *width,
74 gint *height,
75 gint *x,
76 gint *y,
77 AtkCoordType coord_type)
78 {
79 g_return_if_fail (MY_IS_ATK_COMPONENT (component));
80
81 MyAtkComponent *self = MY_ATK_COMPONENT (component);
82 *width = self->extent.width;
83 *height = self->extent.height;
84 *x = self->extent.x;
85 *y = self->extent.y;
86 }
87
88 static gboolean
my_atk_component_set_extents(AtkComponent * component,gint x,gint y,gint width,gint height,AtkCoordType coord_type)89 my_atk_component_set_extents (AtkComponent *component,
90 gint x,
91 gint y,
92 gint width,
93 gint height,
94 AtkCoordType coord_type)
95 {
96 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), FALSE);
97
98 MyAtkComponent *self = MY_ATK_COMPONENT (component);
99
100 if (self->extent_may_change) {
101 self->extent.width = width;
102 self->extent.height = height;
103 self->extent.x = x;
104 self->extent.y = y;
105 return TRUE;
106 }
107 return FALSE;
108 }
109
110 static gboolean
my_atk_component_contains(AtkComponent * component,gint c_x,gint c_y,AtkCoordType coord_type)111 my_atk_component_contains (AtkComponent *component,
112 gint c_x,
113 gint c_y,
114 AtkCoordType coord_type)
115 {
116 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), FALSE);
117
118 gint x, y, w, h;
119 my_atk_component_get_extents (component, &x, &y, &w, &h, coord_type);
120
121 if ((c_x >= x) && (c_y >= y) && (c_x < x + w) && (c_y < y + h))
122 return TRUE;
123 else
124 return FALSE;
125 }
126
127 static AtkObject *
my_atk_component_ref_accessible_at_point(AtkComponent * component,gint x,gint y,AtkCoordType coord_type)128 my_atk_component_ref_accessible_at_point (AtkComponent *component,
129 gint x,
130 gint y,
131 AtkCoordType coord_type)
132 {
133 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), NULL);
134
135 gint count,i;
136 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
137
138 for (i = 0; i < count; i++) {
139 AtkObject *obj;
140 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
141
142 if (obj != NULL) {
143 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
144 return obj;
145 else
146 g_object_unref (obj);
147 }
148 }
149 return NULL;
150 }
151
152 static gboolean
my_atk_component_grab_focus(AtkComponent * component)153 my_atk_component_grab_focus (AtkComponent *component)
154 {
155 return TRUE;
156 }
157
158 static AtkLayer
my_atk_component_get_layer(AtkComponent * component)159 my_atk_component_get_layer (AtkComponent *component)
160 {
161 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
162
163 return MY_ATK_COMPONENT (component)->layer;
164 }
165
166 static gint
my_atk_component_get_mdi_zorder(AtkComponent * component)167 my_atk_component_get_mdi_zorder (AtkComponent *component)
168 {
169 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
170
171 return MY_ATK_COMPONENT (component)->zorder;
172 }
173
174 static gdouble
my_atk_component_get_alpha(AtkComponent * component)175 my_atk_component_get_alpha (AtkComponent *component)
176 {
177 g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
178
179 return MY_ATK_COMPONENT (component)->alpha;
180 }
181
182 static void
atk_component_interface_init(AtkComponentIface * iface)183 atk_component_interface_init (AtkComponentIface *iface)
184 {
185 g_return_if_fail (iface);
186
187 iface->add_focus_handler = NULL;
188 iface->contains = my_atk_component_contains;
189 iface->ref_accessible_at_point = my_atk_component_ref_accessible_at_point;
190 iface->get_extents = my_atk_component_get_extents;
191 iface->get_position = NULL;
192 iface->get_size = NULL;
193 iface->grab_focus = my_atk_component_grab_focus;
194 iface->remove_focus_handler = NULL;
195 iface->set_extents = my_atk_component_set_extents;
196 iface->set_position = NULL;
197 iface->set_size = NULL;
198 iface->get_layer = my_atk_component_get_layer;
199 iface->get_mdi_zorder = my_atk_component_get_mdi_zorder;
200 iface->bounds_changed = NULL;
201 iface->get_alpha = my_atk_component_get_alpha;
202 }
203
204 static void
my_atk_component_initialize(AtkObject * obj,gpointer data)205 my_atk_component_initialize (AtkObject *obj, gpointer data)
206 {
207 }
208
209 static void
my_atk_component_finalize(GObject * object)210 my_atk_component_finalize (GObject *object)
211 {
212 }
213
214 static void
my_atk_component_init(MyAtkComponent * obj)215 my_atk_component_init(MyAtkComponent *obj)
216 {
217 obj->extent.x = 0;
218 obj->extent.y = 0;
219 obj->extent.width = 0;
220 obj->extent.height = 0;
221 obj->extent_may_change = TRUE;
222 obj->layer = ATK_LAYER_BACKGROUND;
223 obj->zorder = -1;
224 obj->alpha = 1.0;
225 }
226
227 static void
my_atk_component_class_init(MyAtkComponentClass * my_class)228 my_atk_component_class_init (MyAtkComponentClass *my_class)
229 {
230 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
231 GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
232
233 gobject_class->finalize = my_atk_component_finalize;
234
235 atk_class->initialize = my_atk_component_initialize;
236 }
237