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>
21 #include "atkobject.h"
22 #include "atkrelation.h"
24 static void atk_relation_class_init (AtkRelationClass *klass);
25 static void atk_relation_finalize (GObject *object);
28 atk_relation_get_type (void)
30 static GType type = 0;
34 static const GTypeInfo typeInfo =
36 sizeof (AtkObjectClass),
38 (GBaseFinalizeFunc) NULL,
39 (GClassInitFunc) atk_relation_class_init,
40 (GClassFinalizeFunc) NULL,
44 (GInstanceInitFunc) NULL,
46 type = g_type_register_static (G_TYPE_OBJECT, "AtkRelation", &typeInfo, 0) ;
52 atk_relation_class_init (AtkRelationClass *klass)
54 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
56 gobject_class->finalize = atk_relation_finalize;
60 atk_relation_type_register (const gchar *name)
62 /* TODO: associate name with new type */
63 static guint type = ATK_RELATION_LAST_DEFINED;
68 atk_relation_new (AtkObject **targets,
70 AtkRelationType relationship)
72 AtkRelation *relation;
76 g_return_val_if_fail (targets != NULL, NULL);
78 relation = g_object_new (ATK_TYPE_RELATION, NULL);
79 array = g_ptr_array_sized_new (n_targets);
80 for (i = 0; i < n_targets; i++)
83 * Add a reference to AtkObject being added to a relation
85 g_object_ref (targets[i]);
86 g_ptr_array_add (array, targets[i]);
89 relation->target = array;
90 relation->relationship = relationship;
96 atk_relation_get_relation_type (AtkRelation *relation)
98 g_return_val_if_fail (relation != NULL, 0);
99 g_return_val_if_fail (ATK_IS_RELATION (relation), 0);
101 return relation->relationship;
105 atk_relation_get_target (AtkRelation *relation)
107 g_return_val_if_fail (relation != NULL, FALSE);
108 g_return_val_if_fail (ATK_IS_RELATION (relation), FALSE);
110 return relation->target;
114 atk_relation_finalize (GObject *object)
116 AtkRelation *relation;
118 g_return_if_fail (ATK_IS_RELATION (object));
120 relation = ATK_RELATION (object);
122 if (relation->target)
126 for (i = 0; i < relation->target->len; i++)
129 * Remove a reference to AtkObject being removed from a relation
131 g_object_unref (g_ptr_array_index (relation->target, i));
133 g_ptr_array_free (relation->target, TRUE);