/**
 * atk_relation_set_add:
 * @set: an #AtkRelationSet
 * @relation: an #AtkRelation
 *
 * 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)
{
  AtkRelationType relationship;

  g_return_if_fail (ATK_IS_RELATION_SET (set));
  g_return_if_fail (relation != NULL);

  if (set->relations == NULL)
  {
    set->relations = g_ptr_array_new ();
  }

  relationship = atk_relation_get_relation_type (relation);
  if (!atk_relation_set_contains (set, relationship))
  {
    g_ptr_array_add (set->relations, relation);
    g_object_ref (relation);
  }
  else
  {
    AtkRelation *exist_relation;
    gint i;
    exist_relation = atk_relation_set_get_relation_by_type (set, relationship);
    for (i = 0; i < relation->target->len; i++)
    {
      AtkObject *target = g_ptr_array_index(relation->target, i);
      atk_relation_add_target (exist_relation, target); 
    }
  }
}
/**
 * atk_relation_set_add_relation_by_type:
 * @set: an #AtkRelationSet
 * @relationship: an #AtkRelationType
 * @target: an #AtkObject
 *
 * Add a new relation of the specified type with the specified target to 
 * the current relation set if the relation set does not contain a relation
 * of that type. If it is does contain a relation of that typea the target
 * is added to the relation.
 *
 * Since: ATK 1.9
 **/
void
atk_relation_set_add_relation_by_type (AtkRelationSet  *set,
                                       AtkRelationType relationship,
                                       AtkObject       *target)
{
  AtkRelation *relation;

  g_return_if_fail (ATK_IS_RELATION_SET (set));
  g_return_if_fail (ATK_IS_OBJECT (target));

  relation = atk_relation_set_get_relation_by_type (set,
                                                    relationship);
  if (relation)
    {
      atk_relation_add_target (relation, target);
    } 
  else 
    {
      /* the relation hasn't been created yet ... */
      relation = atk_relation_new (&target, 1, relationship);
      atk_relation_set_add (set, relation);
      g_object_unref(relation);
    }
}
Exemple #3
0
static VALUE
rbatkrel_add_target(VALUE self, VALUE obj)
{
    atk_relation_add_target(_SELF(self), ATK_OBJECT(RVAL2GOBJ(obj)));
    return self;
}