(**************************************************************************

     $RCSfile: Workbench.mod $
  Description: Interface to workbench.library

   Created by: fjc (Frank Copeland)
    $Revision: 3.2 $
      $Author: fjc $
        $Date: 1994/08/08 01:11:46 $

  Includes Release 40.15

  (C) Copyright 1985-1993 Commodore-Amiga, Inc.
      All Rights Reserved

  Oberon-A interface Copyright © 1994, Frank Copeland.
  This file is part of the Oberon-A Interface.
  See Oberon-A.doc for conditions of use and distribution.

***************************************************************************)

MODULE Workbench;

(*
** $C- CaseChk       $I- IndexChk  $L+ LongAdr   $N- NilChk
** $P- PortableCode  $R- RangeChk  $S- StackChk  $T- TypeChk
** $V- OvflChk       $Z- ZeroVars
*)

IMPORT
  SYS := SYSTEM, E := Exec, U := Utility, D := Dos, I := Intuition;


(* Pointers are declared first for convenience *)

TYPE

  OldDrawerDataPtr * = CPOINTER TO OldDrawerData;
  DrawerDataPtr *    = CPOINTER TO DrawerData;
  DiskObjectPtr *    = CPOINTER TO DiskObject;
  FreeListPtr *      = CPOINTER TO FreeList;
  AppMessagePtr *    = CPOINTER TO AppMessage;
  WBStartupPtr *     = CPOINTER TO WBStartup;
  WBArgPtr *         = CPOINTER TO WBArg;
  AppWindowPtr *     = CPOINTER TO AppWindow;
  AppIconPtr *       = CPOINTER TO AppIcon;
  AppMenuItemPtr *   = CPOINTER TO AppMenuItem;


(*
**      $VER: startup.h 36.3 (11.7.90)
**
**      workbench startup definitions
*)


TYPE

  WBArg * = RECORD
    lock * : D.FileLockPtr;      (* a lock descriptor *)
    name * : E.STRPTR;           (* a string relative to that lock *)
  END; (* WBArg *)

  WBArguments * = ARRAY 32767 OF WBArg;
  WBArgumentsPtr * = CPOINTER TO WBArguments;

  WBStartup * = RECORD (E.Message) (* a standard message structure *)
    process *    : D.ProcessId;    (* the process descriptor for you *)
    segment *    : D.BPTR;         (* a descriptor for your code *)
    numArgs *    : LONGINT;        (* the number of elements in ArgList *)
    toolWindow * : E.STRPTR;       (* description of window *)
    argList *    : WBArgumentsPtr; (* the arguments themselves *)
  END; (* WBStartup *)


(*
**      $VER: workbench.h 40.1 (26.8.93)
**
**      workbench.library general definitions
*)

CONST

  disk *    = 1;
  drawer *  = 2;
  tool *    = 3;
  project * = 4;
  garbage * = 5;
  device *  = 6;
  kick *    = 7;
  appIcon * = 8;

TYPE

  OldDrawerData * = (* pre V36 definition *)
  RECORD (I.NewWindow)         (* args to open window *)
    currentX *  : LONGINT;     (* current x coordinate of origin *)
    currentY *  : LONGINT;     (* current y coordinate of origin *)
  END; (* OldDrawerData *)

CONST

(* the amount of DrawerData actually written to disk *)
  oldDrawerDataFileSize * = SIZE (OldDrawerData);

TYPE

  DrawerData * = RECORD (I.NewWindow) (* args to open window *)
    currentX *  : LONGINT;     (* current x coordinate of origin *)
    currentY *  : LONGINT;     (* current y coordinate of origin *)
    ddFlags *   : SET;         (* flags for drawer *)
    viewModes * : E.WSET;      (* view mode for drawer *)
  END; (* DrawerData *)

CONST

(* the amount of DrawerData actually written to disk *)
  drawerDataFileSize * = SIZE (DrawerData);

TYPE

  ToolTypePtr * = CPOINTER TO ARRAY 32767 OF E.STRPTR;

  DiskObject * = RECORD
    magic *       : E.UWORD;  (* a magic number at the start of the file *)
    version *     : E.UWORD;  (* a version number, so we can change it *)
    gadget *      : I.Gadget; (* a copy of in core gadget *)
    type *        : E.UBYTE;
    defaultTool * : E.STRPTR;
    toolTypes *   : ToolTypePtr;
    currentX *    : LONGINT;
    currentY *    : LONGINT;
    drawerData *  : DrawerDataPtr;
    toolWindow *  : E.STRPTR; (* only applies to tools *)
    stackSize *   : LONGINT;  (* only applies to tools *)
  END; (* DiskObject *)

CONST

  diskMagic *    = 0E310H;  (* a magic number, not easily impersonated *)
  diskVersion *  = 1;       (* our current version number *)
  diskRevision * = 1;       (* our current revision number *)
(* I only use the lower 8 bits of Gadget.UserData for the revision # *)
  diskRevisionMask * = 255;

TYPE

  FreeList * = RECORD
    numFree * : INTEGER;
    memList * : E.List;
  END; (* FreeList *)

CONST

(* workbench does different complement modes for its gadgets.
** It supports separate images, complement mode, and backfill mode.
** The first two are identical to intuitions GADGIMAGE and GADGHCOMP.
** backfill is similar to GADGHCOMP, but the region outside of the
** image (which normally would be color three when complemented)
** is flood-filled to color zero.
*)
  gflgGadgBackFill * = {0};
  gadgBackFill * = {0};

(* if an icon does not really live anywhere, set its current position
** to here
*)
  noIconPosition * = 80000000H;

(* workbench now is a library.  this is it's name *)
  name * = "workbench.library";

(* If you find amVersion >= amVERSION, you know this structure has
 * at least the fields defined in this version of the include file
 *)
  amVersion * = 1;

TYPE

  AppMessage * = RECORD (E.Message)  (* standard message structure *)
    amType *   : E.UWORD;            (* message type *)
    userData * : SYS.LONGWORD;       (* application specific *)
    id *       : E.ULONG;            (* application definable ID *)
    numArgs *  : LONGINT;            (* # of elements in arglist *)
    argList *  : WBArgumentsPtr;     (* the arguements themselves *)
    version *  : E.UWORD;            (* will be amVERSION *)
    class *    : E.WSET;             (* message class *)
    mouseX *   : INTEGER;            (* mouse x position of event *)
    mouseY *   : INTEGER;            (* mouse y position of event *)
    seconds *  : E.ULONG;            (* current system clock time *)
    micros *   : E.ULONG;            (* current system clock time *)
    reserved * : ARRAY 8 OF E.ULONG; (* avoid recompilation *)
  END; (* AppMessage *)

CONST

(* types of app messages *)
  amTypeAppWindow *   = 7;  (* app window message    *)
  amTypeAppIcon *     = 8;  (* app icon message      *)
  amTypeAppMenuItem * = 9;  (* app menu item message *)

TYPE

(*
 * The following structures are private.  These are just stub
 * structures for code compatibility...
 *)
  AppWindow *   = RECORD END;
  AppIcon *     = RECORD END;
  AppMenuItem * = RECORD END;

(*-- Library Base variable --------------------------------------------*)

TYPE

  WorkbenchBasePtr * = CPOINTER TO WorkbenchBase;
  WorkbenchBase = RECORD (E.Library) END;

VAR

  base *  : WorkbenchBasePtr;


(*-- Library Functions ------------------------------------------------*)

(*
**      $VER: wb_protos.h 38.4 (31.5.92)
*)

(* --- functions in V36 or higher (distributed as Release 2.0) ---*)

LIBCALL (base : WorkbenchBasePtr) AddAppWindowA*
  ( id       [0] : E.ULONG;
    userdata [1] : SYS.LONGWORD;
    window   [8] : I.WindowPtr;
    msgport  [9] : E.MsgPortPtr;
    taglist [10] : ARRAY OF U.TagItem )
  : AppWindowPtr;
  -48;
LIBCALL (base : WorkbenchBasePtr) AddAppWindow*
  ( id       [0]   : E.ULONG;
    userdata [1]   : SYS.LONGWORD;
    window   [8]   : I.WindowPtr;
    msgport  [9]   : E.MsgPortPtr;
    taglist [10].. : U.Tag )
  : AppWindowPtr;
  -48;
LIBCALL (base : WorkbenchBasePtr) RemoveAppWindow*
  ( appWindow [8] : AppWindowPtr )
  : BOOLEAN;
  -54;
(*
 * This function is not yet implemented.  It passes a parameter in A4,
 * which will require a change in the compiler.  Use the procedure
 * defined later in the module until this is fixed.
 *)
LIBCALL (base : WorkbenchBasePtr) AddAppIconA*
  ( id       [0] : E.ULONG;
    userdata [1] : SYS.LONGWORD;
    text     [8] : ARRAY OF CHAR;
    msgport  [9] : E.MsgPortPtr;
    lock    [10] : D.FileLockPtr;
    diskobj [11] : DiskObjectPtr;
    taglist [12] : ARRAY OF U.TagItem )
  : AppIconPtr;
  -60;
LIBCALL (base : WorkbenchBasePtr) AddAppIcon*
  ( id       [0]  : E.ULONG;
    userdata [1]  : SYS.LONGWORD;
    text     [8]  : ARRAY OF CHAR;
    msgport  [9]  : E.MsgPortPtr;
    lock    [10]  : D.FileLockPtr;
    diskobj [11]  : DiskObjectPtr;
    taglist [12]..: U.Tag )
  : AppIconPtr;
  -60;
(**)

LIBCALL (base : WorkbenchBasePtr) RemoveAppIcon*
  ( appIcon [8] : AppIconPtr )
  : BOOLEAN;
  -66;
LIBCALL (base : WorkbenchBasePtr) AddAppMenuItemA*
  ( id       [0] : E.ULONG;
    userdata [1] : SYS.LONGWORD;
    text     [8] : ARRAY OF CHAR;
    msgport  [9] : E.MsgPortPtr;
    taglist [10] : ARRAY OF U.TagItem )
  : AppMenuItemPtr;
  -72;
LIBCALL (base : WorkbenchBasePtr) AddAppMenuItem*
  ( id       [0]   : E.ULONG;
    userdata [1]   : SYS.LONGWORD;
    text     [8]   : ARRAY OF CHAR;
    msgport  [9]   : E.MsgPortPtr;
    taglist [10].. : U.Tag )
  : AppMenuItemPtr;
  -72;
LIBCALL (base : WorkbenchBasePtr) RemoveAppMenuItem*
  ( appMenuItem [8] : AppMenuItemPtr )
  : BOOLEAN;
  -78;

(*--- functions in V39 or higher (Release 3) ---*)

LIBCALL (base : WorkbenchBasePtr) WBInfo *
  ( lock    [8] : D.FileLockPtr;
    name    [9] : ARRAY OF CHAR;
    screen [10] : I.ScreenPtr );
  -90;


(*-- Library Base variable --------------------------------------------*)
(* $L- Address globals through A4 *)


(*-----------------------------------*)
PROCEDURE* CloseLib ();

BEGIN (* CloseLib *)
  IF base # NIL THEN E.base.CloseLibrary (base) END;
END CloseLib;

(*-----------------------------------*)
PROCEDURE OpenLib * (mustOpen : BOOLEAN);

BEGIN (* OpenLib *)
  IF base = NIL THEN
    base :=
      SYS.VAL
        ( WorkbenchBasePtr,
          E.base.OpenLibrary (name, E.libraryMinimum) );
    IF base # NIL THEN SYS.SETCLEANUP (CloseLib)
    ELSIF mustOpen THEN HALT (100)
    END;
  END;
END OpenLib;


BEGIN
  base := NIL
END Workbench.
