From 8cda7dca56cb647f1fba4fa75b648bbbe4dc03ad Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 5 Aug 2009 14:17:07 +0200 Subject: [PATCH] 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(+) diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c index 858c1e2c44..6070dd0688 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 d47225696c..3231ae6231 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__ */