Debian Codegraph @

clutter/cally/cally-actor.c

raw
1 /* CALLY - The Clutter Accessibility Implementation Library
2 *
3 * Copyright (C) 2008 Igalia, S.L.
4 *
5 * Author: Alejandro PiƱeiro Iglesias <[email protected]>
6 *
7 * Some parts are based on GailWidget from GAIL
8 * GAIL - The GNOME Accessibility Implementation Library
9 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 /**
26 * SECTION:cally-actor
27 * @Title: CallyActor
28 * @short_description: Implementation of the ATK interfaces for #ClutterActor
29 * @see_also: #ClutterActor
30 *
31 * #CallyActor implements the required ATK interfaces of #ClutterActor
32 * exposing the common elements on each actor (position, extents, etc).
33 */
34
35 /*
36 *
37 * IMPLEMENTATION NOTES:
38 *
39 * ####
40 *
41 * Focus: clutter hasn't got the focus concept in the same way that GTK, but it
42 * has a key focus managed by the stage. Basically any actor can be focused using
43 * clutter_stage_set_key_focus. So, we will use this approach: all actors are
44 * focusable, and we get the currently focused using clutter_stage_get_key_focus
45 * This affects focus related stateset and some atk_componenet focus methods (like
46 * grab focus).
47 *
48 * In the same way, we will manage the focus state change management
49 * on the cally-stage object. The reason is avoid missing a focus
50 * state change event if the object is focused just before the
51 * accessibility object being created.
52 *
53 * #AtkAction implementation: on previous releases ClutterActor added
54 * the actions "press", "release" and "click", as at that time some
55 * general-purpose actors like textures were directly used as buttons.
56 *
57 * But now, new toolkits appeared, providing high-level widgets, like
58 * buttons. So in this environment, it doesn't make sense to keep
59 * adding them as default.
60 *
61 * Anyway, current implementation of AtkAction is done at CallyActor
62 * providing methods to add and remove actions. This is based on the
63 * one used at gailcell, and proposed as a change on #AtkAction
64 * interface:
65 *
66 * https://bugzilla.gnome.org/show_bug.cgi?id=649804
67 *
68 */
69
70 #ifdef HAVE_CONFIG_H
71 #include "config.h"
72 #endif
73
74 #include <glib.h>
75 #include <clutter/clutter.h>
76
77 #ifdef CLUTTER_WINDOWING_X11
78 #include <clutter/x11/clutter-x11.h>
79 #endif
80
81 #include <math.h>
82
83 #include "cally-actor.h"
84 #include "cally-actor-private.h"
85
86 typedef struct _CallyActorActionInfo CallyActorActionInfo;
87
88 /*< private >
89 * CallyActorActionInfo:
90 * @name: name of the action
91 * @description: description of the action
92 * @keybinding: keybinding related to the action
93 * @do_action_func: callback
94 * @user_data: data to be passed to @do_action_func
95 * @notify: function to be called when removing the action
96 *
97 * Utility structure to maintain the different actions added to the
98 * #CallyActor
99 */
100 struct _CallyActorActionInfo
101 {
102 gchar *name;
103 gchar *description;
104 gchar *keybinding;
105
106 CallyActionCallback do_action_func;
107 gpointer user_data;
108 GDestroyNotify notify;
109 };
110
111 static void cally_actor_initialize (AtkObject *obj,
112 gpointer data);
113 static void cally_actor_finalize (GObject *obj);
114
115 /* AtkObject.h */
116 static AtkObject* cally_actor_get_parent (AtkObject *obj);
117 static gint cally_actor_get_index_in_parent (AtkObject *obj);
118 static AtkStateSet* cally_actor_ref_state_set (AtkObject *obj);
119 static gint cally_actor_get_n_children (AtkObject *obj);
120 static AtkObject* cally_actor_ref_child (AtkObject *obj,
121 gint i);
122 static AtkAttributeSet * cally_actor_get_attributes (AtkObject *obj);
123
124 /* ClutterContainer */
125 static gint cally_actor_add_actor (ClutterActor *container,
126 ClutterActor *actor,
127 gpointer data);
128 static gint cally_actor_remove_actor (ClutterActor *container,
129 ClutterActor *actor,
130 gpointer data);
131 static gint cally_actor_real_add_actor (ClutterActor *container,
132 ClutterActor *actor,
133 gpointer data);
134 static gint cally_actor_real_remove_actor (ClutterActor *container,
135 ClutterActor *actor,
136 gpointer data);
137
138 /* AtkComponent.h */
139 static void cally_actor_component_interface_init (AtkComponentIface *iface);
140 static void cally_actor_get_extents (AtkComponent *component,
141 gint *x,
142 gint *y,
143 gint *width,
144 gint *height,
145 AtkCoordType coord_type);
146 static gint cally_actor_get_mdi_zorder (AtkComponent *component);
147 static gboolean cally_actor_grab_focus (AtkComponent *component);
148
149 /* AtkAction.h */
150 static void cally_actor_action_interface_init (AtkActionIface *iface);
151 static gboolean cally_actor_action_do_action (AtkAction *action,
152 gint i);
153 static gboolean idle_do_action (gpointer data);
154 static gint cally_actor_action_get_n_actions (AtkAction *action);
155 static const gchar* cally_actor_action_get_description (AtkAction *action,
156 gint i);
157 static const gchar* cally_actor_action_get_keybinding (AtkAction *action,
158 gint i);
159 static const gchar* cally_actor_action_get_name (AtkAction *action,
160 gint i);
161 static gboolean cally_actor_action_set_description (AtkAction *action,
162 gint i,
163 const gchar *desc);
164 static void _cally_actor_destroy_action_info (gpointer action_info,
165 gpointer user_data);
166 static void _cally_actor_clean_action_list (CallyActor *cally_actor);
167
168 static CallyActorActionInfo* _cally_actor_get_action_info (CallyActor *cally_actor,
169 gint index);
170 /* Misc functions */
171 static void cally_actor_notify_clutter (GObject *obj,
172 GParamSpec *pspec);
173 static void cally_actor_real_notify_clutter (GObject *obj,
174 GParamSpec *pspec);
175
176 struct _CallyActorPrivate
177 {
178 GQueue *action_queue;
179 guint action_idle_handler;
180 GList *action_list;
181
182 GList *children;
183 };
184
185 G_DEFINE_TYPE_WITH_CODE (CallyActor,
186 cally_actor,
187 ATK_TYPE_GOBJECT_ACCESSIBLE,
188 G_ADD_PRIVATE (CallyActor)
189 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
190 cally_actor_component_interface_init)
191 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION,
192 cally_actor_action_interface_init));
193
194 /**
195 * cally_actor_new:
196 * @actor: a #ClutterActor
197 *
198 * Creates a new #CallyActor for the given @actor
199 *
200 * Return value: the newly created #AtkObject
201 *
202 * Since: 1.4
203 */
204 AtkObject *
205 cally_actor_new (ClutterActor *actor)
206 {
207 gpointer object;
208 AtkObject *atk_object;
209
210 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
211
212 object = g_object_new (CALLY_TYPE_ACTOR, NULL);
213
214 atk_object = ATK_OBJECT (object);
215 atk_object_initialize (atk_object, actor);
216
217 return atk_object;
218 }
219
220 static void
221 cally_actor_initialize (AtkObject *obj,
222 gpointer data)
223 {
224 CallyActor *self = NULL;
225 CallyActorPrivate *priv = NULL;
226 ClutterActor *actor = NULL;
227 guint handler_id;
228
229 ATK_OBJECT_CLASS (cally_actor_parent_class)->initialize (obj, data);
230
231 self = CALLY_ACTOR(obj);
232 priv = self->priv;
233 actor = CLUTTER_ACTOR (data);
234
235 g_signal_connect (actor,
236 "notify",
237 G_CALLBACK (cally_actor_notify_clutter),
238 NULL);
239
240 g_object_set_data (G_OBJECT (obj), "atk-component-layer",
241 GINT_TO_POINTER (ATK_LAYER_MDI));
242
243 priv->children = clutter_actor_get_children (actor);
244
245 /*
246 * We store the handler ids for these signals in case some objects
247 * need to remove these handlers.
248 */
249 handler_id = g_signal_connect (actor,
250 "actor-added",
251 G_CALLBACK (cally_actor_add_actor),
252 obj);
253 g_object_set_data (G_OBJECT (obj), "cally-add-handler-id",
254 GUINT_TO_POINTER (handler_id));
255 handler_id = g_signal_connect (actor,
256 "actor-removed",
257 G_CALLBACK (cally_actor_remove_actor),
258 obj);
259 g_object_set_data (G_OBJECT (obj), "cally-remove-handler-id",
260 GUINT_TO_POINTER (handler_id));
261
262 obj->role = ATK_ROLE_PANEL; /* typically objects implementing ClutterContainer
263 interface would be a panel */
264 }
265
266 static void
267 cally_actor_class_init (CallyActorClass *klass)
268 {
269 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
270 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
271
272 klass->notify_clutter = cally_actor_real_notify_clutter;
273 klass->add_actor = cally_actor_real_add_actor;
274 klass->remove_actor = cally_actor_real_remove_actor;
275
276 /* GObject */
277 gobject_class->finalize = cally_actor_finalize;
278
279 /* AtkObject */
280 class->get_parent = cally_actor_get_parent;
281 class->get_index_in_parent = cally_actor_get_index_in_parent;
282 class->ref_state_set = cally_actor_ref_state_set;
283 class->initialize = cally_actor_initialize;
284 class->get_n_children = cally_actor_get_n_children;
285 class->ref_child = cally_actor_ref_child;
286 class->get_attributes = cally_actor_get_attributes;
287 }
288
289 static void
290 cally_actor_init (CallyActor *cally_actor)
291 {
292 CallyActorPrivate *priv = cally_actor_get_instance_private (cally_actor);
293
294 cally_actor->priv = priv;
295
296 priv->action_queue = NULL;
297 priv->action_idle_handler = 0;
298
299 priv->action_list = NULL;
300
301 priv->children = NULL;
302 }
303
304 static void
305 cally_actor_finalize (GObject *obj)
306 {
307 CallyActor *cally_actor = NULL;
308 CallyActorPrivate *priv = NULL;
309
310 cally_actor = CALLY_ACTOR (obj);
311 priv = cally_actor->priv;
312
313 _cally_actor_clean_action_list (cally_actor);
314
315 if (priv->action_idle_handler)
316 {
317 g_source_remove (priv->action_idle_handler);
318 priv->action_idle_handler = 0;
319 }
320
321 if (priv->action_queue)
322 {
323 g_queue_free (priv->action_queue);
324 }
325
326 if (priv->children)
327 {
328 g_list_free (priv->children);
329 priv->children = NULL;
330 }
331
332 G_OBJECT_CLASS (cally_actor_parent_class)->finalize (obj);
333 }
334
335 /* AtkObject */
336
337 static AtkObject *
338 cally_actor_get_parent (AtkObject *obj)
339 {
340 ClutterActor *parent_actor = NULL;
341 AtkObject *parent = NULL;
342 ClutterActor *actor = NULL;
343 CallyActor *cally_actor = NULL;
344
345 g_return_val_if_fail (CALLY_IS_ACTOR (obj), NULL);
346
347 /* Check if we have and assigned parent */
348 if (obj->accessible_parent)
349 return obj->accessible_parent;
350
351 /* Try to get it from the clutter parent */
352 cally_actor = CALLY_ACTOR (obj);
353 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
354 if (actor == NULL) /* Object is defunct */
355 return NULL;
356
357 parent_actor = clutter_actor_get_parent (actor);
358 if (parent_actor == NULL)
359 return NULL;
360
361 parent = clutter_actor_get_accessible (parent_actor);
362
363 /* FIXME: I need to review the clutter-embed, to check if in this case I
364 * should get the widget accessible
365 */
366
367 return parent;
368 }
369
370 static gint
371 cally_actor_get_index_in_parent (AtkObject *obj)
372 {
373 CallyActor *cally_actor = NULL;
374 ClutterActor *actor = NULL;
375 ClutterActor *parent_actor = NULL;
376 ClutterActor *iter;
377 gint index = -1;
378
379 g_return_val_if_fail (CALLY_IS_ACTOR (obj), -1);
380
381 if (obj->accessible_parent)
382 {
383 gint n_children, i;
384 gboolean found = FALSE;
385
386 n_children = atk_object_get_n_accessible_children (obj->accessible_parent);
387 for (i = 0; i < n_children; i++)
388 {
389 AtkObject *child;
390
391 child = atk_object_ref_accessible_child (obj->accessible_parent, i);
392 if (child == obj)
393 found = TRUE;
394
395 g_object_unref (child);
396 if (found)
397 return i;
398 }
399 return -1;
400 }
401
402 cally_actor = CALLY_ACTOR (obj);
403 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
404 if (actor == NULL) /* Object is defunct */
405 return -1;
406
407 index = 0;
408 parent_actor = clutter_actor_get_parent (actor);
409 if (parent_actor == NULL)
410 return -1;
411
412 for (iter = clutter_actor_get_first_child (parent_actor);
413 iter != NULL && iter != actor;
414 iter = clutter_actor_get_next_sibling (iter))
415 {
416 index += 1;
417 }
418
419 return index;
420 }
421
422 static AtkStateSet*
423 cally_actor_ref_state_set (AtkObject *obj)
424 {
425 ClutterActor *actor = NULL;
426 AtkStateSet *state_set = NULL;
427 ClutterStage *stage = NULL;
428 ClutterActor *focus_actor = NULL;
429 CallyActor *cally_actor = NULL;
430
431 g_return_val_if_fail (CALLY_IS_ACTOR (obj), NULL);
432 cally_actor = CALLY_ACTOR (obj);
433
434 state_set = ATK_OBJECT_CLASS (cally_actor_parent_class)->ref_state_set (obj);
435
436 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
437
438 if (actor == NULL) /* Object is defunct */
439 {
440 atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
441 }
442 else
443 {
444 if (clutter_actor_get_reactive (actor))
445 {
446 atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
447 atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
448 }
449
450 if (clutter_actor_is_visible (actor))
451 {
452 atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
453
454 /* It would be good to also check if the actor is on screen,
455 like the old and removed clutter_actor_is_on_stage*/
456 if (clutter_actor_get_paint_visibility (actor))
457 atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
458
459 }
460
461 /* See focus section on implementation notes */
462 atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
463
464 stage = CLUTTER_STAGE (clutter_actor_get_stage (actor));
465 if (stage != NULL)
466 {
467 focus_actor = clutter_stage_get_key_focus (stage);
468 if (focus_actor == actor)
469 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
470 }
471 }
472
473 return state_set;
474 }
475
476 static gint
477 cally_actor_get_n_children (AtkObject *obj)
478 {
479 ClutterActor *actor = NULL;
480
481 g_return_val_if_fail (CALLY_IS_ACTOR (obj), 0);
482
483 actor = CALLY_GET_CLUTTER_ACTOR (obj);
484
485 if (actor == NULL) /* State is defunct */
486 return 0;
487
488 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), 0);
489
490 return clutter_actor_get_n_children (actor);
491 }
492
493 static AtkObject*
494 cally_actor_ref_child (AtkObject *obj,
495 gint i)
496 {
497 ClutterActor *actor = NULL;
498 ClutterActor *child = NULL;
499
500 g_return_val_if_fail (CALLY_IS_ACTOR (obj), NULL);
501
502 actor = CALLY_GET_CLUTTER_ACTOR (obj);
503 if (actor == NULL) /* State is defunct */
504 return NULL;
505
506 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
507
508 if (i >= clutter_actor_get_n_children (actor))
509 return NULL;
510
511 child = clutter_actor_get_child_at_index (actor, i);
512 if (child == NULL)
513 return NULL;
514
515 return g_object_ref (clutter_actor_get_accessible (child));
516 }
517
518 static AtkAttributeSet *
519 cally_actor_get_attributes (AtkObject *obj)
520 {
521 AtkAttributeSet *attributes;
522 AtkAttribute *toolkit;
523
524 toolkit = g_new (AtkAttribute, 1);
525 toolkit->name = g_strdup ("toolkit");
526 toolkit->value = g_strdup ("clutter");
527
528 attributes = g_slist_append (NULL, toolkit);
529
530 return attributes;
531 }
532
533 /* ClutterContainer */
534 static gint
535 cally_actor_add_actor (ClutterActor *container,
536 ClutterActor *actor,
537 gpointer data)
538 {
539 CallyActor *cally_actor = CALLY_ACTOR (data);
540 CallyActorClass *klass = NULL;
541
542 klass = CALLY_ACTOR_GET_CLASS (cally_actor);
543
544 if (klass->add_actor)
545 return klass->add_actor (container, actor, data);
546 else
547 return 1;
548 }
549
550 static gint
551 cally_actor_remove_actor (ClutterActor *container,
552 ClutterActor *actor,
553 gpointer data)
554 {
555 CallyActor *cally_actor = CALLY_ACTOR (data);
556 CallyActorClass *klass = NULL;
557
558 klass = CALLY_ACTOR_GET_CLASS (cally_actor);
559
560 if (klass->remove_actor)
561 return klass->remove_actor (container, actor, data);
562 else
563 return 1;
564 }
565
566
567 static gint
568 cally_actor_real_add_actor (ClutterActor *container,
569 ClutterActor *actor,
570 gpointer data)
571 {
572 AtkObject *atk_parent = ATK_OBJECT (data);
573 AtkObject *atk_child = clutter_actor_get_accessible (actor);
574 CallyActor *cally_actor = CALLY_ACTOR (atk_parent);
575 CallyActorPrivate *priv = cally_actor->priv;
576 gint index;
577
578 g_return_val_if_fail (CLUTTER_IS_CONTAINER (container), 0);
579 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), 0);
580
581 g_object_notify (G_OBJECT (atk_child), "accessible_parent");
582
583 g_list_free (priv->children);
584
585 priv->children = clutter_actor_get_children (CLUTTER_ACTOR (container));
586
587 index = g_list_index (priv->children, actor);
588 g_signal_emit_by_name (atk_parent, "children_changed::add",
589 index, atk_child, NULL);
590
591 return 1;
592 }
593
594 static gint
595 cally_actor_real_remove_actor (ClutterActor *container,
596 ClutterActor *actor,
597 gpointer data)
598 {
599 AtkPropertyValues values = { NULL };
600 AtkObject* atk_parent = NULL;
601 AtkObject *atk_child = NULL;
602 CallyActorPrivate *priv = NULL;
603 gint index;
604
605 g_return_val_if_fail (CLUTTER_IS_CONTAINER (container), 0);
606 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), 0);
607
608 atk_parent = ATK_OBJECT (data);
609 atk_child = clutter_actor_get_accessible (actor);
610
611 if (atk_child)
612 {
613 g_value_init (&values.old_value, G_TYPE_POINTER);
614 g_value_set_pointer (&values.old_value, atk_parent);
615
616 values.property_name = "accessible-parent";
617
618 g_object_ref (atk_child);
619 g_signal_emit_by_name (atk_child,
620 "property_change::accessible-parent", &values, NULL);
621 g_object_unref (atk_child);
622 }
623
624 priv = CALLY_ACTOR (atk_parent)->priv;
625 index = g_list_index (priv->children, actor);
626 g_list_free (priv->children);
627
628 priv->children = clutter_actor_get_children (CLUTTER_ACTOR (container));
629
630 if (index >= 0 && index <= g_list_length (priv->children))
631 g_signal_emit_by_name (atk_parent, "children_changed::remove",
632 index, atk_child, NULL);
633
634 return 1;
635 }
636
637 /* AtkComponent implementation */
638 static void
639 cally_actor_component_interface_init (AtkComponentIface *iface)
640 {
641 g_return_if_fail (iface != NULL);
642
643 iface->get_extents = cally_actor_get_extents;
644 iface->get_mdi_zorder = cally_actor_get_mdi_zorder;
645
646 /* focus management */
647 iface->grab_focus = cally_actor_grab_focus;
648 }
649
650 static void
651 cally_actor_get_extents (AtkComponent *component,
652 gint *x,
653 gint *y,
654 gint *width,
655 gint *height,
656 AtkCoordType coord_type)
657 {
658 CallyActor *cally_actor = NULL;
659 ClutterActor *actor = NULL;
660 gint top_level_x, top_level_y;
661 gfloat f_width, f_height;
662 ClutterVertex verts[4];
663 ClutterActor *stage = NULL;
664
665 g_return_if_fail (CALLY_IS_ACTOR (component));
666
667 cally_actor = CALLY_ACTOR (component);
668 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
669
670 if (actor == NULL) /* actor is defunct */
671 return;
672
673 /* If the actor is not placed in any stage, we can't compute the
674 * extents */
675 stage = clutter_actor_get_stage (actor);
676 if (stage == NULL)
677 return;
678
679 clutter_actor_get_abs_allocation_vertices (actor, verts);
680 clutter_actor_get_transformed_size (actor, &f_width, &f_height);
681
682 *x = verts[0].x;
683 *y = verts[0].y;
684 *width = ceilf (f_width);
685 *height = ceilf (f_height);
686
687 /* In the ATK_XY_WINDOW case, we consider the stage as the
688 * "top-level-window"
689 *
690 * http://library.gnome.org/devel/atk/stable/AtkUtil.html#AtkCoordType
691 */
692
693 if (coord_type == ATK_XY_SCREEN)
694 {
695 _cally_actor_get_top_level_origin (actor, &top_level_x, &top_level_y);
696
697 *x += top_level_x;
698 *y += top_level_y;
699 }
700
701 return;
702 }
703
704 static gint
705 cally_actor_get_mdi_zorder (AtkComponent *component)
706 {
707 CallyActor *cally_actor = NULL;
708 ClutterActor *actor = NULL;
709
710 g_return_val_if_fail (CALLY_IS_ACTOR (component), G_MININT);
711
712 cally_actor = CALLY_ACTOR(component);
713 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
714
715 return clutter_actor_get_z_position (actor);
716 }
717
718 static gboolean
719 cally_actor_grab_focus (AtkComponent *component)
720 {
721 ClutterActor *actor = NULL;
722 ClutterActor *stage = NULL;
723 CallyActor *cally_actor = NULL;
724
725 g_return_val_if_fail (CALLY_IS_ACTOR (component), FALSE);
726
727 /* See focus section on implementation notes */
728 cally_actor = CALLY_ACTOR(component);
729 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
730 stage = clutter_actor_get_stage (actor);
731
732 clutter_stage_set_key_focus (CLUTTER_STAGE (stage),
733 actor);
734
735 return TRUE;
736 }
737
738 /*
739 *
740 * This gets the top level origin, it is, the position of the stage in
741 * the global screen. You can see it as the absolute display position
742 * of the stage.
743 *
744 * FIXME: only the case with x11 is implemented, other backends are
745 * required
746 *
747 */
748 void
749 _cally_actor_get_top_level_origin (ClutterActor *actor,
750 gint *xp,
751 gint *yp)
752 {
753 /* default values */
754 gint x = 0;
755 gint y = 0;
756
757 #ifdef CLUTTER_WINDOWING_X11
758 if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
759 {
760 ClutterActor *stage = NULL;
761 Display *display = NULL;
762 Window root_window;
763 Window stage_window;
764 Window child;
765 gint return_val = 0;
766
767 stage = clutter_actor_get_stage (actor);
768
769 /* FIXME: what happens if you use another display with
770 clutter_backend_x11_set_display ?*/
771 display = clutter_x11_get_default_display ();
772 root_window = clutter_x11_get_root_window ();
773 stage_window = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
774
775 return_val = XTranslateCoordinates (display, stage_window, root_window,
776 0, 0, &x, &y,
777 &child);
778
779 if (!return_val)
780 g_warning ("[x11] We were not able to get proper absolute "
781 "position of the stage");
782 }
783 else
784 #else
785 {
786 static gboolean yet_warned = FALSE;
787
788 if (!yet_warned)
789 {
790 yet_warned = TRUE;
791
792 g_warning ("The current Clutter backend does not support using "
793 "atk_component_get_extents() with ATK_XY_SCREEN.");
794 }
795 }
796 #endif
797
798 if (xp)
799 *xp = x;
800
801 if (yp)
802 *yp = y;
803 }
804
805 /* AtkAction implementation */
806 static void
807 cally_actor_action_interface_init (AtkActionIface *iface)
808 {
809 g_return_if_fail (iface != NULL);
810
811 iface->do_action = cally_actor_action_do_action;
812 iface->get_n_actions = cally_actor_action_get_n_actions;
813 iface->get_description = cally_actor_action_get_description;
814 iface->get_keybinding = cally_actor_action_get_keybinding;
815 iface->get_name = cally_actor_action_get_name;
816 iface->set_description = cally_actor_action_set_description;
817 }
818
819 static gboolean
820 cally_actor_action_do_action (AtkAction *action,
821 gint index)
822 {
823 CallyActor *cally_actor = NULL;
824 AtkStateSet *set = NULL;
825 CallyActorPrivate *priv = NULL;
826 CallyActorActionInfo *info = NULL;
827
828 cally_actor = CALLY_ACTOR (action);
829 priv = cally_actor->priv;
830
831 set = atk_object_ref_state_set (ATK_OBJECT (cally_actor));
832
833 if (atk_state_set_contains_state (set, ATK_STATE_DEFUNCT))
834 return FALSE;
835
836 if (!atk_state_set_contains_state (set, ATK_STATE_SENSITIVE) ||
837 !atk_state_set_contains_state (set, ATK_STATE_SHOWING))
838 return FALSE;
839
840 g_object_unref (set);
841
842 info = _cally_actor_get_action_info (cally_actor, index);
843
844 if (info == NULL)
845 return FALSE;
846
847 if (info->do_action_func == NULL)
848 return FALSE;
849
850 if (!priv->action_queue)
851 priv->action_queue = g_queue_new ();
852
853 g_queue_push_head (priv->action_queue, info);
854
855 if (!priv->action_idle_handler)
856 priv->action_idle_handler = g_idle_add (idle_do_action, cally_actor);
857
858 return TRUE;
859 }
860
861 static gboolean
862 idle_do_action (gpointer data)
863 {
864 CallyActor *cally_actor = NULL;
865 CallyActorPrivate *priv = NULL;
866 ClutterActor *actor = NULL;
867
868 cally_actor = CALLY_ACTOR (data);
869 priv = cally_actor->priv;
870 actor = CALLY_GET_CLUTTER_ACTOR (cally_actor);
871 priv->action_idle_handler = 0;
872
873 if (actor == NULL) /* state is defunct*/
874 return FALSE;
875
876 while (!g_queue_is_empty (priv->action_queue))
877 {
878 CallyActorActionInfo *info = NULL;
879
880 info = (CallyActorActionInfo *) g_queue_pop_head (priv->action_queue);
881
882 info->do_action_func (cally_actor, info->user_data);
883 }
884
885 return FALSE;
886 }
887
888 static gint
889 cally_actor_action_get_n_actions (AtkAction *action)
890 {
891 CallyActor *cally_actor = NULL;
892 CallyActorPrivate *priv = NULL;
893
894 g_return_val_if_fail (CALLY_IS_ACTOR (action), 0);
895
896 cally_actor = CALLY_ACTOR (action);
897 priv = cally_actor->priv;
898
899 return g_list_length (priv->action_list);
900 }
901
902 static const gchar*
903 cally_actor_action_get_name (AtkAction *action,
904 gint i)
905 {
906 CallyActor *cally_actor = NULL;
907 CallyActorActionInfo *info = NULL;
908
909 g_return_val_if_fail (CALLY_IS_ACTOR (action), NULL);
910 cally_actor = CALLY_ACTOR (action);
911 info = _cally_actor_get_action_info (cally_actor, i);
912
913 if (info == NULL)
914 return NULL;
915
916 return info->name;
917 }
918
919 static const gchar*
920 cally_actor_action_get_description (AtkAction *action,
921 gint i)
922 {
923 CallyActor *cally_actor = NULL;
924 CallyActorActionInfo *info = NULL;
925
926 g_return_val_if_fail (CALLY_IS_ACTOR (action), NULL);
927 cally_actor = CALLY_ACTOR (action);
928 info = _cally_actor_get_action_info (cally_actor, i);
929
930 if (info == NULL)
931 return NULL;
932
933 return info->description;
934 }
935
936 static gboolean
937 cally_actor_action_set_description (AtkAction *action,
938 gint i,
939 const gchar *desc)
940 {
941 CallyActor *cally_actor = NULL;
942 CallyActorActionInfo *info = NULL;
943
944 g_return_val_if_fail (CALLY_IS_ACTOR (action), FALSE);
945 cally_actor = CALLY_ACTOR (action);
946 info = _cally_actor_get_action_info (cally_actor, i);
947
948 if (info == NULL)
949 return FALSE;
950
951 g_free (info->description);
952 info->description = g_strdup (desc);
953
954 return TRUE;
955 }
956
957 static const gchar*
958 cally_actor_action_get_keybinding (AtkAction *action,
959 gint i)
960 {
961 CallyActor *cally_actor = NULL;
962 CallyActorActionInfo *info = NULL;
963
964 g_return_val_if_fail (CALLY_IS_ACTOR (action), NULL);
965 cally_actor = CALLY_ACTOR (action);
966 info = _cally_actor_get_action_info (cally_actor, i);
967
968 if (info == NULL)
969 return NULL;
970
971 return info->keybinding;
972 }
973
974 /* Misc functions */
975
976 /*
977 * This function is a signal handler for notify signal which gets emitted
978 * when a property changes value on the ClutterActor associated with the object.
979 *
980 * It calls a function for the CallyActor type
981 */
982 static void
983 cally_actor_notify_clutter (GObject *obj,
984 GParamSpec *pspec)
985 {
986 CallyActor *cally_actor = NULL;
987 CallyActorClass *klass = NULL;
988
989 cally_actor = CALLY_ACTOR (clutter_actor_get_accessible (CLUTTER_ACTOR (obj)));
990 klass = CALLY_ACTOR_GET_CLASS (cally_actor);
991
992 if (klass->notify_clutter)
993 klass->notify_clutter (obj, pspec);
994 }
995
996 /*
997 * This function is a signal handler for notify signal which gets emitted
998 * when a property changes value on the ClutterActor associated with a CallyActor
999 *
1000 * It constructs an AtkPropertyValues structure and emits a "property_changed"
1001 * signal which causes the user specified AtkPropertyChangeHandler
1002 * to be called.
1003 */
1004 static void
1005 cally_actor_real_notify_clutter (GObject *obj,
1006 GParamSpec *pspec)
1007 {
1008 ClutterActor* actor = CLUTTER_ACTOR (obj);
1009 AtkObject* atk_obj = clutter_actor_get_accessible (CLUTTER_ACTOR(obj));
1010 AtkState state;
1011 gboolean value;
1012
1013 if (g_strcmp0 (pspec->name, "visible") == 0)
1014 {
1015 state = ATK_STATE_VISIBLE;
1016 value = clutter_actor_is_visible (actor);
1017 }
1018 else if (g_strcmp0 (pspec->name, "mapped") == 0)
1019 {
1020 /* Clones may temporarily map an actor in order to
1021 * paint it; we don't want this to generate an ATK
1022 * state change
1023 */
1024 if (clutter_actor_is_in_clone_paint (actor))
1025 return;
1026
1027 state = ATK_STATE_SHOWING;
1028 value = clutter_actor_is_mapped (actor);
1029 }
1030 else if (g_strcmp0 (pspec->name, "reactive") == 0)
1031 {
1032 state = ATK_STATE_SENSITIVE;
1033 value = clutter_actor_get_reactive (actor);
1034 }
1035 else
1036 return;
1037
1038 atk_object_notify_state_change (atk_obj, state, value);
1039 }
1040
1041 static void
1042 _cally_actor_clean_action_list (CallyActor *cally_actor)
1043 {
1044 CallyActorPrivate *priv = NULL;
1045
1046 priv = cally_actor->priv;
1047
1048 if (priv->action_list)
1049 {
1050 g_list_foreach (priv->action_list,
1051 (GFunc) _cally_actor_destroy_action_info,
1052 NULL);
1053 g_list_free (priv->action_list);
1054 priv->action_list = NULL;
1055 }
1056 }
1057
1058 static CallyActorActionInfo *
1059 _cally_actor_get_action_info (CallyActor *cally_actor,
1060 gint index)
1061 {
1062 CallyActorPrivate *priv = NULL;
1063 GList *node = NULL;
1064
1065 g_return_val_if_fail (CALLY_IS_ACTOR (cally_actor), NULL);
1066
1067 priv = cally_actor->priv;
1068
1069 if (priv->action_list == NULL)
1070 return NULL;
1071
1072 node = g_list_nth (priv->action_list, index);
1073
1074 if (node == NULL)
1075 return NULL;
1076
1077 return (CallyActorActionInfo *)(node->data);
1078 }
1079
1080 /**
1081 * cally_actor_add_action: (skip)
1082 * @cally_actor: a #CallyActor
1083 * @action_name: the action name
1084 * @action_description: the action description
1085 * @action_keybinding: the action keybinding
1086 * @action_func: the callback of the action, to be executed with do_action
1087 *
1088 * Adds a new action to be accessed with the #AtkAction interface.
1089 *
1090 * Return value: added action id, or -1 if failure
1091 *
1092 * Since: 1.4
1093 */
1094 guint
1095 cally_actor_add_action (CallyActor *cally_actor,
1096 const gchar *action_name,
1097 const gchar *action_description,
1098 const gchar *action_keybinding,
1099 CallyActionFunc action_func)
1100 {
1101 return cally_actor_add_action_full (cally_actor,
1102 action_name,
1103 action_description,
1104 action_keybinding,
1105 (CallyActionCallback) action_func,
1106 NULL, NULL);
1107 }
1108
1109 /**
1110 * cally_actor_add_action_full: (rename-to cally_actor_add_action)
1111 * @cally_actor: a #CallyActor
1112 * @action_name: the action name
1113 * @action_description: the action description
1114 * @action_keybinding: the action keybinding
1115 * @callback: (scope notified): the callback of the action
1116 * @user_data: (closure): data to be passed to @callback
1117 * @notify: function to be called when removing the action
1118 *
1119 * Adds a new action to be accessed with the #AtkAction interface.
1120 *
1121 * Return value: added action id, or -1 if failure
1122 *
1123 * Since: 1.6
1124 */
1125 guint
1126 cally_actor_add_action_full (CallyActor *cally_actor,
1127 const gchar *action_name,
1128 const gchar *action_description,
1129 const gchar *action_keybinding,
1130 CallyActionCallback callback,
1131 gpointer user_data,
1132 GDestroyNotify notify)
1133 {
1134 CallyActorActionInfo *info = NULL;
1135 CallyActorPrivate *priv = NULL;
1136
1137 g_return_val_if_fail (CALLY_IS_ACTOR (cally_actor), -1);
1138 g_return_val_if_fail (callback != NULL, -1);
1139
1140 priv = cally_actor->priv;
1141
1142 info = g_slice_new (CallyActorActionInfo);
1143 info->name = g_strdup (action_name);
1144 info->description = g_strdup (action_description);
1145 info->keybinding = g_strdup (action_keybinding);
1146 info->do_action_func = callback;
1147 info->user_data = user_data;
1148 info->notify = notify;
1149
1150 priv->action_list = g_list_append (priv->action_list, info);
1151
1152 return g_list_length (priv->action_list);
1153 }
1154
1155 /**
1156 * cally_actor_remove_action:
1157 * @cally_actor: a #CallyActor
1158 * @action_id: the action id
1159 *
1160 * Removes a action, using the @action_id returned by cally_actor_add_action()
1161 *
1162 * Return value: %TRUE if the operation was succesful, %FALSE otherwise
1163 *
1164 * Since: 1.4
1165 */
1166 gboolean
1167 cally_actor_remove_action (CallyActor *cally_actor,
1168 gint action_id)
1169 {
1170 GList *list_node = NULL;
1171 CallyActorPrivate *priv = NULL;
1172
1173 g_return_val_if_fail (CALLY_IS_ACTOR (cally_actor), FALSE);
1174 priv = cally_actor->priv;
1175
1176 list_node = g_list_nth (priv->action_list, action_id - 1);
1177
1178 if (!list_node)
1179 return FALSE;
1180
1181 _cally_actor_destroy_action_info (list_node->data, NULL);
1182
1183 priv->action_list = g_list_remove_link (priv->action_list, list_node);
1184
1185 return TRUE;
1186 }
1187
1188 /**
1189 * cally_actor_remove_action_by_name:
1190 * @cally_actor: a #CallyActor
1191 * @action_name: the name of the action to remove
1192 *
1193 * Removes an action, using the @action_name used when the action was added
1194 * with cally_actor_add_action()
1195 *
1196 * Return value: %TRUE if the operation was succesful, %FALSE otherwise
1197 *
1198 * Since: 1.4
1199 */
1200 gboolean
1201 cally_actor_remove_action_by_name (CallyActor *cally_actor,
1202 const gchar *action_name)
1203 {
1204 GList *node = NULL;
1205 gboolean action_found = FALSE;
1206 CallyActorPrivate *priv = NULL;
1207
1208 g_return_val_if_fail (CALLY_IS_ACTOR (cally_actor), FALSE);
1209 priv = CALLY_ACTOR (cally_actor)->priv;
1210
1211 for (node = priv->action_list; node && !action_found;
1212 node = node->next)
1213 {
1214 CallyActorActionInfo *ainfo = node->data;
1215
1216 if (!g_ascii_strcasecmp (ainfo->name, action_name))
1217 {
1218 action_found = TRUE;
1219 break;
1220 }
1221 }
1222 if (!action_found)
1223 return FALSE;
1224
1225 _cally_actor_destroy_action_info (node->data, NULL);
1226 priv->action_list = g_list_remove_link (priv->action_list, node);
1227
1228 return TRUE;
1229 }
1230
1231
1232 static void
1233 _cally_actor_destroy_action_info (gpointer action_info,
1234 gpointer user_data)
1235 {
1236 CallyActorActionInfo *info = action_info;
1237
1238 g_assert (info != NULL);
1239
1240 g_free (info->name);
1241 g_free (info->description);
1242 g_free (info->keybinding);
1243
1244 if (info->notify)
1245 info->notify (info->user_data);
1246
1247 g_slice_free (CallyActorActionInfo, info);
1248 }