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 <atk/atk.h>
24
#include <stdio.h>
25
#include <string.h>
26

            
27
#include "my-atk-object.h"
28

            
29
#include "my-atk-component.h"
30

            
31
typedef struct _MyAtkComponentInfo MyAtkComponentInfo;
32

            
33
static void atk_component_interface_init (AtkComponentIface *iface);
34

            
35
9
G_DEFINE_TYPE_WITH_CODE (MyAtkComponent,
36
                         my_atk_component,
37
                         MY_TYPE_ATK_OBJECT,
38
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
39
                                                atk_component_interface_init));
40

            
41
void
42
27
my_atk_component_set_layer (AtkComponent *component,
43
                            AtkLayer layer)
44
{
45
27
  g_return_if_fail (MY_IS_ATK_COMPONENT (component));
46

            
47
27
  MyAtkComponent *self = MY_ATK_COMPONENT (component);
48
27
  self->layer = layer;
49
}
50

            
51
void
52
27
my_atk_component_set_mdi_zorder (AtkComponent *component,
53
                                 gint mdi_zorder)
54
{
55
27
  g_return_if_fail (MY_IS_ATK_COMPONENT (component));
56

            
57
27
  MyAtkComponent *self = MY_ATK_COMPONENT (component);
58
27
  self->zorder = mdi_zorder;
59
}
60

            
61
void
62
27
my_atk_component_set_alpha (AtkComponent *component,
63
                            gdouble alpha)
64
{
65

            
66
27
  g_return_if_fail (MY_IS_ATK_COMPONENT (component));
67

            
68
27
  MyAtkComponent *self = MY_ATK_COMPONENT (component);
69
27
  self->alpha = alpha;
70
}
71

            
72
static void
73
5
my_atk_component_get_extents (AtkComponent *component,
74
                              gint *width,
75
                              gint *height,
76
                              gint *x,
77
                              gint *y,
78
                              AtkCoordType coord_type)
79
{
80
5
  g_return_if_fail (MY_IS_ATK_COMPONENT (component));
81

            
82
5
  MyAtkComponent *self = MY_ATK_COMPONENT (component);
83
5
  *width = self->extent.width;
84
5
  *height = self->extent.height;
85
5
  *x = self->extent.x;
86
5
  *y = self->extent.y;
87
}
88

            
89
static gboolean
90
28
my_atk_component_set_extents (AtkComponent *component,
91
                              gint x,
92
                              gint y,
93
                              gint width,
94
                              gint height,
95
                              AtkCoordType coord_type)
96
{
97
28
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), FALSE);
98

            
99
28
  MyAtkComponent *self = MY_ATK_COMPONENT (component);
100

            
101
28
  if (self->extent_may_change)
102
    {
103
28
      self->extent.width = width;
104
28
      self->extent.height = height;
105
28
      self->extent.x = x;
106
28
      self->extent.y = y;
107
28
      return TRUE;
108
    }
109
  return FALSE;
110
}
111

            
112
static gboolean
113
2
my_atk_component_contains (AtkComponent *component,
114
                           gint c_x,
115
                           gint c_y,
116
                           AtkCoordType coord_type)
117
{
118
2
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), FALSE);
119

            
120
  gint x, y, w, h;
121
2
  my_atk_component_get_extents (component, &x, &y, &w, &h, coord_type);
122

            
123
2
  if ((c_x >= x) && (c_y >= y) && (c_x < x + w) && (c_y < y + h))
124
2
    return TRUE;
125
  else
126
    return FALSE;
127
}
128

            
129
static AtkObject *
130
1
my_atk_component_ref_accessible_at_point (AtkComponent *component,
131
                                          gint x,
132
                                          gint y,
133
                                          AtkCoordType coord_type)
134
{
135
1
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), NULL);
136

            
137
  gint count, i;
138
1
  count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
139

            
140
1
  for (i = 0; i < count; i++)
141
    {
142
      AtkObject *obj;
143
1
      obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
144

            
145
1
      if (obj != NULL)
146
        {
147
1
          if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
148
1
            return obj;
149
          else
150
            g_object_unref (obj);
151
        }
152
    }
153
  return NULL;
154
}
155

            
156
static gboolean
157
1
my_atk_component_grab_focus (AtkComponent *component)
158
{
159
1
  return TRUE;
160
}
161

            
162
static AtkLayer
163
1
my_atk_component_get_layer (AtkComponent *component)
164
{
165
1
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
166

            
167
1
  return MY_ATK_COMPONENT (component)->layer;
168
}
169

            
170
static gint
171
1
my_atk_component_get_mdi_zorder (AtkComponent *component)
172
{
173
1
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
174

            
175
1
  return MY_ATK_COMPONENT (component)->zorder;
176
}
177

            
178
static gdouble
179
1
my_atk_component_get_alpha (AtkComponent *component)
180
{
181
1
  g_return_val_if_fail (MY_IS_ATK_COMPONENT (component), -1);
182

            
183
1
  return MY_ATK_COMPONENT (component)->alpha;
184
}
185

            
186
static void
187
9
atk_component_interface_init (AtkComponentIface *iface)
188
{
189
9
  g_return_if_fail (iface);
190

            
191
9
  iface->add_focus_handler = NULL;
192
9
  iface->contains = my_atk_component_contains;
193
9
  iface->ref_accessible_at_point = my_atk_component_ref_accessible_at_point;
194
9
  iface->get_extents = my_atk_component_get_extents;
195
9
  iface->get_position = NULL;
196
9
  iface->get_size = NULL;
197
9
  iface->grab_focus = my_atk_component_grab_focus;
198
9
  iface->remove_focus_handler = NULL;
199
9
  iface->set_extents = my_atk_component_set_extents;
200
9
  iface->set_position = NULL;
201
9
  iface->set_size = NULL;
202
9
  iface->get_layer = my_atk_component_get_layer;
203
9
  iface->get_mdi_zorder = my_atk_component_get_mdi_zorder;
204
9
  iface->bounds_changed = NULL;
205
9
  iface->get_alpha = my_atk_component_get_alpha;
206
}
207

            
208
static void
209
my_atk_component_initialize (AtkObject *obj, gpointer data)
210
{
211
}
212

            
213
static void
214
my_atk_component_finalize (GObject *object)
215
{
216
}
217

            
218
static void
219
27
my_atk_component_init (MyAtkComponent *obj)
220
{
221
27
  obj->extent.x = 0;
222
27
  obj->extent.y = 0;
223
27
  obj->extent.width = 0;
224
27
  obj->extent.height = 0;
225
27
  obj->extent_may_change = TRUE;
226
27
  obj->layer = ATK_LAYER_BACKGROUND;
227
27
  obj->zorder = -1;
228
27
  obj->alpha = 1.0;
229
27
}
230

            
231
static void
232
9
my_atk_component_class_init (MyAtkComponentClass *my_class)
233
{
234
9
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
235
9
  GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
236

            
237
9
  gobject_class->finalize = my_atk_component_finalize;
238

            
239
9
  atk_class->initialize = my_atk_component_initialize;
240
9
}