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"
24 #include "atk-enum-types.h"
26 GPtrArray
*extra_names
= NULL
;
28 static gpointer parent_class
= NULL
;
30 static void atk_relation_class_init (AtkRelationClass
*klass
);
31 static void atk_relation_finalize (GObject
*object
);
34 atk_relation_get_type (void)
36 static GType type
= 0;
40 static const GTypeInfo typeInfo
=
42 sizeof (AtkRelationClass
),
44 (GBaseFinalizeFunc
) NULL
,
45 (GClassInitFunc
) atk_relation_class_init
,
46 (GClassFinalizeFunc
) NULL
,
50 (GInstanceInitFunc
) NULL
,
52 type
= g_type_register_static (G_TYPE_OBJECT
, "AtkRelation", &typeInfo
, 0) ;
58 atk_relation_class_init (AtkRelationClass
*klass
)
60 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
62 parent_class
= g_type_class_peek_parent (klass
);
64 gobject_class
->finalize
= atk_relation_finalize
;
68 * atk_relation_type_register:
69 * @name: a name string
71 * Associate @name with a new #AtkRelationType
73 * Returns: an #AtkRelationType associated with @name
76 atk_relation_type_register (const gchar
*name
)
78 g_return_val_if_fail (name
, ATK_RELATION_NULL
);
81 extra_names
= g_ptr_array_new ();
83 g_ptr_array_add (extra_names
, g_strdup (name
));
84 return extra_names
->len
+ ATK_RELATION_LAST_DEFINED
;
88 * atk_relation_type_get_name:
89 * @type: The #AtkRelationType whose name is required
91 * Gets the description string describing the #AtkRelationType @type.
93 * Returns: the string describing the AtkRelationType
96 atk_relation_type_get_name (AtkRelationType type
)
98 GTypeClass
*type_class
;
102 type_class
= g_type_class_ref (ATK_TYPE_RELATION_TYPE
);
103 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), NULL
);
105 value
= g_enum_get_value (G_ENUM_CLASS (type_class
), type
);
109 name
= value
->value_nick
;
117 n
-= ATK_RELATION_LAST_DEFINED
+ 1;
119 if (n
< extra_names
->len
)
120 name
= g_ptr_array_index (extra_names
, n
);
123 g_type_class_unref (type_class
);
128 * atk_relation_type_for_name:
129 * @name: a string which is the (non-localized) name of an ATK relation type.
131 * Get the #AtkRelationType type corresponding to a relation name.
133 * Returns: the #AtkRelationType enumerated type corresponding to the specified name,
134 * or #ATK_RELATION_NULL if no matching relation type is found.
137 atk_relation_type_for_name (const gchar
*name
)
139 GTypeClass
*type_class
;
141 AtkRelationType type
= ATK_RELATION_NULL
;
143 g_return_val_if_fail (name
, ATK_RELATION_NULL
);
145 type_class
= g_type_class_ref (ATK_TYPE_RELATION_TYPE
);
146 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), ATK_RELATION_NULL
);
148 value
= g_enum_get_value_by_nick (G_ENUM_CLASS (type_class
), name
);
160 for (i
= 0; i
< extra_names
->len
; i
++)
162 gchar
*extra_name
= (gchar
*)g_ptr_array_index (extra_names
, i
);
164 g_return_val_if_fail (extra_name
, ATK_RELATION_NULL
);
166 if (strcmp (name
, extra_name
) == 0)
168 type
= i
+ 1 + ATK_RELATION_LAST_DEFINED
;
174 g_type_class_unref (type_class
);
182 * @targets: an array of pointers to #AtkObjects
183 * @n_targets: number of #AtkObjects pointed to by @targets
184 * @relationship: an #AtkRelationType with which to create the new
187 * Create a new relation for the specified key and the specified list
190 * Returns: a pointer to a new #AtkRelation
193 atk_relation_new (AtkObject
**targets
,
195 AtkRelationType relationship
)
197 AtkRelation
*relation
;
201 g_return_val_if_fail (targets
!= NULL
, NULL
);
203 relation
= g_object_new (ATK_TYPE_RELATION
, NULL
);
204 array
= g_ptr_array_sized_new (n_targets
);
205 for (i
= 0; i
< n_targets
; i
++)
208 * Add a reference to AtkObject being added to a relation
210 g_object_ref (targets
[i
]);
211 g_ptr_array_add (array
, targets
[i
]);
214 relation
->target
= array
;
215 relation
->relationship
= relationship
;
221 * atk_relation_get_relation_type:
222 * @relation: an #AtkRelation
224 * Gets the type of @relation
226 * Returns: the type of @relation
229 atk_relation_get_relation_type (AtkRelation
*relation
)
231 g_return_val_if_fail (ATK_IS_RELATION (relation
), 0);
233 return relation
->relationship
;
237 * atk_relation_get_target:
238 * @relation: an #AtkRelation
240 * Gets the target list of @relation
242 * Returns: the target list of @relation
245 atk_relation_get_target (AtkRelation
*relation
)
247 g_return_val_if_fail (ATK_IS_RELATION (relation
), FALSE
);
249 return relation
->target
;
253 atk_relation_finalize (GObject
*object
)
255 AtkRelation
*relation
;
257 g_return_if_fail (ATK_IS_RELATION (object
));
259 relation
= ATK_RELATION (object
);
261 if (relation
->target
)
265 for (i
= 0; i
< relation
->target
->len
; i
++)
268 * Remove a reference to AtkObject being removed from a relation
270 g_object_unref (g_ptr_array_index (relation
->target
, i
));
272 g_ptr_array_free (relation
->target
, TRUE
);
275 G_OBJECT_CLASS (parent_class
)->finalize (object
);