# Definitions

A Definition is a user-defined widget hierarchy which has been declared as a reusable object. Definitions can be inserted into and used just like any other icon in the Palette.

A widget hierarchy must satisfy a number of constraints before it may be designated as a definition: the widget at the top of the hierarchy must be named; the top of the hierarchy must be designated a structure or C++ class; the widget must not already form part of or contain an existing definition; and the hierarchy must not contain any global or static widgets (and therefore fall outside the containing class). You can specify these class attributes using the Code Generation page of the Core Resources Panel.

To mark a hierarchy as a definition, select the top of the hierarchy you want to make a definition. Then set the Definition option from the Widget menu at the top of the WorkShop Visual Window. The widget and all descendent children are enclosed within a colored box to indicate that they constitute a definition.

If you want to add the definition to the Palette, you must save the design first. You can have many definitions within a single save file.

To add a definition, select the Edit Definitions option from the Palette menu to display the Edit Definitions dialog. A quick way to add a definition to the Palette is to use the 'Define' option from the Palette menu. The currently selected widget will form a definition, the design will be saved and the definition added to the Palette. No icon is used: a simple push button labeled with the widget name is inserted into the Palette.

A definition can be used in exactly the same manner as an ordinary widget on the Palette. An instance of the definition is added to the Design Area and new widgets can be added to the instantiated structure, as well as resources set for individual components of the instance.

C++ code generated from a definition has two parts: a declaration which takes the form of a public header file (which defines the class) and the code module, which provides the implementation of the class.

NOTES

A Definition hierarchy cannot normally be directly modified and the resource panels for components of a definition are read-only. If you want to change a definition, you must turn the definition toggle off, make the changes, then turn the definition toggle on again.

See also:

- Definitions base directory
- Definitions Editor
- Definitions file selector
- Core resources panel
- About WorkShop Visual