diff options
author | crupest <crupest@outlook.com> | 2022-03-29 12:24:06 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-29 12:24:06 +0800 |
commit | 7a564d98db0b7c7be5b3bfac955cb88998a472ac (patch) | |
tree | 891abaf06a4e011a798c8daf5f063230ec67f995 /include/cru | |
parent | 91695b78f565239223fc6f3a10b0219b8dc1b6f8 (diff) | |
download | cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.tar.gz cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.tar.bz2 cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.zip |
...
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/ui/DeleteLater.h | 5 | ||||
-rw-r--r-- | include/cru/ui/components/Component.h | 3 | ||||
-rw-r--r-- | include/cru/ui/controls/Control.h | 4 | ||||
-rw-r--r-- | include/cru/ui/controls/TextHostControlService.h | 3 | ||||
-rw-r--r-- | include/cru/ui/host/WindowHost.h | 10 |
5 files changed, 23 insertions, 2 deletions
diff --git a/include/cru/ui/DeleteLater.h b/include/cru/ui/DeleteLater.h index 84c0e1c2..34c48c14 100644 --- a/include/cru/ui/DeleteLater.h +++ b/include/cru/ui/DeleteLater.h @@ -8,6 +8,9 @@ class DeleteLaterImpl { public: virtual ~DeleteLaterImpl(); void DeleteLater(); + + protected: + virtual void OnPrepareDelete(); }; template <typename T> @@ -19,7 +22,7 @@ template <typename T> using DeleteLaterPtr = std::unique_ptr<T, DeleteLaterDeleter<T>>; template <typename T, typename... Args> -DeleteLaterPtr<T> CreateDeleteLaterPtr(Args&&... args) { +DeleteLaterPtr<T> MakeDeleteLaterPtr(Args&&... args) { return DeleteLaterPtr<T>(new T(std::forward<Args>(args)...)); } } // namespace cru::ui diff --git a/include/cru/ui/components/Component.h b/include/cru/ui/components/Component.h index 2625f445..a2f83149 100644 --- a/include/cru/ui/components/Component.h +++ b/include/cru/ui/components/Component.h @@ -30,6 +30,9 @@ class CRU_UI_API Component : public Object, if (delete_by_parent_) delete this; } + protected: + void OnPrepareDelete() override; + private: bool delete_by_parent_ = false; }; diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 8c9f11d3..38a9a86b 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -23,6 +23,8 @@ class CRU_UI_API Control : public Object, public DeleteLaterImpl { friend class RootControl; + CRU_DEFINE_CLASS_LOG_TAG(u"Control") + protected: Control(); @@ -174,6 +176,8 @@ class CRU_UI_API Control : public Object, protected: virtual void OnMouseHoverChange(bool newHover) { CRU_UNUSED(newHover) } + void OnPrepareDelete() override; + private: void OnParentChangedCore(Control* old_parent, Control* new_parent); void OnWindowHostChangedCore(host::WindowHost* old_host, diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index dec9b3e0..ae86e1e9 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -3,6 +3,7 @@ #include "cru/platform/gui/InputMethod.h" #include "cru/platform/gui/TimerHelper.h" #include "cru/platform/gui/UiApplication.h" +#include "cru/ui/DeleteLater.h" #include "cru/ui/controls/Control.h" #include "cru/ui/helper/ShortcutHub.h" @@ -217,6 +218,6 @@ class CRU_UI_API TextHostControlService : public Object { bool mouse_move_selecting_ = false; bool context_menu_dirty_ = true; - std::unique_ptr<components::PopupMenu> context_menu_; + DeleteLaterPtr<components::PopupMenu> context_menu_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h index d88482c4..0d2e0341 100644 --- a/include/cru/ui/host/WindowHost.h +++ b/include/cru/ui/host/WindowHost.h @@ -21,6 +21,14 @@ class CRU_UI_API WindowHost : public Object, public SelfResolvable<WindowHost> { friend controls::Control; CRU_DEFINE_CLASS_LOG_TAG(u"WindowHost") + private: + static int event_handling_depth_; + + public: + static bool IsInEventHandling() { return event_handling_depth_ > 0; } + static void EnterEventHandling(); + static void LeaveEventHandling(); + public: explicit WindowHost(controls::Control* root_control); @@ -139,6 +147,8 @@ class CRU_UI_API WindowHost : public Object, public SelfResolvable<WindowHost> { const Point& point, bool no_leave, bool no_enter); + void OnControlDetach(controls::Control* control); + private: controls::Control* root_control_ = nullptr; render::RenderObject* root_render_object_ = nullptr; |