Removed comments from atkrelation.h
[platform/upstream/atk.git] / atk / atkrelationset.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <glib-object.h>
21
22 #include "atk.h"
23
24 static void            atk_relation_set_class_init       (AtkRelationSetClass  *klass);
25 static void            atk_relation_set_finalize         (GObject              *object);
26
27 GType
28 atk_relation_set_get_type (void)
29 {
30   static GType type = 0;
31
32   if (!type)
33     {
34       static const GTypeInfo typeInfo =
35       {
36         sizeof (AtkObjectClass),
37         (GBaseInitFunc) NULL,
38         (GBaseFinalizeFunc) NULL,
39         (GClassInitFunc) atk_relation_set_class_init,
40         (GClassFinalizeFunc) NULL,
41         NULL,
42         sizeof (AtkObject),
43         0,
44         (GInstanceInitFunc) NULL,
45       } ;
46       type = g_type_register_static (G_TYPE_OBJECT, "AtkRelatioSet", &typeInfo, 0) ;
47     }
48   return type;
49 }
50
51 static void
52 atk_relation_set_class_init (AtkRelationSetClass *klass)
53 {
54   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
55
56   gobject_class->finalize = atk_relation_set_finalize;
57 }
58
59 /**
60  * atk_relation_set_new
61  * return values: a new #AtkRelationSet 
62  * 
63  * Creates a new empty relation set.
64  **/
65 AtkRelationSet*
66 atk_relation_set_new (void)
67 {
68   AtkRelationSet *relation_set;
69
70   relation_set = g_object_new (ATK_TYPE_RELATION_SET, NULL);
71   return relation_set;
72 }
73
74 /**
75  * atk_relation_set_contains
76  * @set: a #AtkRelationSet
77  * @relationtype: a #AtkRelationType
78  * return values: %TRUE if @relationtype is the relationship type of a relation in @set.
79  *
80  * Determines whether the relation set contains a relation that matches the
81  * specified type.
82  **/
83 gboolean
84 atk_relation_set_contains (AtkRelationSet   *set,
85                            AtkRelationType  relationship)
86 {
87   GPtrArray *array_item;
88   AtkRelation *item;
89   gint  i;
90
91   g_return_val_if_fail (set != NULL, FALSE);
92   g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
93
94   array_item = set->relations;
95   if (array_item == NULL)
96     return FALSE;
97   for (i = 0; i < array_item->len; i++)
98   {
99     item = g_ptr_array_index (array_item, i);
100     if (item->relationship == relationship)
101       return TRUE;
102   }
103   return FALSE;
104 }
105
106 /**
107  * atk_relation_set_remove
108  * @set: a #AtkRelationSet
109  * @relation: a #AtkRelation
110  *
111  * Removes a relation from the relation set.
112  *
113  * This function unref's the AtkRelation so it will be deleted unless there
114  * is another reference to it.
115  **/
116 void
117 atk_relation_set_remove (AtkRelationSet *set,
118                          AtkRelation    *relation)
119 {
120   GPtrArray *array_item;
121
122   g_return_if_fail (set != NULL);
123   g_return_if_fail (ATK_IS_RELATION_SET (set));
124   g_return_if_fail (relation != NULL);
125
126   array_item = set->relations;
127   if (array_item == NULL)
128     return;
129   
130   if (g_ptr_array_remove (array_item, relation))
131   {
132     g_object_unref (relation);
133   }
134 }
135
136 /**
137  * atk_relation_set_add
138  * @set: a #AtkRelationSet
139  * @relation: a #AtkRelation
140  *
141  * Add a new relation to the current relation set if it is not already
142  * present.
143  *
144  * This function ref's the AtkRelation so the caller of this function
145  * should unref it to ensure that it will be destroyed when the AtkRelationSet
146  * is destroyed.
147  **/
148 void
149 atk_relation_set_add (AtkRelationSet *set,
150                       AtkRelation    *relation)
151 {
152   g_return_if_fail (set != NULL);
153   g_return_if_fail (ATK_IS_RELATION_SET (set));
154   g_return_if_fail (relation != NULL);
155
156   if (set->relations == NULL)
157   {
158     set->relations = g_ptr_array_new ();
159   }
160   g_ptr_array_add (set->relations, relation);
161   g_object_ref (relation);
162 }
163
164 /**
165  * atk_relation_set_get_n_relations
166  * @set: a #AtkRelationSet
167  * return values: a gint representing the number of relations in the set.
168  *
169  * Determines the number of relations in a relation set.
170  **/
171 gint
172 atk_relation_set_get_n_relations (AtkRelationSet *set)
173 {
174   g_return_val_if_fail (set != NULL, 0);
175   g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
176
177   if (set->relations == NULL)
178     return 0;
179
180   return set->relations->len;
181 }
182
183 /**
184  * atk_relation_set_get_relation
185  * @set: a #AtkRelationSet
186  * @i: a gint representing a position in the set, starting from 0.
187  * return values: a #AtkRelation, which is the relation at position i in the set.
188  *
189  * Determines the relation at the specified position in the relation set.
190  **/
191 AtkRelation*
192 atk_relation_set_get_relation (AtkRelationSet *set,
193                                gint           i)
194 {
195   GPtrArray *array_item;
196   AtkRelation* item;
197
198   g_return_val_if_fail (set != NULL, NULL);
199   g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
200   g_return_val_if_fail (i >= 0, NULL);
201
202   array_item = set->relations;
203   if (array_item == NULL)
204     return NULL;
205   item = g_ptr_array_index (array_item, i);
206   if (item == NULL)
207     return NULL;
208
209   return item;
210 }
211
212 /**
213  * atk_relation_set_get_relation_type
214  * @set: a #AtkRelationSet
215  * @relationship: a #AtkRelationType
216  * return values: a #AtkRelation, which is a relation matching the specified type.
217  *
218  * Finds a relation that matches the specified type.
219  **/
220 AtkRelation*
221 atk_relation_set_get_relation_by_type (AtkRelationSet  *set,
222                                        AtkRelationType relationship)
223 {
224   GPtrArray *array_item;
225   AtkRelation *item;
226   gint i;
227
228   g_return_val_if_fail (set != NULL, NULL);
229   g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);
230
231   array_item = set->relations;
232   if (array_item == NULL)
233     return NULL;
234   for (i = 0; i < array_item->len; i++)
235   {
236     item = g_ptr_array_index (array_item, i);
237     if (item->relationship == relationship)
238       return item;
239   }
240   return NULL;
241 }
242
243 static void
244 atk_relation_set_finalize (GObject *object)
245 {
246   AtkRelationSet     *relation_set;
247   GPtrArray             *array;
248   gint               i;
249
250   g_return_if_fail (ATK_IS_RELATION_SET (object));
251
252   relation_set = ATK_RELATION_SET (object);
253   array = relation_set->relations;
254
255   if (array)
256   {
257     for (i = 0; i < array->len; i++)
258     {
259       g_object_unref (g_ptr_array_index (array, i));
260     }
261     g_ptr_array_free (array, TRUE);
262   }
263 }