FLTK 1.3.4
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. More...
 
int exists ()
 Returns 1, if the watched widget exists (has not been deleted). More...
 
 Fl_Widget_Tracker (Fl_Widget *wi)
 The constructor adds a widget to the watch list.
 
Fl_Widgetwidget ()
 Returns a pointer to the watched widget. More...
 
 ~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, if 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 autmatically releases the widget pointer from the widget watch list.

It is intended to be used as an automatic (local/stack) variable, such that the automatic 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 not needed any more.

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.
// It is safe to access the widget
clear_changed(); // access the widget
}
}

Member Function Documentation

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.

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.

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: