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.
21 #include <glib-object.h>
22 #include "atkobject.h"
23 #include "atkrelation.h"
25 static gchar *relation_names[ATK_RELATION_LAST_DEFINED] = {
35 GPtrArray *extra_names = NULL;
37 static void atk_relation_class_init (AtkRelationClass *klass);
38 static void atk_relation_finalize (GObject *object);
41 atk_relation_get_type (void)
43 static GType type = 0;
47 static const GTypeInfo typeInfo =
49 sizeof (AtkRelationClass),
51 (GBaseFinalizeFunc) NULL,
52 (GClassInitFunc) atk_relation_class_init,
53 (GClassFinalizeFunc) NULL,
57 (GInstanceInitFunc) NULL,
59 type = g_type_register_static (G_TYPE_OBJECT, "AtkRelation", &typeInfo, 0) ;
65 atk_relation_class_init (AtkRelationClass *klass)
67 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
69 gobject_class->finalize = atk_relation_finalize;
73 * atk_relation_type_register:
74 * @name: a name string
76 * Associate @name with a new #AtkRelationType
78 * Returns: an #AtkRelationType associated with @name
81 atk_relation_type_register (const gchar *name)
83 g_return_val_if_fail (name, ATK_RELATION_NULL);
86 extra_names = g_ptr_array_new ();
88 g_ptr_array_add (extra_names, g_strdup (name));
89 return extra_names->len + ATK_RELATION_LAST_DEFINED - 1;
93 * atk_relation_type_get_name:
94 * @type: The #AtkRelationType whose name is required
96 * Gets the description string describing the #AtkRelationType @type.
98 * Returns: the string describing the AtkRelationType
100 G_CONST_RETURN gchar*
101 atk_relation_type_get_name (AtkRelationType type)
109 if (n < ATK_RELATION_LAST_DEFINED)
110 return relation_names[n];
111 else if (extra_names)
113 n -= ATK_RELATION_LAST_DEFINED;
115 if (n < extra_names->len)
116 return g_ptr_array_index (extra_names, n);
119 return relation_names[ATK_RELATION_NULL];
124 * atk_relation_type_for_name:
125 * @name: a string which is the (non-localized) name of an ATK relation type.
127 * Get the #AtkRelationType type corresponding to a relation name.
129 * Returns: the #AtkRelationType enumerated type corresponding to the specified name,
130 * or #ATK_RELATION_NULL if no matching relation type is found.
133 atk_relation_type_for_name (const gchar *name)
137 g_return_val_if_fail (name, ATK_RELATION_NULL);
139 for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
141 if (strcmp (name, relation_names[i]) == 0)
147 for (i = 0; i < extra_names->len; i++)
149 gchar *extra_name = (gchar *)g_ptr_array_index (extra_names, i);
151 g_return_val_if_fail (extra_name, ATK_RELATION_NULL);
153 if (strcmp (name, extra_name) == 0)
154 return i + ATK_RELATION_LAST_DEFINED;
157 return ATK_RELATION_NULL;
163 * @targets: an array of pointers to #AtkObjects
164 * @n_targets: number of #AtkObjects pointed to by @targets
165 * @relationship: an #AtkRelationType with which to create the new
168 * Create a new relation for the specified key and the specified list
171 * Returns: a pointer to a new #AtkRelation
174 atk_relation_new (AtkObject **targets,
176 AtkRelationType relationship)
178 AtkRelation *relation;
182 g_return_val_if_fail (targets != NULL, NULL);
184 relation = g_object_new (ATK_TYPE_RELATION, NULL);
185 array = g_ptr_array_sized_new (n_targets);
186 for (i = 0; i < n_targets; i++)
189 * Add a reference to AtkObject being added to a relation
191 g_object_ref (targets[i]);
192 g_ptr_array_add (array, targets[i]);
195 relation->target = array;
196 relation->relationship = relationship;
202 * atk_relation_get_relation_type:
203 * @relation: an #AtkRelation
205 * Gets the type of @relation
207 * Returns: the type of @relation
210 atk_relation_get_relation_type (AtkRelation *relation)
212 g_return_val_if_fail (ATK_IS_RELATION (relation), 0);
214 return relation->relationship;
218 * atk_relation_get_target:
219 * @relation: an #AtkRelation
221 * Gets the target list of @relation
223 * Returns: the target list of @relation
226 atk_relation_get_target (AtkRelation *relation)
228 g_return_val_if_fail (ATK_IS_RELATION (relation), FALSE);
230 return relation->target;
234 atk_relation_finalize (GObject *object)
236 AtkRelation *relation;
238 g_return_if_fail (ATK_IS_RELATION (object));
240 relation = ATK_RELATION (object);
242 if (relation->target)
246 for (i = 0; i < relation->target->len; i++)
249 * Remove a reference to AtkObject being removed from a relation
251 g_object_unref (g_ptr_array_index (relation->target, i));
253 g_ptr_array_free (relation->target, TRUE);