summaryrefslogtreecommitdiff
path: root/atspi/atspi-relation.c
blob: 5d166fd44e14fa74ce1e37b1f33987717302cc9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2001, 2002 Sun Microsystems Inc.,
 * Copyright 2001, 2002 Ximian, Inc.
 * Copyright 2010, 2011 Novell, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "atspi-private.h"

/**
 * AtspiRelation:
 *
 * An interface via which non-hierarchical relationships
 * are indicated.
 *
 * An interface via which non-hierarchical relationships
 * are indicated. An instance of this interface represents
 * a "one-to-many" correspondence.
 */

/**
 * atspi_relation_get_relation_type:
 * @obj: a pointer to the #AtspiRelation object to query.
 *
 * Gets the type of relationship represented by an #AtspiRelation.
 *
 * Returns: an #AtspiRelationType indicating the type of relation
 *         encapsulated in this #AtspiRelation object.
 *
 **/
AtspiRelationType
atspi_relation_get_relation_type (AtspiRelation *obj)
{
  return obj->relation_type;
}

/**
 * atspi_relation_get_n_targets:
 * @obj: a pointer to the #AtspiRelation object to query.
 *
 * Gets the number of objects which this relationship has as its
 *       target objects (the subject is the #AtspiAccessible from which this
 *       #AtspiRelation originated).
 *
 * Returns: a #gint indicating how many target objects which the
 *       originating #AtspiAccessible object has the #AtspiRelation
 *       relationship with.
 **/
gint
atspi_relation_get_n_targets (AtspiRelation *obj)
{
  return obj->targets->len;
}

/**
 * atspi_relation_get_target:
 * @obj: a pointer to the #AtspiRelation object to query.
 * @i: a (zero-index) #gint indicating which (of possibly several) target is requested.
 *
 * Gets the @i-th target of a specified #AtspiRelation relationship.
 *
 * Returns: (transfer full): an #AtspiAccessible which is the @i-th object
 *          with which the originating #AtspiAccessible has relationship
 *          specified in the #AtspiRelation object.
 *
 **/
AtspiAccessible *
atspi_relation_get_target (AtspiRelation *obj, gint i)
{
  g_return_val_if_fail (obj, NULL);

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

AtspiRelation *
_atspi_relation_new_from_iter (DBusMessageIter *iter)
{
  DBusMessageIter iter_struct, iter_array;
  dbus_uint32_t d_type;
  AtspiRelation *relation = g_object_new (ATSPI_TYPE_RELATION, NULL);

  if (!relation)
    return NULL;

  dbus_message_iter_recurse (iter, &iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &d_type);
  relation->relation_type = d_type;
  dbus_message_iter_next (&iter_struct);

  relation->targets = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
  dbus_message_iter_recurse (&iter_struct, &iter_array);
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
    {
      AtspiAccessible *accessible;
      accessible = _atspi_dbus_consume_accessible (&iter_array);
      relation->targets = g_array_append_val (relation->targets, accessible);
      /* Iter was moved already, so no need to call dbus_message_iter_next */
    }
  return relation;
}

G_DEFINE_TYPE (AtspiRelation, atspi_relation, G_TYPE_OBJECT)

static void
atspi_relation_init (AtspiRelation *relation)
{
}

static void
atspi_relation_finalize (GObject *object)
{
  AtspiRelation *relation = ATSPI_RELATION (object);
  gint i;

  for (i = 0; i < relation->targets->len; i++)
    g_object_unref (g_array_index (relation->targets, AtspiAccessible *, i));
  g_array_free (relation->targets, TRUE);

  G_OBJECT_CLASS (atspi_relation_parent_class)->finalize (object);
}

static void
atspi_relation_class_init (AtspiRelationClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = atspi_relation_finalize;
}