-- file: LaurelMenuDefs.mesa
-- Edited by Brotz, November 19, 1981 1:25 PM

DIRECTORY
inD: FROM "InteractorDefs" USING [CommandProcedure, HousePtr, leftMargin,
ScreenXCoord],
lsD: FROM "LaurelStateDefs" USING [StateSegment];

lmD: DEFINITIONS =

BEGIN
OPEN inD;


-- Types --

HouseNumber: TYPE = CARDINAL;

EditorMenuState: TYPE = {singleLine, getPut, run, find, substitute, copy};


-- Constants --

printerCommandNumber: HouseNumber = 0;
printerBracketsNumber: HouseNumber = 1;
overrideFormCommandNumber: HouseNumber = 2;
overrideFormBracketsNumber: HouseNumber = 3;
hardcopyConfirmCommandNumber: HouseNumber = 4;
copiesCommandNumber: HouseNumber = 5;
copiesBracketsNumber: HouseNumber = 6;
duplexCommandNumber: HouseNumber = 7;
duplexBracketsNumber: HouseNumber = 8;
passwordPrintingCommandNumber: HouseNumber = 9;
passwordPrintingBracketsNumber: HouseNumber = 10;
hardcopyCancelCommandNumber: HouseNumber = 11;

newFormCommandNumber: HouseNumber = 0;
answerCommandNumber: HouseNumber = 1;
forwardCommandNumber: HouseNumber = 2;
getCommandNumber: HouseNumber = 3;
putCommandNumber: HouseNumber = 4;
runCommandNumber: HouseNumber = 5;
deliverCommandNumber: HouseNumber = 6;

findCommandNumber: HouseNumber = 7;
findBracketsNumber: HouseNumber = 8;

substituteCommandNumber: HouseNumber = 7;
substituteNewBracketsNumber: HouseNumber = 8;
substituteForTextNumber: HouseNumber = 9;
substituteOldBracketsNumber: HouseNumber = 10;

copySourceTextNumber: HouseNumber = 7;
copySourceBracketsNumber: HouseNumber = 8;
copyTargetTextNumber: HouseNumber = 9;
copyTargetBracketsNumber: HouseNumber = 10;

filenameTextNumber: HouseNumber = 7;
getPutBracketsNumber: HouseNumber = 8;

programTextNumber: HouseNumber = 7;
runBracketsNumber: HouseNumber = 8;


-- Menu Segments are Laurel Segments that contain relocatable House data structures along
-- with their text strings. The Houses are laid out in the segment with the first House
-- occupying the first words of the segment, immediately followed by its text. This is
-- immediately followed by the next House and its text, etc. The nextHouse field of each
-- House other than the last House contains a 1. The nextHouse field of the last House
-- contains a 0.


-- Procedures --


SwapInMenu: PROCEDURE [menuSegment: lsD.StateSegment] RETURNS [hp: HousePtr];
-- Swaps in the menu contained in menuSegment and locks it in memory. Sets all nextHouse
-- pointers in the house list swapped in to be true pointers to the next House in the list.
-- Returns a pointer to the head of the list.


ReleaseMenu: PROCEDURE [menuSegment: lsD.StateSegment];
-- Resets all pointers in the menuSegment to their canonical swapped out form: all nextHouse
-- fields are set to 1 except for the last which is set to 0. Releases the menuSegment.


MapHouseNumberToHousePtr: PROCEDURE [knownHp: HousePtr, knownHpNumber,
number: HouseNumber] RETURNS [hp: HousePtr];
-- Returns a pointer to the number’th house (first cnp.houses is number 0) in the house list
-- pointed to by knownHp. KnownHp’s HouseNumber is knownHpNumber. This procedure
-- should be used to set HousePtr’s for houses that are relocated in segments.


MapHouseTextToHousePtr:
PROCEDURE [knownHp: HousePtr, s: STRING] RETURNS [hp: HousePtr];
-- Returns a pointer to the house in the house list started by knownHp whose text field
-- matches "s". To obtain the HousePtr for a brackets house, use
-- MapHouseTextToHousePtr[hp, textOfCommandHouse].nextHouse.


ChangeEditorMenu: PROCEDURE [newState: EditorMenuState];
-- Change the Editor menu to reflect the newState. Raises the resumable SIGNAL
-- MenuChange if the menu is actually changing.


MenuChange: SIGNAL;
-- Raised by ChangeCommandMenu to notify any HousePtr holders that they may be
-- invalid.

HouseDescriptor: TYPE = RECORD
[text: STRING,
type: HouseType ← command,
bracketsText: STRING ← NIL,
endOfLine: BOOLEAN ← FALSE,
rightFlush: BOOLEAN ← FALSE,
command: CommandProcedure ← NIL,
indicDone: BOOLEAN ← TRUE,
needsConfirmation: BOOLEAN ← TRUE];

HouseType: TYPE = {command, text, brackets};

CreateCommandHouses: PROCEDURE
[items: DESCRIPTOR FOR ARRAY OF HouseDescriptor,
allocateNode: PROCEDURE [CARDINAL] RETURNS [POINTER],
allocateString: PROCEDURE [CARDINAL] RETURNS [STRING],
firstLine: CARDINAL ← 0,
firstLeftX: ScreenXCoord ← leftMargin]
RETURNS [hp: HousePtr];


END. -- of LaurelMenuDefs --