diff --git a/src/ui/close_event.h b/src/ui/close_event.h index 521165172..20ac627e7 100644 --- a/src/ui/close_event.h +++ b/src/ui/close_event.h @@ -16,7 +16,12 @@ namespace ui { { public: CloseEvent(Component* source) - : Event(source) { } + : m_canceled(false), Event(source) { } + void cancel() { m_canceled = true; } + bool canceled() const { return m_canceled; } + + private: + bool m_canceled; }; } // namespace ui diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 8ef052b2d..3da3d7389 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -325,12 +325,16 @@ void Window::openWindowInForeground() void Window::closeWindow(Widget* closer) { + // Close event + CloseEvent ev(closer); + onBeforeClose(ev); + if (ev.canceled()) + return; + m_closer = closer; manager()->_closeWindow(this, true); - // Close event - CloseEvent ev(closer); onClose(ev); } diff --git a/src/ui/window.h b/src/ui/window.h index 069264b9c..2da44dc30 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -65,6 +65,7 @@ namespace ui { virtual void onSetText() override; // New events + virtual void onBeforeClose(CloseEvent& ev) {} virtual void onClose(CloseEvent& ev); virtual void onHitTest(HitTestEvent& ev); virtual void onWindowResize();