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 Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 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
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include "atspi-private.h"
26

            
27
/**
28
 * AtspiRelation:
29
 *
30
 * An interface via which non-hierarchical relationships
31
 * are indicated.
32
 *
33
 * An interface via which non-hierarchical relationships
34
 * are indicated. An instance of this interface represents
35
 * a "one-to-many" correspondence.
36
 */
37

            
38
/**
39
 * atspi_relation_get_relation_type:
40
 * @obj: a pointer to the #AtspiRelation object to query.
41
 *
42
 * Gets the type of relationship represented by an #AtspiRelation.
43
 *
44
 * Returns: an #AtspiRelationType indicating the type of relation
45
 *         encapsulated in this #AtspiRelation object.
46
 *
47
 **/
48
AtspiRelationType
49
1
atspi_relation_get_relation_type (AtspiRelation *obj)
50
{
51
1
  return obj->relation_type;
52
}
53

            
54
/**
55
 * atspi_relation_get_n_targets:
56
 * @obj: a pointer to the #AtspiRelation object to query.
57
 *
58
 * Gets the number of objects which this relationship has as its
59
 *       target objects (the subject is the #AtspiAccessible from which this
60
 *       #AtspiRelation originated).
61
 *
62
 * Returns: a #gint indicating how many target objects which the
63
 *       originating #AtspiAccessible object has the #AtspiRelation
64
 *       relationship with.
65
 **/
66
gint
67
1
atspi_relation_get_n_targets (AtspiRelation *obj)
68
{
69
1
  return obj->targets->len;
70
}
71

            
72
/**
73
 * atspi_relation_get_target:
74
 * @obj: a pointer to the #AtspiRelation object to query.
75
 * @i: a (zero-index) #gint indicating which (of possibly several) target is requested.
76
 *
77
 * Gets the @i-th target of a specified #AtspiRelation relationship.
78
 *
79
 * Returns: (transfer full): an #AtspiAccessible which is the @i-th object
80
 *          with which the originating #AtspiAccessible has relationship
81
 *          specified in the #AtspiRelation object.
82
 *
83
 **/
84
AtspiAccessible *
85
1
atspi_relation_get_target (AtspiRelation *obj, gint i)
86
{
87
1
  g_return_val_if_fail (obj, NULL);
88

            
89
1
  g_return_val_if_fail (i >= 0 && i < obj->targets->len, NULL);
90
1
  return g_object_ref (g_array_index (obj->targets, AtspiAccessible *, i));
91
}
92

            
93
AtspiRelation *
94
2
_atspi_relation_new_from_iter (DBusMessageIter *iter)
95
{
96
  DBusMessageIter iter_struct, iter_array;
97
  dbus_uint32_t d_type;
98
2
  AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL);
99

            
100
2
  if (!relation)
101
    return NULL;
102

            
103
2
  dbus_message_iter_recurse (iter, &iter_struct);
104
2
  dbus_message_iter_get_basic (&iter_struct, &d_type);
105
2
  relation->relation_type = d_type;
106
2
  dbus_message_iter_next (&iter_struct);
107

            
108
2
  relation->targets = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
109
2
  dbus_message_iter_recurse (&iter_struct, &iter_array);
110
4
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
111
    {
112
      AtspiAccessible *accessible;
113
2
      accessible = _atspi_dbus_consume_accessible (&iter_array);
114
2
      relation->targets = g_array_append_val (relation->targets, accessible);
115
      /* Iter was moved already, so no need to call dbus_message_iter_next */
116
    }
117
2
  return relation;
118
}
119

            
120
1
G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT)
121

            
122
static void
123
2
atspi_relation_init (AtspiRelation *relation)
124
{
125
2
}
126

            
127
static void
128
2
atspi_relation_finalize (GObject *object)
129
{
130
2
  AtspiRelation *relation = ATSPI_RELATION (object);
131
  gint i;
132

            
133
4
  for (i = 0; i < relation->targets->len; i++)
134
2
    g_object_unref (g_array_index (relation->targets, AtspiAccessible *, i));
135
2
  g_array_free (relation->targets, TRUE);
136

            
137
2
  G_OBJECT_CLASS (atspi_relation_parent_class)->finalize (object);
138
2
}
139

            
140
static void
141
1
atspi_relation_class_init (AtspiRelationClass *klass)
142
{
143
1
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
144

            
145
1
  object_class->finalize = atspi_relation_finalize;
146
1
}