Functions | |
static void | Fl::clear_widget_pointer (Fl_Widget const *w) |
Clears a widget pointer in the watch list. | |
static void | Fl::delete_widget (Fl_Widget *w) |
Schedules a widget for deletion at the next call to the event loop. | |
static void | Fl::do_widget_deletion () |
Deletes widgets previously scheduled for deletion. | |
static void | Fl::release_widget_pointer (Fl_Widget *&w) |
Releases a widget pointer from the watch list. | |
static void | Fl::watch_widget_pointer (Fl_Widget *&w) |
Adds a widget pointer to the widget watch list. |
Fl::delete_widget() should be called when deleting widgets or complete widget trees (Fl_Group, Fl_Window, ...) inside callbacks.
The other functions are intended for internal use. The preferred way to use them is by using the helper class Fl_Widget_Tracker.
The following is to show how it works ...
There are three groups of related methods:
void Fl::clear_widget_pointer | ( | Fl_Widget const * | w | ) | [static, inherited] |
Clears a widget pointer in the watch list.
This is called when a widget is destroyed (by its destructor). You should never call this directly.
class Fl_Widget_Tracker
void Fl::delete_widget | ( | Fl_Widget * | wi | ) | [static, inherited] |
Schedules a widget for deletion at the next call to the event loop.
Use this method to delete a widget inside a callback function.
To avoid early deletion of widgets, this function should be called toward the end of a callback and only after any call to the event loop (Fl::wait(), Fl::flush(), Fl::check(), fl_ask(), etc.).
When deleting groups or windows, you must only delete the group or window widget and not the individual child widgets.
void Fl::do_widget_deletion | ( | ) | [static, inherited] |
Deletes widgets previously scheduled for deletion.
This is for internal use only. You should never call this directly.
Fl::do_widget_deletion() is called from the FLTK event loop or whenever you call Fl::wait(). The previously scheduled widgets are deleted in the same order they were scheduled by calling Fl::delete_widget().
void Fl::release_widget_pointer | ( | Fl_Widget *& | w | ) | [static, inherited] |
Releases a widget pointer from the watch list.
This is used to remove a widget pointer that has been added to the watch list with Fl::watch_widget_pointer(), when it is not needed anymore.
void Fl::watch_widget_pointer | ( | Fl_Widget *& | w | ) | [static, inherited] |
Adds a widget pointer to the widget watch list.
After accessing the widget, the widget pointer must be released from the watch list by calling Fl::release_widget_pointer().
Example for a button that is clicked (from its handle() method):
Fl_Widget *wp = this; // save 'this' in a pointer variable Fl::watch_widget_pointer(wp); // add the pointer to the watch list set_changed(); // set the changed flag do_callback(); // call the callback if (!wp) { // the widget has been deleted // DO NOT ACCESS THE DELETED WIDGET ! } else { // the widget still exists clear_changed(); // reset the changed flag } Fl::release_widget_pointer(wp); // remove the pointer from the watch list
This works, because all widgets call Fl::clear_widget_pointer() in their destructors.
An easier and more convenient method to control widget deletion during callbacks is to use the class Fl_Widget_Tracker with a local (automatic) variable.