DEFINITION MODULE EditUtils;

FROM Polysys IMPORT Polygon;
FROM PolyFix IMPORT MaskList;
FROM KERN IMPORT CELL;

EXPORT QUALIFIED

   CacheActive,
   
   EDITPROC,
   NewCommandMenu,
   AddMenuCommand,
   SelectCommandMenu,
   CommandMenuHit,
   NewLayerMenu,
   AddMenuLayer,
   SelectLayerMenu,
   LayerMenuHit,
   NewContextMenu,
   AddMenuContext,
   ActivateContextMenu,
   ContextMenuHit,
   FindContext,
   NewContext,
   SaveContext,
   DrawContext,
   DrawMenu,
   edit,
   
   INTEGERptr,
   MENU, MenuItem,
   MASKptr,
   Context, ContextPTR;

TYPE
     INTEGERptr = POINTER TO INTEGER;
   
     EDITPROC =   PROCEDURE (INTEGER, INTEGER);

     MENU     =   RECORD
                     MenuHead       :POINTER TO MenuItem;
                     LastMenu       :INTEGER
                  END;
                  
     MenuItem =   RECORD
                     Next           :MENU;
                     Xl, Yb, Xr, Yt :INTEGER;
                     TextX, TextY   :INTEGER;
                     Text           :ARRAY [0..10] OF CHAR;
                     Action         :EDITPROC
                  END ;

     MASKptr = POINTER TO ARRAY [0..31] OF Polygon;

     Context = RECORD
                  Cell           :CELL;                (* NIL if masks only *)
                  Cached         :BOOLEAN;      (* TRUE if on local storage *)
                  Generated      :MaskList;     (* Layers generated *)
                  Masks          :MASKptr;          (* Array of 32 Polygons *)
                                   (* Would be much better as a linked list -
                                          could then cache generated layers *)
                  Xl, Yb, Xr, Yt :INTEGER;  (* bounding box of this context *)
                                   (* Note that a new context may be derived
                        from an old one merely by changing the bounding box *)
                  CacheName      :ARRAY [0..10] OF CHAR;
                              (* Name of cache on local storage (if needed) *)
                  ContextName    :ARRAY [0..255] OF CHAR;   (* Name of cell. *)
                  Sequence       :INTEGERptr;
                  Incarnation    :INTEGER
               END ;
     ContextPTR = POINTER TO Context;
(*------------------------------------------------------------------------*)

VAR
   CacheActive :BOOLEAN;
   
(*------------------------------------------------------------------------*)
   
PROCEDURE NewCommandMenu (MenuName :ARRAY OF CHAR);
PROCEDURE AddMenuCommand (MenuName, CommandName :ARRAY OF CHAR;
                          Action                :EDITPROC);
PROCEDURE SelectCommandMenu (MenuName :ARRAY OF CHAR);
PROCEDURE CommandMenuHit (X, Y :INTEGER) :BOOLEAN;
PROCEDURE NewLayerMenu (MenuName :ARRAY OF CHAR; Action :EDITPROC);
PROCEDURE AddMenuLayer (MenuName, LayerDesignation :ARRAY OF CHAR);
PROCEDURE SelectLayerMenu (MenuName :ARRAY OF CHAR);
PROCEDURE LayerMenuHit (X, Y :INTEGER) :BOOLEAN;
PROCEDURE NewContextMenu (MenuName :ARRAY OF CHAR);
PROCEDURE AddMenuContext (MenuName :ARRAY OF CHAR; Context :ContextPTR);
PROCEDURE ActivateContextMenu (MenuName :ARRAY OF CHAR);
PROCEDURE ContextMenuHit (X, Y :INTEGER; VAR Context :ContextPTR) :BOOLEAN;
PROCEDURE FindContext (Name :ARRAY OF CHAR) :ContextPTR;
PROCEDURE NewContext (Cell           :CELL;
                      Masks          :MASKptr;
                      Sequence       :INTEGERptr;
                      Xl, Yb, Xr, Yt :INTEGER;
                      WhatsOn        :MaskList;
                      Name           :ARRAY OF CHAR) :ContextPTR;
PROCEDURE SaveContext (VAR Context :ContextPTR);
PROCEDURE DrawContext (Context :ContextPTR; Xl, Yb, Xr, Yt :INTEGER);
PROCEDURE DrawMenu ();
PROCEDURE edit (Context :ContextPTR);
END EditUtils.
