{
AtkRelation *relation;
int i;
- GArray *array;
+ GPtrArray *array;
g_return_val_if_fail (targets != NULL, NULL);
relation = g_object_new (ATK_TYPE_RELATION, NULL);
- array = g_array_sized_new (FALSE, FALSE, sizeof (AtkObject *), n_targets);
+ array = g_ptr_array_sized_new (n_targets);
for (i = 0; i < n_targets; i++)
{
- g_array_insert_vals (array, i, &targets[i], sizeof (AtkObject *));
+ /*
+ * Add a reference to AtkObject being added to a relation
+ */
+ g_object_ref (targets[i]);
+ g_ptr_array_add (array, targets[i]);
}
relation->target = array;
return relation->relationship;
}
-GArray*
+GPtrArray*
atk_relation_get_target (AtkRelation *relation)
{
g_return_val_if_fail (relation != NULL, FALSE);
if (relation->target)
{
- g_array_free (relation->target, TRUE);
+ gint i;
+
+ for (i = 0; i < relation->target->len; i++)
+ {
+ /*
+ * Remove a reference to AtkObject being removed from a relation
+ */
+ g_object_unref (g_ptr_array_index (relation->target, i));
+ }
+ g_ptr_array_free (relation->target, TRUE);
}
}
atk_relation_set_contains (AtkRelationSet *set,
AtkRelationType relationship)
{
- GArray *array_item;
+ GPtrArray *array_item;
AtkRelation *item;
gint i;
return FALSE;
for (i = 0; i < array_item->len; i++)
{
- item = g_array_index (array_item, AtkRelation*, i);
+ item = g_ptr_array_index (array_item, i);
if (item->relationship == relationship)
return TRUE;
}
atk_relation_set_remove (AtkRelationSet *set,
AtkRelation *relation)
{
- GArray *array_item;
- AtkRelation *item;
- gint i;
+ GPtrArray *array_item;
g_return_if_fail (set != NULL);
g_return_if_fail (ATK_IS_RELATION_SET (set));
array_item = set->relations;
if (array_item == NULL)
return;
- for (i = 0; i < array_item->len; i++)
+
+ if (g_ptr_array_remove (array_item, relation))
{
- item = g_array_index (array_item, AtkRelation*, i);
- if (item == relation)
- {
- g_array_remove_index (array_item, i);
- return;
- }
+ g_object_unref (relation);
}
}
if (set->relations == NULL)
{
- set->relations = g_array_new (FALSE, TRUE, sizeof (AtkRelation));
+ set->relations = g_ptr_array_new ();
}
- set->relations = g_array_append_val (set->relations, relation);
+ g_ptr_array_add (set->relations, relation);
+ g_object_ref (relation);
}
gint
atk_relation_set_get_relation (AtkRelationSet *set,
gint i)
{
- GArray *array_item;
+ GPtrArray *array_item;
AtkRelation* item;
g_return_val_if_fail (set != NULL, NULL);
array_item = set->relations;
if (array_item == NULL)
return NULL;
- item = g_array_index (array_item, AtkRelation*, i);
+ item = g_ptr_array_index (array_item, i);
if (item == NULL)
return NULL;
atk_relation_set_get_relation_by_type (AtkRelationSet *set,
AtkRelationType relationship)
{
- GArray *array_item;
+ GPtrArray *array_item;
AtkRelation *item;
gint i;
return NULL;
for (i = 0; i < array_item->len; i++)
{
- item = g_array_index (array_item, AtkRelation*, i);
+ item = g_ptr_array_index (array_item, i);
if (item->relationship == relationship)
return item;
}
atk_relation_set_finalize (GObject *object)
{
AtkRelationSet *relation_set;
- GArray *array;
+ GPtrArray *array;
gint i;
g_return_if_fail (ATK_IS_RELATION_SET (object));
{
for (i = 0; i < array->len; i++)
{
- g_object_unref (g_array_index (array, AtkRelation *, i));
+ g_object_unref (g_ptr_array_index (array, i));
}
- g_array_free (array, TRUE);
+ g_ptr_array_free (array, TRUE);
}
}
{
GObject parent;
- GArray *relations;
+ GPtrArray *relations;
};
struct _AtkRelationSetClass
GType atk_relation_set_get_type (void);
-AtkRelationType atk_relation_type_register (const gchar *name);
-
/*
* Create a new relation set.
*/
gboolean atk_relation_set_contains (AtkRelationSet *set,
AtkRelationType relationship);
/*
- * Remove a relation from the from the relation set.
+ * Remove a relation from the relation set.
+ *
+ * This function unref's the AtkRelation so it will be deleted unless there
+ * is another reference to it.
*/
void atk_relation_set_remove (AtkRelationSet *set,
AtkRelation *relation);
/*
* Add a new relation to the current relation set if it is not already
* present.
+ *
+ * This function ref's the AtkRelation so the caller of this function
+ * should unref it to ensure that it will be destroyed when the AtkRelationSet
+ * is destroyed.
*/
void atk_relation_set_add (AtkRelationSet *set,
AtkRelation *relation);