2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include "atspi-private.h"
27 * atspi_relation_get_relation_type:
28 * @obj: a pointer to the #AtspiRelation object to query.
30 * Get the type of relationship represented by an #AtspiRelation.
32 * Returns: an #AtspiRelationType indicating the type of relation
33 * encapsulated in this #AtspiRelation object.
37 atspi_relation_get_relation_type (AtspiRelation *obj)
39 return obj->relation_type;
43 * atspi_relation_get_n_targets:
44 * @obj: a pointer to the #AtspiRelation object to query.
46 * Get the number of objects which this relationship has as its
47 * target objects (the subject is the #Accessible from which this
48 * #AtspiRelation originated).
50 * Returns: a short integer indicating how many target objects which the
51 * originating #Accessible object has the #AtspiRelation
55 atspi_relation_get_n_targets (AtspiRelation *obj)
57 return obj->targets->len;
61 * atspi_relation_get_target:
62 * @obj: a pointer to the #AtspiRelation object to query.
63 * @i: a (zero-index) integer indicating which (of possibly several) target is requested.
65 * Get the @i-th target of a specified #AtspiRelation relationship.
67 * Returns: (transfer full): an #AtspiAccessible which is the @i-th object
68 * with which the originating #AtspiAccessible has relationship
69 * specified in the #AtspiRelation object.
73 atspi_relation_get_target (AtspiRelation *obj, gint i)
75 g_return_val_if_fail (obj, NULL);
77 g_return_val_if_fail (i >= 0 && i < obj->targets->len, NULL);
78 return g_object_ref (g_array_index (obj->targets, AtspiAccessible *, i));
82 _atspi_relation_new_from_iter (DBusMessageIter *iter)
84 DBusMessageIter iter_struct, iter_array;
86 AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL);
91 dbus_message_iter_recurse (iter, &iter_struct);
92 dbus_message_iter_get_basic (&iter_struct, &d_type);
93 relation->relation_type = d_type;
94 dbus_message_iter_next (&iter_struct);
96 relation->targets = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
97 dbus_message_iter_recurse (&iter_struct, &iter_array);
98 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
100 AtspiAccessible *accessible;
102 accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
103 new_array = g_array_append_val (relation->targets, accessible);
105 relation->targets = new_array;
106 /* Iter was moved already, so no need to call dbus_message_iter_next */
111 G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT)
114 atspi_relation_init (AtspiRelation *relation)
119 atspi_relation_finalize (GObject *obj)
121 AtspiRelation *relation = ATSPI_RELATION (obj);
124 for (i = 0; i < relation->targets->len; i++)
125 g_object_unref (g_array_index (relation->targets, AtspiAccessible *, i));
126 g_array_free (relation->targets, TRUE);
130 atspi_relation_class_init (AtspiRelationClass *klass)
132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
134 object_class->finalize = atspi_relation_finalize;