X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk%2Fatkrelationset.c;h=95d50e66b905af27cdf6ca7cd2d3d8d9dd14d5ae;hb=dd7c22e2586adf23bc7d9f52c793cbf127b2a753;hp=40bf487d0b225eac786087c7937d401fefd6809c;hpb=c91521a0a6359218d8b76b5f5c63c5d649bca7b6;p=platform%2Fupstream%2Fatk.git diff --git a/atk/atkrelationset.c b/atk/atkrelationset.c old mode 100755 new mode 100644 index 40bf487..95d50e6 --- a/atk/atkrelationset.c +++ b/atk/atkrelationset.c @@ -17,10 +17,28 @@ * Boston, MA 02111-1307, USA. */ +#include "config.h" + #include #include "atk.h" +/** + * SECTION:atkrelationset + * @Short_description: A set of AtkRelations, normally the set of + * AtkRelations which an AtkObject has. + * @Title:AtkRelationSet + * + * The AtkRelationSet held by an object establishes its relationships + * with objects beyond the normal "parent/child" hierarchical + * relationships that all user interface objects have. + * AtkRelationSets establish whether objects are labelled or + * controlled by other components, share group membership with other + * components (for instance within a radio-button group), or share + * content which "flows" between them, among other types of possible + * relationships. + */ + static gpointer parent_class = NULL; static void atk_relation_set_class_init (AtkRelationSetClass *klass); @@ -123,17 +141,33 @@ 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); + } + } + } } /** @@ -151,6 +185,8 @@ 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); @@ -158,8 +194,24 @@ atk_relation_set_add (AtkRelationSet *set, { set->relations = g_ptr_array_new (); } - g_ptr_array_add (set->relations, relation); - g_object_ref (relation); + + 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); + } + } } /** @@ -173,7 +225,7 @@ atk_relation_set_add (AtkRelationSet *set, gint atk_relation_set_get_n_relations (AtkRelationSet *set) { - g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE); + g_return_val_if_fail (ATK_IS_RELATION_SET (set), 0); if (set->relations == NULL) return 0; @@ -182,13 +234,14 @@ atk_relation_set_get_n_relations (AtkRelationSet *set) } /** - * atk_relation_set_get_relation + * 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. + * Returns: (transfer none): a #AtkRelation, which is the relation at + * position i in the set. **/ AtkRelation* atk_relation_set_get_relation (AtkRelationSet *set, @@ -197,7 +250,7 @@ atk_relation_set_get_relation (AtkRelationSet *set, GPtrArray *array_item; AtkRelation* item; - g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE); + g_return_val_if_fail (ATK_IS_RELATION_SET (set), NULL); g_return_val_if_fail (i >= 0, NULL); array_item = set->relations; @@ -217,7 +270,8 @@ atk_relation_set_get_relation (AtkRelationSet *set, * * Finds a relation that matches the specified type. * - * Returns: an #AtkRelation, which is a relation matching the specified type. + * Returns: (transfer none): an #AtkRelation, which is a relation matching the + * specified type. **/ AtkRelation* atk_relation_set_get_relation_by_type (AtkRelationSet *set, @@ -227,7 +281,7 @@ atk_relation_set_get_relation_by_type (AtkRelationSet *set, AtkRelation *item; gint i; - g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE); + g_return_val_if_fail (ATK_IS_RELATION_SET (set), NULL); array_item = set->relations; if (array_item == NULL) @@ -264,3 +318,92 @@ atk_relation_set_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } + +/** + * 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: 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); + } +} + +/** + * atk_relation_set_contains_target: + * @set: an #AtkRelationSet + * @relationship: an #AtkRelationType + * @target: an #AtkObject + * + * Determines whether the relation set contains a relation that + * matches the specified pair formed by type @relationship and object + * @target. + * + * Returns: %TRUE if @set contains a relation with the relationship + * type @relationship with an object @target, %FALSE otherwise + **/ + +gboolean +atk_relation_set_contains_target (AtkRelationSet *set, + AtkRelationType relationship, + AtkObject *target) +{ + GPtrArray *array_relations; + GPtrArray *array_target; + AtkObject *current_target; + AtkRelation *relation; + gint i; + gint c; + + g_return_val_if_fail (ATK_IS_RELATION_SET (set), FALSE); + g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE); + + array_relations = set->relations; + if (array_relations == NULL) + return FALSE; + + for (i = 0; i < array_relations->len; i++) + { + relation = g_ptr_array_index (array_relations, i); + if (relation->relationship == relationship) + { + array_target = atk_relation_get_target (relation); + for (c = 0; c < array_target->len; c++) + { + current_target = g_ptr_array_index (array_target, c); + if (target == current_target) + return TRUE; + } + } + } + + return FALSE; +}