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