[gimp] Add gimp_viewable_is_ancestor()



commit 8cda7dca56cb647f1fba4fa75b648bbbe4dc03ad
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 5 14:17:07 2009 +0200

    Add gimp_viewable_is_ancestor()
    
    The new functions figures if one viewable is another's parent or
    grandparent or grandgrand... Note that unlike gtk_widget_is_ancestor(),
    this function has its parameters in the right order.

 app/core/gimpviewable.c |   20 ++++++++++++++++++++
 app/core/gimpviewable.h |    3 +++
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index 858c1e2..6070dd0 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -1127,3 +1127,23 @@ gimp_viewable_get_children (GimpViewable *viewable)
 
   return GIMP_VIEWABLE_GET_CLASS (viewable)->get_children (viewable);
 }
+
+gboolean
+gimp_viewable_is_ancestor (GimpViewable *ancestor,
+                           GimpViewable *descendant)
+{
+  g_return_val_if_fail (GIMP_IS_VIEWABLE (ancestor), FALSE);
+  g_return_val_if_fail (GIMP_IS_VIEWABLE (descendant), FALSE);
+
+  while (descendant)
+    {
+      GimpViewable *parent = gimp_viewable_get_parent (descendant);
+
+      if (parent == ancestor)
+        return TRUE;
+
+      descendant = parent;
+    }
+
+  return FALSE;
+}
diff --git a/app/core/gimpviewable.h b/app/core/gimpviewable.h
index d472256..3231ae6 100644
--- a/app/core/gimpviewable.h
+++ b/app/core/gimpviewable.h
@@ -182,5 +182,8 @@ void            gimp_viewable_set_parent         (GimpViewable  *viewable,
 
 GimpContainer * gimp_viewable_get_children       (GimpViewable  *viewable);
 
+gboolean        gimp_viewable_is_ancestor        (GimpViewable  *ancestor,
+                                                  GimpViewable  *descendant);
+
 
 #endif  /* __GIMP_VIEWABLE_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]