Adding Data to Controls

OBJECTS

  typedef void (*actionfn)(control c);
  typedef void (*intfn)(control c, int value);

FUNCTIONS

  void  setvalue(control c, int value);		/* set integer */
  int   getvalue(control c);			/* find it again */

  void  setdata(control c, void *data);		/* set pointer */
  void *getdata(control c);			/* find it again */

  void  setaction(control c, actionfn fn);	/* action call-back */
  void  sethit(control c, intfn fn);		/* hit call-back */

  void  activatecontrol(control c);		/* call action/hit */

  void  setdel(control c, actionfn fn);		/* on deletion... */

NOTES

Every control can have an integer value associated with it. Some controls, such as scrollbars and listboxes use this integer value to represent the current state of the control. This value is passed to the control's call-back function whenever it changes, to inform the application that something has happened.

For programmer-defined controls, the setvalue and getvalue functions exist to allow setting this value, or finding the value.

If a control's state is more complex than an integer, more data must be stored with a control. The setdata function can store a pointer with a control, which could point to a data structure in memory. To find the value of this data pointer, use getdata. Note that getdata returns the pointer as a void pointer so it is necessary to cast this to the appropriate pointer type before use.

A control can have two kinds of call-back functions associated with it for normal uses. These are known as the action call-back and the hit call-back. The action call-back is called by objects such as buttons whenver the user clicks on the control, whereas the hit call-back (which is passed an integer value) is called by objects such as scrollbars, which need to know an integer value to decide what to do.

The action call-back can be set using the setaction function. This can be used to set or change a button's response to events.

The hit call-back is set with the sethit function, which can be used to change a scrollbar's response to events. The integer value which is passed to a hit call-back is the same as that used by the setvalue and getvalue functions above.

The activatecontrol function will call a control's action call-back (if one exists) or else call the hit call-back if there is no action.

The setdel function sets the call-back to be called when a window or control is about to be deleted. This call-back could automatically destroy any data structures which had been previously associated with a control with setdata, for instance.