From 065a50d9d5cc8fb719a59494ea6e63e24ba7a47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Wed, 13 Apr 2016 21:34:03 +0300 Subject: [PATCH] Widgets|libcore: Checking for a potential ancestor widget --- doomsday/sdk/libcore/include/de/widgets/widget.h | 1 + doomsday/sdk/libcore/src/widgets/widget.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/doomsday/sdk/libcore/include/de/widgets/widget.h b/doomsday/sdk/libcore/include/de/widgets/widget.h index 2cccbb0529..7050159c4b 100644 --- a/doomsday/sdk/libcore/include/de/widgets/widget.h +++ b/doomsday/sdk/libcore/include/de/widgets/widget.h @@ -223,6 +223,7 @@ class DENG2_PUBLIC Widget Widget *remove(Widget &child); Widget *find(String const &name); bool isInTree(Widget const &child) const; + bool hasAncestor(Widget const &ancestorOrParent) const; Widget const *find(String const &name) const; void moveChildBefore(Widget *child, Widget const &otherChild); void moveChildToLast(Widget &child); diff --git a/doomsday/sdk/libcore/src/widgets/widget.cpp b/doomsday/sdk/libcore/src/widgets/widget.cpp index 1077f9e546..8f448aa2da 100644 --- a/doomsday/sdk/libcore/src/widgets/widget.cpp +++ b/doomsday/sdk/libcore/src/widgets/widget.cpp @@ -393,6 +393,15 @@ bool Widget::isInTree(Widget const &child) const return false; } +bool Widget::hasAncestor(Widget const &ancestorOrParent) const +{ + for(Widget const *iter = parent(); iter; iter = iter->parent()) + { + if(iter == &ancestorOrParent) return true; + } + return false; +} + Widget const *Widget::find(String const &name) const { return const_cast(this)->find(name);