2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2007 IBM Corp.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
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 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* collection.c: implements the Collection interface */
28 #include <droute/droute.h>
30 #include "common/bitarray.h"
31 #include "common/spi-dbus.h"
32 #include "common/spi-stateset.h"
34 #include "accessible-register.h"
36 #include "introspection.h"
38 typedef struct _MatchRulePrivate MatchRulePrivate;
39 struct _MatchRulePrivate
42 Accessibility_Collection_MatchType statematchtype;
43 AtkAttributeSet *attributes;
44 Accessibility_Collection_MatchType attributematchtype;
46 Accessibility_Collection_MatchType rolematchtype;
48 Accessibility_Collection_MatchType interfacematchtype;
53 child_interface_p (AtkObject * child, gchar * repo_id)
55 if (!strcasecmp (repo_id, "action"))
56 return ATK_IS_ACTION (child);
57 if (!strcasecmp (repo_id, "component"))
58 return ATK_IS_COMPONENT (child);
59 if (!strcasecmp (repo_id, "editabletext"))
60 return ATK_IS_EDITABLE_TEXT (child);
61 if (!strcasecmp (repo_id, "text"))
62 return ATK_IS_TEXT (child);
63 if (!strcasecmp (repo_id, "hypertext"))
64 return ATK_IS_HYPERTEXT (child);
65 if (!strcasecmp (repo_id, "image"))
66 return ATK_IS_IMAGE (child);
67 if (!strcasecmp (repo_id, "selection"))
68 return ATK_IS_SELECTION (child);
69 if (!strcasecmp (repo_id, "table"))
70 return ATK_IS_TABLE (child);
71 if (!strcasecmp (repo_id, "value"))
72 return ATK_IS_VALUE (child);
73 if (!strcasecmp (repo_id, "streamablecontent"))
74 return ATK_IS_STREAMABLE_CONTENT (child);
75 if (!strcasecmp (repo_id, "document"))
76 return ATK_IS_DOCUMENT (child);
80 #define child_collection_p(ch) (TRUE)
83 match_states_all_p (AtkObject * child, gint * set)
89 if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
92 chs = atk_object_ref_state_set (child);
94 // TODO: use atk-state_set_contains_states; would be more efficient
95 for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
97 if (!atk_state_set_contains_state (chs, set[i]))
104 g_object_unref (chs);
109 match_states_any_p (AtkObject * child, gint * set)
113 gboolean ret = FALSE;
115 if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
118 chs = atk_object_ref_state_set (child);
120 for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
122 if (!atk_state_set_contains_state (chs, set[i]))
129 g_object_unref (chs);
134 match_states_none_p (AtkObject * child, gint * set)
140 if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
143 chs = atk_object_ref_state_set (child);
145 for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
147 if (atk_state_set_contains_state (chs, set[i]))
154 g_object_unref (chs);
158 // TODO: need to convert at-spi roles/states to atk roles/states */
160 match_states_lookup (AtkObject * child, MatchRulePrivate * mrp)
162 switch (mrp->statematchtype)
164 case Accessibility_Collection_MATCH_ALL:
165 if (match_states_all_p (child, mrp->states))
169 case Accessibility_Collection_MATCH_ANY:
170 if (match_states_any_p (child, mrp->states))
174 case Accessibility_Collection_MATCH_NONE:
175 if (match_states_none_p (child, mrp->states))
186 // TODO: Map at-spi -> atk roles at mrp creation instead of doing this;
187 // would be more efficient
188 #define spi_get_role(obj) spi_accessible_role_from_atk_role(atk_object_get_role(obj))
191 match_roles_all_p (AtkObject * child, gint * roles)
193 if (roles == NULL || roles[0] == BITARRAY_SEQ_TERM)
195 else if (roles[1] != BITARRAY_SEQ_TERM)
198 return (atk_object_get_role (child) == roles[0]);
203 match_roles_any_p (AtkObject * child, gint * roles)
205 Accessibility_Role role;
208 if (roles == NULL || roles[0] == BITARRAY_SEQ_TERM)
211 role = spi_accessible_role_from_atk_role (atk_object_get_role (child));
213 for (i = 0; roles[i] != BITARRAY_SEQ_TERM; i++)
214 if (role == roles[i])
221 match_roles_none_p (AtkObject * child, gint * roles)
226 if (roles == NULL || roles[0] == BITARRAY_SEQ_TERM)
229 role = atk_object_get_role (child);
231 for (i = 0; roles[i] != BITARRAY_SEQ_TERM; i++)
232 if (role == roles[i])
239 match_roles_lookup (AtkObject * child, MatchRulePrivate * mrp)
241 switch (mrp->rolematchtype)
243 case Accessibility_Collection_MATCH_ALL:
244 if (match_roles_all_p (child, mrp->roles))
248 case Accessibility_Collection_MATCH_ANY:
249 if (match_roles_any_p (child, mrp->roles))
253 case Accessibility_Collection_MATCH_NONE:
254 if (match_roles_none_p (child, mrp->roles))
266 match_interfaces_all_p (AtkObject * obj, gchar ** ifaces)
273 for (i = 0; ifaces[i]; i++)
274 if (!child_interface_p (obj, ifaces[i]))
282 match_interfaces_any_p (AtkObject * obj, gchar ** ifaces)
290 for (i = 0; ifaces[i]; i++)
291 if (child_interface_p (obj, ifaces[i]))
299 match_interfaces_none_p (AtkObject * obj, gchar ** ifaces)
303 for (i = 0; ifaces[i]; i++)
304 if (child_interface_p (obj, ifaces[i]))
311 match_interfaces_lookup (AtkObject * child, MatchRulePrivate * mrp)
313 switch (mrp->interfacematchtype)
316 case Accessibility_Collection_MATCH_ALL:
317 if (match_interfaces_all_p (child, mrp->ifaces))
321 case Accessibility_Collection_MATCH_ANY:
322 if (match_interfaces_any_p (child, mrp->ifaces))
326 case Accessibility_Collection_MATCH_NONE:
327 if (match_interfaces_none_p (child, mrp->ifaces))
338 #define split_attributes(attributes) (g_strsplit (attributes, ";", 0))
341 match_attributes_all_p (AtkObject * child, AtkAttributeSet * attributes)
345 gint length, oa_length;
346 gboolean flag = FALSE;
348 if (attributes == NULL || g_slist_length (attributes) == 0)
351 oa = atk_object_get_attributes (child);
352 length = g_slist_length (attributes);
353 oa_length = g_slist_length (oa);
355 for (i = 0; i < length; i++)
357 AtkAttribute *attr = g_slist_nth_data (attributes, i);
358 for (k = 0; k < oa_length; k++)
360 AtkAttribute *oa_attr = g_slist_nth_data (attributes, i);
361 if (!g_ascii_strcasecmp (oa_attr->name, attr->name) &&
362 !g_ascii_strcasecmp (oa_attr->value, attr->value))
372 atk_attribute_set_free (oa);
376 atk_attribute_set_free (oa);
381 match_attributes_any_p (AtkObject * child, AtkAttributeSet * attributes)
386 gint length, oa_length;
388 length = g_slist_length (attributes);
392 oa = atk_object_get_attributes (child);
393 oa_length = g_slist_length (oa);
395 for (i = 0; i < length; i++)
397 AtkAttribute *attr = g_slist_nth_data (attributes, i);
398 for (k = 0; k < oa_length; k++)
400 AtkAttribute *oa_attr = g_slist_nth_data (attributes, i);
401 if (!g_ascii_strcasecmp (oa_attr->name, attr->name) &&
402 !g_ascii_strcasecmp (oa_attr->value, attr->value))
404 atk_attribute_set_free (oa);
409 atk_attribute_set_free (oa);
414 match_attributes_none_p (AtkObject * child, AtkAttributeSet * attributes)
419 gint length, oa_length;
421 length = g_slist_length (attributes);
425 oa = atk_object_get_attributes (child);
426 oa_length = g_slist_length (oa);
428 for (i = 0; i < length; i++)
430 AtkAttribute *attr = g_slist_nth_data (attributes, i);
431 for (k = 0; k < oa_length; k++)
433 AtkAttribute *oa_attr = g_slist_nth_data (attributes, i);
434 if (!g_ascii_strcasecmp (oa_attr->name, attr->name) &&
435 !g_ascii_strcasecmp (oa_attr->value, attr->value))
437 atk_attribute_set_free (oa);
442 atk_attribute_set_free (oa);
447 match_attributes_lookup (AtkObject * child, MatchRulePrivate * mrp)
449 switch (mrp->attributematchtype)
452 case Accessibility_Collection_MATCH_ALL:
453 if (match_attributes_all_p (child, mrp->attributes))
457 case Accessibility_Collection_MATCH_ANY:
458 if (match_attributes_any_p (child, mrp->attributes))
462 case Accessibility_Collection_MATCH_NONE:
463 if (match_attributes_none_p (child, mrp->attributes))
474 traverse_p (AtkObject * child, const gboolean traverse)
479 return !child_collection_p (child);
483 sort_order_canonical (MatchRulePrivate * mrp, GList * ls,
484 gint kount, gint max,
485 AtkObject * obj, glong index, gboolean flag,
486 AtkObject * pobj, gboolean recurse, gboolean traverse)
489 glong acount = atk_object_get_n_accessible_children (obj);
490 gboolean prev = pobj ? TRUE : FALSE;
492 for (; i < acount && (max == 0 || kount < max); i++)
494 AtkObject *child = atk_object_ref_accessible_child (obj, i);
496 g_object_unref (child);
497 if (prev && child == pobj)
502 if (flag && match_interfaces_lookup (child, mrp)
503 && match_states_lookup (child, mrp)
504 && match_roles_lookup (child, mrp)
505 && match_attributes_lookup (child, mrp))
508 ls = g_list_append (ls, child);
515 if (recurse && traverse_p (child, traverse))
516 kount = sort_order_canonical (mrp, ls, kount,
518 pobj, recurse, traverse);
524 sort_order_rev_canonical (MatchRulePrivate * mrp, GList * ls,
525 gint kount, gint max,
526 AtkObject * obj, gboolean flag, AtkObject * pobj)
532 /* This breaks us out of the recursion. */
533 if (!obj || obj == pobj)
538 /* Add to the list if it matches */
539 if (flag && match_interfaces_lookup (obj, mrp)
540 && match_states_lookup (obj, mrp)
541 && match_roles_lookup (obj, mrp) && match_attributes_lookup (obj, mrp)
542 && (max == 0 || kount < max))
544 ls = g_list_append (ls, obj);
551 /* Get the current nodes index in it's parent and the parent object. */
552 indexinparent = atk_object_get_index_in_parent (obj);
553 parent = atk_object_get_parent (obj);
555 if (indexinparent > 0 && (max == 0 || kount < max))
557 /* there are still some siblings to visit so get the previous sibling
558 and get it's last descendant.
559 First, get the previous sibling */
560 nextobj = atk_object_ref_accessible_child (parent, indexinparent - 1);
561 g_object_unref (nextobj);
563 /* Now, drill down the right side to the last descendant */
564 while (atk_object_get_n_accessible_children (nextobj) > 0)
566 nextobj = atk_object_ref_accessible_child (nextobj,
567 atk_object_get_n_accessible_children
569 g_object_unref (nextobj);
571 /* recurse with the last descendant */
572 kount = sort_order_rev_canonical (mrp, ls, kount, max,
573 nextobj, TRUE, pobj);
575 else if (max == 0 || kount < max)
577 /* no more siblings so next node must be the parent */
578 kount = sort_order_rev_canonical (mrp, ls, kount, max,
586 query_exec (MatchRulePrivate * mrp, Accessibility_Collection_SortOrder sortby,
587 GList * ls, gint kount, gint max,
588 AtkObject * obj, glong index,
590 AtkObject * pobj, gboolean recurse, gboolean traverse)
594 case Accessibility_Collection_SORT_ORDER_CANONICAL:
595 kount = sort_order_canonical (mrp, ls, 0, max, obj, index, flag,
596 pobj, recurse, traverse);
598 case Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL:
599 kount = sort_order_canonical (mrp, ls, 0, max, obj, index, flag,
600 pobj, recurse, traverse);
604 g_warning ("Sort method not implemented yet");
612 bitarray_to_seq (int *array, int array_count, int **ret)
617 int *out = (int *) g_malloc (out_size * sizeof (int));
621 for (i = 0; i < array_count; i++)
623 for (j = 0; j < 32; j++)
625 if (array[i] & (1 << j))
627 if (out_count == out_size - 2)
630 out = (int *) g_realloc (out, out_size * sizeof (int));
634 out[out_count++] = i * 32 + j;
638 out[out_count] = BITARRAY_SEQ_TERM;
645 read_mr (DBusMessageIter * iter, MatchRulePrivate * mrp)
647 DBusMessageIter iter_struct, iter_array, iter_dict, iter_dict_entry;
648 dbus_uint32_t *array;
649 dbus_int32_t matchType;
654 char *interfaces = NULL;
656 dbus_message_iter_recurse (iter, &iter_struct);
659 dbus_message_iter_recurse (&iter_struct, &iter_array);
660 dbus_message_iter_get_fixed_array (&iter_array, &array, &array_count);
661 bitarray_to_seq (array, array_count, &mrp->states);
662 for (i = 0; mrp->states[i] != BITARRAY_SEQ_TERM; i++)
664 mrp->states[i] = spi_atk_state_from_spi_state (mrp->states[i]);
666 dbus_message_iter_next (&iter_struct);
667 dbus_message_iter_get_basic (&iter_struct, &matchType);
668 dbus_message_iter_next (&iter_struct);
669 mrp->statematchtype = matchType;;
672 mrp->attributes = NULL;
673 dbus_message_iter_recurse (&iter_struct, &iter_dict);
674 while (dbus_message_iter_get_arg_type (&iter_dict) != DBUS_TYPE_INVALID)
676 const char *key, *val;
677 dbus_message_iter_recurse (&iter_dict, &iter_dict_entry);
678 dbus_message_iter_get_basic (&iter_dict_entry, &key);
679 dbus_message_iter_get_basic (&iter_dict_entry, &val);
680 attr = g_new (AtkAttribute, 1);
683 attr->name = g_strdup (key);
684 attr->value = g_strdup (val);
685 mrp->attributes = g_slist_prepend (mrp->attributes, attr);
687 dbus_message_iter_next (&iter_dict);
689 dbus_message_iter_next (&iter_struct);
690 dbus_message_iter_get_basic (&iter_struct, &matchType);
691 mrp->attributematchtype = matchType;;
692 dbus_message_iter_next (&iter_struct);
694 /* Get roles and role match */
695 dbus_message_iter_recurse (&iter_struct, &iter_array);
696 dbus_message_iter_get_fixed_array (&iter_array, &array, &array_count);
697 bitarray_to_seq (array, array_count, &mrp->roles);
698 dbus_message_iter_next (&iter_struct);
699 dbus_message_iter_get_basic (&iter_struct, &matchType);
700 mrp->rolematchtype = matchType;;
701 dbus_message_iter_next (&iter_struct);
703 /* Get interfaces and interface match */
704 dbus_message_iter_recurse (&iter_struct, &iter_array);
705 mrp->ifaces = g_new0 (gchar *, 16);
707 while (i < 15 && dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
710 dbus_message_iter_get_basic (&iter_array, &iface);
711 mrp->ifaces [i] = g_strdup (iface);
713 dbus_message_iter_next (&iter_array);
715 dbus_message_iter_next (&iter_struct);
716 dbus_message_iter_get_basic (&iter_struct, &matchType);
717 mrp->interfacematchtype = matchType;;
718 dbus_message_iter_next (&iter_struct);
720 dbus_message_iter_get_basic (&iter_struct, &mrp->invert);
721 dbus_message_iter_next (iter);
726 return_and_free_list (DBusMessage * message, GList * ls)
729 DBusMessageIter iter, iter_array;
732 reply = dbus_message_new_method_return (message);
735 dbus_message_iter_init_append (reply, &iter);
736 if (!dbus_message_iter_open_container
737 (&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array))
739 for (item = ls; item; item = g_list_next (item))
741 spi_object_append_reference (&iter_array, ATK_OBJECT (item->data));
743 if (!dbus_message_iter_close_container (&iter, &iter_array))
748 // TODO: Handle out of memory
754 free_mrp_data (MatchRulePrivate * mrp)
756 g_free (mrp->states);
757 atk_attribute_set_free (mrp->attributes);
759 g_strfreev (mrp->ifaces);
763 GetMatchesFrom (DBusMessage * message,
764 AtkObject * current_object,
765 MatchRulePrivate * mrp,
766 const Accessibility_Collection_SortOrder sortby,
767 const dbus_bool_t isrestrict,
768 dbus_int32_t count, const dbus_bool_t traverse)
772 glong index = atk_object_get_index_in_parent (current_object);
775 ls = g_list_append (ls, current_object);
779 parent = atk_object_get_parent (current_object);
780 kount = query_exec (mrp, sortby, ls, 0, count, parent, index,
781 FALSE, NULL, TRUE, traverse);
784 kount = query_exec (mrp, sortby, ls, 0, count,
785 current_object, 0, FALSE, NULL, TRUE, traverse);
787 ls = g_list_remove (ls, ls->data);
789 if (sortby == Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL)
790 ls = g_list_reverse (ls);
793 return return_and_free_list (message, ls);
797 inorder traversal from a given object in the hierarchy
801 inorder (AtkObject * collection, MatchRulePrivate * mrp,
802 GList * ls, gint kount, gint max,
804 gboolean flag, AtkObject * pobj, dbus_bool_t traverse)
808 /* First, look through the children recursively. */
809 kount = sort_order_canonical (mrp, ls, kount, max, obj, 0, TRUE,
812 /* Next, we look through the right subtree */
813 while ((max == 0 || kount < max) && obj != collection)
815 AtkObject *parent = atk_object_get_parent (obj);
816 i = atk_object_get_index_in_parent (obj);
817 kount = sort_order_canonical (mrp, ls, kount, max, parent,
818 i + 1, TRUE, FALSE, TRUE, TRUE);
822 if (max == 0 || kount < max)
824 kount = sort_order_canonical (mrp, ls, kount, max,
825 obj, i + 1, TRUE, FALSE, TRUE, TRUE);
832 GetMatchesInOrder: get matches from a given object in an inorder traversal.
836 GetMatchesInOrder (DBusMessage * message,
837 AtkObject * current_object,
838 MatchRulePrivate * mrp,
839 const Accessibility_Collection_SortOrder sortby,
840 const dbus_bool_t recurse,
841 dbus_int32_t count, const dbus_bool_t traverse)
847 ls = g_list_append (ls, current_object);
849 obj = ATK_OBJECT(spi_register_path_to_object (spi_global_register, dbus_message_get_path (message)));
851 kount = inorder (obj, mrp, ls, 0, count,
852 current_object, TRUE, NULL, traverse);
854 ls = g_list_remove (ls, ls->data);
856 if (sortby == Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL)
857 ls = g_list_reverse (ls);
860 return return_and_free_list (message, ls);
864 GetMatchesInBackOrder: get matches from a given object in a
865 reverse order traversal.
869 GetMatchesInBackOrder (DBusMessage * message,
870 AtkObject * current_object,
871 MatchRulePrivate * mrp,
872 const Accessibility_Collection_SortOrder sortby,
876 AtkObject *collection;
879 ls = g_list_append (ls, current_object);
881 collection = ATK_OBJECT(spi_register_path_to_object (spi_global_register, dbus_message_get_path (message)));
883 kount = sort_order_rev_canonical (mrp, ls, 0, count, current_object,
886 ls = g_list_remove (ls, ls->data);
888 if (sortby == Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL)
889 ls = g_list_reverse (ls);
892 return return_and_free_list (message, ls);
896 GetMatchesTo (DBusMessage * message,
897 AtkObject * current_object,
898 MatchRulePrivate * mrp,
899 const Accessibility_Collection_SortOrder sortby,
900 const dbus_bool_t recurse,
901 const dbus_bool_t isrestrict,
902 dbus_int32_t count, const dbus_bool_t traverse)
907 ls = g_list_append (ls, current_object);
911 obj = ATK_OBJECT (atk_object_get_parent (current_object));
912 kount = query_exec (mrp, sortby, ls, 0, count,
913 obj, 0, TRUE, current_object, TRUE, traverse);
917 obj = ATK_OBJECT (spi_register_path_to_object (spi_global_register, dbus_message_get_path (message)));
918 kount = query_exec (mrp, sortby, ls, 0, count,
919 obj, 0, TRUE, current_object, TRUE, traverse);
923 ls = g_list_remove (ls, ls->data);
925 if (sortby != Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL)
926 ls = g_list_reverse (ls);
929 return return_and_free_list (message, ls);
933 impl_GetMatchesFrom (DBusConnection * bus, DBusMessage * message,
936 char *current_object_path = NULL;
937 AtkObject *current_object;
938 DBusMessageIter iter;
939 MatchRulePrivate rule;
940 dbus_uint32_t sortby;
943 dbus_bool_t traverse;
945 const char *signature;
947 signature = dbus_message_get_signature (message);
948 if (strcmp (signature, "o(aiia{ss}iaiiasib)uuib") != 0)
950 return droute_invalid_arguments_error (message);
953 dbus_message_iter_init (message, &iter);
954 dbus_message_iter_get_basic (&iter, ¤t_object_path);
955 current_object = ATK_OBJECT (spi_register_path_to_object (spi_global_register, current_object_path));
958 // TODO: object-not-found error
959 return spi_dbus_general_error (message);
961 dbus_message_iter_next (&iter);
962 if (!read_mr (&iter, &rule))
964 return spi_dbus_general_error (message);
966 dbus_message_iter_get_basic (&iter, &sortby);
967 dbus_message_iter_next (&iter);
968 dbus_message_iter_get_basic (&iter, &tree);
969 dbus_message_iter_next (&iter);
970 dbus_message_iter_get_basic (&iter, &count);
971 dbus_message_iter_next (&iter);
972 dbus_message_iter_get_basic (&iter, &traverse);
973 dbus_message_iter_next (&iter);
977 case Accessibility_Collection_TREE_RESTRICT_CHILDREN:
978 return GetMatchesFrom (message, current_object,
979 &rule, sortby, TRUE, count, traverse);
981 case Accessibility_Collection_TREE_RESTRICT_SIBLING:
982 return GetMatchesFrom (message, current_object,
983 &rule, sortby, FALSE, count, traverse);
985 case Accessibility_Collection_TREE_INORDER:
986 return GetMatchesInOrder (message, current_object,
987 &rule, sortby, TRUE, count, traverse);
995 impl_GetMatchesTo (DBusConnection * bus, DBusMessage * message,
998 char *current_object_path = NULL;
999 AtkObject *current_object;
1000 DBusMessageIter iter;
1001 MatchRulePrivate rule;
1002 dbus_uint32_t sortby;
1004 dbus_bool_t recurse;
1006 dbus_bool_t traverse;
1008 const char *signature;
1010 signature = dbus_message_get_signature (message);
1011 if (strcmp (signature, "o(aiia{ss}iaiiasib)uubib") != 0)
1013 return droute_invalid_arguments_error (message);
1016 dbus_message_iter_init (message, &iter);
1017 dbus_message_iter_get_basic (&iter, ¤t_object_path);
1018 current_object = ATK_OBJECT (spi_register_path_to_object (spi_global_register, current_object_path));
1019 if (!current_object)
1021 // TODO: object-not-found error
1022 return spi_dbus_general_error (message);
1024 dbus_message_iter_next (&iter);
1025 if (!read_mr (&iter, &rule))
1027 return spi_dbus_general_error (message);
1029 dbus_message_iter_get_basic (&iter, &sortby);
1030 dbus_message_iter_next (&iter);
1031 dbus_message_iter_get_basic (&iter, &tree);
1032 dbus_message_iter_next (&iter);
1033 dbus_message_iter_get_basic (&iter, &recurse);
1034 dbus_message_iter_next (&iter);
1035 dbus_message_iter_get_basic (&iter, &count);
1036 dbus_message_iter_next (&iter);
1037 dbus_message_iter_get_basic (&iter, &traverse);
1038 dbus_message_iter_next (&iter);
1042 case Accessibility_Collection_TREE_RESTRICT_CHILDREN:
1043 return GetMatchesTo (message, current_object,
1044 &rule, sortby, recurse, TRUE, count, traverse);
1046 case Accessibility_Collection_TREE_RESTRICT_SIBLING:
1047 return GetMatchesTo (message, current_object,
1048 &rule, sortby, recurse, FALSE, count, traverse);
1050 case Accessibility_Collection_TREE_INORDER:
1051 return GetMatchesInBackOrder (message, current_object,
1052 &rule, sortby, count);
1059 static DBusMessage *
1060 impl_GetMatches (DBusConnection * bus, DBusMessage * message, void *user_data)
1062 AtkObject *obj = ATK_OBJECT (spi_register_path_to_object (spi_global_register, dbus_message_get_path (message)));
1063 DBusMessageIter iter;
1064 MatchRulePrivate rule;
1065 dbus_uint32_t sortby;
1067 dbus_bool_t traverse;
1069 const char *signature;
1071 signature = dbus_message_get_signature (message);
1072 if (strcmp (signature, "(aiia{ss}iaiiasib)uib") != 0)
1074 return droute_invalid_arguments_error (message);
1077 dbus_message_iter_init (message, &iter);
1078 if (!read_mr (&iter, &rule))
1080 return spi_dbus_general_error (message);
1082 dbus_message_iter_get_basic (&iter, &sortby);
1083 dbus_message_iter_next (&iter);
1084 dbus_message_iter_get_basic (&iter, &count);
1085 dbus_message_iter_next (&iter);
1086 dbus_message_iter_get_basic (&iter, &traverse);
1087 dbus_message_iter_next (&iter);
1088 ls = g_list_prepend (ls, obj);
1089 count = query_exec (&rule, sortby, ls, 0, count,
1090 obj, 0, TRUE, NULL, TRUE, traverse);
1091 ls = g_list_remove (ls, ls->data);
1093 if (sortby == Accessibility_Collection_SORT_ORDER_REVERSE_CANONICAL)
1094 ls = g_list_reverse (ls);
1095 free_mrp_data (&rule);
1096 return return_and_free_list (message, ls);
1099 static DRouteMethod methods[] = {
1100 {impl_GetMatchesFrom, "GetMatchesFrom"},
1101 {impl_GetMatchesTo, "GetMatchesTo"},
1102 {impl_GetMatches, "GetMatches"},
1107 spi_initialize_collection (DRoutePath * path)
1109 droute_path_add_interface (path,
1110 SPI_DBUS_INTERFACE_COLLECTION, spi_org_a11y_atspi_Collection, methods, NULL);