From cc61e89ff7006c5b39bdb3a72083ade99849e673 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 12 Dec 2019 13:07:50 +0000 Subject: [PATCH] CtrlCore: Ctrl::GetAscendant git-svn-id: svn://ultimatepp.org/upp/trunk@13756 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/CtrlCore.h | 12 ++++++++++++ uppsrc/CtrlCore/src.tpp/Ctrl_en-us.tpp | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index d62789bac..94740f14e 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -912,6 +912,8 @@ public: int GetChildIndex(const Ctrl *child) const; Ctrl *GetIndexChild(int i) const; int GetChildCount() const; + template + T *GetAscendant() const; int GetViewChildIndex(const Ctrl *child) const; int GetViewChildCount() const; @@ -1662,6 +1664,16 @@ void WriteClipboardHTML(const String& html); #include GUIPLATFORM_INCLUDE_AFTER +template +T *Ctrl::GetAscendant() const +{ + T *main; + for(Ctrl *p = GetParent(); p; p = p->GetParent()) + if(T *a = dynamic_cast(p)) + return a; + return NULL; +} + } #endif diff --git a/uppsrc/CtrlCore/src.tpp/Ctrl_en-us.tpp b/uppsrc/CtrlCore/src.tpp/Ctrl_en-us.tpp index dd4a06eb0..5f983def0 100644 --- a/uppsrc/CtrlCore/src.tpp/Ctrl_en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/Ctrl_en-us.tpp @@ -988,6 +988,12 @@ st]&] sequential scan of child (results in O(n) complexity).&] [s3; &] [s4;%- &] +[s5;:Upp`:`:Ctrl`:`:GetAscendant`(`)const:%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T +]>_[*@4 T]_`*[* GetAscendant]()_[@(0.0.255) const]&] +[s2; Returns first ascendant (parent, parent of parent etc..) that +has type [%-*@4 T].&] +[s3;%- &] +[s4;%- &] [s5;:Ctrl`:`:GetIndexChild`(int`)const:%- [_^Ctrl^ Ctrl]_`*[* GetIndexChild]([@(0.0.255) in t]_[*@3 i])_[@(0.0.255) const]&] [s2; Retruns child at index [%-*@3 i] or NULL if there is none. Note