diff options
| author | Matthias Melcher <github@matthiasm.com> | 2024-07-21 13:19:00 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2024-07-26 18:00:25 +0200 |
| commit | 8cffbd694106a2371d297caa008f2290185fed2f (patch) | |
| tree | 52eaa856bc85c87a34ade06d36f3fd4f010169e3 /src/Fl_Group.cxx | |
| parent | b740c48ee8505f93662065384d84b449d5e33438 (diff) | |
Adds the FL_AUTO_DELETE_EVENT to suppress auto delete.
Language wrappers can have major issues with FLTK auto deleting
all children of a group if a group is deleted. This event gives individual
widget the opportunity to override auto delete.
Diffstat (limited to 'src/Fl_Group.cxx')
| -rw-r--r-- | src/Fl_Group.cxx | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 2576efea7..134b49998 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -375,6 +375,19 @@ Fl_Group::Fl_Group(int X,int Y,int W,int H,const char *l) \internal If the Fl_Group widget contains the Fl::focus() or the Fl::pushed() widget these are set to sensible values (other widgets or the Fl_Group widget itself). + + \note FLTK's auto-delete feature efficiently manages widget hierarchies in + C++ applications by automatically cleaning up. However, this feature can + cause issues when FLTK is used with reference-counting languages like Python, + where automatic deletion might interfere with reference counting. To address + this, auto-delete can be disabled for individual widgets. When + \ref Fl_Group::clear() is called, it sends an \ref FL_AUTO_DELETE event to + each widget. If a widget returns 1 in response to this event, it will not + be deleted. In a Python wrapper, this behavior would typically involve + decrementing the widget's reference count instead of deleting it. + + \see Fl_Group::remove(int), Fl_Group::delete_child(int), + Fl_Group::~Fl_Group() */ void Fl_Group::clear() { savedfocus_ = 0; @@ -417,7 +430,8 @@ void Fl_Group::clear() { } else { // slow removal remove(idx); } - delete w; // delete the child + if (w->handle(FL_AUTO_DELETE_EVENT)==0) + delete w; // delete the child } else { // should never happen remove(idx); // remove it anyway } |
