summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-08-03 13:05:26 +0200
committerMatthias Melcher <github@matthiasm.com>2024-08-03 13:05:31 +0200
commit97b1df805e84797071a1b2544c68691327e6b506 (patch)
tree04cd76b35c577851038e046cee5e267b73732628 /src
parentabb2971654f62f7a9861a6aa5ef95a4916465183 (diff)
Better Fl_Tabs callback handling.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tabs.cxx31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx
index f47cbc240..5f60a1dde 100644
--- a/src/Fl_Tabs.cxx
+++ b/src/Fl_Tabs.cxx
@@ -388,19 +388,28 @@ void Fl_Tabs::take_focus(Fl_Widget *o) {
/**
Set tab o as selected an call callbacks if needed.
\param[in] o the newly selected tab
+ \return 0 if o is invalide or was deleted by the callback and must no longer be used
*/
-void Fl_Tabs::maybe_do_callback(Fl_Widget *o) {
- if (o && // Released on a tab and..
- (value(o) || // tab changed value or..
- (when()&(FL_WHEN_NOT_CHANGED)) // ..no change but WHEN_NOT_CHANGED set,
- ) // handles FL_WHEN_RELEASE_ALWAYS too.
- ) {
- Fl_Widget_Tracker wp(o);
+int Fl_Tabs::maybe_do_callback(Fl_Widget *o) {
+ // chaeck if o is valid
+ if ( o == NULL )
+ return 0;
+
+ // set the new tab value
+ int tab_changed = value(o);
+ if ( tab_changed )
set_changed();
- do_callback(FL_REASON_SELECTED);
- if (wp.deleted()) return;
+
+ // do we need to call the callback?
+ if ( tab_changed || ( when() & (FL_WHEN_NOT_CHANGED) ) ) {
+ Fl_Widget_Tracker wp(o); // we want to know if the widget lives on
+ do_callback(FL_REASON_SELECTED); // this may delete the tab
+ if (wp.deleted()) return 0; // if it did, return 0
}
- return;
+
+ // if o is still valid, do remaining tasks
+ Fl_Tooltip::current(o);
+ return 1;
}
/**
@@ -448,7 +457,6 @@ void Fl_Tabs::handle_overflow_menu() {
push(0);
take_focus(o);
maybe_do_callback(o);
- Fl_Tooltip::current(o);
}
// delete the menu until we need it next time
@@ -572,7 +580,6 @@ int Fl_Tabs::handle(int event) {
return 1; // o may be deleted at this point
}
maybe_do_callback(o);
- Fl_Tooltip::current(o);
} else {
push(o);
}