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.
7 * Copyright 2010, 2011 Novell, Inc.
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.
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.
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.
25 #include "atspi-private.h"
28 * atspi_relation_get_relation_type:
29 * @obj: a pointer to the #AtspiRelation object to query.
31 * Gets the type of relationship represented by an #AtspiRelation.
33 * Returns: an #AtspiRelationType indicating the type of relation
34 * encapsulated in this #AtspiRelation object.
38 atspi_relation_get_relation_type (AtspiRelation *obj)
40 return obj->relation_type;
44 * atspi_relation_get_n_targets:
45 * @obj: a pointer to the #AtspiRelation object to query.
47 * Gets the number of objects which this relationship has as its
48 * target objects (the subject is the #AtspiAccessible from which this
49 * #AtspiRelation originated).
51 * Returns: a #gint indicating how many target objects which the
52 * originating #AtspiAccessible object has the #AtspiRelation
56 atspi_relation_get_n_targets (AtspiRelation *obj)
58 return obj->targets->len;
62 * atspi_relation_get_target:
63 * @obj: a pointer to the #AtspiRelation object to query.
64 * @i: a (zero-index) #gint indicating which (of possibly several) target is requested.
66 * Gets the @i-th target of a specified #AtspiRelation relationship.
68 * Returns: (transfer full): an #AtspiAccessible which is the @i-th object
69 * with which the originating #AtspiAccessible has relationship
70 * specified in the #AtspiRelation object.
74 atspi_relation_get_target (AtspiRelation *obj, gint i)
76 g_return_val_if_fail (obj, NULL);
78 g_return_val_if_fail (i >= 0 && i < obj->targets->len, NULL);
79 return g_object_ref (g_array_index (obj->targets, AtspiAccessible *, i));
83 _atspi_relation_new_from_iter (DBusMessageIter *iter)
85 DBusMessageIter iter_struct, iter_array;
87 AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL);
92 dbus_message_iter_recurse (iter, &iter_struct);
93 dbus_message_iter_get_basic (&iter_struct, &d_type);
94 relation->relation_type = d_type;
95 dbus_message_iter_next (&iter_struct);
97 relation->targets = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
98 dbus_message_iter_recurse (&iter_struct, &iter_array);
99 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
101 AtspiAccessible *accessible;
102 accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
103 relation->targets = g_array_append_val (relation->targets, accessible);
104 /* Iter was moved already, so no need to call dbus_message_iter_next */
109 G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT)
112 atspi_relation_init (AtspiRelation *relation)
117 atspi_relation_finalize (GObject *object)
119 AtspiRelation *relation = ATSPI_RELATION (object);
122 for (i = 0; i < relation->targets->len; i++)
123 g_object_unref (g_array_index (relation->targets, AtspiAccessible *, i));
124 g_array_free (relation->targets, TRUE);
126 G_OBJECT_CLASS (atspi_relation_parent_class)->finalize (object);
130 atspi_relation_class_init (AtspiRelationClass *klass)
132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
134 object_class->finalize = atspi_relation_finalize;