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)
72 GPtrArray *array_item;
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_ptr_array_index (array_item, i);
85 if (item->relationship == relationship)
92 atk_relation_set_remove (AtkRelationSet *set,
93 AtkRelation *relation)
95 GPtrArray *array_item;
97 g_return_if_fail (set != NULL);
98 g_return_if_fail (ATK_IS_RELATION_SET (set));
99 g_return_if_fail (relation != NULL);
101 array_item = set->relations;
102 if (array_item == NULL)
105 if (g_ptr_array_remove (array_item, relation))
107 g_object_unref (relation);
112 atk_relation_set_add (AtkRelationSet *set,
113 AtkRelation *relation)
115 g_return_if_fail (set != NULL);
116 g_return_if_fail (ATK_IS_RELATION_SET (set));
117 g_return_if_fail (relation != NULL);
119 if (set->relations == NULL)
121 set->relations = g_ptr_array_new ();
123 g_ptr_array_add (set->relations, relation);
124 g_object_ref (relation);
128 atk_relation_set_get_n_relations (AtkRelationSet *set)
130 g_return_val_if_fail (set != NULL, 0);
131 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
133 if (set->relations == NULL)
136 return set->relations->len;
140 atk_relation_set_get_relation (AtkRelationSet *set,
143 GPtrArray *array_item;
146 g_return_val_if_fail (set != NULL, NULL);
147 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
148 g_return_val_if_fail (i >= 0, NULL);
150 array_item = set->relations;
151 if (array_item == NULL)
153 item = g_ptr_array_index (array_item, i);
161 atk_relation_set_get_relation_by_type (AtkRelationSet *set,
162 AtkRelationType relationship)
164 GPtrArray *array_item;
168 g_return_val_if_fail (set != NULL, NULL);
169 g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
171 array_item = set->relations;
172 if (array_item == NULL)
174 for (i = 0; i < array_item->len; i++)
176 item = g_ptr_array_index (array_item, i);
177 if (item->relationship == relationship)
184 atk_relation_set_finalize (GObject *object)
186 AtkRelationSet *relation_set;
190 g_return_if_fail (ATK_IS_RELATION_SET (object));
192 relation_set = ATK_RELATION_SET (object);
193 array = relation_set->relations;
197 for (i = 0; i < array->len; i++)
199 g_object_unref (g_ptr_array_index (array, i));
201 g_ptr_array_free (array, TRUE);