From: Mikko Rasa Date: Wed, 25 Sep 2019 18:44:04 +0000 (+0300) Subject: Improve Dialog staleness checks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bea19bdc0d51a2ebacb007b9503e851258fd148f;p=libs%2Fgltk.git 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. --- 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) { }