From e6a5c9c85fabd1b473d22fb4abbdd0b927e6053f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 23 May 2014 12:33:49 +0200 Subject: [PATCH] [DEV] add owner to auto remove an object --- sources/ewol/context/Context.cpp | 7 +- sources/ewol/context/Context.h | 2 +- sources/ewol/object/Manager.cpp | 29 ++++- sources/ewol/object/Manager.h | 5 + sources/ewol/object/Object.cpp | 7 +- sources/ewol/object/Object.h | 2 + sources/ewol/object/Owner.h | 188 ++++++++++++++++++++++++++++ sources/ewol/object/RemoveEvent.cpp | 17 +++ sources/ewol/object/RemoveEvent.h | 27 ++++ sources/ewol/object/Shared.h | 39 ++++++ sources/ewol/resource/Manager.cpp | 28 +++-- sources/ewol/resource/Manager.h | 3 +- sources/ewol/widget/Container.h | 2 +- sources/ewol/widget/Container2.h | 2 +- sources/ewol/widget/ContainerN.cpp | 110 ++++++---------- sources/ewol/widget/ContainerN.h | 3 +- sources/ewol/widget/Layer.cpp | 10 +- sources/ewol/widget/Sizer.cpp | 46 +++---- sources/ewol/widget/Widget.cpp | 7 +- sources/ewol/widget/Windows.h | 4 +- sources/lutin_ewol.py | 3 +- 21 files changed, 410 insertions(+), 131 deletions(-) create mode 100644 sources/ewol/object/Owner.h create mode 100644 sources/ewol/object/RemoveEvent.cpp create mode 100644 sources/ewol/object/RemoveEvent.h diff --git a/sources/ewol/context/Context.cpp b/sources/ewol/context/Context.cpp index 4c3afc33..8f66e840 100644 --- a/sources/ewol/context/Context.cpp +++ b/sources/ewol/context/Context.cpp @@ -380,13 +380,10 @@ ewol::Context::~Context() { // TODO : Clean the message list ... // set the curent interface : lockContext(); + // Remove current windows + m_windowsCurrent.reset(); // call application to uninit APP_UnInit(*this); - if (m_windowsCurrent != nullptr) { - EWOL_DEBUG("Main windows has not been auto-removed..."); - m_windowsCurrent->removeObject(); - m_windowsCurrent.reset(); - } // unset all windows m_msgSystem.clean(); diff --git a/sources/ewol/context/Context.h b/sources/ewol/context/Context.h index 83ed6428..53da0740 100644 --- a/sources/ewol/context/Context.h +++ b/sources/ewol/context/Context.h @@ -158,7 +158,7 @@ namespace ewol { */ virtual void stop(); private: - ewol::object::Shared m_windowsCurrent; //!< curent displayed windows + ewol::object::Owner m_windowsCurrent; //!< curent displayed windows public: /** * @brief set the current windows to display : diff --git a/sources/ewol/object/Manager.cpp b/sources/ewol/object/Manager.cpp index d0ca42ac..3a839be0 100644 --- a/sources/ewol/object/Manager.cpp +++ b/sources/ewol/object/Manager.cpp @@ -35,17 +35,19 @@ ewol::object::Manager::~Manager() { void ewol::object::Manager::unInit() { EWOL_DEBUG(" == > Un-Init Object-Manager"); + for (auto &it : m_eObjectList) { + if (it != nullptr) { + //it->removeObject(); + } + } removeAllRemovedObject(); EWOL_INFO(" remove missing user object"); size_t iii=0; if (m_eObjectListActive.size() != 0) { EWOL_ERROR("Have " << m_eObjectListActive.size() << " active Object"); } - while(iii < m_eObjectListActive.size()) { - if (m_eObjectListActive[iii] != nullptr) { - m_eObjectListActive.erase(m_eObjectListActive.begin()+iii); - } - } + m_eObjectListActive.clear(); + m_eObjectList.clear(); removeAllRemovedObject(); } @@ -68,6 +70,9 @@ void ewol::object::Manager::informOneObjectIsRemoved(const ewol::object::Shared< it->onObjectRemove(_object); } } + for (auto &it : m_removeEventList) { + it->onObjectRemove(_object); + } // inform the context ... ewol::getContext().onObjectRemove(_object); } @@ -136,3 +141,17 @@ ewol::object::Shared ewol::object::Manager::get(const std::string& return nullptr; } + +void ewol::object::Manager::add(ewol::object::RemoveEvent* _class) { + m_removeEventList.push_back(_class); +} + +void ewol::object::Manager::rm(ewol::object::RemoveEvent* _class) { + for (size_t iii=0; iii #include #include +#include namespace ewol { namespace object { class Manager { private: + std::vector m_removeEventList; std::vector> m_eObjectList; // all widget allocated == > all time increment ... never removed ... std::vector> m_eObjectListActive; // all active widget public: @@ -61,6 +63,9 @@ namespace ewol { ewol::object::MultiCast& multiCast() { return m_multiCast; }; + + void add(ewol::object::RemoveEvent* _class); + void rm(ewol::object::RemoveEvent* _class); }; }; }; diff --git a/sources/ewol/object/Object.cpp b/sources/ewol/object/Object.cpp index 62698a74..c03e74e2 100644 --- a/sources/ewol/object/Object.cpp +++ b/sources/ewol/object/Object.cpp @@ -49,6 +49,7 @@ void ewol::Object::operator delete[](void* _ptr, std::size_t _sz) { } void ewol::Object::autoDestroy() { + EWOL_VERBOSE("Destroy object : [" << m_valUID << "] type:" << getTypeDescription()); { std::unique_lock lock(m_lockRefCount); if (m_isDestroyed == true) { @@ -114,7 +115,7 @@ ewol::Object::~Object() { const char * const ewol::Object::getObjectType() { if (m_listType.size() == 0) { - return "ewol::object::Shared"; + return "ewol::Object"; } return m_listType.back(); } @@ -127,7 +128,7 @@ void ewol::Object::addObjectType(const char* _type) { m_listType.push_back(_type); } std::string ewol::Object::getTypeDescription() { - std::string ret("ewol::object::Shared"); + std::string ret("ewol::Object"); for(auto element : m_listType) { ret += "|"; ret += element; @@ -136,7 +137,7 @@ std::string ewol::Object::getTypeDescription() { } bool ewol::Object::isTypeCompatible(const std::string& _type) { - if (_type == "ewol::object::Shared") { + if (_type == "ewol::Object") { return true; } for(auto element : m_listType) { diff --git a/sources/ewol/object/Object.h b/sources/ewol/object/Object.h index bd7ddec5..bf46377f 100644 --- a/sources/ewol/object/Object.h +++ b/sources/ewol/object/Object.h @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace ewol { @@ -50,6 +51,7 @@ namespace ewol { */ class Object { template friend class ewol::object::Shared; + template friend class ewol::object::Owner; private: //! @not-in-doc std::mutex m_lockRefCount; diff --git a/sources/ewol/object/Owner.h b/sources/ewol/object/Owner.h new file mode 100644 index 00000000..51f898e1 --- /dev/null +++ b/sources/ewol/object/Owner.h @@ -0,0 +1,188 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD 3 clauses (see license file) + */ + +#ifndef __EWOL_OBJECT_OWNER_H__ +#define __EWOL_OBJECT_OWNER_H__ + +#include + +namespace ewol { + namespace object { + template + class Owner { + private: + T* m_pointer; + public: + Owner() : + m_pointer(nullptr) { + // nothing to do ... + } + Owner(T* _pointer) : + m_pointer(_pointer) { + if (m_pointer == nullptr) { + return; + } + m_pointer->objRefCountIncrement(); + } + ~Owner() { + reset(); + } + // copy constructor + Owner(const Owner& _obj) : + m_pointer(nullptr) { + EWOL_CRITICAL("You can not user copy operator for Owner reference..."); + } + // Move Constructor + Owner(Owner&& _obj) : + m_pointer(nullptr) { + // transfert pointer + m_pointer = _obj.m_pointer; + _obj.m_pointer = nullptr; + } + Owner& operator=(const Owner& _obj) noexcept { + if(this == &_obj) { + return *this; + } + reset(); + m_pointer = _obj.get(); + if (m_pointer != nullptr) { + m_pointer->objRefCountIncrement(); + } + return *this; + } + + void reset() { + if (m_pointer == nullptr) { + return; + } + m_pointer->removeObject(); + if (m_pointer->m_objRefCount <= 0) { + EWOL_ERROR("Object will be already removed"); + } else if (m_pointer->m_objRefCount == 1) { + EWOL_ERROR("Remove object (in Owner)"); + delete m_pointer; + } else { + m_pointer->objRefCountDecrement(); + } + m_pointer = nullptr; + } + void resetShared() { + if (m_pointer == nullptr) { + return; + } + if (m_pointer->m_objRefCount <= 0) { + EWOL_ERROR("Object will be already removed"); + } else if (m_pointer->m_objRefCount == 1) { + EWOL_ERROR("Remove object (in Owner)"); + delete m_pointer; + } else { + m_pointer->objRefCountDecrement(); + } + m_pointer = nullptr; + } + T* get() noexcept { + return m_pointer; + } + T* get() const noexcept { + return m_pointer; + } + T& operator*() const noexcept { + return *m_pointer; + } + T* operator->() const noexcept { + return m_pointer; + } + }; + }; + // section to compare Owner pointer of an object with an other + + //! @not in doc + template + inline bool operator==(const object::Owner& _obj, const object::Owner& _obj2) noexcept { + return _obj.get() == _obj2.get(); + } + //! @not in doc + template + inline bool operator==(const object::Owner& _obj, std::nullptr_t) noexcept { + return _obj.get() == nullptr; + } + //! @not in doc + template + inline bool operator==(std::nullptr_t, const object::Owner& _obj) noexcept { + return _obj.get() == nullptr; + } + //! @not in doc + template::value>::type> + inline bool operator==(const object::Owner& _obj, const T2* _obj2) noexcept { + return _obj.get() == _obj2; + } + //! @not in doc + template::value>::type> + inline bool operator==(const T* _obj, const object::Owner& _obj2) noexcept { + return _obj == _obj2.get(); + } + + //! @not in doc + template + inline bool operator!=(const object::Owner& _obj, const object::Owner& _obj2) noexcept { + return _obj.get() != _obj2.get(); + } + //! @not in doc + template + inline bool operator!=(const object::Owner& _obj, std::nullptr_t) noexcept { + return _obj.get() != nullptr; + } + //! @not in doc + template + inline bool operator!=(std::nullptr_t, const object::Owner& _obj) noexcept { + return _obj.get() != nullptr; + } + //! @not in doc + template::value>::type> + inline bool operator!=(const object::Owner& _obj, const T2* _obj2) noexcept { + return _obj.get() != _obj2; + } + //! @not in doc + template::value>::type> + inline bool operator!=(const T* _obj, const object::Owner& _obj2) noexcept { + return _obj != _obj2.get(); + } + + //! @not in doc + template + inline void swap(object::Owner& _obj, object::Owner& _obj2) noexcept { + _obj2.swap(_obj); + } + + //! @not in doc + template + inline object::Owner static_pointer_cast(const object::Owner& _obj) noexcept { + return object::Owner(_obj, static_cast(_obj.get())); + } + + //! @not in doc + template + inline object::Owner const_pointer_cast(const object::Owner& _obj) noexcept { + return object::Owner(_obj, const_cast(_obj.get())); + } + + //! @not in doc + template + inline object::Owner dynamic_pointer_cast(const object::Owner& _obj) noexcept { + if (T2* obj = dynamic_cast(_obj.get())) { + return object::Owner(_obj, obj); + } + return object::Owner(); + } +}; +#endif + diff --git a/sources/ewol/object/RemoveEvent.cpp b/sources/ewol/object/RemoveEvent.cpp new file mode 100644 index 00000000..464a2230 --- /dev/null +++ b/sources/ewol/object/RemoveEvent.cpp @@ -0,0 +1,17 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD 3 clauses (see license file) + */ + +#include + +ewol::object::RemoveEvent::RemoveEvent() { + +} + +ewol::object::RemoveEvent::~RemoveEvent() { + +} diff --git a/sources/ewol/object/RemoveEvent.h b/sources/ewol/object/RemoveEvent.h new file mode 100644 index 00000000..3e2548c5 --- /dev/null +++ b/sources/ewol/object/RemoveEvent.h @@ -0,0 +1,27 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD 3 clauses (see license file) + */ + +#ifndef __EWOL_OBJECT_REMOVE_EVENT_H__ +#define __EWOL_OBJECT_REMOVE_EVENT_H__ + +#include +#include + +namespace ewol { + namespace object { + class RemoveEvent { + public: + virtual void onObjectRemove(const ewol::object::Shared& _object) = 0; + public: + RemoveEvent(); + ~RemoveEvent(); + }; + } +}; + +#endif diff --git a/sources/ewol/object/Shared.h b/sources/ewol/object/Shared.h index 0b0ff8ea..e1c22887 100644 --- a/sources/ewol/object/Shared.h +++ b/sources/ewol/object/Shared.h @@ -32,6 +32,15 @@ namespace ewol { ~Shared() { reset(); } + // shared to private constructor + Shared(const Owner& _obj) : + m_pointer(nullptr) { + m_pointer = _obj.get(); + if (m_pointer == nullptr) { + return; + } + m_pointer->objRefCountIncrement(); + } // copy constructor Shared(const Shared& _obj) : m_pointer(nullptr) { @@ -48,6 +57,13 @@ namespace ewol { m_pointer = _obj.m_pointer; _obj.m_pointer = nullptr; } + bool hasOwner() { + if (m_pointer == nullptr) { + return false; + } + return m_pointer->getRefOwner(); + } + Shared& operator=(const Shared& _obj) noexcept { if(this == &_obj) { return *this; @@ -83,6 +99,9 @@ namespace ewol { T* operator->() const noexcept { return m_pointer; } + operator ewol::object::Owner() const noexcept { + return m_pointer; + } template operator ewol::object::Shared() const noexcept { return m_pointer; } @@ -127,6 +146,16 @@ namespace ewol { inline bool operator==(const T* _obj, const object::Shared& _obj2) noexcept { return _obj == _obj2.get(); } + //! @not in doc + template + inline bool operator==(const object::Owner& _obj, const object::Shared& _obj2) noexcept { + return _obj.get() == _obj2.get(); + } + //! @not in doc + template + inline bool operator==(const object::Shared& _obj, const object::Owner& _obj2) noexcept { + return _obj.get() == _obj2.get(); + } //! @not in doc template @@ -155,6 +184,16 @@ namespace ewol { inline bool operator!=(const T* _obj, const object::Shared& _obj2) noexcept { return _obj != _obj2.get(); } + //! @not in doc + template + inline bool operator!=(const object::Owner& _obj, const object::Shared& _obj2) noexcept { + return _obj.get() != _obj2.get(); + } + //! @not in doc + template + inline bool operator!=(const object::Shared& _obj, const object::Owner& _obj2) noexcept { + return _obj.get() != _obj2.get(); + } //! @not in doc template diff --git a/sources/ewol/resource/Manager.cpp b/sources/ewol/resource/Manager.cpp index c9649cea..18dfd9b9 100644 --- a/sources/ewol/resource/Manager.cpp +++ b/sources/ewol/resource/Manager.cpp @@ -215,16 +215,26 @@ bool ewol::resource::Manager::release(ewol::object::Shared _obje */ // in case of error ... void ewol::resource::Manager::onObjectRemove(const ewol::object::Shared& _removeObject) { - for (size_t iii=0; iii=0; --iii) { + if (m_resourceListToUpdate[iii] == nullptr) { + continue; } - } - for (size_t iii=0; iiigetRefCount() >= 3) { + continue; } + m_resourceListToUpdate.erase(m_resourceListToUpdate.begin() + iii); + break; } + for (int64_t iii = (int64_t)m_resourceList.size()-1; iii>=0; --iii) { + if (m_resourceList[iii] == nullptr) { + continue; + } + if (m_resourceList[iii]->getRefCount() >= 2) { + continue; + } + m_resourceList.erase(m_resourceList.begin() + iii); + break; + } + } diff --git a/sources/ewol/resource/Manager.h b/sources/ewol/resource/Manager.h index 7c3ee842..12ff4259 100644 --- a/sources/ewol/resource/Manager.h +++ b/sources/ewol/resource/Manager.h @@ -12,10 +12,11 @@ #include #include #include +#include namespace ewol { namespace resource { - class Manager { + class Manager : private ewol::object::RemoveEvent { private: std::vector> m_resourceList; std::vector> m_resourceListToUpdate; diff --git a/sources/ewol/widget/Container.h b/sources/ewol/widget/Container.h index fdaf8ca3..351dd18d 100644 --- a/sources/ewol/widget/Container.h +++ b/sources/ewol/widget/Container.h @@ -21,7 +21,7 @@ namespace ewol { */ class Container : public ewol::Widget { protected: - ewol::object::Shared m_subWidget; + ewol::object::Owner m_subWidget; public: /** * @brief Constructor diff --git a/sources/ewol/widget/Container2.h b/sources/ewol/widget/Container2.h index fad3433c..c7761fb4 100644 --- a/sources/ewol/widget/Container2.h +++ b/sources/ewol/widget/Container2.h @@ -22,7 +22,7 @@ namespace ewol { */ class Container2 : public ewol::Widget { protected: - ewol::object::Shared m_subWidget[2]; //!< 2 subwidget possible + ewol::object::Owner m_subWidget[2]; //!< 2 subwidget possible int32_t m_idWidgetDisplayed; //!< current widget displayed public: /** diff --git a/sources/ewol/widget/ContainerN.cpp b/sources/ewol/widget/ContainerN.cpp index 2bb768e4..406f9c54 100644 --- a/sources/ewol/widget/ContainerN.cpp +++ b/sources/ewol/widget/ContainerN.cpp @@ -86,16 +86,10 @@ void ewol::widget::ContainerN::subWidgetRemove(ewol::object::SharedremoveUpperWidget(); - m_subWidget[iii]->removeObject(); - // no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ... - if (errorControl == m_subWidget.size()) { - EWOL_CRITICAL("[" << getId() << "] {" << getObjectType() << "} The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function..."); - m_subWidget[iii] = nullptr; - m_subWidget.erase(m_subWidget.begin()+iii); - } + for (auto it(m_subWidget.begin()) ; it != m_subWidget.end() ; ++it) { + if (_newWidget == *it) { + (*it)->removeUpperWidget(); + m_subWidget.erase(it); markToRedraw(); requestUpdateSize(); return; @@ -107,11 +101,11 @@ void ewol::widget::ContainerN::subWidgetUnLink(ewol::object::SharedremoveUpperWidget(); - m_subWidget[iii] = nullptr; - m_subWidget.erase(m_subWidget.begin()+iii); + for (auto it(m_subWidget.begin()) ; it != m_subWidget.end() ; ++it) { + if (_newWidget == *it) { + (*it)->removeUpperWidget(); + (*it).resetShared(); + m_subWidget.erase(it); markToRedraw(); requestUpdateSize(); return; @@ -120,38 +114,16 @@ void ewol::widget::ContainerN::subWidgetUnLink(ewol::object::Shared 0 ) { - if (nullptr != m_subWidget[0]) { - m_subWidget[0]->removeUpperWidget(); - m_subWidget[0]->removeObject(); - // no remove, this element is removed with the function onObjectRemove == > it does not exist anymore ... - if (errorControl == m_subWidget.size()) { - EWOL_CRITICAL("[" << getId() << "] {" << getObjectType() << "} The number of element might have been reduced ... == > it is not the case ==> the herited class must call the \"OnObjectRemove\" function..."); - m_subWidget[0] = nullptr; - } - } else { - EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Must not have null pointer on the subWidget list ..."); - m_subWidget.erase(m_subWidget.begin()); + for (auto it : m_subWidget) { + if (it != nullptr) { + it->removeUpperWidget(); } - errorControl = m_subWidget.size(); } m_subWidget.clear(); } void ewol::widget::ContainerN::subWidgetRemoveAllDelayed() { - // the size automaticly decrement with the auto call of the onObjectRemove function - for (size_t iii=0; iiiremoveUpperWidget(); - m_subWidget[iii]->removeObject(); - m_subWidget[iii] = nullptr; - } else { - EWOL_WARNING("[" << getId() << "] {" << getObjectType() << "} Must not have null pointer on the subWidget list ..."); - } - } - m_subWidget.clear(); + subWidgetRemoveAll(); } ewol::object::Shared ewol::widget::ContainerN::getWidgetNamed(const std::string& _widgetName) { @@ -159,10 +131,10 @@ ewol::object::Shared ewol::widget::ContainerN::getWidgetNamed(cons if (nullptr!=tmpUpperWidget) { return tmpUpperWidget; } - for (size_t iii=0; iii tmpWidget = m_subWidget[iii]->getWidgetNamed(_widgetName); - if (nullptr != tmpWidget) { + for (auto it : m_subWidget) { + if (nullptr != it) { + ewol::object::Shared tmpWidget = it->getWidgetNamed(_widgetName); + if (tmpWidget != nullptr) { return tmpWidget; } } @@ -174,11 +146,9 @@ void ewol::widget::ContainerN::onObjectRemove(const ewol::object::Shared= 0; iii--) { - if(m_subWidget[iii] == _removeObject) { - EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} remove sizer sub Element [" << iii << "/" << m_subWidget.size()-1 << "] == > destroyed object"); - m_subWidget[iii] = nullptr; - m_subWidget.erase(m_subWidget.begin()+iii); + for (auto it(m_subWidget.begin()) ; it != m_subWidget.end() ; ++it) { + if(*it == _removeObject) { + m_subWidget.erase(it); } } } @@ -193,19 +163,19 @@ void ewol::widget::ContainerN::systemDraw(const ewol::DrawProperty& _displayProp // subwidget draw ewol::DrawProperty prop = _displayProp; prop.limit(m_origin, m_size); - for (int64_t iii=m_subWidget.size()-1; iii >= 0; iii--) { - if (nullptr != m_subWidget[iii]) { - m_subWidget[iii]->systemDraw(prop); + for (auto it : m_subWidget) { + if (it != nullptr) { + it->systemDraw(prop); } } } void ewol::widget::ContainerN::calculateSize(const vec2& _availlable) { m_size = _availlable; - for (size_t iii=0; iiisetOrigin(m_origin+m_offset); - m_subWidget[iii]->calculateSize(m_size); + for (auto it : m_subWidget) { + if (it != nullptr) { + it->setOrigin(m_origin+m_offset); + it->calculateSize(m_size); } } markToRedraw(); @@ -216,17 +186,17 @@ void ewol::widget::ContainerN::calculateMinMaxSize() { m_minSize.setValue(0,0); m_maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE); //EWOL_ERROR("[" << getId() << "] {" << getObjectType() << "} set min size : " << m_minSize); - for (size_t iii=0; iiicalculateMinMaxSize(); - bvec2 subExpendProp = m_subWidget[iii]->canExpand(); + for (auto it : m_subWidget) { + if (it != nullptr) { + it->calculateMinMaxSize(); + bvec2 subExpendProp = it->canExpand(); if (true == subExpendProp.x()) { m_subExpend.setX(true); } if (true == subExpendProp.y()) { m_subExpend.setY(true); } - vec2 tmpSize = m_subWidget[iii]->getCalculateMinSize(); + vec2 tmpSize = it->getCalculateMinSize(); m_minSize.setValue( etk_max(tmpSize.x(), m_minSize.x()), etk_max(tmpSize.y(), m_minSize.y()) ); } @@ -235,9 +205,9 @@ void ewol::widget::ContainerN::calculateMinMaxSize() { } void ewol::widget::ContainerN::onRegenerateDisplay() { - for (size_t iii=0; iiionRegenerateDisplay(); + for (auto it : m_subWidget) { + if (it != nullptr) { + it->onRegenerateDisplay(); } } } @@ -247,14 +217,14 @@ ewol::object::Shared ewol::widget::ContainerN::getWidgetAtPos(cons return nullptr; } // for all element in the sizer ... - for (size_t iii=0; iiigetSize(); - vec2 tmpOrigin = m_subWidget[iii]->getOrigin(); + for (auto it : m_subWidget) { + if (it != nullptr) { + vec2 tmpSize = it->getSize(); + vec2 tmpOrigin = it->getOrigin(); if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) { - ewol::object::Shared tmpWidget = m_subWidget[iii]->getWidgetAtPos(_pos); + ewol::object::Shared tmpWidget = it->getWidgetAtPos(_pos); if (nullptr != tmpWidget) { return tmpWidget; } diff --git a/sources/ewol/widget/ContainerN.h b/sources/ewol/widget/ContainerN.h index 6acfaf1f..255192d9 100644 --- a/sources/ewol/widget/ContainerN.h +++ b/sources/ewol/widget/ContainerN.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace ewol { namespace widget { @@ -21,7 +22,7 @@ namespace ewol { */ class ContainerN : public ewol::Widget { protected: - std::vector> m_subWidget; + std::list> m_subWidget; public: /** * @brief Constructor diff --git a/sources/ewol/widget/Layer.cpp b/sources/ewol/widget/Layer.cpp index 3e610a43..6dc12297 100644 --- a/sources/ewol/widget/Layer.cpp +++ b/sources/ewol/widget/Layer.cpp @@ -34,14 +34,14 @@ ewol::object::Shared ewol::widget::Layer::getWidgetAtPos(const vec return nullptr; } // for all element in the sizer ... - for (size_t iii=0; iiigetSize(); - vec2 tmpOrigin = m_subWidget[iii]->getOrigin(); + for (auto it : m_subWidget) { + if (it != nullptr) { + vec2 tmpSize = it->getSize(); + vec2 tmpOrigin = it->getOrigin(); if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x()) && (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) ) { - ewol::object::Shared tmpWidget = m_subWidget[iii]->getWidgetAtPos(_pos); + ewol::object::Shared tmpWidget = it->getWidgetAtPos(_pos); if (nullptr != tmpWidget) { return tmpWidget; } diff --git a/sources/ewol/widget/Sizer.cpp b/sources/ewol/widget/Sizer.cpp index 293936ed..417864a6 100644 --- a/sources/ewol/widget/Sizer.cpp +++ b/sources/ewol/widget/Sizer.cpp @@ -65,19 +65,19 @@ void ewol::widget::Sizer::calculateSize(const vec2& _availlable) { float unexpandableSize=0.0; int32_t nbWidgetFixedSize=0; int32_t nbWidgetNotFixedSize=0; - for (size_t iii=0; iiigetCalculateMinSize(); + for (auto it : m_subWidget) { + if (it != nullptr) { + vec2 tmpSize = it->getCalculateMinSize(); if (m_mode == ewol::widget::Sizer::modeVert) { unexpandableSize += tmpSize.y(); - if (false == m_subWidget[iii]->canExpand().y()) { + if (false == it->canExpand().y()) { nbWidgetFixedSize++; } else { nbWidgetNotFixedSize++; } } else { unexpandableSize += tmpSize.x(); - if (false == m_subWidget[iii]->canExpand().x()) { + if (false == it->canExpand().x()) { nbWidgetFixedSize++; } else { nbWidgetNotFixedSize++; @@ -99,27 +99,27 @@ void ewol::widget::Sizer::calculateSize(const vec2& _availlable) { } } vec2 tmpOrigin = m_origin + tmpBorderSize; - for (size_t iii=0; iiigetCalculateMinSize(); + for (auto it : m_subWidget) { + if (it != nullptr) { + vec2 tmpSize = it->getCalculateMinSize(); // set the origin : - EWOL_VERBOSE("[" << getId() << "] set iii=" << iii << " ORIGIN : " << tmpOrigin << " & offset=" << m_offset); - m_subWidget[iii]->setOrigin(vec2ClipInt32(tmpOrigin+m_offset)); + EWOL_VERBOSE("[" << getId() << "] set ORIGIN : " << tmpOrigin << " & offset=" << m_offset); + it->setOrigin(vec2ClipInt32(tmpOrigin+m_offset)); // Now update his size his size in X and the curent sizer size in Y: if (m_mode == ewol::widget::Sizer::modeVert) { - if (true == m_subWidget[iii]->canExpand().y()) { - m_subWidget[iii]->calculateSize(vec2ClipInt32(vec2(m_size.x(), tmpSize.y()+sizeToAddAtEveryOne))); + if (it->canExpand().y() == true) { + it->calculateSize(vec2ClipInt32(vec2(m_size.x(), tmpSize.y()+sizeToAddAtEveryOne))); tmpOrigin.setY(tmpOrigin.y() + tmpSize.y()+sizeToAddAtEveryOne); } else { - m_subWidget[iii]->calculateSize(vec2ClipInt32(vec2(m_size.x(), tmpSize.y()))); + it->calculateSize(vec2ClipInt32(vec2(m_size.x(), tmpSize.y()))); tmpOrigin.setY(tmpOrigin.y() + tmpSize.y()); } } else { - if (true == m_subWidget[iii]->canExpand().x()) { - m_subWidget[iii]->calculateSize(vec2ClipInt32(vec2(tmpSize.x()+sizeToAddAtEveryOne, m_size.y()))); + if (it->canExpand().x() == true) { + it->calculateSize(vec2ClipInt32(vec2(tmpSize.x()+sizeToAddAtEveryOne, m_size.y()))); tmpOrigin.setX(tmpOrigin.x() + tmpSize.x()+sizeToAddAtEveryOne); } else { - m_subWidget[iii]->calculateSize(vec2ClipInt32(vec2(tmpSize.x(), m_size.y()))); + it->calculateSize(vec2ClipInt32(vec2(tmpSize.x(), m_size.y()))); tmpOrigin.setX(tmpOrigin.x() + tmpSize.x()); } } @@ -136,18 +136,18 @@ void ewol::widget::Sizer::calculateMinMaxSize() { vec2 tmpBorderSize = m_borderSize.getPixel(); EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} set min size : " << m_minSize); m_minSize += tmpBorderSize*2; - for (int32_t iii=0; iiicalculateMinMaxSize(); - if (true == m_subWidget[iii]->canExpand().x()) { + for (auto it : m_subWidget) { + if (it != nullptr) { + it->calculateMinMaxSize(); + if (it->canExpand().x() == true) { m_subExpend.setX(true); } - if (true == m_subWidget[iii]->canExpand().y()) { + if (it->canExpand().y() == true) { m_subExpend.setY(true); } - vec2 tmpSize = m_subWidget[iii]->getCalculateMinSize(); + vec2 tmpSize = it->getCalculateMinSize(); EWOL_VERBOSE("[" << getId() << "] NewMinSize=" << tmpSize); - EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} Get minSize[" << iii << "] "<< tmpSize); + EWOL_VERBOSE("[" << getId() << "] {" << getObjectType() << "} Get minSize="<< tmpSize); if (m_mode == ewol::widget::Sizer::modeVert) { m_minSize.setY(m_minSize.y() + tmpSize.y()); if (tmpSize.x()>m_minSize.x()) { diff --git a/sources/ewol/widget/Widget.cpp b/sources/ewol/widget/Widget.cpp index c49f8bb4..17bf76d3 100644 --- a/sources/ewol/widget/Widget.cpp +++ b/sources/ewol/widget/Widget.cpp @@ -133,7 +133,7 @@ ewol::Widget::Widget() : m_annimationType[1] = nullptr; m_annimationTime[0] = 0.1f; // annimation will be 100ms at the first state m_annimationTime[1] = 0.1f; // annimation will be 100ms at the first state - addObjectType("ewol::object::Shared"); + addObjectType("ewol::Widget"); // set all the config in the list : registerConfig(ewol::Widget::configFill, "bvec2", nullptr, "Fill the widget available size"); registerConfig(ewol::Widget::configExpand, "bvec2", nullptr, "Request the widget Expand size wile space is available"); @@ -171,8 +171,9 @@ void ewol::Widget::setUpperWidget(ewol::object::Shared _upper) { m_up = _upper; } -void ewol::Widget::onObjectRemove(const ewol::object::Shared& _removeObject) { - if (_removeObject == m_up) { +void ewol::Widget::onObjectRemove(const ewol::object::Shared& _object) { + ewol::Object::onObjectRemove(_object); + if (_object == m_up) { EWOL_WARNING("[" << getId() << "] remove upper widget before removing this widget ..."); m_up = nullptr; } diff --git a/sources/ewol/widget/Windows.h b/sources/ewol/widget/Windows.h index ceb18cf4..c3565740 100644 --- a/sources/ewol/widget/Windows.h +++ b/sources/ewol/widget/Windows.h @@ -56,8 +56,8 @@ namespace ewol { m_hasDecoration = true; } private: - ewol::object::Shared m_subWidget; - std::vector> m_popUpWidgetList; + ewol::object::Owner m_subWidget; + std::vector> m_popUpWidgetList; public: void setSubWidget(ewol::object::Shared _widget); void popUpWidgetPush(ewol::object::Shared _widget); diff --git a/sources/lutin_ewol.py b/sources/lutin_ewol.py index fe3a9524..ba14e7b4 100755 --- a/sources/lutin_ewol.py +++ b/sources/lutin_ewol.py @@ -93,7 +93,8 @@ def create(target): 'ewol/object/Manager.cpp', 'ewol/object/Message.cpp', 'ewol/object/MultiCast.cpp', - 'ewol/object/Object.cpp' + 'ewol/object/Object.cpp', + 'ewol/object/RemoveEvent.cpp' ]) # OpenGL interface :