{ This program demonstrates how to open a simple window }
{ using Intuition.                                      }
{                                                       }
{ An EXECUTE file to build the executable progam is;    }
{                                                       }
{ STACK 8000                                            }
{ PASCAL EXAMPLES/WINDOW.PAS TO WINDOW.OBJ -X -C WS 200 }
{ ALINK P:PSTARTUP.OBJ,WINDOW.OBJ                       }
{       LIB P:PAS.LIB,PASCAL:LIB/AMIGA.LIB TO WINDOW    }

PROGRAM window( output );

INCLUDE 'intuition/intuition.h';

CONST
 INTUITION_REV = 33;
 GRAPHICS_REV  = 33;

VAR
 greeting,
 libname : STRING;
 nw      : NewWindowPtrType;
 window  : WindowPtrType;
 ns      : NewScreenPtrType;
 screen  : ScreenPtrType;
 myfont  : TextAttr;
 signal  : INTEGER;

INCLUDE 'exec/libraries';       { For OpenLibrary }
INCLUDE 'exec/signals';         { For Wait }
INCLUDE 'graphics/rastport';    { For Move }
INCLUDE 'graphics/text';        { For Text }
INCLUDE 'libraries/intuition';  { For Get/SetIntuitionBase }
INCLUDE 'libraries/gfx';        { For Get/SetGfxBase }
INCLUDE 'intuition/screens';    { For Open/CloseScreen }
INCLUDE 'intuition/windows';    { For Open/CloseWindow }

PROCEDURE UnableToOpen( name : STRING );
BEGIN
 WRITELN( 'Unable to open ', name );
 HALT( 10 )
END;

BEGIN
 { Open the Intuition library for the Intuition routines }

 libname := 'intuition.library';
 SetIntuitionBase( OpenLibrary( libname, INTUITION_REV ) );

 IF GetIntuitionBase = NIL
 THEN UnableToOpen( libname );

 { Open the Graphics library for the Graphics routines }

 libname := 'graphics.library';
 SetGfxBase( OpenLibrary( libname, GRAPHICS_REV ) );

 IF GetGfxBase = NIL
 THEN UnableToOpen( libname );

 WITH myfont DO
 BEGIN
  NEW( ta_Name ); ta_Name^ := 'topaz.font';
  ta_YSize := TOPAZ_SIXTY;
  ta_Style := FS_NORMAL;
  ta_Flags := FPF_ROMFONT
 END;

 { Create a new screen in which the window will reside }

 NEW( ns );
 WITH ns^ DO
 BEGIN
  LeftEdge := 0; TopEdge := 0;
  Width := 320; Height := 200;
  Depth := 2;
  DetailPen := 0; BlockPen := 1;
  ViewModes := 0;
  Type := CUSTOMSCREEN;
  NEW( Font ); Font^ := myfont;
  NEW( DefaultTitle ); DefaultTitle^ := 'My own screen';
  Gadgets := NIL; CustomBitMap := NIL
 END;

 screen := OpenScreen( ns );

 IF screen = NIL
 THEN UnableToOpen( 'screen' );

 { Create the simple window. Give it various system gadgets and set the }
 { IDCMP to only tell us if the window is closed.                       }

 NEW( nw );
 WITH nw^ DO
 BEGIN
  LeftEdge := 20; TopEdge := 20;
  Width := 300; Height := 100;
  DetailPen := 0; BlockPen := 1;
  NEW( Title ); Title^ := 'A simple window';
  Flags := WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
           WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH;
  IDCMPFlags := CLOSEWINDOW;
  Type := CUSTOMSCREEN;
  FirstGadget := NIL;
  CheckMark := NIL;
  Screen := screen;
  BitMap := NIL;
  MinWidth := 100; MinHeight := 25;
  MaxWidth := 640; MaxHeight := 200
 END;

 window := OpenWindow( nw );

 IF window = NIL
 THEN UnableToOpen( 'window' );

 { Write the greeting to the window }

 greeting := 'Hello Window';
 Move( window^.RPort, 20, 20 );
 Text( window^.RPort, greeting, LENGTH( greeting ) );

 { Wait until we receive a signal from the window. Assume }
 { its from the close gadget as thats the only one that   }
 { we've set then tidy up.                                }

 signal := Wait( 1 << window^.UserPort^.mp_SigBit );

 CloseWindow( window );
 CloseScreen( screen )
END.
