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 /src/ui/host | |
parent | 91695b78f565239223fc6f3a10b0219b8dc1b6f8 (diff) | |
download | cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.tar.gz cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.tar.bz2 cru-7a564d98db0b7c7be5b3bfac955cb88998a472ac.zip |
...
Diffstat (limited to 'src/ui/host')
-rw-r--r-- | src/ui/host/RoutedEventDispatch.h | 9 | ||||
-rw-r--r-- | src/ui/host/WindowHost.cpp | 22 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h index 2f437b31..5d1c8ce5 100644 --- a/src/ui/host/RoutedEventDispatch.h +++ b/src/ui/host/RoutedEventDispatch.h @@ -3,10 +3,11 @@ #include "cru/common/log/Logger.h" #include "cru/ui/DebugFlags.h" #include "cru/ui/controls/Control.h" +#include "cru/ui/host/WindowHost.h" #include <vector> -namespace cru::ui { +namespace cru::ui::host { // Dispatch the event. // // This will raise routed event of the control and its parent and parent's @@ -40,6 +41,8 @@ void DispatchEvent( return; } + WindowHost::EnterEventHandling(); + std::vector<ObjectResolver<controls::Control>> receive_list; auto parent = original_sender; @@ -119,5 +122,7 @@ void DispatchEvent( if constexpr (debug_flags::routed_event) CRU_LOG_DEBUG(u"Routed event dispatch finished."); + + WindowHost::LeaveEventHandling(); } -} // namespace cru::ui +} // namespace cru::ui::host diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index f4a9a928..737a7594 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -7,6 +7,7 @@ #include "cru/platform/gui/InputMethod.h" #include "cru/platform/gui/UiApplication.h" #include "cru/platform/gui/Window.h" +#include "cru/ui/Base.h" #include "cru/ui/DebugFlags.h" #include "cru/ui/host/LayoutPaintCycler.h" #include "cru/ui/render/MeasureRequirement.h" @@ -105,6 +106,15 @@ inline void BindNativeEvent( } } // namespace +int WindowHost::event_handling_depth_ = 0; + +void WindowHost::EnterEventHandling() { event_handling_depth_++; } + +void WindowHost::LeaveEventHandling() { + Expects(event_handling_depth_ > 0); + event_handling_depth_--; +} + WindowHost::WindowHost(controls::Control* root_control) : root_control_(root_control), focus_control_(root_control) { root_render_object_ = root_control->GetRenderObject(); @@ -438,4 +448,16 @@ void WindowHost::SetOverrideCursor( override_cursor_ = cursor; UpdateCursor(); } + +void WindowHost::OnControlDetach(controls::Control* control) { + if (GetFocusControl() == control) { + SetFocusControl(nullptr); + } + if (GetMouseCaptureControl() == control) { + CaptureMouseFor(nullptr); + } + if (GetMouseHoverControl() == control) { + mouse_hover_control_ = HitTest(GetNativeWindow()->GetMousePosition()); + } +} } // namespace cru::ui::host |