diff options
Diffstat (limited to 'lib-apps-common/inc/Ui/Control.h')
-rw-r--r-- | lib-apps-common/inc/Ui/Control.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib-apps-common/inc/Ui/Control.h b/lib-apps-common/inc/Ui/Control.h index 24481a7..34d1616 100644 --- a/lib-apps-common/inc/Ui/Control.h +++ b/lib-apps-common/inc/Ui/Control.h @@ -18,6 +18,7 @@ #define UI_CONTROL_H #include <Elementary.h> +#include <memory> #include <tizen.h> #include <typeinfo> @@ -34,6 +35,9 @@ namespace Ui { + class Control; + typedef std::weak_ptr<Control> ControlPtr; + /** * @brief Evas_Object wrapper. * @details Ties the lifetime of this object to the underlying Evas_Object. @@ -72,6 +76,18 @@ namespace Ui */ Evas_Object *getEvasObject() const; + /** + * @return Weak pointer to control. + */ + ControlPtr getWeakPtr(); + + /** + * @brief Lock weak pointer and cast it to pointer to ControlType. + * @return Pointer to ControlType if success, otherwise nullptr. + */ + template <typename ControlType> + static ControlType *getPtr(ControlPtr weakPtr); + /**@{*/ /** * @brief Get Control object from Evas_Object by type. @@ -140,9 +156,16 @@ namespace Ui Evas_Object *m_Object; Ecore_Timer *m_CreateTimer; + std::shared_ptr<Control> m_SelfPtr; }; template <typename ControlType> + ControlType *Control::getPtr(ControlPtr weakPtr) + { + return static_cast<ControlType *>(weakPtr.lock().get()); + } + + template <typename ControlType> ControlType *Control::getControl(Evas_Object *object) { return static_cast<ControlType *>(getControl(object, typeid(ControlType))); |