-- SimpleTool.mesa;  Edited by McGregor on 15-Jan-82 14:51:08

DIRECTORY
  Buttons USING [Button, ButtonProc, Create],
  Convert USING [IntFromRope, ValueToRope],
  Labels USING [Create, Label, Set],
  Rope USING [Ref],
  ViewerClasses USING [Viewer],
  ViewerTools USING [GetContents, MakeNewContainer, MakeNewTextBox];

SimpleTool: PROGRAM

IMPORTS Buttons, Convert, Labels, ViewerTools =

BEGIN

-- simple tool that has an imput field (editable), an output field (not editable) and
-- a button.  When you click at the button, it takes the number in the input field,
-- adds one and stuffs it into the output field.

container: ViewerClasses.Viewer ← ViewerTools.MakeNewContainer["SimpleTool"];

button: Buttons.Button ← Buttons.Create[	-- the button that causes the conversion
	name: "Input Plus One",
	proc: InputPlusOne,
	x: 10, y: 10,
	parent: container
	];

input: ViewerClasses.Viewer ← ViewerTools.MakeNewTextBox[	-- editable input field
	parent: container,
	x: button.wx+button.ww+20, y: button.wy,
	w: 50, h: button.wh,
	scrollable: FALSE,
	contents: "0"
	];

output: Labels.Label ← Labels.Create[	-- non-editable output field
	parent: container,
	x: input.wx+input.ww+20, y: button.wy,
	w: 50, h: button.wh,
	name: "1"
	];

InputPlusOne: Buttons.ButtonProc = BEGIN	-- the proc that does the conversion
	argRope: Rope.Ref ← ViewerTools.GetContents[input];
	newInt: LONG INTEGER ← Convert.IntFromRope[argRope] + 1;
	Labels.Set[output, Convert.ValueToRope[[signed[newInt, 10]]]];
	END;

END.