File: cally-root.c

package info (click to toggle)
clutter-1.0 1.26.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,352 kB
  • sloc: ansic: 128,533; sh: 5,580; xml: 1,641; makefile: 1,613; ruby: 149; perl: 142; sed: 16
file content (294 lines) | stat: -rw-r--r-- 8,887 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* CALLY - The Clutter Accessibility Implementation Library
 *
 * Copyright (C) 2008 Igalia, S.L.
 *
 * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:cally-root
 * @short_description: Root object for the Cally toolkit
 * @see_also: #ClutterStage
 *
 * #CallyRoot is the root object of the accessibility tree-like
 * hierarchy, exposing the application level.
 *
 * Somewhat equivalent to #GailTopLevel. We consider that this class
 * expose the a11y information of the #ClutterStageManager, as the
 * children of this object are the different ClutterStage managed (so
 * the #GObject used in the atk_object_initialize() is the
 * #ClutterStageManager).
 */

#include "config.h"

#include "cally-root.h"

#include "clutter-actor.h"
#include "clutter-stage-private.h"
#include "clutter-stage-manager.h"


/* GObject */
static void cally_root_finalize   (GObject *object);

/* AtkObject.h */
static void             cally_root_initialize           (AtkObject *accessible,
                                                         gpointer   data);
static gint             cally_root_get_n_children       (AtkObject *obj);
static AtkObject *      cally_root_ref_child            (AtkObject *obj,
                                                         gint i);
static AtkObject *      cally_root_get_parent           (AtkObject *obj);
static const char *     cally_root_get_name             (AtkObject *obj);

/* Private */
static void             cally_util_stage_added_cb       (ClutterStageManager *stage_manager,
                                                         ClutterStage *stage,
                                                         gpointer data);
static void             cally_util_stage_removed_cb     (ClutterStageManager *stage_manager,
                                                         ClutterStage *stage,
                                                         gpointer data);

struct _CallyRootPrivate
{
/* We save the CallyStage objects. Other option could save the stage
 * list, and then just get the a11y object on the ref_child, etc. But
 * the ref_child is more common that the init and the stage-add,
 * stage-remove, so we avoid getting the accessible object
 * constantly
 */
  GSList *stage_list;

  /* signals id */
  guint stage_added_id;
  guint stage_removed_id;
};

G_DEFINE_TYPE_WITH_PRIVATE (CallyRoot, cally_root,  ATK_TYPE_GOBJECT_ACCESSIBLE)

static void
cally_root_class_init (CallyRootClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

  gobject_class->finalize = cally_root_finalize;

  /* AtkObject */
  class->get_n_children = cally_root_get_n_children;
  class->ref_child = cally_root_ref_child;
  class->get_parent = cally_root_get_parent;
  class->initialize = cally_root_initialize;
  class->get_name = cally_root_get_name;
}

static void
cally_root_init (CallyRoot *root)
{
  root->priv = cally_root_get_instance_private (root);

  root->priv->stage_list = NULL;
  root->priv->stage_added_id = 0;
  root->priv->stage_removed_id = 0;
}

/**
 * cally_root_new:
 *
 * Creates a new #CallyRoot object.
 *
 * Return value: the newly created #AtkObject
 *
 * Since: 1.4
 */
AtkObject*
cally_root_new (void)
{
  GObject *object = NULL;
  AtkObject *accessible = NULL;
  ClutterStageManager *stage_manager = NULL;

  object = g_object_new (CALLY_TYPE_ROOT, NULL);

  accessible = ATK_OBJECT (object);
  stage_manager = clutter_stage_manager_get_default ();

  atk_object_initialize (accessible, stage_manager);

  return accessible;
}

static void
cally_root_finalize (GObject *object)
{
  CallyRoot *root = CALLY_ROOT (object);
  GObject *stage_manager = NULL;

  g_return_if_fail (CALLY_IS_ROOT (object));

  if (root->priv->stage_list)
    {
      g_slist_free (root->priv->stage_list);
      root->priv->stage_list = NULL;
    }

  stage_manager = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (root));

  g_signal_handler_disconnect (stage_manager,
                               root->priv->stage_added_id);

  g_signal_handler_disconnect (stage_manager,
                               root->priv->stage_added_id);

  G_OBJECT_CLASS (cally_root_parent_class)->finalize (object);
}

/* AtkObject.h */
static void
cally_root_initialize (AtkObject              *accessible,
                       gpointer                data)
{
  ClutterStageManager *stage_manager = NULL;
  const GSList        *iter          = NULL;
  const GSList        *stage_list    = NULL;
  ClutterStage        *clutter_stage = NULL;
  AtkObject           *cally_stage   = NULL;
  CallyRoot           *root          = NULL;

  accessible->role = ATK_ROLE_APPLICATION;
  accessible->accessible_parent = NULL;

  /* children initialization */
  root = CALLY_ROOT (accessible);
  stage_manager = CLUTTER_STAGE_MANAGER (data);
  stage_list = clutter_stage_manager_peek_stages (stage_manager);

  for (iter = stage_list; iter != NULL; iter = g_slist_next (iter))
    {
      clutter_stage = CLUTTER_STAGE (iter->data);
      cally_stage = clutter_actor_get_accessible (CLUTTER_ACTOR (clutter_stage));

      atk_object_set_parent (cally_stage, ATK_OBJECT (root));

      root->priv->stage_list = g_slist_append (root->priv->stage_list,
                                               cally_stage);
    }

  root->priv->stage_added_id =
    g_signal_connect (G_OBJECT (stage_manager), "stage-added",
                      G_CALLBACK (cally_util_stage_added_cb), root);

  root->priv->stage_removed_id =
    g_signal_connect (G_OBJECT (stage_manager), "stage-removed",
                      G_CALLBACK (cally_util_stage_removed_cb), root);

  ATK_OBJECT_CLASS (cally_root_parent_class)->initialize (accessible, data);
}


static gint
cally_root_get_n_children (AtkObject *obj)
{
  CallyRoot *root = CALLY_ROOT (obj);

  return g_slist_length (root->priv->stage_list);
}

static AtkObject*
cally_root_ref_child (AtkObject *obj,
                     gint i)
{
  CallyRoot *cally_root = NULL;
  GSList *stage_list = NULL;
  gint num = 0;
  AtkObject *item = NULL;

  cally_root = CALLY_ROOT (obj);
  stage_list = cally_root->priv->stage_list;
  num = g_slist_length (stage_list);

  g_return_val_if_fail ((i < num)&&(i >= 0), NULL);

  item = g_slist_nth_data (stage_list, i);
  if (!item)
    {
      return NULL;
    }

  g_object_ref (item);

  return item;
}

static AtkObject*
cally_root_get_parent (AtkObject *obj)
{
  return NULL;
}

static const char *
cally_root_get_name (AtkObject *obj)
{
  return g_get_prgname ();
}

/* -------------------------------- PRIVATE --------------------------------- */

static void
cally_util_stage_added_cb (ClutterStageManager *stage_manager,
                           ClutterStage *stage,
                           gpointer data)
{
  CallyRoot *root = CALLY_ROOT (data);
  AtkObject *cally_stage = NULL;
  gint index = -1;

  cally_stage = clutter_actor_get_accessible (CLUTTER_ACTOR (stage));

  atk_object_set_parent (cally_stage, ATK_OBJECT (root));

  root->priv->stage_list = g_slist_append (root->priv->stage_list,
                                           cally_stage);

  index = g_slist_index (root->priv->stage_list, cally_stage);
  g_signal_emit_by_name (root, "children_changed::add",
                         index, cally_stage, NULL);
  g_signal_emit_by_name (cally_stage, "create", 0);
}

static void
cally_util_stage_removed_cb (ClutterStageManager *stage_manager,
                             ClutterStage *stage,
                             gpointer data)
{
  CallyRoot *root = CALLY_ROOT (data);
  AtkObject *cally_stage = NULL;
  gint index = -1;

  cally_stage = clutter_actor_get_accessible (CLUTTER_ACTOR (stage));

  index = g_slist_index (root->priv->stage_list, cally_stage);

  root->priv->stage_list = g_slist_remove (root->priv->stage_list,
                                           cally_stage);

  index = g_slist_index (root->priv->stage_list, cally_stage);
  g_signal_emit_by_name (root, "children_changed::remove",
                         index, cally_stage, NULL);
  g_signal_emit_by_name (cally_stage, "destroy", 0);
}