ChoiceButtons.mesa; Written by Linda Gass on August 20, 1982 2:36 pm
Last Edit by Linda Gass September 24, 1982 2:26 pm
Last Edited by: Maxwell, December 17, 1982 10:08 am
Last Edited by: McGregor, July 21, 1983 10:59 am
DIRECTORY
Buttons USING [Button],
Rope USING [ROPE],
VFonts USING [defaultFont, Font],
ViewerClasses USING [Viewer];
ChoiceButtons: CEDAR DEFINITIONS IMPORTS Buttons, VFonts = BEGIN

********************* For diplaying Enumerated Types ******************************
EnumTypeRef: TYPE = REF EnumTypeRec;
EnumTypeRec: TYPE = RECORD [
 proc: SelectionNotifierProc ← NIL,  -- procedure called everytime a button's selected(optional)
 permission: EnumPermissionProc ← NIL, --(optional)permission proc called before doing anything
 namesOfButtons: ButtonList ← NIL, -- list of names of buttons in this Enumerated type
 nextx: CARDINAL,      -- next x position in container that client may begin
            -- displaying info so that it wont overwrite the buttons
 nexty: CARDINAL,      -- same as nextx
 type: DisplayStyle,
 buttonOn: Buttons.Button ← NIL,  -- The button currently on for a given enumerated type
 flipLabel: ViewerClasses.Viewer ← NIL, -- Points to the Viewer to re-label
 clientdata: REF ANYNIL    -- optional data provided by the client and used when the
            -- selection notifier procedure is called.
 ];
(NOTE: It would have seemed natural to make the above record a variant record but because
   of language constraints, it would have been more trouble than it was worth to
   implement it)
ButtonList: TYPE = LIST OF Rope.ROPE;
A ButtonList is a list of the names of the buttons to be displayed as Choices.
StyleChoice: TYPE = {menuSelection, flipThru};
DisplayStyle: TYPE = {menuStyle, flipThruWithTitle, flipThruNoTitle};
BuildEnumTypeSelection: PROC [viewer: ViewerClasses.Viewer, x, y: CARDINAL ← 0, title: Rope.ROPENIL, buttonNames: ButtonList, default: Rope.ROPENIL, borderOnButtons: BOOLTRUE, notifyClientProc: SelectionNotifierProc ← NIL, permit: EnumPermissionProc ← NIL, clientdata: REF ANYNIL, style: StyleChoice, allInOneRow: BOOLTRUE, maxWidth: INTEGERLAST[INTEGER]] RETURNS [EnumTypeRef];
SIGNALS DefaultDoesntExist
See documentation below
GetSelectedButton: PROC [handle: EnumTypeRef] RETURNS [Rope.ROPE];
Using the handle, it returns the currently selected button
UpdateChoiceButtons: PROC [viewer: ViewerClasses.Viewer, enumTypeInfo: EnumTypeRef, newName: Rope.ROPE];
SIGNALS ChoiceDoesntExist and ButtonsCannotBeUpdated
SelectionNotifierProc: TYPE = PROC [name: Rope.ROPE, clientdata: REF ANY];
EnumPermissionProc: TYPE = PROC [handle: EnumTypeRef] RETURNS [BOOL];
client returns true if "giving permission", false otherwise.


********************* For diplaying Three state buttons ******************************

ThreeStateRef: TYPE = REF ThreeState;
ThreeState: TYPE = RECORD [
 button: Buttons.Button ← NIL,
 state: StateType ← off
 ]; 
StateType: TYPE = {off, on, default};
BuildTriStateButton: PROC [viewer: ViewerClasses.Viewer, x,y: INTEGER ← 0, name: Rope.ROPE] RETURNS [stateInfo: ThreeStateRef, nextX: INTEGER];
SetButtonState: PROC [buttonSelected: Buttons.Button, state: StateType];


********************* For diplaying Text Prompts ******************************

PromptDataRef: TYPE = REF PromptDataRec;
PromptDataRec: TYPE = RECORD [
 promptButton: Buttons.Button,
 textViewer: ViewerClasses.Viewer,
 newy, newx: CARDINAL,
 clientdata: REF ANYNIL,
 permission: PromptPermissionProc,
 notify: SelectionNotifierProc
 ];
PromptPermissionProc: TYPE = PROC [handle: PromptDataRef] RETURNS [BOOL]; 
BuildTextPrompt: PROC [viewer: ViewerClasses.Viewer, x,y: CARDINAL ← 0, title: Rope.ROPE, default: Rope.ROPENIL, font: VFonts.Font ← VFonts.defaultFont, textViewerWidth: INTEGERLAST[INTEGER], clientdata: REF ANYNIL, notify: SelectionNotifierProc ← NIL, permit: PromptPermissionProc ← NIL] RETURNS [promptData: PromptDataRef];
See documentation below
DefaultDoesntExist: SIGNAL;
ChoiceDoesntExist: SIGNAL;
ButtonsCannotBeUpdated: SIGNAL; 
END.



         **** BuildEnumTypeSelection ****
Takes an enumerated type in the form of a list and displays it either as a menu selection of
buttons or a sequence of labels displayed when a button is selected.

"container" is the Container that this selection of buttons is to be displayed in
"x, y" are the x and y positions in the Container at which this menu is to be displayed
"title" is the name to be displayed before the selection. It can be left empty.
"buttonNames" is the list of names to appear in the buttons
"default" is the button which will originally be turned "on" when this menu is first
 displayed.
 NOTE: Signals "DefaultDoesntExist" if specified default wasn't found in button list
"borderOnButtons" indicates if a border should be placed around the buttons in the
 enumerated type selection. NOTE: the labels will never have a border.
"permit" is a procedure which is called when a button is selected. It is intended to be some sort
 of "permission" which enables the button switching procedure to continue with its task.
 There are times when the client may want to prevent anything from happening when a
 button is selected
"notifyClientProc" is a procedure which is called when a button is selected. It makes
 available to the client a rope containing the name associated with that button.
"clientdata" optional information for use by the client. Returned when the notifyClientProc is
 called.
"style" allows the user to choose different display styles for the EnumTypeSelection
 menuSelection - displays all the different button names but only one button can be
  "on" at a given point in time.
 flipThru - displays only one button name at a time, "flipping through" all the
  different possibilities. Optional title preceding it.
"allInOneRow - optional. When menu selection is used, tell whether all should be in one row.
"maxWidth - optional. When menu selection is used and allInOneRow is FALSE. Tells how
 wide to make each row of the menu.
Returns a SelectionRef which contains information about the button which is currently "on"
 This Ref may be used in conjunction with the "GetSelectedButton" procedure to find out
 which button is currently "on" rather than using the notifyClientProc everytime a new
 button is selected. (i.e. - the client actually has two options for using BuildEnumType-
 Selection: (1) The client can be notified everytime a new button is selected by providing
 a notifyClientProc or (2) The client can save the SelectionRef returned from BuildEnum-
 TypeSelection and use this Ref and GetSelectedButton to inquire which button is on at a
 given time. NOTE: the SelectionRef.buttonOn returned by BuildEnumTypeSelection
 initially is the default value provided, it does NOT necessarily contain the CURRENT
 button on.
         **** BuildTriStateButton ****
Builds a button which cycles through three states. The states are indicated by different color backgrounds. The state may be initialized by using the procedure "SetButtonState"

         **** BuildTextPrompt ****
Builds a "label" and a corresponding text viewer. The "label" is really a button such that when
the "label" is selected it forces the selection into the corresponding text field. If the "label" was selected with red mouse button then this causes the text viewer to become pending delete.
Otherwise displays the default if one was specified initially. If no default was specified initially then sets contents of text viewer to NIL.

"container" is the parent container that this text prompt will be displayed in
"x, y" are the x and y positions in the container at which this text prompt is to be displayed
"title" is the text displayed on the "label"
"default" (optional) text to be displayed initially and when text prompt is selected with yellow or
 blue mouse button
"font" is the font that the "label" will be displayed in
"textViewerWidth" is how wide to make the text viewer. If not specified then will make the text
 viewer as wide as the container.