% (C) Copyright International Business Machines Corporation 23 January 
% 1990.  All Rights Reserved. 
%  
% See the file USERAGREEMENT distributed with this software for full 
% terms and conditions of use. 
\subsection{Windows}
If you are running Hermes on a SUN workstation with Sunview, you
may create Sunview {\em ttywindows} from your Hermes program.
You may then use the {\tt terminalio} operations
{\tt PutString}, {\tt PutLine}, {\tt GetString}, {\tt PutChar}, and {\tt GetChar} 
to read from and write to these windows.

The {\tt openwindow} server uses the {\tt CLoader} to build the
stub which connects Hermes to Sunview.  This service
is inherently dangerous, because it allows users to
load arbitrary C language programs into Hermes.
Since we want Hermes programs
to be able to open windows without giving them the capability to
the {\tt CLoader}, we provide a filter program called {\tt safewindow}.
You should instantiate {\tt safewindow} from a process having
the {\tt main} or {\tt rmain} interface.  You initialize {\tt safewindow}
by passing it the CLoader capability, and you receive
in return a capability to a safe {\tt openwindow} service:

\begin{prxmp}
safewindow <- create of process safewindow;
openwindow <- safewindow(CLoader);
\end{prxmp}

The initialization interface for {\tt safewindow} is defined in definition
{\tt safewindowinit.d}.

The {\tt openwindow} service is of type
{\tt safewindowFn}, defined in definition
{\tt safewindow.d}. This definition should be imported
by any application wishing to open windows.  It is copied below:

\begin{prxmp}    
safewindow: callmessage (
    label: charstring, -- stripe label\+\+
    options: charstring, -- other options
    terminal: terminalCM -- access to window,
  )\-
constant (label,options)\-
exit \{full\}
exception Failure \{init(label),init(options)\};
safewindowQ: inport of safewindow 
  \{init(label),init(options)\};\+
safewindowFn: outport of safewindowQ;\-
\medskip
terminalCM: callmessage (
    terminal: terminalFunctions\+\+
  )\-
constant (terminal) exit \{full\};\-
terminalQ: inport of terminalCM \{full\};
terminalFn: outport of terminalQ;
\end{prxmp}

To open a window, call {\tt openwindow} and pass two parameters:
{\tt label},  the character string which is to appear on the window's
banner, and {\tt options}, a character string defined in the
section ``Generic Tool Arguments'' in the {\em sunview(1)} man pages.
The return value from {\tt openwindow} is a callmessage with
a single parameter, {\tt terminal}, whose components are
the standard terminal functions defined in {\tt terminalio.d}.
\begin{prxmp}
w <- openwindow("command", "-Wh 5 -Ww 40");
call w.terminal.PutLine("Enter command:");
\end{prxmp}

You close the window by discarding the callmessage.  Typestate analysis
will insert {\tt discard} statements to close the window
upon process termination if you do not close it yourself.
