Added missing gtk-doc comments for atk_relation_type_from_string.
[platform/upstream/atk.git] / atk / atkrelation.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 #include "atkobject.h"
22 #include "atkrelation.h"
23
24 static void            atk_relation_class_init       (AtkRelationClass  *klass);
25 static void            atk_relation_finalize         (GObject           *object);
26
27 GType
28 atk_relation_get_type (void)
29 {
30   static GType type = 0;
31
32   if (!type)
33     {
34       static const GTypeInfo typeInfo =
35       {
36         sizeof (AtkRelationClass),
37         (GBaseInitFunc) NULL,
38         (GBaseFinalizeFunc) NULL,
39         (GClassInitFunc) atk_relation_class_init,
40         (GClassFinalizeFunc) NULL,
41         NULL,
42         sizeof (AtkRelation),
43         0,
44         (GInstanceInitFunc) NULL,
45       } ;
46       type = g_type_register_static (G_TYPE_OBJECT, "AtkRelation", &typeInfo, 0) ;
47     }
48   return type;
49 }
50
51 static void
52 atk_relation_class_init (AtkRelationClass *klass)
53 {
54   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
55
56   gobject_class->finalize = atk_relation_finalize;
57 }
58
59 /**
60  * atk_relation_type_register:
61  * @name: a name string
62  *
63  * Associate @name with a new #AtkRelationType
64  *
65  * Returns: an #AtkRelationType associated with @name
66  **/
67 AtkRelationType
68 atk_relation_type_register (const gchar *name)
69 {
70   /* TODO: associate name with new type */
71   static guint type = ATK_RELATION_LAST_DEFINED;
72   return (++type);
73 }
74
75
76 /**
77  * atk_relation_type_from_string:
78  * @name: a string which is the (non-localized) name of an ATK relation type.
79  *
80  * Get the #AtkRelationType type corresponding to a relation name.
81  *
82  * Returns: the #AtkRelationType enumerated type corresponding to the specified name,
83  *          or #ATK_RELATION_NULL if no matching relation type is found.
84  **/
85 AtkRelationType
86 atk_relation_type_from_string (const gchar *name)
87 {
88   /*
89    * TODO: implement properly,
90    *  checking type namelist in conjunction with above function.
91    */
92         if ( !strcmp (name, "controlled_by") ) return ATK_RELATION_CONTROLLED_BY;
93         else if (!strcmp (name, "controller_for")) return ATK_RELATION_CONTROLLER_FOR;
94         else if (!strcmp (name, "label_for")) return ATK_RELATION_LABEL_FOR;
95         else if (!strcmp (name, "labelled_by")) return ATK_RELATION_LABELLED_BY;
96         else if (!strcmp (name, "member_of")) return ATK_RELATION_MEMBER_OF;
97         else return ATK_RELATION_NULL;
98 }
99
100
101 /**
102  * atk_relation_new:
103  * @targets: an array of pointers to #AtkObjects  
104  * @n_targets: number of #AtkObjects pointed to by @targets
105  * @relationship: an #AtkRelationType with which to create the new
106  *  #AtkRelation
107  *
108  * Create a new relation for the specified key and the specified list
109  * of targets.
110  *
111  * Returns: a pointer to a new #AtkRelation
112  **/
113 AtkRelation*
114 atk_relation_new (AtkObject       **targets,
115                   gint            n_targets,
116                   AtkRelationType relationship)
117 {
118   AtkRelation *relation;
119   int         i;
120   GPtrArray      *array;
121
122   g_return_val_if_fail (targets != NULL, NULL);
123
124   relation = g_object_new (ATK_TYPE_RELATION, NULL);
125   array = g_ptr_array_sized_new (n_targets);
126   for (i = 0; i < n_targets; i++)
127   {
128     /*
129      * Add a reference to AtkObject being added to a relation
130      */
131     g_object_ref (targets[i]);
132     g_ptr_array_add (array, targets[i]);
133   }
134   
135   relation->target = array;
136   relation->relationship = relationship;
137
138   return relation;
139 }
140
141 /**
142  * atk_relation_get_relation_type:
143  * @relation: an #AtkRelation 
144  *
145  * Gets the type of @relation
146  *
147  * Returns: the type of @relation
148  **/
149 AtkRelationType
150 atk_relation_get_relation_type (AtkRelation *relation)
151 {
152   g_return_val_if_fail (ATK_IS_RELATION (relation), 0);
153   
154   return relation->relationship;
155 }
156
157 /**
158  * atk_relation_get_target:
159  * @relation: an #AtkRelation
160  *
161  * Gets the target list of @relation
162  *
163  * Returns: the target list of @relation
164  **/
165 GPtrArray*
166 atk_relation_get_target (AtkRelation *relation)
167 {
168   g_return_val_if_fail (ATK_IS_RELATION (relation), FALSE);
169
170   return relation->target;
171 }
172
173 static void
174 atk_relation_finalize (GObject *object)
175 {
176   AtkRelation        *relation;
177
178   g_return_if_fail (ATK_IS_RELATION (object));
179
180   relation = ATK_RELATION (object);
181
182   if (relation->target)
183   {
184     gint i;
185
186     for (i = 0; i < relation->target->len; i++)
187     {
188       /*
189        * Remove a reference to AtkObject being removed from a relation
190        */
191       g_object_unref (g_ptr_array_index (relation->target, i));
192     }
193     g_ptr_array_free (relation->target, TRUE);
194   } 
195 }