From bea19bdc0d51a2ebacb007b9503e851258fd148f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 25 Sep 2019 21:44:04 +0300 Subject: [PATCH] Improve Dialog staleness checks Buttons may be activated by a navigation event. There's now a protected function that derived classes can call if they implement custom mechanisms for producing a response. --- source/dialog.cpp | 19 +++++++++++++++---- source/dialog.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/dialog.cpp b/source/dialog.cpp index 0b22e98..a264fbe 100644 --- a/source/dialog.cpp +++ b/source/dialog.cpp @@ -31,15 +31,20 @@ void Dialog::set_modal(bool m) void Dialog::button_release(int x, int y, unsigned button) { Panel::button_release(x, y, button); - if(stale) - delete this; + check_stale(); } bool Dialog::key_release(unsigned key, unsigned mod) { bool result = Panel::key_release(key, mod); - if(stale) - delete this; + check_stale(); + return result; +} + +bool Dialog::navigate(Navigation nav) +{ + bool result = Panel::navigate(nav); + check_stale(); return result; } @@ -50,6 +55,12 @@ void Dialog::response(int code) stale = true; } +void Dialog::check_stale() +{ + if(stale) + delete this; +} + Dialog::Loader::Loader(Dialog &d, WidgetMap &wm): DerivedObjectLoader(d, wm) diff --git a/source/dialog.h b/source/dialog.h index 10519b1..e910085 100644 --- a/source/dialog.h +++ b/source/dialog.h @@ -43,8 +43,10 @@ public: virtual void button_release(int, int, unsigned); virtual bool key_release(unsigned, unsigned); + virtual bool navigate(Navigation); protected: void response(int); + void check_stale(); /** Called when an action button is pressed. */ virtual void on_response(int) { } -- 2.43.0