Disable caching if ATSPI_NO_CACHE is set in the environment and not 0
[platform/upstream/at-spi2-core.git] / atspi / atspi-accessible.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  * Copyright 2010, 2011 Novell, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "atspi-private.h"
26 #include <string.h>
27
28 static void
29 atspi_action_interface_init (AtspiAction *action)
30 {
31 }
32
33 static void
34 atspi_collection_interface_init (AtspiCollection *component)
35 {
36 }
37
38 static void
39 atspi_component_interface_init (AtspiComponent *component)
40 {
41 }
42
43 static void
44 atspi_document_interface_init (AtspiDocument *document)
45 {
46 }
47
48 static void
49 atspi_editable_text_interface_init (AtspiEditableText *editable_text)
50 {
51 }
52
53 static void
54 atspi_hypertext_interface_init (AtspiHypertext *hypertext)
55 {
56 }
57
58 static void
59 atspi_image_interface_init (AtspiImage *image)
60 {
61 }
62
63 static void
64 atspi_selection_interface_init (AtspiSelection *selection)
65 {
66 }
67
68 static void
69 atspi_table_interface_init (AtspiTable *table)
70 {
71 }
72
73 static void
74 atspi_text_interface_init (AtspiText *text)
75 {
76 }
77
78 static void
79 atspi_value_interface_init (AtspiValue *value)
80 {
81 }
82
83 G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
84                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
85                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
86                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
87                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
88                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
89                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
90                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
91                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_SELECTION, atspi_selection_interface_init)
92                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TABLE, atspi_table_interface_init)
93                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_TEXT, atspi_text_interface_init)
94                          G_IMPLEMENT_INTERFACE (ATSPI_TYPE_VALUE, atspi_value_interface_init))
95
96 #ifdef DEBUG_REF_COUNTS
97 static gint accessible_count = 0;
98 #endif
99
100 static void
101 atspi_accessible_init (AtspiAccessible *accessible)
102 {
103 #ifdef DEBUG_REF_COUNTS
104   accessible_count++;
105   printf("at-spi: init: %d objects\n", accessible_count);
106 #endif
107 }
108
109 static void
110 atspi_accessible_dispose (GObject *object)
111 {
112   AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
113   AtspiEvent e;
114   AtspiAccessible *parent;
115
116   /* TODO: Only fire if object not already marked defunct */
117   memset (&e, 0, sizeof (e));
118   e.type = "object:state-change:defunct";
119   e.source = accessible;
120   e.detail1 = 1;
121   e.detail2 = 0;
122   _atspi_send_event (&e);
123
124   if (accessible->states)
125   {
126     g_object_unref (accessible->states);
127     accessible->states = NULL;
128   }
129
130   parent = accessible->accessible_parent;
131   if (parent && parent->children)
132   {
133     GList*ls = g_list_find (parent->children, accessible);
134     if(ls)
135     {
136       gboolean replace = (ls == parent->children);
137       ls = g_list_remove (ls, accessible);
138       if (replace)
139         parent->children = ls;
140       g_object_unref (object);
141     }
142   }
143
144   if (parent)
145   {
146     g_object_unref (parent);
147     accessible->accessible_parent = NULL;
148   }
149
150   G_OBJECT_CLASS (atspi_accessible_parent_class) ->dispose (object);
151 }
152
153 static void
154 atspi_accessible_finalize (GObject *object)
155 {
156   AtspiAccessible *accessible = ATSPI_ACCESSIBLE (object);
157
158     g_free (accessible->description);
159     g_free (accessible->name);
160
161 #ifdef DEBUG_REF_COUNTS
162   accessible_count--;
163   printf("at-spi: finalize: %d objects\n", accessible_count);
164 #endif
165
166   G_OBJECT_CLASS (atspi_accessible_parent_class)
167     ->finalize (object);
168 }
169
170 static void
171 atspi_accessible_class_init (AtspiAccessibleClass *klass)
172 {
173   GObjectClass *object_class = G_OBJECT_CLASS (klass);
174
175   object_class->dispose = atspi_accessible_dispose;
176   object_class->finalize = atspi_accessible_finalize;
177 }
178
179 /* TODO: Generate following from spec? */
180 static const char *role_names [] =
181 {
182   "invalid",
183   "accel-label",
184   "alert",
185   "animation",
186   "arrow",
187   "calendar",
188   "canvas",
189   "check-box",
190   "check-menu-item",
191   "color-chooser",
192   "column-header",
193   "combo-box",
194   "date-editor",
195   "desktop-icon",
196   "desktop-frame",
197   "dial",
198   "dialog",
199   "directory-pane",
200   "drawing-area",
201   "file-chooser",
202   "filler",
203   "font-chooser",
204   "frame",
205   "glass-pane",
206   "html-container",
207   "icon",
208   "image",
209   "internalframe",
210   "label",
211   "layered-pane",
212   "list",
213   "list-item",
214   "menu",
215   "menu-bar",
216   "menu-item",
217   "option-pane",
218   "page-tab",
219   "page-tab-list",
220   "panel",
221   "password-text",
222   "popup-menu",
223   "progress-bar",
224   "push-button",
225   "radio-button",
226   "radio-menu-item",
227   "root-pane",
228   "row-header",
229   "scroll-bar",
230   "scroll-pane",
231   "separator",
232   "slider",
233   "spin-button",
234   "split-pane",
235   "statusbar",
236   "table",
237   "table-cell",
238   "table-column-header",
239   "table-row-header",
240   "tear-off-menu-item",
241   "terminal",
242   "text",
243   "toggle-button",
244   "tool-bar",
245   "tool-tip",
246   "tree",
247   "tree-table",
248   "unknown",
249   "viewport",
250   "window",
251   NULL,
252   "header",
253   "fooler",
254   "paragraph",
255   "ruler",
256   "application",
257   "autocomplete",
258   "editbar",
259   "embedded",
260   "entry",
261   "chart",
262   "caption",
263   "document_frame",
264   "heading",
265   "page",
266   "section",
267   "form",
268   "redundant object",
269   "link",
270   "input method window"
271 };
272
273 #define MAX_ROLES (sizeof (role_names) / sizeof (char *))
274
275 /**
276  * atspi_role_get_name
277  * @role: an #AtspiAccessibleRole object to query.
278  *
279  * Get a localizeable string that indicates the name of an #AtspiAccessibleRole.
280  * <em>DEPRECATED.</em>
281  *
282  * Returns: a localizable string name for an #AtspiAccessibleRole enumerated type.
283  **/
284 gchar *
285 atspi_role_get_name (AtspiRole role)
286 {
287   if (role < MAX_ROLES && role_names [(int) role])
288     {
289       return g_strdup (role_names [(int) role]);
290     }
291   else
292     {
293       return g_strdup ("");
294     }
295 }
296
297 /**
298  * atspi_accessible_get_name:
299  * @obj: a pointer to the #AtspiAccessible object on which to operate.
300  *
301  * Get the name of an #AtspiAccessible object.
302  *
303  * Returns: a UTF-8 string indicating the name of the #AtspiAccessible object.
304  * or NULL on exception
305  **/
306 gchar *
307 atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
308 {
309   g_return_val_if_fail (obj != NULL, g_strdup (""));
310   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_NAME))
311   {
312     if (!_atspi_dbus_get_property (obj, atspi_interface_accessible, "Name", error,
313                                    "s", &obj->name))
314       return g_strdup ("");
315     _atspi_accessible_add_cache (obj, ATSPI_CACHE_NAME);
316   }
317   return g_strdup (obj->name);
318 }
319
320 /**
321  * atspi_accessible_get_description:
322  * @obj: a pointer to the #AtspiAccessible object on which to operate.
323  *
324  * Get the description of an #AtspiAccessible object.
325  *
326  * Returns: a UTF-8 string describing the #AtspiAccessible object.
327  * or NULL on exception
328  **/
329 gchar *
330 atspi_accessible_get_description (AtspiAccessible *obj, GError **error)
331 {
332   g_return_val_if_fail (obj != NULL, g_strdup (""));
333
334   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_DESCRIPTION))
335   {
336     if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
337                                    "Description", error, "s",
338                                    &obj->description))
339       return g_strdup ("");
340     _atspi_accessible_add_cache (obj, ATSPI_CACHE_DESCRIPTION);
341   }
342   return g_strdup (obj->description);
343 }
344
345 const char *str_parent = "Parent";
346
347 /**
348  * atspi_accessible_get_parent:
349  * @obj: a pointer to the #AtspiAccessible object to query.
350  *
351  * Get an #AtspiAccessible object's parent container.
352  *
353  * Returns: (transfer full): a pointer to the #AtspiAccessible object which
354  *          contains the given #AtspiAccessible instance, or NULL if the @obj
355  *          has no parent container.
356  *
357  **/
358 AtspiAccessible *
359 atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
360 {
361   g_return_val_if_fail (obj != NULL, NULL);
362
363   if (obj->parent.app &&
364       !_atspi_accessible_test_cache (obj, ATSPI_CACHE_PARENT))
365   {
366     DBusMessage *message, *reply;
367     DBusMessageIter iter, iter_variant;
368     message = dbus_message_new_method_call (obj->parent.app->bus_name,
369                                             obj->parent.path,
370                                             DBUS_INTERFACE_PROPERTIES, "Get");
371     if (!message)
372       return NULL;
373     dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_accessible,
374                                DBUS_TYPE_STRING, &str_parent,
375                               DBUS_TYPE_INVALID);
376     reply = _atspi_dbus_send_with_reply_and_block (message, error);
377     if (!reply)
378       return NULL;
379     if (strcmp (dbus_message_get_signature (reply), "v") != 0)
380     {
381       dbus_message_unref (reply);
382       return NULL;
383     }
384     dbus_message_iter_init (reply, &iter);
385     dbus_message_iter_recurse (&iter, &iter_variant);
386     obj->accessible_parent = _atspi_dbus_return_accessible_from_iter (&iter_variant);
387     dbus_message_unref (reply);
388     _atspi_accessible_add_cache (obj, ATSPI_CACHE_PARENT);
389   }
390   if (!obj->accessible_parent)
391     return NULL;
392   return g_object_ref (obj->accessible_parent);
393 }
394
395 /**
396  * atspi_accessible_get_child_count:
397  * @obj: a pointer to the #AtspiAccessible object on which to operate.
398  *
399  * Get the number of children contained by an #AtspiAccessible object.
400  *
401  * Returns: a #long indicating the number of #AtspiAccessible children
402  *          contained by an #AtspiAccessible object. or -1 on exception
403  *
404  **/
405 gint
406 atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
407 {
408   g_return_val_if_fail (obj != NULL, -1);
409
410   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
411   {
412     dbus_int32_t ret;
413     if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
414                                    "ChildCount", error, "i", &ret))
415       return -1;
416     return ret;
417   }
418
419   return g_list_length (obj->children);
420 }
421
422 /**
423  * atspi_accessible_get_child_at_index:
424  * @obj: a pointer to the #AtspiAccessible object on which to operate.
425  * @child_index: a #long indicating which child is specified.
426  *
427  * Get the #AtspiAccessible child of an #AtspiAccessible object at a given index.
428  *
429  * Returns: (transfer full): a pointer to the #AtspiAccessible child object at
430  * index @child_index. or NULL on exception
431  **/
432 AtspiAccessible *
433 atspi_accessible_get_child_at_index (AtspiAccessible *obj,
434                             gint    child_index,
435                             GError **error)
436 {
437   AtspiAccessible *child;
438
439   g_return_val_if_fail (obj != NULL, NULL);
440
441   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_CHILDREN))
442   {
443     DBusMessage *reply;
444     reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
445                                      "GetChildAtIndex", error, "i",
446                                      child_index);
447     return _atspi_dbus_return_accessible_from_message (reply);
448   }
449
450   child = g_list_nth_data (obj->children, child_index);
451   if (!child)
452     return NULL;
453   return g_object_ref (child);
454 }
455
456 /**
457  * atspi_accessible_get_index_in_parent
458  * @obj: a pointer to the #AtspiAccessible object on which to operate.
459  *
460  * Get the index of an #AtspiAccessible object in its containing #AtspiAccessible.
461  *
462  * Returns: a #glong indicating the index of the #AtspiAccessible object
463  *          in its parent (i.e. containing) #AtspiAccessible instance,
464  *          or -1 if @obj has no containing parent or on exception.
465  **/
466 gint
467 atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
468 {
469   GList *l;
470   gint i = 0;
471
472   g_return_val_if_fail (obj != NULL, -1);
473   if (!obj->accessible_parent) return -1;
474   if (!_atspi_accessible_test_cache (obj->accessible_parent,
475                                      ATSPI_CACHE_CHILDREN))
476   {
477     dbus_uint32_t ret = -1;
478     _atspi_dbus_call (obj, atspi_interface_accessible,
479                       "GetIndexInParent", NULL, "=>u", &ret);
480     return ret;
481   }
482
483   l = obj->accessible_parent->children;
484   while (l)
485   {
486     if (l->data == obj) return i;
487     l = g_list_next (l);
488     i++;
489   }
490   return -1;
491 }
492
493 typedef struct
494 {
495   dbus_uint32_t type;
496   GArray *targets;
497 } Accessibility_Relation;
498
499 /**
500  * atspi_accessible_get_relation_set:
501  * @obj: a pointer to the #AtspiAccessible object on which to operate.
502  *
503  * Get the set of #AtspiRelation objects which describe this #AtspiAccessible object's
504  *       relationships with other #AtspiAccessible objects.
505  *
506  * Returns: (element-type AtspiAccessible*) (transfer full): an array of
507  *          #AtspiAccessibleRelation pointers. or NULL on exception
508  **/
509 GArray *
510 atspi_accessible_get_relation_set (AtspiAccessible *obj, GError **error)
511 {
512   DBusMessage *reply;
513   DBusMessageIter iter, iter_array;
514   GArray *ret;
515
516   g_return_val_if_fail (obj != NULL, NULL);
517
518   reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetRelationSet", error, "");
519   if (!reply)
520     return NULL;
521   _ATSPI_DBUS_CHECK_SIG (reply, "a(ua(so))", error, NULL);
522
523   ret = g_array_new (TRUE, TRUE, sizeof (AtspiRelation *));
524   dbus_message_iter_init (reply, &iter);
525   dbus_message_iter_recurse (&iter, &iter_array);
526   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
527   {
528     AtspiRelation *relation;
529     relation = _atspi_relation_new_from_iter (&iter_array);
530     ret = g_array_append_val (ret, relation);
531     dbus_message_iter_next (&iter_array);
532   }
533   dbus_message_unref (reply);
534   return ret;
535 }
536
537 /**
538  * atspi_accessible_get_role:
539  * @obj: a pointer to the #AtspiAccessible object on which to operate.
540  *
541  * Get the UI role of an #AtspiAccessible object.
542  * A UTF-8 string describing this role can be obtained via atspi_accessible_getRoleName ().
543  *
544  * Returns: the #AtspiRole of the object.
545  *
546  **/
547 AtspiRole
548 atspi_accessible_get_role (AtspiAccessible *obj, GError **error)
549 {
550   g_return_val_if_fail (obj != NULL, ATSPI_ROLE_INVALID);
551
552   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_ROLE))
553   {
554     dbus_uint32_t role;
555     /* TODO: Make this a property */
556     if (_atspi_dbus_call (obj, atspi_interface_accessible, "GetRole", error, "=>u", &role))
557     {
558       obj->role = role;
559     _atspi_accessible_add_cache (obj, ATSPI_CACHE_ROLE);
560     }
561   }
562   return obj->role;
563 }
564
565 /**
566  * atspi_accessible_get_role_name:
567  * @obj: a pointer to the #AtspiAccessible object on which to operate.
568  *
569  * Get a UTF-8 string describing the role this object plays in the UI.
570  * This method will return useful values for roles that fall outside the
571  * enumeration used in atspi_accessible_getRole ().
572  *
573  * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
574  *
575  **/
576 gchar *
577 atspi_accessible_get_role_name (AtspiAccessible *obj, GError **error)
578 {
579   char *retval = NULL;
580
581   g_return_val_if_fail (obj != NULL, NULL);
582
583   _atspi_dbus_call (obj, atspi_interface_accessible, "GetRoleName", error, "=>s", &retval);
584
585   if (!retval)
586     retval = g_strdup ("");
587
588   return retval;
589 }
590
591 /**
592  * atspi_accessible_get_localized_role_name:
593  * @obj: a pointer to the #AtspiAccessible object on which to operate.
594  *
595  * Get a UTF-8 string describing the (localized) role this object plays in the UI.
596  * This method will return useful values for roles that fall outside the
597  * enumeration used in atspi_accessible_getRole ().
598  *
599  * Returns: a UTF-8 string specifying the role of this #AtspiAccessible object.
600  *
601  **/
602 gchar *
603 atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error)
604 {
605   char *retval = NULL;
606
607   g_return_val_if_fail (obj != NULL, NULL);
608
609   _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval);
610
611   if (!retval)
612     return g_strdup ("");
613
614   return retval;
615 }
616
617 static AtspiStateSet *
618 defunct_set ()
619 {
620   AtspiStateSet *set = atspi_state_set_new (NULL);
621   atspi_state_set_add (set, ATSPI_STATE_DEFUNCT);
622   return set;
623 }
624
625 /**
626  * atspi_accessible_get_state_set:
627  * @obj: a pointer to the #AtspiAccessible object on which to operate.
628  *
629  * Gets the current state of an object.
630  *
631  * Returns: (transfer full): a pointer to an #AtspiStateSet representing the
632  *          object's current state.
633  **/
634 AtspiStateSet *
635 atspi_accessible_get_state_set (AtspiAccessible *obj)
636 {
637   if (!obj->parent.app || !obj->parent.app->bus)
638     return defunct_set ();
639
640
641   if (!_atspi_accessible_test_cache (obj, ATSPI_CACHE_STATES))
642   {
643     DBusMessage *reply;
644     DBusMessageIter iter;
645     reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
646                                       "GetState", NULL, "");
647     _ATSPI_DBUS_CHECK_SIG (reply, "au", NULL, defunct_set ());
648     dbus_message_iter_init (reply, &iter);
649     _atspi_dbus_set_state (obj, &iter);
650     dbus_message_unref (reply);
651     _atspi_accessible_add_cache (obj, ATSPI_CACHE_STATES);
652   }
653
654   return g_object_ref (obj->states);
655 }
656
657 /**
658  * atspi_accessible_get_attributes:
659  * @obj: The #AtspiAccessible being queried.
660  *
661  * Get the #AttributeSet representing any assigned 
662  * name-value pair attributes or annotations for this object.
663  * For typographic, textual, or textually-semantic attributes, see
664  * atspi_text_get_attributes instead.
665  *
666  * Returns: (element-type gchar* gchar*) (transfer full): The name-value-pair
667  *          attributes assigned to this object.
668  */
669 GHashTable *
670 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
671 {
672   DBusMessage *message;
673
674     g_return_val_if_fail (obj != NULL, NULL);
675
676   message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
677   return _atspi_dbus_return_hash_from_message (message);
678 }
679
680 /**
681  * atspi_accessible_get_attributes_as_array:
682  * @obj: The #AtspiAccessible being queried.
683  *
684  * Get the #AttributeSet representing any assigned 
685  * name-value pair attributes or annotations for this object.
686  * For typographic, textual, or textually-semantic attributes, see
687  * atspi_text_get_attributes_as_array instead.
688  *
689  * Returns: (element-type gchar*) (transfer full): The name-value-pair
690  *          attributes assigned to this object.
691  */
692 GArray *
693 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
694 {
695   DBusMessage *message;
696
697     g_return_val_if_fail (obj != NULL, NULL);
698
699   message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
700   return _atspi_dbus_return_attribute_array_from_message (message);
701 }
702
703 /**
704  * atspi_accessible_get_application:
705  * @obj: The #AtspiAccessible being queried.
706  *
707  * Get the containing #AtspiApplication for an object.
708  *
709  * Returns: (transfer full): the containing AtspiApplication instance for
710  *          this object.
711  */
712 AtspiAccessible *
713 atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
714 {
715   AtspiAccessible *parent;
716
717   g_object_ref (obj);
718   for (;;)
719   {
720     parent = atspi_accessible_get_parent (obj, NULL);
721     if (!parent && obj->parent.app &&
722         atspi_accessible_get_role (obj, NULL) != ATSPI_ROLE_APPLICATION)
723     {
724       AtspiAccessible *root = g_object_ref (obj->parent.app->root);
725       if (root)
726       {
727         g_object_unref (obj);
728         if (atspi_accessible_get_role (root, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
729         {
730           g_object_unref (root);
731           return NULL;
732         }
733         return root;
734       }
735     }
736     if (!parent || parent == obj ||
737         atspi_accessible_get_role (parent, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
738     return obj;
739     g_object_unref (obj);
740     obj = parent;
741   }
742 }
743
744 /* Application-specific methods */
745
746 /**
747  * atspi_accessible_get_toolkit_name:
748  * @obj: a pointer to the #AtspiAccessible object on which to operate.
749  *
750  * Get the toolkit for a #AtspiAccessible object.
751  * Only works on application root objects.
752  *
753  * Returns: a UTF-8 string indicating the toolkit name for the #AtspiAccessible object.
754  * or NULL on exception
755  **/
756 gchar *
757 atspi_accessible_get_toolkit_name (AtspiAccessible *obj, GError **error)
758 {
759   gchar *ret = NULL;
760
761   g_return_val_if_fail (obj != NULL, NULL);
762
763   if (!_atspi_dbus_get_property (obj, atspi_interface_application, "ToolkitName", error, "s", &ret))
764       return NULL;
765   return ret;
766 }
767
768 /**
769  * atspi_accessible_get_toolkit_version:
770  * @obj: a pointer to the #AtspiAccessible object on which to operate.
771  *
772  * Get the toolkit version for a #AtspiAccessible object.
773  * Only works on application root objects.
774  *
775  * Returns: a UTF-8 string indicating the toolkit ersion for the #AtspiAccessible object.
776  * or NULL on exception
777  **/
778 gchar *
779 atspi_accessible_get_toolkit_version (AtspiAccessible *obj, GError **error)
780 {
781   gchar *ret = NULL;
782
783   g_return_val_if_fail (obj != NULL, NULL);
784
785   if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Version", error, "s", &ret))
786       return NULL;
787   return ret;
788 }
789
790 /**
791  * atspi_accessible_get_atspi_version:
792  * @obj: a pointer to the #AtspiAccessible object on which to operate.
793  *
794  * Get the AT-SPI IPC specification version supported by the application
795  * pointed to by the #AtspiAccessible object.
796  * Only works on application root objects.
797  *
798  * Returns: a UTF-8 string indicating the AT-SPI ersion for the #AtspiAccessible object.
799  * or NULL on exception
800  **/
801 gchar *
802 atspi_accessible_get_atspi_version (AtspiAccessible *obj, GError **error)
803 {
804   gchar *ret = NULL;
805
806   g_return_val_if_fail (obj != NULL, NULL);
807
808   if (!_atspi_dbus_get_property (obj, atspi_interface_application, "AtspiVersion", error, "s", &ret))
809       return NULL;
810   return ret;
811 }
812
813 /**
814  * atspi_accessible_get_toolkit_version:
815  * @obj: a pointer to the #AtspiAccessible object on which to operate.
816  *
817  * Get the application id for a #AtspiAccessible object.
818  * Only works on application root objects.
819  *
820  * Returns: a gint indicating the id for the #AtspiAccessible object.
821  * or -1 on exception
822  **/
823 gint
824 atspi_accessible_get_id (AtspiAccessible *obj, GError **error)
825 {
826   gint ret = -1;
827
828   g_return_val_if_fail (obj != NULL, -1);
829
830   if (!_atspi_dbus_get_property (obj, atspi_interface_application, "Id", error, "i", &ret))
831       return -1;
832   return ret;
833 }
834
835
836 /* Interface query methods */
837
838 static gboolean
839 _atspi_accessible_is_a (AtspiAccessible *accessible,
840                       const char *interface_name)
841 {
842   int n;
843
844   if (accessible == NULL)
845     {
846       return FALSE;
847     }
848
849   if (!_atspi_accessible_test_cache (accessible, ATSPI_CACHE_INTERFACES))
850   {
851     DBusMessage *reply;
852     DBusMessageIter iter;
853     reply = _atspi_dbus_call_partial (accessible, atspi_interface_accessible,
854                                       "GetInterfaces", NULL, "");
855     _ATSPI_DBUS_CHECK_SIG (reply, "as", NULL, FALSE);
856     dbus_message_iter_init (reply, &iter);
857     _atspi_dbus_set_interfaces (accessible, &iter);
858     dbus_message_unref (reply);
859     _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
860   }
861
862   n = _atspi_get_iface_num (interface_name);
863   if (n == -1) return FALSE;
864   return (gboolean) ((accessible->interfaces & (1 << n))? TRUE: FALSE);
865 }
866
867 /**
868  * atspi_accessible_is_action:
869  * @obj: a pointer to the #AtspiAccessible instance to query.
870  *
871  * Query whether the specified #AtspiAccessible implements #AtspiAction.
872  *
873  * Returns: #TRUE if @obj implements the #AtspiAction interface,
874  *          #FALSE otherwise.
875  **/
876 gboolean
877 atspi_accessible_is_action (AtspiAccessible *obj)
878 {
879   return _atspi_accessible_is_a (obj,
880                               atspi_interface_action);
881 }
882
883 /**
884  * atspi_accessible_is_application:
885  * @obj: a pointer to the #AtspiAccessible instance to query.
886  *
887  * Query whether the specified #AtspiAccessible implements #AtspiApplication.
888  *
889  * Returns: #TRUE if @obj implements the #AtspiApplication interface,
890  *          #FALSE otherwise.
891  **/
892 gboolean
893 atspi_accessible_is_application (AtspiAccessible *obj)
894 {
895   return _atspi_accessible_is_a (obj,
896                               atspi_interface_application);
897 }
898
899 /**                      
900  * atspi_accessible_is_collection:                                                                                                                                                                          * @obj: a pointer to the #AtspiAccessible instance to query.                                                                                                                                          
901  *                          
902  * Query whether the specified #AtspiAccessible implements #AtspiCollection.    
903  * Returns: #TRUE if @obj implements the #AtspiCollection interface,                                                                                                               
904  *          #FALSE otherwise.
905  **/
906 gboolean
907 atspi_accessible_is_collection (AtspiAccessible *obj)
908 {
909      return _atspi_accessible_is_a (obj,
910                               atspi_interface_collection);
911 }
912
913 /**
914  * atspi_accessible_is_component:
915  * @obj: a pointer to the #AtspiAccessible instance to query.
916  *
917  * Query whether the specified #AtspiAccessible implements #AtspiComponent.
918  *
919  * Returns: #TRUE if @obj implements the #AtspiComponent interface,
920  *          #FALSE otherwise.
921  **/
922 gboolean
923 atspi_accessible_is_component (AtspiAccessible *obj)
924 {
925   return _atspi_accessible_is_a (obj,
926                               atspi_interface_component);
927 }
928
929 /**
930  * atspi_accessible_is_document:
931  * @obj: a pointer to the #AtspiAccessible instance to query.
932  *
933  * Query whether the specified #AtspiAccessible implements #AtspiDocument.
934  *
935  * Returns: #TRUE if @obj implements the #AtspiDocument interface,
936  *          #FALSE otherwise.
937  **/
938 gboolean
939 atspi_accessible_is_document (AtspiAccessible *obj)
940 {
941   return _atspi_accessible_is_a (obj,
942                               atspi_interface_document);
943 }
944
945 /**
946  * atspi_accessible_is_editable_text:
947  * @obj: a pointer to the #AtspiAccessible instance to query.
948  *
949  * Query whether the specified #AtspiAccessible implements #AtspiEditableText.
950  *
951  * Returns: #TRUE if @obj implements the #AtspiEditableText interface,
952  *          #FALSE otherwise.
953  **/
954 gboolean
955 atspi_accessible_is_editable_text (AtspiAccessible *obj)
956 {
957   return _atspi_accessible_is_a (obj,
958                               atspi_interface_editable_text);
959 }
960                                                                                                                                                                         
961 /**
962  * atspi_accessible_is_hypertext:
963  * @obj: a pointer to the #AtspiAccessible instance to query.
964  *
965  * Query whether the specified #AtspiAccessible implements #AtspiHypertext.
966  *
967  * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
968  *          #FALSE otherwise.
969  **/
970 gboolean
971 atspi_accessible_is_hypertext (AtspiAccessible *obj)
972 {
973   return _atspi_accessible_is_a (obj,
974                               atspi_interface_hypertext);
975 }
976
977 /**
978  * atspi_accessible_is_hyperlink:
979  * @obj: a pointer to the #AtspiAccessible instance to query.
980  *
981  * Query whether the specified #AtspiAccessible implements #AtspiHyperlink.
982  *
983  * Returns: #TRUE if @obj implements the #AtspiHypertext interface,
984  *          #FALSE otherwise.
985  **/
986 gboolean
987 atspi_accessible_is_hyperlink (AtspiAccessible *obj)
988 {
989   return _atspi_accessible_is_a (obj,
990                               atspi_interface_hyperlink);
991 }
992
993 /**
994  * atspi_accessible_is_image:
995  * @obj: a pointer to the #AtspiAccessible instance to query.
996  *
997  * Query whether the specified #AtspiAccessible implements #AtspiImage.
998  *
999  * Returns: #TRUE if @obj implements the #AtspiImage interface,
1000  *          #FALSE otherwise.
1001 **/
1002 gboolean
1003 atspi_accessible_is_image (AtspiAccessible *obj)
1004 {
1005   return _atspi_accessible_is_a (obj,
1006                               atspi_interface_image);
1007 }
1008
1009 /**
1010  * atspi_accessible_is_selection:
1011  * @obj: a pointer to the #AtspiAccessible instance to query.
1012  *
1013  * Query whether the specified #AtspiAccessible implements #AtspiSelection.
1014  *
1015  * Returns: #TRUE if @obj implements the #AtspiSelection interface,
1016  *          #FALSE otherwise.
1017 **/
1018 gboolean
1019 atspi_accessible_is_selection (AtspiAccessible *obj)
1020 {
1021   return _atspi_accessible_is_a (obj,
1022                               atspi_interface_selection);
1023 }
1024
1025 /**
1026  * atspi_accessible_is_table:
1027  * @obj: a pointer to the #AtspiAccessible instance to query.
1028  *
1029  * Query whether the specified #AtspiAccessible implements #AtspiTable.
1030  *
1031  * Returns: #TRUE if @obj implements the #AtspiTable interface,
1032  *          #FALSE otherwise.
1033 **/
1034 gboolean
1035 atspi_accessible_is_table (AtspiAccessible *obj)
1036 {
1037   return _atspi_accessible_is_a (obj,
1038                               atspi_interface_table);
1039 }
1040
1041 /**
1042  * atspi_accessible_is_streamable_content:
1043  * @obj: a pointer to the #AtspiAccessible instance to query.
1044  *
1045  * Query whether the specified #AtspiAccessible implements
1046  *          #AtspiStreamableContent.
1047  *
1048  * Returns: #TRUE if @obj implements the #AtspiStreamableContent interface,
1049  *          #FALSE otherwise.
1050 **/
1051 gboolean
1052 atspi_accessible_is_streamable_content (AtspiAccessible *obj)
1053 {
1054 #if 0
1055   return _atspi_accessible_is_a (obj,
1056                               atspi_interface_streamable_content);
1057 #else
1058   g_warning ("Streamable content not implemented");
1059   return FALSE;
1060 #endif
1061 }
1062
1063 /**
1064  * atspi_accessible_is_text:
1065  * @obj: a pointer to the #AtspiAccessible instance to query.
1066  *
1067  * Query whether the specified #AtspiAccessible implements #AtspiText.
1068  *
1069  * Returns: #TRUE if @obj implements the #AtspiText interface,
1070  *          #FALSE otherwise.
1071 **/
1072 gboolean
1073 atspi_accessible_is_text (AtspiAccessible *obj)
1074 {
1075   return _atspi_accessible_is_a (obj,
1076                               atspi_interface_text);
1077 }
1078
1079 /**
1080  * atspi_accessible_is_value:
1081  * @obj: a pointer to the #AtspiAccessible instance to query.
1082  *
1083  * Query whether the specified #AtspiAccessible implements #AtspiValue.
1084  *
1085  * Returns: #TRUE if @obj implements the #AtspiValue interface,
1086  *          #FALSE otherwise.
1087 **/
1088 gboolean
1089 atspi_accessible_is_value (AtspiAccessible *obj)
1090 {
1091   return _atspi_accessible_is_a (obj,
1092                               atspi_interface_value);
1093 }
1094
1095 /**
1096  * atspi_accessible_get_action:
1097  * @obj: a pointer to the #AtspiAccessible instance to query.
1098  *
1099  * Get the #AtspiAction interface for an #AtspiAccessible.
1100  *
1101  * Returns: (transfer full): a pointer to an #AtspiAction interface
1102  *          instance, or NULL if @obj does not implement #AtspiAction.
1103  **/
1104 AtspiAction *
1105 atspi_accessible_get_action (AtspiAccessible *accessible)
1106 {
1107   return (_atspi_accessible_is_a (accessible, atspi_interface_action) ?
1108           g_object_ref (ATSPI_ACTION (accessible)) : NULL);  
1109 }
1110
1111 /**
1112  * atspi_accessible_get_collection:
1113  * @obj: a pointer to the #AtspiAccessible instance to query.
1114  *
1115  * Get the #AtspiCollection interface for an #AtspiAccessible.
1116  *
1117  * Returns: (transfer full): a pointer to an #AtspiCollection interface
1118  *          instance, or NULL if @obj does not implement #AtspiCollection.
1119  **/
1120 AtspiCollection *
1121 atspi_accessible_get_collection (AtspiAccessible *accessible)
1122 {
1123   return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ?
1124           g_object_ref (ATSPI_COLLECTION (accessible)) : NULL);  
1125 }
1126
1127 /**
1128  * atspi_accessible_get_component:
1129  * @obj: a pointer to the #AtspiAccessible instance to query.
1130  *
1131  * Get the #AtspiComponent interface for an #AtspiAccessible.
1132  *
1133  * Returns: (transfer full): a pointer to an #AtspiComponent interface
1134  *          instance, or NULL if @obj does not implement #AtspiComponent.
1135  **/
1136 AtspiComponent *
1137 atspi_accessible_get_component (AtspiAccessible *obj)
1138 {
1139   return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
1140           g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
1141 }
1142
1143 /**
1144  * atspi_accessible_get_document:
1145  * @obj: a pointer to the #AtspiAccessible instance to query.
1146  *
1147  * Get the #AtspiDocument interface for an #AtspiAccessible.
1148  *
1149  * Returns: (transfer full): a pointer to an #AtspiDocument interface
1150  *          instance, or NULL if @obj does not implement #AtspiDocument.
1151  **/
1152 AtspiDocument *
1153 atspi_accessible_get_document (AtspiAccessible *accessible)
1154 {
1155   return (_atspi_accessible_is_a (accessible, atspi_interface_document) ?
1156           g_object_ref (ATSPI_DOCUMENT (accessible)) : NULL);  
1157 }
1158
1159 /**
1160  * atspi_accessible_get_editable_text:
1161  * @obj: a pointer to the #AtspiAccessible instance to query.
1162  *
1163  * Get the #AtspiEditableText interface for an #AtspiAccessible.
1164  *
1165  * Returns: (transfer full): a pointer to an #AtspiEditableText interface
1166  *          instance, or NULL if @obj does not implement #AtspiEditableText.
1167  **/
1168 AtspiEditableText *
1169 atspi_accessible_get_editable_text (AtspiAccessible *accessible)
1170 {
1171   return (_atspi_accessible_is_a (accessible, atspi_interface_editable_text) ?
1172           g_object_ref (ATSPI_EDITABLE_TEXT (accessible)) : NULL);  
1173 }
1174
1175 /**
1176  * atspi_accessible_get_hyperlink:
1177  * @obj: a pointer to the #AtspiAccessible object on which to operate.
1178  *
1179  * Get the #AtspiHyperlink associated with the given #AtspiAccessible, if
1180  * supported.
1181  *
1182  * Returns: (transfer full): the #AtspiHyperlink object associated with
1183  *          the given #AtspiAccessible, or NULL if not supported.
1184  **/
1185 AtspiHyperlink *
1186 atspi_accessible_get_hyperlink (AtspiAccessible *accessible)
1187 {
1188   return (_atspi_accessible_is_a (accessible, atspi_interface_hyperlink) ?
1189           atspi_hyperlink_new (accessible->parent.app, accessible->parent.path) : NULL);
1190 }
1191
1192 /**
1193  * atspi_accessible_get_hypertext:
1194  * @obj: a pointer to the #AtspiAccessible instance to query.
1195  *
1196  * Get the #AtspiHypertext interface for an #AtspiAccessible.
1197  *
1198  * Returns: (transfer full): a pointer to an #AtspiHypertext interface
1199  *          instance, or NULL if @obj does not implement #AtspiHypertext.
1200  **/
1201 AtspiHypertext *
1202 atspi_accessible_get_hypertext (AtspiAccessible *accessible)
1203 {
1204   return (_atspi_accessible_is_a (accessible, atspi_interface_hypertext) ?
1205           g_object_ref (ATSPI_HYPERTEXT (accessible)) : NULL);  
1206 }
1207
1208 /**
1209  * atspi_accessible_get_image:
1210  * @obj: a pointer to the #AtspiAccessible instance to query.
1211  *
1212  * Get the #AtspiImage interface for an #AtspiAccessible.
1213  *
1214  * Returns: (transfer full): a pointer to an #AtspiImage interface instance, or
1215  *          NULL if @obj does not implement #AtspiImage.
1216  **/
1217 AtspiImage *
1218 atspi_accessible_get_image (AtspiAccessible *accessible)
1219 {
1220   return (_atspi_accessible_is_a (accessible, atspi_interface_image) ?
1221           g_object_ref (ATSPI_IMAGE (accessible)) : NULL);  
1222 }
1223
1224 /**
1225  * atspi_accessible_get_selection:
1226  * @obj: a pointer to the #AtspiAccessible instance to query.
1227  *
1228  * Get the #AtspiSelection interface for an #AtspiAccessible.
1229  *
1230  * Returns: (transfer full): a pointer to an #AtspiSelection interface
1231  *          instance, or NULL if @obj does not implement #AtspiSelection.
1232  **/
1233 AtspiSelection *
1234 atspi_accessible_get_selection (AtspiAccessible *accessible)
1235 {
1236   return (_atspi_accessible_is_a (accessible, atspi_interface_selection) ?
1237           g_object_ref (ATSPI_SELECTION (accessible)) : NULL);  
1238 }
1239
1240 #if 0
1241 /**
1242  * atspi_accessible_get_streamable_content:
1243  * @obj: a pointer to the #AtspiAccessible instance to query.
1244  *
1245  * Get the #AtspiStreamableContent interface for an #AtspiAccessible.
1246  *
1247  * Returns: (transfer full): a pointer to an #AtspiStreamableContent interface
1248  *          instance, or NULL if @obj does not implement #AtspiStreamableContent.
1249  **/
1250 AtspiStreamableContent *
1251 atspi_accessible_get_streamable_content (AtspiAccessible *accessible)
1252 {
1253   return (_atspi_accessible_is_a (accessible, atspi_interface_streamable_content) ?
1254           accessible : NULL);  
1255 }
1256 #endif
1257
1258 /**
1259  * atspi_accessible_get_table:
1260  * @obj: a pointer to the #AtspiAccessible instance to query.
1261  *
1262  * Get the #AtspiTable interface for an #AtspiAccessible.
1263  *
1264  * Returns: (transfer full): a pointer to an #AtspiTable interface instance, or
1265  *          NULL if @obj does not implement #AtspiTable.
1266  **/
1267 AtspiTable *
1268 atspi_accessible_get_table (AtspiAccessible *obj)
1269 {
1270   return (_atspi_accessible_is_a (obj, atspi_interface_table) ?
1271           g_object_ref (ATSPI_TABLE (obj)) : NULL);  
1272 }
1273
1274 /**
1275  * atspi_accessible_get_text:
1276  * @obj: a pointer to the #AtspiAccessible instance to query.
1277  *
1278  * Get the #AtspiTable interface for an #AtspiAccessible.
1279  *
1280  * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
1281  *          NULL if @obj does not implement #AtspiText.
1282  **/
1283 AtspiText *
1284 atspi_accessible_get_text (AtspiAccessible *obj)
1285 {
1286   return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
1287           g_object_ref (ATSPI_TEXT (obj)) : NULL);
1288 }
1289
1290 /**
1291  * atspi_accessible_get_value:
1292  * @obj: a pointer to the #AtspiAccessible instance to query.
1293  *
1294  * Get the #AtspiTable interface for an #AtspiAccessible.
1295  *
1296  * Returns: (transfer full): a pointer to an #AtspiValue interface instance, or
1297  *          NULL if @obj does not implement #AtspiValue.
1298  **/
1299 AtspiValue *
1300 atspi_accessible_get_value (AtspiAccessible *accessible)
1301 {
1302   return (_atspi_accessible_is_a (accessible, atspi_interface_value) ?
1303           g_object_ref (ATSPI_VALUE (accessible)) : NULL);  
1304 }
1305
1306 static void
1307 append_const_val (GArray *array, const gchar *val)
1308 {
1309   gchar *dup = g_strdup (val);
1310
1311   if (dup)
1312     g_array_append_val (array, dup);
1313 }
1314
1315 /**
1316  * atspi_accessible_get_interfaces:
1317  *
1318  * #obj: The #AtspiAccessible to query.
1319  *
1320  * Returns: (element-type gchar*) (transfer full): A #GArray of strings
1321  *          describing the interfaces supported by the object.  Interfaces are
1322  *          denoted in short-hand (ie, "Component", "Text", etc.)
1323  **/
1324 GArray *
1325 atspi_accessible_get_interfaces (AtspiAccessible *obj)
1326 {
1327   GArray *ret = g_array_new (TRUE, TRUE, sizeof (gchar *));
1328
1329   g_return_val_if_fail (obj != NULL, NULL);
1330
1331   append_const_val (ret, "Accessible");
1332   if (atspi_accessible_is_action (obj))
1333     append_const_val (ret, "Action");
1334   if (atspi_accessible_is_collection (obj))
1335     append_const_val (ret, "Collection");
1336   if (atspi_accessible_is_component (obj))
1337     append_const_val (ret, "Component");
1338   if (atspi_accessible_is_document (obj))
1339     append_const_val (ret, "Document");
1340   if (atspi_accessible_is_editable_text (obj))
1341     append_const_val (ret, "EditableText");
1342   if (atspi_accessible_is_hypertext (obj))
1343     append_const_val (ret, "Hypertext");
1344   if (atspi_accessible_is_hyperlink (obj))
1345     append_const_val (ret, "Hyperlink");
1346   if (atspi_accessible_is_image (obj))
1347     append_const_val (ret, "Image");
1348   if (atspi_accessible_is_selection (obj))
1349     append_const_val (ret, "Selection");
1350   if (atspi_accessible_is_table (obj))
1351     append_const_val (ret, "Table");
1352   if (atspi_accessible_is_text (obj))
1353     append_const_val (ret, "Text");
1354   if (atspi_accessible_is_value (obj))
1355     append_const_val (ret, "Value");
1356
1357   return ret;
1358 }
1359
1360 AtspiAccessible *
1361 atspi_accessible_new (AtspiApplication *app, const gchar *path)
1362 {
1363   AtspiAccessible *accessible;
1364   
1365   accessible = g_object_new (ATSPI_TYPE_ACCESSIBLE, NULL);
1366   g_return_val_if_fail (accessible != NULL, NULL);
1367
1368   accessible->parent.app = g_object_ref (app);
1369   accessible->parent.path = g_strdup (path);
1370
1371   return accessible;
1372 }
1373
1374 /**
1375  * atspi_accessible_set_cache_mask:
1376  *
1377  * @accessible: The #AtspiAccessible to operate on.  Must be the desktop or
1378  *             the root of an application.
1379  * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
1380  *
1381  * Sets the type of data to cache for accessibles.
1382  * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
1383  * then the desktop's cache flag will be used.
1384  * If the desktop's cache flag is also undefined, then all possible data will
1385  * be cached.
1386  * This function is intended to work around bugs in toolkits where the proper
1387  * events are not raised / to aid in testing for such bugs.
1388  **/
1389 void
1390 atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
1391 {
1392   g_return_if_fail (accessible != NULL);
1393   g_return_if_fail (accessible->parent.app != NULL);
1394   g_return_if_fail (accessible == accessible->parent.app->root);
1395   accessible->parent.app->cache = mask;
1396 }
1397
1398 /**
1399  * atspi_accessible_clear_cache:
1400  * @accessible: The #AtspiAccessible whose cache to clear.
1401  *
1402  * Clears the cached information for the given accessible and all of its
1403  * descendants.
1404  */
1405 void
1406 atspi_accessible_clear_cache (AtspiAccessible *accessible)
1407 {
1408   GList *l;
1409
1410   if (accessible)
1411   {
1412     accessible->cached_properties = ATSPI_CACHE_NONE;
1413     for (l = accessible->children; l; l = l->next)
1414       atspi_accessible_clear_cache (l->data);
1415   }
1416 }
1417
1418 static AtspiCache
1419 _atspi_accessible_get_cache_mask (AtspiAccessible *accessible)
1420 {
1421   AtspiCache mask;
1422
1423   if (!accessible->parent.app)
1424     return ATSPI_CACHE_NONE;
1425
1426  mask = accessible->parent.app->cache;
1427   if (mask == ATSPI_CACHE_UNDEFINED &&
1428       accessible->parent.app->root &&
1429       accessible->parent.app->root->accessible_parent)
1430   {
1431     AtspiAccessible *desktop = atspi_get_desktop (0);
1432     mask = desktop->parent.app->cache;
1433     g_object_unref (desktop);
1434   }
1435
1436   if (mask == ATSPI_CACHE_UNDEFINED)
1437     mask = ATSPI_CACHE_ALL;
1438
1439   return mask;
1440 }
1441
1442 gboolean
1443 _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
1444 {
1445   AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1446   AtspiCache result = accessible->cached_properties & mask & flag;
1447   return (result != 0 && atspi_main_loop && !atspi_no_cache);
1448 }
1449
1450 void
1451 _atspi_accessible_add_cache (AtspiAccessible *accessible, AtspiCache flag)
1452 {
1453   AtspiCache mask = _atspi_accessible_get_cache_mask (accessible);
1454
1455   accessible->cached_properties |= flag & mask;
1456 }