Add cancelation support to CloseEvent

This commit is contained in:
Martín Capello 2021-09-06 12:18:01 -03:00
parent e6d0c1858a
commit 05dfd75743
3 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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();