previous chapter contents page top page next chapter

ComputedChoiceBox

April 1, 1994
last modified February 14, 1995

Defined in Control.Def 
Inherits from ChoiceBox



Class Description

ClassComputedChoiceBox provides you with a framework for computing choice lists for choice boxes. Given a source list and a way to tranform that list, class ComputedChoiceBox creates a new choice list, then uses it the way ordinary choice boxes do.

Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.

Using a ComputedChoiceBox Object

Computed choice boxes allow you to create choice boxes with a "none of the above" entry. The none entry looks like this:

Programming Information

Instantiate: sometimes
Subclass: sometimes
Call its methods: rarely

You probably won't call any of the methods of class ComputedChoiceBox yourself. You'll use computed choice boxes in much the same way you would regular choice boxes: you'll put them into place in your object definition files, and edit their fields.

Class ComputedChoiceBox defines only one transformation: it adds a "none of the above" choice to the source choice list. If you require different transformations, you should create a subclass and override the ComputeChoices method.

Methods you might call

Class ComputedChoiceBox defines the following methods:

Method Description
AboutToShow Overridden to call computechoices to construct a new choice list
ComputeChoices Create a choice list, given a transformation type and a choice list to transform

Methods you might override

Whenever you create a subclass of class ComputedChoiceBox, you might want to override the following method:

Method When to override
ComputeChoices To add transformation types

Description of fields

Class ComputedChoiceBox defines the following fields:

border
Field Type Description
Inherited from SingleLinkable
next Object Next item in view list
Inherited from Linkable
previous Object Previous item in view list
superview Viewable Container for this object
subview Viewable Object contained by this object
relativeOrigin Dot Origin relative to superview
contentSize Dot Size of content rectangle
viewFlags Flags Property settings
labelStyle TextStyle Text style of object's label
color Unsigned Color of object's content
altColor Unsigned Alternative color for object
shadow Shadow Shadow drawn with object
sound Sound Sound associated with object
Inherited from HasBorder Border Frame drawn around control
Inherited from Control
image Image Image used to draw control
textStyle TextStyle Text style used for control's label
controlFlags Unsigned Various settings for control
level Fixed Current setting of control
min Fixed Minimum setting allowed for control
max Fixed Maximum setting allowed for control
target Object Object watched and controlled by control
targetAttribute Unsigned Selected attribute of watched object
Inherited from Meter
upDownImages Object The image used for changing the setting; a small right arrow by default
Inherited from ChoiceBox
choices Object The list of available choices
choiceFlags Flags Various settings for the choice box
Defined by ComputedChoiceBox
transformationType Unsigned How to transform the choice list
transformObject Object Used with tranformation type to create choice list

Method Descriptions

ComputeChoices

operation ComputeChoices(choices: Object)

Call: rarely
Override: sometimes

Call ComputeChoices to construct a complete choice list for your choice box by transforming it in the manner specified by the value in the transformationType field.

ComputeChoices computes a choice list by starting with the list passed to it in the choices parameter. It clears that list. Then it checks the transformation type. Class ComputedChoiceBox defines only one transformation type:

#define transformAddNoneToList1

If the transformation type isn't transformAddNoneToList, ComputeChoices returns without doing anything further.

The transformAddNoneToList transformation changes the empty choices list this way: It adds the list in the transformObject field to the end of the choices list. It then adds a "none of the above" choice (represented by a nilObject choice) at the end of the choice list. The new choice list is returned as a side effect in the choices parameter.

If you need other choice list transformations, you should subclass ComputedChoiceBox and override this method. Be sure to store your computed choices list in the choices parameter, because that's where AboutToShow expects to find it.

AboutToShow

overrides AboutToShow()

Call: rarely
Override: sometimes

Class ComputedChoiceBox overrides AboutToShow to call ComputeChoices and construct a complete choice list. You will probably never need to call or override this method yourself.

AboutToShow passes to ComputeChoices the object list from the computed choice box's choices field.If the choices list is nilObject, AboutToShow creates a new object list and passes that to ComputeChoices. ComputeChoices transforms the choice list in some way. AboutToShow then calls SetChoices with the transformed list.

AboutToShow then calls its inherited method.

Note that the inherited method will ignore the transientChoices flag, since if ChoiceBox_AboutToShow finds a valid (non-nil) ObjectList in its choices field, it will not touch it. However, if you've set the transientChoices flag, a computed choice box will, like other choices boxes, destroy its choices list when it's hidden. SoComputedChoiceBox_AboutToShow will reallocate a new ObjectList the next time the computed choice box is displayed.

If you need to use transient choices with a computed choice box, you will need to create a subclass of class ComputedChoiceBox. You should override ComputeChoices to define a "transformTransientChoices" transformation type.