-- Copyright (C) 1984  by Xerox Corporation. All rights reserved. 
-- PupGatewayWindow.mesa, HGM,  2-Sep-84  7:30:11

DIRECTORY
  Put USING [CR, Text],
  Process USING [SetPriority],
  Tool USING [Create, MakeSWsProc, MakeFileSW],
  ToolWindow USING [TransitionProcType],
  UserInput USING [
    CancelPeriodicNotify, CreateIndirectStringOut, CreatePeriodicNotify,
    DestroyIndirectStringOut, GetDefaultWindow, PeriodicNotifyHandle, PeriodicProcType],
  Window USING [Handle],

  GateDefs USING [GetVersionText],
  Stats USING [StatStart];

PupGatewayWindow: PROGRAM
  IMPORTS Put, Process, Tool, UserInput, GateDefs, Stats
  EXPORTS GateDefs =
  BEGIN OPEN GateDefs;

  typescript: PUBLIC Window.Handle ← NIL;

  MakeSWs: Tool.MakeSWsProc =
    BEGIN
    typescript ← Tool.MakeFileSW[window: window, name: "PupGateway.Typescript"L];
    END;

  ClientTransition: ToolWindow.TransitionProcType =
    BEGIN
    SELECT TRUE FROM
      old = inactive => NULL;
      new = inactive => typescript ← NIL;
      ENDCASE;
    END;

  SetupWindow: PUBLIC PROCEDURE =
    BEGIN
    Push: PROCEDURE [s: LONG STRING, clientData: LONG POINTER] =
      BEGIN Put.Text[NIL, s]; END;
    version: LONG STRING = GateDefs.GetVersionText[];
    defaultWindow: Window.Handle = UserInput.GetDefaultWindow[];
    Put.CR[NIL];
    Stats.StatStart[Push, version];
    [] ← Tool.Create[
      name: version, makeSWsProc: MakeSWs, clientTransition: ClientTransition,
      cmSection: "PupGateway"L, initialState: active];
    UserInput.DestroyIndirectStringOut[defaultWindow];
    UserInput.CreateIndirectStringOut[from: defaultWindow, to: typescript];
    FixNotifier[];
    END;

  
  trash: UserInput.PeriodicNotifyHandle;
  FixNotifier: PROCEDURE =
    BEGIN
    trash ← UserInput.CreatePeriodicNotify[SmashNotifiersPriority, typescript, 1];
    END;

  SmashNotifiersPriority: UserInput.PeriodicProcType =
    BEGIN
    Process.SetPriority[1];
    trash ← UserInput.CancelPeriodicNotify[trash];
    END;

  END.