Bug #477708. Only remove the target, not the relation if there are still
authorLi Yuan <li.yuan@sun.com>
Tue, 11 Nov 2008 07:17:06 +0000 (07:17 +0000)
committerLi Yuan <liyuan@src.gnome.org>
Tue, 11 Nov 2008 07:17:06 +0000 (07:17 +0000)
2008-11-10  Li Yuan  <li.yuan@sun.com>

        * atk/atkobject.c: (atk_object_remove_relationship):
        Bug #477708. Only remove the target, not the relation if
        there are still are targets.
        * atk/atkrelation.c: (atk_relation_remove_target):
        * atk/atkrelation.h: New API.
        * atk/atkrelationset.c: (atk_relation_set_add),
        (atk_relation_set_remove):
        Add/remove the new relation's targets to/from the existed
        relation if there has been a relation with the same type.
        * atk/atkstateset.c: (atk_state_set_or_sets):
        Bug #478595. Return NULL if sets are empty.

svn path=/trunk/; revision=1297

ChangeLog
atk/atkobject.c
atk/atkrelation.c
atk/atkrelation.h
atk/atkrelationset.c
atk/atkstateset.c

index 871d4c37f01cdf307ab2a14c42ef57ab2b63a37f..9f8d904d28937e74f0f2997174a255eb837b973e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-11-10  Li Yuan  <li.yuan@sun.com>
+
+       * atk/atkobject.c: (atk_object_remove_relationship):
+       Bug #477708. Only remove the target, not the relation if
+       there are still are targets.
+       * atk/atkrelation.c: (atk_relation_remove_target):
+       * atk/atkrelation.h: New API.
+       * atk/atkrelationset.c: (atk_relation_set_add),
+       (atk_relation_set_remove): 
+       Add/remove the new relation's targets to/from the existed 
+       relation if there has been a relation with the same type.
+       * atk/atkstateset.c: (atk_state_set_or_sets):
+       Bug #478595. Return NULL if sets are empty.
+
 2008-11-10  Li Yuan  <li.yuan@sun.com>
 
        * atk/atkrelationset.c: (atk_relation_set_add):
index 80af51466d2d0eed77119fa7e3d3c31b2b6af49f..234a68afe887c5b0f2c901e6bf8b6aacfb123e58 100755 (executable)
@@ -1522,32 +1522,22 @@ atk_object_remove_relationship (AtkObject       *object,
                                 AtkRelationType relationship,
                                 AtkObject       *target)
 {
-  gint n_relations, i;
   gboolean ret = FALSE;
   AtkRelation *relation;
+  GPtrArray *array;
 
   g_return_val_if_fail (ATK_IS_OBJECT (object), FALSE);
   g_return_val_if_fail (ATK_IS_OBJECT (target), FALSE);
 
-  n_relations = atk_relation_set_get_n_relations (object->relation_set);
-  for (i = 0; i < n_relations; i++)
-    {
-      relation = atk_relation_set_get_relation (object->relation_set, i);
-      if (atk_relation_get_relation_type (relation) == relationship)
-        {
-          GPtrArray *array;
+  relation = atk_relation_set_get_relation_by_type (object->relation_set, relationship);
 
-          array = atk_relation_get_target (relation);
-        
-          if (g_ptr_array_index (array, 0) == target)
-            {
-              atk_relation_set_remove (object->relation_set, relation); 
-              ret = TRUE;
-              break;
-            }
-        }
+  if (relation)
+    {
+      ret = atk_relation_remove_target (relation, target);
+      array = atk_relation_get_target (relation);
+      if (!array || array->len == 0)
+        atk_relation_set_remove (object->relation_set, relation);
     }
-
   return ret;
 }
 
index 92000c99ba18f793b56eff303a22a6fbbe7a7657..970d947bbc234bb935af71fc5ca24d4d3149eb2e 100755 (executable)
@@ -333,6 +333,35 @@ atk_relation_add_target (AtkRelation *relation,
   g_object_weak_ref (G_OBJECT (target), (GWeakNotify) delete_object_while_in_relation, relation->target);
 }
 
+/**
+ * atk_relation_remove_target:
+ * @relation: an #AtkRelation
+ * @target: an #AtkObject
+ *
+ * Remove the specified AtkObject from the target for the relation.
+ *
+ * Returns TRUE if the removal is successful.
+ **/
+
+gboolean
+atk_relation_remove_target (AtkRelation *relation,
+                            AtkObject *target)
+{
+  gboolean ret = FALSE;
+  GPtrArray *array;
+
+  array = atk_relation_get_target (relation);
+
+  if (array && g_ptr_array_remove (array, target))
+    {
+      g_object_weak_unref (G_OBJECT (target),
+                           (GWeakNotify) delete_object_while_in_relation,
+                           relation->target);
+      ret = TRUE;
+    }
+  return ret;
+}
+
 static void
 atk_relation_finalize (GObject *object)
 {
index 88db375c581ca0cff17de9e83b71b599d13c4726..794747c12c4328d2e91d3bf74ee5111094396034 100755 (executable)
@@ -81,6 +81,8 @@ AtkRelationType       atk_relation_get_relation_type  (AtkRelation     *relation
 GPtrArray*            atk_relation_get_target         (AtkRelation     *relation);
 void                  atk_relation_add_target         (AtkRelation     *relation,
                                                        AtkObject       *target);
+gboolean              atk_relation_remove_target      (AtkRelation     *relation,
+                                                       AtkObject       *target);
 
 G_END_DECLS
 
index 2264595df1d04229cb165d6774d0699fd86f1b4e..f594cac96d32c64a217cae8d7c1d4b900af1ab37 100755 (executable)
@@ -123,17 +123,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);
+      }
+    }
+  }
 }
 
 /**
@@ -160,12 +176,24 @@ atk_relation_set_add (AtkRelationSet *set,
   {
     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); 
+    }
+  }
 }
 
 /**
index 2b98fa4af7e9b2e33c100c49b7296b32d92cec8f..b7654b0ef46fef1537f1dac7a2884a95c7a6531b 100755 (executable)
@@ -308,8 +308,11 @@ atk_state_set_or_sets (AtkStateSet  *set,
 
   state = real_set->state | real_compare_set->state;
 
-  return_set = atk_state_set_new();
-  ((AtkRealStateSet *) return_set)->state = state;
+  if (state)
+  {
+    return_set = atk_state_set_new();
+    ((AtkRealStateSet *) return_set)->state = state;
+  }
 
   return return_set;
 }