home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
TOT11.ZIP
/
TOTDOC11.ZIP
/
CHAPT20.TXT
< prev
next >
Wrap
Text File
|
1991-02-11
|
35KB
|
799 lines
Extending
Input
Field
Types
"Stay humble. Always answer the phone - no matter who else is in the
car."
Jack Lemmon
One of the most used elements of the Toolkit is the full screen input
facility. If the Toolkit field types do not meet your exact needs, you
can create your own custom field types. This chapter explains how.
The Input Object Hierarchy
The objects FormOBJ and WinFormOBJ are used to manage and control full
screen input. You may recall that the method AddItem is used to add
individual input fields to the form. AddItem accepts any of the input
fields shown in the TOTIO Object Hierarchy on page 11.5. As the diagram
illustrates, all IO objects are descended from the root object Base-
IOOBJ. If you want to create new input field objects which can be
managed by the form objects, the new objects must be descended from
BaseIOOBJ, or any object descended from BaseIOOBJ.
The BaseIOOBJ object includes the following data and methods, which are
inherited by all descendant objects:
ItemIOOBJ = object
vBoundary: tCoords;
vHotKey: word;
vID: word;
vActive: boolean;
{methods ...}
constructor Init;
procedure SetActiveStatus(Selectable:boolean);
function Active:boolean;
function GetHotKey: word;
procedure SetHotkey(HK:word);
function GetID: word;
procedure SetID(ID:word);
function Visible: boolean; VIRTUAL;
procedure Display(Status:tStatus); VIRTUAL;
function Select(K:word; X,Y:byte):tAction; VIRTUAL;
function ProcessKey(InKey:word;X,Y:byte):tAction; VIRTUAL;
function Suspend:boolean; VIRTUAL;
destructor Done; VIRTUAL;
end; {ItemIOOBJ}
Note: the BaseIOOBJ also includes signal-related methods. These are
discussed in a later section.
20-2 Extending the Toolkit
--------------------------------------------------------------------------------
The vBoundary variable identifies the (X1,Y1) and (X2,Y2) coordinates
of the field. When the user clicks the left mouse button during full-
form input, the form object scans the list of active input objects and
moves the user to the input object with coordinates corresponding to
the mouse cursor position. Any descendant field should therefore update
the vBoundary variable to indicate the physical location of the field.
The other three BaseIOOBJ variables identify the field's hotkey, ID and
whether the field is active or selectable. These variables are managed
by the BaseIOOBJ methods SetActiveStatus, Active, GetHotkey, SetHotkey,
SetID and GetID. All these methods are suitable for any field type, and
should not need modification in descendant objects. Just inherit them
and use them!
The virtual methods, highlighted in bold, are specific to each descen-
dant object. As a minimum, any descendant objects should redefine these
bold methods -- they are the main methods called by the form object
during full-screen input.
Apart from special hotkeys and navigation control keys, all the user
input fields are visible. That is, the user can see them. As the TOTIO
Hierarchy Diagram illustrates, all visible fields are descended from
VisibleIOOBJ, which is, in turn, descended from BaseIOOBJ. In addition
to the BaseIOOBJ objects just discussed, the VisibleIOOBJ objects
inherit the following methods:
procedure SetLabel(Lbl:string);
procedure SetMessage(X,Y:byte; Msg:string);
procedure WriteMessage;
procedure WriteLabel(Status:tStatus); VIRTUAL;
As their names suggest, these methods are used to set and display
labels and messages. Labels are displayed to the immediate left of a
field and act as a field title. A message is the field's descriptive
text which is displayed when the user moves to the field. Under normal
circumstances you will not need to modify these methods. They are
appropriate to any field type.
Creating New Field Types
When you want to create a new field object, you must decide which
existing field object has the properties most closely resembling the
new field type you want to create. For example, if the field includes
data input, then you would probably create a descendant of CharIOOBJ.
However, if the field has multiple lines (like a radio button or list),
then the new object would best be a descendant of MultiLineIOOBJ. If
none of the existing fields come anywhere close, create a descendant
from VisibleIOOBJ.
Extending Input Field Types 20-3
--------------------------------------------------------------------------------
To illustrate the principles, a new boolean object will be created.
This object will display two different options, e.g. Yes or No, True or
False, Live or Die, etc. The field will display one of the options, and
when the user presses the space bar or clicks the mouse, the field will
flip to the other option.
Since the boolean object does not process individual character input,
and does not occupy multiple lines, the best object to descend from is
VisibleIOOBJ. The following methods are inherited from VisibleIOOBJ and
do not need to be modified:
procedure SetActiveStatus(Selectable:boolean);
function Active:boolean;
function GetHotKey: word;
procedure SetHotkey(HK:word);
function GetID: word;
procedure SetID(ID:word);
procedure SetLabel(Lbl:string);
procedure SetMessage(X,Y:byte; Msg:string);
procedure WriteMessage;
procedure WriteLabel(Status:tStatus); VIRTUAL;
function Visible: boolean; VIRTUAL;
As well as replacing Init and Done, the primary inherited methods which
need to be over-written are Display, Select, Processkey and Suspend.
These four methods are called by the form object during full screen
input. Additionally, if you want the new boolean object to function
stand-alone, i.e. without being part of a form, an Activate method
should be added. Activate will display the field and process user input
until [KEYCAP] or [KEYCAP] is pressed.
In keeping with the Toolkit style, SetValue and GetValue methods should
also be added. These methods are used to set the object's default
value, i.e. which option to display when the field is activated, and to
get the user-selected value after input is complete.
The new boolean object will need to include three data variables: the
two strings that represent the true and false settings, and a boolean
to record the object's actual value.
After all the methods and data have been included, the definition of
the