1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <glib-object.h>
24 static void atk_relation_set_class_init (AtkRelationSetClass *klass);
25 static void atk_relation_set_finalize (GObject *object);
28 atk_relation_set_get_type (void)
30 static GType type = 0;
34 static const GTypeInfo typeInfo =
36 sizeof (AtkObjectClass),
38 (GBaseFinalizeFunc) NULL,
39 (GClassInitFunc) atk_relation_set_class_init,
40 (GClassFinalizeFunc) NULL,
44 (GInstanceInitFunc) NULL,
46 type = g_type_register_static (G_TYPE_OBJECT, "AtkRelatioSet", &typeInfo, 0) ;
52 atk_relation_set_class_init (AtkRelationSetClass *klass)
54 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
56 gobject_class->finalize = atk_relation_set_finalize;
60 atk_relation_set_new (void)
62 AtkRelationSet *relation_set;
64 relation_set = g_object_new (ATK_TYPE_RELATION_SET, NULL);
69 atk_relation_set_contains (AtkRelationSet *set,
70 AtkRelationType relationship)
76 g_return_val_if_fail (set != NULL, FALSE);
77 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
79 array_item = set->relations;
80 if (array_item == NULL)
82 for (i = 0; i < array_item->len; i++)
84 item = g_array_index (array_item, AtkRelation*, i);
85 if (item->relationship == relationship)
92 atk_relation_set_remove (AtkRelationSet *set,
93 AtkRelation *relation)
99 g_return_if_fail (set != NULL);
100 g_return_if_fail (ATK_IS_RELATION_SET (set));
101 g_return_if_fail (relation != NULL);
103 array_item = set->relations;
104 if (array_item == NULL)
106 for (i = 0; i < array_item->len; i++)
108 item = g_array_index (array_item, AtkRelation*, i);
109 if (item == relation)
111 g_array_remove_index (array_item, i);
118 atk_relation_set_add (AtkRelationSet *set,
119 AtkRelation *relation)
121 g_return_if_fail (set != NULL);
122 g_return_if_fail (ATK_IS_RELATION_SET (set));
123 g_return_if_fail (relation != NULL);
125 if (set->relations == NULL)
127 set->relations = g_array_new (FALSE, TRUE, sizeof (AtkRelation));
129 set->relations = g_array_append_val (set->relations, relation);
133 atk_relation_set_get_n_relations (AtkRelationSet *set)
135 g_return_val_if_fail (set != NULL, 0);
136 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
138 if (set->relations == NULL)
141 return set->relations->len;
145 atk_relation_set_get_relation (AtkRelationSet *set,
151 g_return_val_if_fail (set != NULL, NULL);
152 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
153 g_return_val_if_fail (i >= 0, NULL);
155 array_item = set->relations;
156 if (array_item == NULL)
158 item = g_array_index (array_item, AtkRelation*, i);
166 atk_relation_set_get_relation_by_type (AtkRelationSet *set,
167 AtkRelationType relationship)
173 g_return_val_if_fail (set != NULL, NULL);
174 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
176 array_item = set->relations;
177 if (array_item == NULL)
179 for (i = 0; i < array_item->len; i++)
181 item = g_array_index (array_item, AtkRelation*, i);
182 if (item->relationship == relationship)
189 atk_relation_set_finalize (GObject *object)
191 AtkRelationSet *relation_set;
195 g_return_if_fail (ATK_IS_RELATION_SET (object));
197 relation_set = ATK_RELATION_SET (object);
198 array = relation_set->relations;
202 for (i = 0; i < array->len; i++)
204 g_object_unref (g_array_index (array, AtkRelation *, i));
206 g_array_free (array, TRUE);