fltk::AssociationType Class Reference

Base class for the association type. More...

#include <WidgetAssociation.h>

Inherited by shortcutAssociationType.

List of all members.

Public Member Functions

virtual void destroy (void *data) const =0
 This function is called when associated data is freed This function must be proveded when creating a data specific subclass. The function must do whatever is necessary to free associated data. Most of the time it will be a cast to the right datatype and a delete.
void * foreach (const Widget *wg, AssociationFunctor &fkt)
 Finds all data of this association type for a widget This function just calls fltk::foreach(this, wg, fkt). If wg is NULL this function will find all data for any widget.

Related Functions

(Note that these are not member functions.)
void * foreach (const AssociationType *, const Widget *, AssociationFunctor &)

Detailed Description

Base class for the association type.

FLTK allows you to attach any kind of user data to a widget. This data is automatically freed when the widget to which it is attached is destroyed. Internally an association table is used to connect the widget pointer with the data pointer that is why all the functions concerned with this feature contain "association" in their name. The advantage of this is that no space is taken on widgets that do not contain the data (or that have the "default value"), and that the destructor code is not linked in if the association is not used.

To be able to associate data and to be able to have a customized way of freeing the data you need to derive from this class and then create an instance of that class. With the pointer to that instance the type of the data is identified.

possible uses:

  • assign key shortcuts to certain widgets
  • assign a tooltip to some widgets
  • assign a help-index to widgets
  • assign a unique identifier to widgets to remote controlling
  • assign additional layouting data for new container widgets
  • assign data needed by typesafe callback mechanisms
  • assign all kind of data not always required within a widget / each widget

Friends And Related Function Documentation

void * foreach ( const AssociationType ,
const Widget ,
AssociationFunctor  
) [related]

This function allows traversing all associations of a certain association type, a certain widget, both, or none of the constraints. For each found widget the handle function in the associaionFunctor class is called. If that function returns true the scan is aborted and the data for the current widget is returned A NULL pointer for the AssociationType or the Widget pointer means to call the functor for all AssociationTypes and/or all Widgets.

The function either returns the first associated data for which the functor returns true, or NULL. See also Widget::foreach() and AssociationType::foreach().


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