FLTK 1.4.4: Fl_Widget_Tracker Class Reference

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Widget_Tracker Class Reference

This class should be used to control safe widget deletion. More...

`#include <Fl.H>`

## Public Member Functions
int | deleted ()
| Returns 1, if the watched widget has been deleted.
int | exists ()
| Returns 1, if the watched widget exists (has not been deleted).
| Fl_Widget_Tracker (Fl_Widget *wi)
| The constructor adds a widget to the watch list.
Fl_Widget * | widget ()
| Returns a pointer to the watched widget.
| ~Fl_Widget_Tracker ()
| The destructor removes a widget from the watch list.

## Detailed Description

This class should be used to control safe widget deletion.

You can use an Fl_Widget_Tracker object to watch another widget, if you need to know whether this widget has been deleted during a callback.

This simplifies the use of the "safe widget deletion" methods Fl::watch_widget_pointer() and Fl::release_widget_pointer() and makes their use more reliable, because the destructor automatically releases the widget pointer from the widget watch list.

Fl_Widget_Tracker is intended to be used as an automatic (local/stack) variable, such that its destructor is called when the object's scope is left. This ensures that no stale widget pointers are left in the widget watch list (see example below).

You can also create Fl_Widget_Tracker objects with `new`, but then it is your responsibility to delete the object (and thus remove the widget pointer from the watch list) when it is no longer needed.

Example:

int MyClass::handle (int event) {
if (...) {
Fl_Widget_Tracker wp(this); // watch myself
do_callback(); // call the callback
if (wp.deleted()) return 1; // exit, if deleted
// Now we are sure that the widget has not been deleted,
// and it is safe to access the widget:
box(FL_FLAT_BOX);
color(FL_WHITE);
redraw();
}
}
FL_FLAT_BOX
@ FL_FLAT_BOX
a flat box
Definition Enumerations.H:647
Fl_Widget_Tracker::Fl_Widget_Tracker
Fl_Widget_Tracker(Fl_Widget *wi)
The constructor adds a widget to the watch list.
Definition Fl.cxx:2158

## Member Function Documentation

## ◆ deleted()

int Fl_Widget_Tracker::deleted | ( |  | ) |
| inline

Returns 1, if the watched widget has been deleted.

This is a convenience method. You can also use something like

if (wp.widget() == 0) // ...

where `wp` is an Fl_Widget_Tracker object.

## ◆ exists()

int Fl_Widget_Tracker::exists | ( |  | ) |
| inline

Returns 1, if the watched widget exists (has not been deleted).

This is a convenience method. You can also use something like

if (wp.widget() != 0) // ...

where `wp` is an Fl_Widget_Tracker object.

## ◆ widget()

Fl_Widget * Fl_Widget_Tracker::widget | ( |  | ) |
| inline

Returns a pointer to the watched widget.

This pointer is `NULL`, if the widget has been deleted.

The documentation for this class was generated from the following files:

- Fl.H
- Fl.cxx