-- wwVTIPTest.mesa
-- Last Edited by Winiger, 23-Sep-81  7:44:39

DIRECTORY
  CedarLists USING [ListOfRefAny],
  CedarAtoms USING [GetPName],
  String USING [AppendDecimal, AppendLongDecimal],
  Rope USING [Ref],
  Real USING [FixI],
  TypeScript USING [Typescript, TSLineProc, CreateTypescript, ClientPutRope, ClientPutChar],
  wwTIPUser USING [CreateClient, InstantiateNewTIPTable, TIPButtonProc, TIPClient,
	TIPScreenCoords, TIPNotifyProc, TIPTable, PushTIPTable];

wwTIPTest: PROGRAM

IMPORTS CedarAtoms, Real, String, TypeScript, wwTIPUser =

BEGIN OPEN TypeScript;

typescript: Typescript;
client: wwTIPUser.TIPClient;
table: wwTIPUser.TIPTable ← wwTIPUser.InstantiateNewTIPTable["ww.tip"];


-- the input procedure to be called from the typescript:
TakeLine: PROC [ts: Typescript, line: Rope.Ref] = BEGIN
  ClientPutRope[typescript,"aha"];
  ClientPutChar[typescript,15C];
  END;


NotifyTestProc: wwTIPUser.TIPNotifyProc = BEGIN

	PutDecimal: PROCEDURE [n: INTEGER] =  BEGIN
		s: STRING ← [10];
		String.AppendDecimal[s,n];
		ClientPutRope[typescript,LOOPHOLE[LONG[s]]];
		END;

	PutLongDecimal: PROCEDURE [n: LONG INTEGER] =  BEGIN
		s: STRING ← [10];
		String.AppendLongDecimal[s,n];
		ClientPutRope[typescript,LOOPHOLE[LONG[s]]];
		END;
	
	WriteCoords: PROCEDURE [coords: wwTIPUser.TIPScreenCoords] = INLINE BEGIN
		ClientPutChar[typescript, '(]; 
		PutDecimal[ Real.FixI[coords.x]]; 
		ClientPutRope[typescript, ", "];
		PutDecimal[ Real.FixI[coords.y]]; 
		ClientPutChar[typescript, ')];
		END;

	params: CedarLists.ListOfRefAny;
	first: BOOLEAN ← TRUE;

	ClientPutRope[typescript, " ["];

	FOR params ← results, params.rest UNTIL params=NIL DO
		IF first THEN first ← FALSE ELSE ClientPutRope[typescript, "; "];
		WITH params.first SELECT FROM
        	x: ATOM			=> ClientPutRope[typescript, LOOPHOLE[CedarAtoms.GetPName[x]]];
		x: REF CHARACTER	=> ClientPutChar[typescript, x↑];
		x: REF LONG INTEGER	=> PutLongDecimal[x↑];
		x: REF TEXT		=> ClientPutRope[typescript,LOOPHOLE[x]];
		x: wwTIPUser.TIPScreenCoords => WriteCoords[x];
		ENDCASE			=> ClientPutRope[typescript,"(unknown parameter flavor)"];
		ENDLOOP;

	ClientPutRope[typescript, "]"];
	ClientPutChar[typescript,15C];

	END;

typescript ← CreateTypescript[line: TakeLine, name: "TIPTest", 
                              iconic: FALSE, fork: TRUE];
IF table = NIL THEN
  ClientPutRope[typescript,"you better check your tiptable"]
ELSE BEGIN
  client ← wwTIPUser.CreateClient[notify: NotifyTestProc];
  wwTIPUser.PushTIPTable[client, table, TRUE];
END;


END.