예제 #1
0
/**
 * 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); 
    }
  }
}
예제 #2
0
/**
 * atk_relation_set_remove:
 * @set: an #AtkRelationSet
 * @relation: an #AtkRelation
 *
 * Removes 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)
{
  GPtrArray *array_item;
  AtkRelationType relationship;

  g_return_if_fail (ATK_IS_RELATION_SET (set));

  array_item = set->relations;
  if (array_item == NULL)
    return;

  if (g_ptr_array_remove (array_item, relation))
  {
    g_object_unref (relation);
  }
  else
  {
    relationship = atk_relation_get_relation_type (relation);
    if (atk_relation_set_contains (set, relationship))
    {
      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_remove_target (exist_relation, target);
      }
    }
  }
}
예제 #3
0
static void
gtk_cell_accessible_object_finalize (GObject *obj)
{
  AtkRelationSet *relation_set;
  AtkRelation *relation;
  GPtrArray *target;
  gpointer target_object;
  gint i;

  relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
  if (ATK_IS_RELATION_SET (relation_set))
    {
      relation = atk_relation_set_get_relation_by_type (relation_set,
                                                        ATK_RELATION_NODE_CHILD_OF);
      if (relation)
        {
          target = atk_relation_get_target (relation);
          for (i = 0; i < target->len; i++)
            {
              target_object = g_ptr_array_index (target, i);
              if (GTK_IS_CELL_ACCESSIBLE (target_object))
                g_object_unref (target_object);
            }
        }
      g_object_unref (relation_set);
    }
  G_OBJECT_CLASS (_gtk_cell_accessible_parent_class)->finalize (obj);
}
예제 #4
0
/**
 * atk_relation_set_get_n_relations:
 * @set: an #AtkRelationSet
 *
 * Determines the number of relations in a relation set.
 *
 * Returns: an integer representing the number of relations in the set.
 **/
gint
atk_relation_set_get_n_relations (AtkRelationSet *set)
{
  g_return_val_if_fail (ATK_IS_RELATION_SET (set), 0);

  if (set->relations == NULL)
    return 0;

  return set->relations->len;
}
예제 #5
0
void
gtk_cell_accessible_parent_update_relationset (GtkCellAccessibleParent *parent,
                                               GtkCellAccessible       *cell,
                                               AtkRelationSet          *relationset)
{
  GtkCellAccessibleParentIface *iface;

  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
  g_return_if_fail (ATK_IS_RELATION_SET (relationset));

  iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);

  if (iface->update_relationset)
    (iface->update_relationset) (parent, cell, relationset);
}
예제 #6
0
/**
 * atk_relation_set_get_relation
 * @set: an #AtkRelationSet
 * @i: a gint representing a position in the set, starting from 0.
 *
 * Determines the relation at the specified position in the relation set.
 *
 * Returns: a #AtkRelation, which is the relation at position i in the set.
 **/
AtkRelation*
atk_relation_set_get_relation (AtkRelationSet *set,
                               gint           i)
{
  GPtrArray *array_item;
  AtkRelation* item;

  g_return_val_if_fail (ATK_IS_RELATION_SET (set), NULL);
  g_return_val_if_fail (i >= 0, NULL);

  array_item = set->relations;
  if (array_item == NULL)
    return NULL;
  item = g_ptr_array_index (array_item, i);
  if (item == NULL)
    return NULL;

  return item;
}
예제 #7
0
/**
 * atk_relation_set_contains:
 * @set: an #AtkRelationSet
 * @relationship: an #AtkRelationType
 *
 * Determines whether the relation set contains a relation that matches the
 * specified type.
 *
 * Returns: %TRUE if @relationship is the relationship type of a relation
 * in @set, %FALSE otherwise
 **/
gboolean
atk_relation_set_contains (AtkRelationSet   *set,
                           AtkRelationType  relationship)
{
  GPtrArray *array_item;
  AtkRelation *item;
  gint  i;

  g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE);

  array_item = set->relations;
  if (array_item == NULL)
    return FALSE;
  for (i = 0; i < array_item->len; i++)
  {
    item = g_ptr_array_index (array_item, i);
    if (item->relationship == relationship)
      return TRUE;
  }
  return FALSE;
}
예제 #8
0
/**
 * atk_relation_set_get_relation_by_type:
 * @set: an #AtkRelationSet
 * @relationship: an #AtkRelationType
 *
 * Finds a relation that matches the specified type.
 *
 * Returns: an #AtkRelation, which is a relation matching the specified type.
 **/
AtkRelation*
atk_relation_set_get_relation_by_type (AtkRelationSet  *set,
                                       AtkRelationType relationship)
{
  GPtrArray *array_item;
  AtkRelation *item;
  gint i;

  g_return_val_if_fail (ATK_IS_RELATION_SET (set), NULL);

  array_item = set->relations;
  if (array_item == NULL)
    return NULL;
  for (i = 0; i < array_item->len; i++)
  {
    item = g_ptr_array_index (array_item, i);
    if (item->relationship == relationship)
      return item;
  }
  return NULL;
}
예제 #9
0
static void
atk_relation_set_finalize (GObject *object)
{
  AtkRelationSet     *relation_set;
  GPtrArray             *array;
  gint               i;

  g_return_if_fail (ATK_IS_RELATION_SET (object));

  relation_set = ATK_RELATION_SET (object);
  array = relation_set->relations;

  if (array)
  {
    for (i = 0; i < array->len; i++)
    {
      g_object_unref (g_ptr_array_index (array, i));
    }
    g_ptr_array_free (array, TRUE);
  }

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
예제 #10
0
/**
 * 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);
    }
}