Make AtkRelation and AtkRelationSet into GObjects.
[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 (AtkObjectClass),
37         (GBaseInitFunc) NULL,
38         (GBaseFinalizeFunc) NULL,
39         (GClassInitFunc) atk_relation_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, "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 AtkRelationType
60 atk_relation_type_register (const gchar *name)
61 {
62   /* TODO: associate name with new type */
63   static guint type = ATK_RELATION_LAST_DEFINED;
64   return (++type);
65 }
66
67 AtkRelation*
68 atk_relation_new (AtkObject       **targets,
69                   gint            n_targets,
70                   AtkRelationType relationship)
71 {
72   AtkRelation *relation;
73   int         i;
74   GArray      *array;
75
76   g_return_val_if_fail (targets != NULL, NULL);
77
78   relation = g_object_new (ATK_TYPE_RELATION, NULL);
79   array = g_array_sized_new (FALSE, FALSE, sizeof (AtkObject *), n_targets);
80   for (i = 0; i < n_targets; i++)
81   {
82     g_array_insert_vals (array, i, &targets[i], sizeof (AtkObject *));
83   }
84   
85   relation->target = array;
86   relation->relationship = relationship;
87
88   return relation;
89 }
90
91 AtkRelationType
92 atk_relation_get_relation_type (AtkRelation *relation)
93 {
94   g_return_val_if_fail (relation != NULL, 0);
95   g_return_val_if_fail (ATK_IS_RELATION (relation), 0);
96   
97   return relation->relationship;
98 }
99
100 GArray*
101 atk_relation_get_target (AtkRelation *relation)
102 {
103   g_return_val_if_fail (relation != NULL, FALSE);
104   g_return_val_if_fail (ATK_IS_RELATION (relation), FALSE);
105
106   return relation->target;
107 }
108
109 static void
110 atk_relation_finalize (GObject *object)
111 {
112   AtkRelation        *relation;
113
114   g_return_if_fail (ATK_IS_RELATION (object));
115
116   relation = ATK_RELATION (object);
117
118   if (relation->target)
119   {
120     g_array_free (relation->target, TRUE);
121   } 
122 }