FLTK 1.4.0
|
These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks. More...
Functions | |
static void | Fl::clear_widget_pointer (Fl_Widget const *w) |
Clears a widget pointer in the watch list. More... | |
static void | Fl::delete_widget (Fl_Widget *w) |
Schedules a widget for deletion at the next call to the event loop. More... | |
static void | Fl::do_widget_deletion () |
Deletes widgets previously scheduled for deletion. More... | |
static void | Fl::release_widget_pointer (Fl_Widget *&w) |
Releases a widget pointer from the watch list. More... | |
static void | Fl::watch_widget_pointer (Fl_Widget *&w) |
Adds a widget pointer to the widget watch list. More... | |
These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks.
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:
|
static |
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.
This method searches the widget watch list for pointers to the widget and clears each pointer that points to it. Widget pointers can be added to the widget watch list by calling Fl::watch_widget_pointer() or by using the helper class Fl_Widget_Tracker (recommended).
|
static |
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.
|
static |
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().
|
static |
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.
|
static |
Adds a widget pointer to the widget watch list.
This can be used, if it is possible that a widget might be deleted during a callback or similar function. The widget pointer must be added to the watch list before calling the callback. After the callback the widget pointer can be queried, if it is NULL. If it is NULL, then the widget has been deleted during the callback and must not be accessed anymore. If the widget pointer is not NULL, then the widget has not been deleted and can be accessed safely.
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):
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.