Controls

OBJECTS

  typedef drawing  control;

  typedef void (*actionfn)(control c);

FUNCTIONS

  control newcontrol(char *text, rect r);	/* create control */
  void    del(control c);			/* delete control */

  void    addto(window w);			/* use another window */
  window  parentwindow(control c);		/* where is it? */

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

NOTES

A control is a area on a window which responds to user's actions, such as mouse clicks and the keyboard, to perform some function. Functions which create controls take as an argument a rectangle, which specifies where on the current window the control should be placed. The rectangle is measured in pixels, relative to the top-left point of the window which is the point (0,0). Controls are usually placed on the last window that was created.

Buttons, checkboxes, text fields, etc are all kinds of controls, so many of the functions described in the following sections apply equally to those objects, as they do to controls of your own creation. Even windows can be manipulated using these functions.

The newcontrol function returns a generic control, which can have call-backs added to it using setredraw, setmousedown etc (see later sections), to allow the control to respond to events. The text parameter is optional, and can be set to NULL and determined by the application later if necessary.

The del function destroys a control and removes it from the window. Normally this function is not used, since destroying a window will destroy all of its child controls.

The addto function can be used to specify which window is to receive any newly created controls. Normally, controls are added to the most recently created window. The addto function provides a way of choosing a destination window instead.

The parentwindow function returns the window where the control resides. Every control has a parent window. The parent window of a window is itself.

The setdel function sets a call-back function to be called when a window or control is about to be deleted. It should de-allocate any extra allocated memory associated with the window or control. Termination of the program will release all memory used by the program normally.