diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-08-15 11:36:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-15 11:36:58 +0200 |
| commit | 10d9010ed9a7624bebebcb0f86fc86d362672027 (patch) | |
| tree | 4303c6f36947046d2baab01f02defd0d4bdb9ab2 /src | |
| parent | e6440ca0a89874e2593b2dc9cf5a3b0e87df94a2 (diff) | |
Improved, yet compatible, widget callback system using macros (#729)
* adds FL/fl_callback.macros.H
* adds FL_FUNCTION_CALLBACK_n(widget, function, [type, data])
* adds FL_METHOD_CALLBACK_n(widget, class, instance, method, [type, data])
* adds FL_INLINE_CALLBACK_n(widget, [type, name, data], callback_body)
* adds `examples/callback`
* full documentation
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Widget.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index 6518f002f..c5b59f5db 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -178,6 +178,8 @@ Fl_Widget::~Fl_Widget() { fl_throw_focus(this); // remove stale entries from default callback queue (Fl::readqueue()) if (callback_ == default_callback) cleanup_readqueue(this); + if ( (flags_ & AUTO_DELETE_USER_DATA) && user_data_) + delete (Fl_Callback_User_Data*)user_data_; } /** @@ -399,3 +401,28 @@ void Fl_Widget::do_callback(Fl_Widget *widget, void *arg, Fl_Callback_Reason rea if (callback_ != default_callback) clear_changed(); } + +/* + \brief Sets the user data for this widget. + Sets the new user data (void *) argument that is passed to the callback function. + \param[in] v new user data + */ +void Fl_Widget::user_data(void* v) { + if ((flags_ & AUTO_DELETE_USER_DATA) && user_data_) + delete (Fl_Callback_User_Data*)user_data_; + clear_flag(AUTO_DELETE_USER_DATA); + user_data_ = v; +} + +/* + \brief Sets the user data for this widget. + Sets the new user data (void *) argument that is passed to the callback function. + \param[in] v new user data + \param[in] auto_free if set, the widget will free user data when destroyed; defaults to false + */ +void Fl_Widget::user_data(Fl_Callback_User_Data* v, bool auto_free) { + user_data((void*)v); + if (auto_free) + set_flag(AUTO_DELETE_USER_DATA); +} + |
