packaging: exclude on non X11 configuration
[platform/core/uifw/at-spi2-core.git] / atspi / atspi-relation.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
27 /**
28  * atspi_relation_get_relation_type:
29  * @obj: a pointer to the #AtspiRelation object to query.
30  *
31  * Gets the type of relationship represented by an #AtspiRelation.
32  *
33  * Returns: an #AtspiRelationType indicating the type of relation
34  *         encapsulated in this #AtspiRelation object.
35  *
36  **/
37 AtspiRelationType
38 atspi_relation_get_relation_type (AtspiRelation *obj)
39 {
40   return obj->relation_type;
41 }
42
43 /**
44  * atspi_relation_get_n_targets:
45  * @obj: a pointer to the #AtspiRelation object to query.
46  *
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).
50  *
51  * Returns: a #gint indicating how many target objects which the
52  *       originating #AtspiAccessible object has the #AtspiRelation
53  *       relationship with.
54  **/
55 gint
56 atspi_relation_get_n_targets (AtspiRelation *obj)
57 {
58   return obj->targets->len;
59 }
60
61 /**
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.
65  *
66  * Gets the @i-th target of a specified #AtspiRelation relationship.
67  *
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.
71  *
72  **/
73 AtspiAccessible *
74 atspi_relation_get_target (AtspiRelation *obj, gint i)
75 {
76   g_return_val_if_fail (obj, NULL);
77
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));
80 }
81
82 AtspiRelation *
83 _atspi_relation_new_from_iter (DBusMessageIter *iter)
84 {
85   DBusMessageIter iter_struct, iter_array;
86   dbus_uint32_t d_type;
87   AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL);
88
89   if (!relation)
90     return NULL;
91
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);
96
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)
100   {
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 */
105   }
106   return relation;
107 }
108
109 G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT)
110
111 static void
112 atspi_relation_init (AtspiRelation *relation)
113 {
114 }
115
116 static void
117 atspi_relation_finalize (GObject *object)
118 {
119   AtspiRelation *relation = ATSPI_RELATION (object);
120   gint i;
121
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);
125
126   G_OBJECT_CLASS (atspi_relation_parent_class)->finalize (object);
127 }
128
129 static void
130 atspi_relation_class_init (AtspiRelationClass *klass)
131 {
132   GObjectClass *object_class = G_OBJECT_CLASS (klass);
133
134   object_class->finalize = atspi_relation_finalize;
135 }