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.
This commit is contained in:
Michael Natterer 2009-08-05 14:17:07 +02:00
parent 85148ea2b9
commit 8cda7dca56
2 changed files with 23 additions and 0 deletions

View File

@ -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;
}

View File

@ -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__ */