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 void atk_relation_class_init (AtkRelationClass *klass);
26 static void atk_relation_finalize (GObject *object);
29 atk_relation_get_type (void)
31 static GType type = 0;
35 static const GTypeInfo typeInfo =
37 sizeof (AtkRelationClass),
39 (GBaseFinalizeFunc) NULL,
40 (GClassInitFunc) atk_relation_class_init,
41 (GClassFinalizeFunc) NULL,
45 (GInstanceInitFunc) NULL,
47 type = g_type_register_static (G_TYPE_OBJECT, "AtkRelation", &typeInfo, 0) ;
53 atk_relation_class_init (AtkRelationClass *klass)
55 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
57 gobject_class->finalize = atk_relation_finalize;
61 * atk_relation_type_register:
62 * @name: a name string
64 * Associate @name with a new #AtkRelationType
66 * Returns: an #AtkRelationType associated with @name
69 atk_relation_type_register (const gchar *name)
71 /* TODO: associate name with new type */
72 static guint type = ATK_RELATION_LAST_DEFINED;
78 * atk_relation_type_from_string:
79 * @name: a string which is the (non-localized) name of an ATK relation type.
81 * Get the #AtkRelationType type corresponding to a relation name.
83 * Returns: the #AtkRelationType enumerated type corresponding to the specified name,
84 * or #ATK_RELATION_NULL if no matching relation type is found.
87 atk_relation_type_from_string (const gchar *name)
90 * TODO: implement properly,
91 * checking type namelist in conjunction with above function.
93 if ( !strcmp (name, "controlled_by") ) return ATK_RELATION_CONTROLLED_BY;
94 else if (!strcmp (name, "controller_for")) return ATK_RELATION_CONTROLLER_FOR;
95 else if (!strcmp (name, "label_for")) return ATK_RELATION_LABEL_FOR;
96 else if (!strcmp (name, "labelled_by")) return ATK_RELATION_LABELLED_BY;
97 else if (!strcmp (name, "member_of")) return ATK_RELATION_MEMBER_OF;
98 else return ATK_RELATION_NULL;
104 * @targets: an array of pointers to #AtkObjects
105 * @n_targets: number of #AtkObjects pointed to by @targets
106 * @relationship: an #AtkRelationType with which to create the new
109 * Create a new relation for the specified key and the specified list
112 * Returns: a pointer to a new #AtkRelation
115 atk_relation_new (AtkObject **targets,
117 AtkRelationType relationship)
119 AtkRelation *relation;
123 g_return_val_if_fail (targets != NULL, NULL);
125 relation = g_object_new (ATK_TYPE_RELATION, NULL);
126 array = g_ptr_array_sized_new (n_targets);
127 for (i = 0; i < n_targets; i++)
130 * Add a reference to AtkObject being added to a relation
132 g_object_ref (targets[i]);
133 g_ptr_array_add (array, targets[i]);
136 relation->target = array;
137 relation->relationship = relationship;
143 * atk_relation_get_relation_type:
144 * @relation: an #AtkRelation
146 * Gets the type of @relation
148 * Returns: the type of @relation
151 atk_relation_get_relation_type (AtkRelation *relation)
153 g_return_val_if_fail (ATK_IS_RELATION (relation), 0);
155 return relation->relationship;
159 * atk_relation_get_target:
160 * @relation: an #AtkRelation
162 * Gets the target list of @relation
164 * Returns: the target list of @relation
167 atk_relation_get_target (AtkRelation *relation)
169 g_return_val_if_fail (ATK_IS_RELATION (relation), FALSE);
171 return relation->target;
175 atk_relation_finalize (GObject *object)
177 AtkRelation *relation;
179 g_return_if_fail (ATK_IS_RELATION (object));
181 relation = ATK_RELATION (object);
183 if (relation->target)
187 for (i = 0; i < relation->target->len; i++)
190 * Remove a reference to AtkObject being removed from a relation
192 g_object_unref (g_ptr_array_index (relation->target, i));
194 g_ptr_array_free (relation->target, TRUE);