(* ------------------------------------------------------------------------
  :Program.       ReqTools
  :Contents.      Interface to Nico François' reqtools.library
  :Author.        Kai Bolay [kai] (C-Version by Nico François)
  :Address.       Hoffmannstraße 168
  :Address.       D-7250 Leonberg 1 (Germany)
  :Address.       UUCP: ...!cbmvax!cbmehq!cbmger!depot1!amokle!kai
  :Address.       FIDO: 2:247/706.3
  :History.       v1.0 [kai] 22-Nov-91 (translated from C)
  :History.       v1.1 [kai] 31-Jan-92 (fixed bug in ReqToolsBase)
  :History.       v1.1n [Nico] 7-Mar-92 (comment added about ta.name bug)
  :Copyright.     Freeware
  :Language.      Oberon
  :Translator.    AMIGA OBERON v2.25e, A+L AG
  :Remark.        Thanks to Nico for his great library
  :Remark.        Thanks to Christian Stiens for finding a bug
  :Bugs.          ReqTools/Arq should support each other
  :Bugs.          Font-Hook: ta.name can contain odd pointer :-(
                  <odd Pointer is fault of AvailFonts function> - Nico
------------------------------------------------------------------------ *)

(*
**  Filename: reqtools.mod
**  Release: 1.0
**  Revision: 37.3
**
**  Oberon interface.
**
**  (C) Copyright 1991 Nico François
**      All Rights Reserved
*)

MODULE ReqTools;

IMPORT
  e: Exec, d: Dos, I: Intuition, g: Graphics, u: Utility;

CONST
  ReqToolsName* = "reqtools.library";
  ReqToolsVersion* = 37;

TYPE
  ReqToolsBasePtr* = UNTRACED POINTER TO ReqToolsBase;
  ReqToolsBase* = STRUCT (libNode: e.Library)
    flags*: SHORTSET;
    pad0, pad1, pad2: SHORTINT;
    segList*: e.BPTR;
    (* The following library bases may be read and used by your program *)
    intuitionBase*: I.IntuitionBasePtr;
    gfxBase*: g.GfxBasePtr;
    dosBase*: d.DosLibraryPtr;
    (* Next two library bases are only (and always) valid on Kickstart 2.0!
       (1.3 version of reqtools also initializes these when run on 2.0) *)
    gadToolsBase*: e.LibraryPtr;
    utilityBase*: e.LibraryPtr;
  END;

CONST
  (* types of requesters, for AllocRequestA() *)
  TypeFileReq* = 0;
  TypeReqInfo* = 1;
  TypeFontReq* = 2;

TYPE
  ReqToolsReqPtr * = UNTRACED POINTER TO ReqToolsReq;
  ReqToolsReq * = STRUCT END; (* make them compatible.. *)


(***********************
*                      *
*    File requester    *
*                      *
***********************)

(* structure _MUST_ be allocated with AllocRequest() *)

TYPE
  FileRequesterPtr* = UNTRACED POINTER TO FileRequester;
  FileRequester* = STRUCT (dummy: ReqToolsReq)
    reqPos*: LONGINT;
    leftOffset*: INTEGER;
    topOffset*: INTEGER;
    flags*: LONGSET;
    hook*: u.HookPtr;
    dir*: e.STRPTR;                (* READ ONLY! Change with ChangeReqAttrA()! *)
    matchPat*: e.STRPTR;           (* READ ONLY! Change with ChangeReqAttrA()! *)
    defaultFont*: g.TextFontPtr;
    waitPointer*: e.ADDRESS;
    (* Lots of private data follows! HANDS OFF :-) *)
  END;

(* returned by FileRequestA() if multiselect is enabled,
   free list with FreeFileList() *)

  FileListPtr* = UNTRACED POINTER TO FileList;
  FileList* = STRUCT
    next*: FileListPtr;
    strLen*: LONGINT;  (* -1 for directories *)
    name*: e.STRPTR;
  END;

(***********************
*                      *
*    Font requester    *
*                      *
***********************)

(* structure _MUST_ be allocated with AllocRequest() *)

  FontRequesterPtr* = UNTRACED POINTER TO FontRequester;
  FontRequester* = STRUCT (dummy: ReqToolsReq)
    reqPos*: LONGINT;
    leftOffset*: INTEGER;
    topOffset*: INTEGER;
    flags*: LONGSET;
    hook*: u.HookPtr;
    attr*: g.TextAttr;  (* READ ONLY! *)
    defaultFont*: g.TextFontPtr;
    waitPointer*: e.ADDRESS;
    (* Lots of private data follows! HANDS OFF :-) *)
  END;

(***********************
*                      *
*    Requester Info    *
*                      *
***********************)

  (* for EZRequestA(), GetLongA(), GetStringA() and PaletteRequestA(),
   _MUST_ be allocated with AllocRequest() *)

  ReqInfoPtr* = UNTRACED POINTER TO ReqInfo;
  ReqInfo* = STRUCT (dummy: ReqToolsReq)
    reqPos*: LONGINT;
    leftOffset*: INTEGER;
    topOffset*: INTEGER;
    width*: LONGINT;              (* not for EZRequestA() *)
    reqTitle*: e.STRPTR;          (* currently only for EZRequestA() *)
    flags*: LONGSET;              (* only for EZRequestA() *)
    defaultFont*: g.TextFontPtr;  (* currently only for PaletteRequestA() *)
    waitPointer*: e.ADDRESS;
    (* structure may be extended in future *)
  END;

(***********************
*                      *
*     Handler Info     *
*                      *
***********************)

(* for ReqHandlerA(), will be allocated for you when you use
   the ReqHandler tag, never try to allocate this yourself! *)

  HandlerInfoPtr* = UNTRACED POINTER TO HandlerInfo;
  HandlerInfo* = STRUCT
    private1: LONGINT;
    waitMask*: LONGSET;
    doNotWait*: I.LONGBOOL; (* ? *)
    (* Private data follows, HANDS OFF :-) *)
  END;

(* possible return codes from ReqHandlerA() *)
CONST
  CallHandler* = 080000000H;


(*************************************
*                                    *
*                TAGS                *
*                                    *
*************************************)

  TagBase* = u.user;

  (*** tags understood by most requester functions ***)
  (* optional pointer to window *)
  Window* = TagBase+1;
  (* idcmp flags requester should abort on (useful for IDCMP_DISKINSERTED) *)
  IDCMPFlags* = TagBase+2;
  (* position of requester window (see below) - default REQPOS_POINTER *)
  ReqPos* = TagBase+3;
  (* signal mask to wait for abort signal *)
  LeftOffset* = TagBase+4;
  (* topedge offset of requester relative to position specified by ReqPos *)
  TopOffset* = TagBase+5;
  (* name of public screen to put requester on (Kickstart 2.0 only!) *)
  PubScrName* = TagBase+6;
  (* address of screen to put requester on *)
  Screen* = TagBase+7;
  (* tagdata must hold the address of (!) an APTR variable *)
  DoReqHandler* = TagBase+8;
  (* font to use when screen font is rejected, _MUST_ be fixed-width font!
   (struct TextFont *, not struct TextAttr *!)
   - default GfxBase->DefaultFont *)
  DefaultFont* = TagBase+9;
  (* boolean to set the standard wait pointer in window - default FALSE *)
  WaitPointer* = TagBase+10;

  (*** tags specific to EZRequestA ***
  *)
  (* title of requester window - default "Request" or "Information" *)
  ezReqTitle* = TagBase+20;
  (* TagBase+21 reserved *)
  (* various flags (see below) *)
  ezFlags* = TagBase+22;
  (* default response (activated by pressing RETURN) - default TRUE *)
  ezDefaultResponse* = TagBase+23;

(*** tags specific to GetLongA ***
*)
  (* minimum allowed value - default MININT *)
  glMin* = TagBase+30;
  (* maximum allowed value - default MAXINT *)
  glMax* = TagBase+31;
  (* suggested width of requester window (in pixels) *)
  glWidth* = TagBase+32;
  (* boolean to show the default value - default TRUE *)
  glShowDefault* = TagBase+33;

(*** tags specific to GetStringA ***
*)
  (* suggested width of requester window (in pixels) *)
  gsWidth* = glWidth;
  (* allow empty string to be accepted - default FALSE *)
  gsAllowEmpty* = TagBase+80;

(*** tags specific to FileRequestA ***
*)
  (* various flags (see below) *)
  fiFlags* = TagBase+40;
  (* suggested height of file requester *)
  fiHeight* = TagBase+41;
  (* replacement text for 'Ok' gadget (max 6 chars) *)
  fiOkText* = TagBase+42;

(*** tags specific to FontRequestA ***
*)
  (* various flags (see below) *)
  foflags* = fiFlags;
  (* suggested height of font requester *)
  foHeight* = fiHeight;
  (* replacement text for 'Ok' gadget (max 6 chars) *)
  foOkText* = fiOkText;
  (* suggested height of font sample display - default 24 *)
  foSampleHeight= TagBase+60;
  (* minimum height of font displayed *)
  foMinHeight* = TagBase+61;
  (* maximum height of font displayed *)
  foMaxHeight* = TagBase+62;
  (* [TagBase+63 to TagBase+66 used below] *)

(*** tags for ChangeReqAttrA ***
*)
  (* file requester - set directory *)
  fiDir* = TagBase+50;
  (* file requester - set wildcard pattern *)
  fiMatchPat* = TagBase+51;
  (* file requester - add a file or directory to the buffer *)
  fiAddEntry* = TagBase+52;
  (* file requester - remove a file or directory from the buffer *)
  fiRemoveEntry* = TagBase+53;
  (* font requester - set font name of selected font *)
  foFontName* = TagBase+63;
  (* font requester - set font size *)
  foFontHeight* = TagBase+64;
  (* font requester - set font style *)
  foFontStyle* = TagBase+65;
  (* font requester - set font flags *)
  foFontFlags* = TagBase+66;

(*** tags for PaletteRequestA ***
*)
  (* initially selected color - default 1 *)
  paColor* = TagBase+70;

(*** tags for ReqHandlerA ***
*)
  (* end requester by software control, set tagdata to REQ_CANCEL, REQ_OK or
   in case of EZRequest to the return value *)
  rhEndRequest* = TagBase+60;

(*** tags for AllocRequestA ***)
  (* no tags defined yet *)


(************
* ReqPos *
************)
  ReqPosPointer* = 0;
  ReqPosCenterWin* = 1;
  ReqPosCenterScr* = 2;
  ReqPosTopLeftWin* = 3;
  ReqPosTopLeftScr* = 4;

(******************
* RTRH_EndRequest *
******************)
  ReqCancel* = 0;
  ReqOK* = 1;

(***************************************
* flags for RTFI_Flags and RTFO_Flags  *
* or filereq->Flags and fontreq->Flags *
***************************************)
  fReqNoBuffer* = 2;
  fReqDoWildFunc* = 11;

(*****************************************
* flags for RTFI_Flags or filereq->Flags *
*****************************************)
  fReqMultiSelect* = 0;
  fReqSave* = 1;
  fReqNoFiles* = 3;
  fReqPatGad* = 4;
  fReqSelectDirs* = 12;

(*****************************************
* flags for RTFO_Flags or fontreq->Flags *
*****************************************)
  fReqFixedWidth* = 5;
  fReqColorFonts* = 6;
  fReqChangePalette* = 7;
  fReqLeavePalette* = 8;
  fReqScale* = 9;
  fReqStyle* = 10;

(*****************************************
* flags for RTEZ_Flags or reqinfo->Flags *
*****************************************)
  ezReqNoReturnKey* = 0;
  ezReqLamigaQual* = 1;
  ezReqCenterText* = 2;

(********
* hooks *
********)
  ReqHookWildFile* = 0;
  ReqHookWildFont* = 1;

VAR
  req*: ReqToolsBasePtr;

PROCEDURE AllocRequestA* {req, -30} (type{0}: LONGINT;
                                     tagList{8}: ARRAY OF u.TagItem): ReqToolsReqPtr;
PROCEDURE AllocRequest* {req, -30} (type{0}: LONGINT;
                                    tag1{8}..: u.Tag): ReqToolsReqPtr;
PROCEDURE FreeRequest* {req, -36} (req{9}: ReqToolsReqPtr);
PROCEDURE FreeReqBuffer* {req, -42} (req{9}: ReqToolsReqPtr);
PROCEDURE ChangeReqAttrA* {req, -48} (req{9}: ReqToolsReqPtr;
                                      tagList{8}: ARRAY OF u.TagItem);
PROCEDURE ChangeReqAttr* {req, -48} (req{9}: ReqToolsReqPtr;
                                     tag1{8}..: u.Tag);
PROCEDURE FileRequestA* {req, -54} (fileReq{9}: FileRequesterPtr;
                                    VAR fileName{10}: ARRAY OF CHAR;
                                    title{11}: ARRAY OF CHAR;
                                    tagList{8}: ARRAY OF u.TagItem): BOOLEAN;
PROCEDURE FileRequest* {req, -54} (fileReq{9}: FileRequesterPtr;
                                   VAR fileName{10}: ARRAY OF CHAR;
                                   title{11}: ARRAY OF CHAR;
                                   tag1{8}..: u.Tag): BOOLEAN;
PROCEDURE FreeFileList* {req, -60} (fileList{8}: FileListPtr);
PROCEDURE EZRequestA* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                  reqInfo{11}: ReqInfoPtr;
                                  argarray{12}: e.ADDRESS;
                                  tagList{8}: ARRAY OF u.TagItem): LONGINT;
PROCEDURE EZRequestTags* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                     reqInfo{11}: ReqInfoPtr;
                                     argarray{12}: e.ADDRESS;
                                     tag1{8}..: u.Tag):LONGINT;
PROCEDURE EZRequest* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                 reqInfo{11}: ReqInfoPtr;
                                 tagList{8}: ARRAY OF u.TagItem;
                                 argarray{12}..: LONGINT): LONGINT;
(* Without result.... *)
PROCEDURE vEZRequestA* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                   reqInfo{11}: ReqInfoPtr;
                                   argarray{12}: e.ADDRESS;
                                   tagList{8}: ARRAY OF u.TagItem);
PROCEDURE vEZRequestTags* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                      reqInfo{11}: ReqInfoPtr;
                                      argarray{12}: e.ADDRESS;
                                      tag1{8}..: u.Tag);
PROCEDURE vEZRequest* {req, -66} (bodyfmt{9}, gadfmt{10}: ARRAY OF CHAR;
                                  reqInfo{11}: ReqInfoPtr;
                                  tagList{8}: ARRAY OF u.TagItem;
                                  argarray{12}..: LONGINT);
PROCEDURE GetStringA* {req, -72} (VAR buffer{9}: ARRAY OF CHAR;
                                  maxchars{0}: LONGINT;
                                  title{10}: ARRAY OF CHAR;
                                  reqInfo{11}: ReqInfoPtr;
                                  tagList{8}: ARRAY OF u.TagItem): BOOLEAN;
PROCEDURE GetString* {req, -72} (VAR buffer{9}: ARRAY OF CHAR;
                                 maxchars{0}: LONGINT;
                                 title{10}: ARRAY OF CHAR;
                                 reqInfo{11}: ReqInfoPtr;
                                 tag1{8}..: u.Tag): BOOLEAN;
PROCEDURE GetLongA* {req, -78} (VAR long{9}: LONGINT; title{10}: ARRAY OF CHAR;
                                reqInfo{11}: ReqInfoPtr;
                                tagList{8}: ARRAY OF u.TagItem): BOOLEAN;
PROCEDURE GetLong* {req, -78} (VAR long{9}: LONGINT; title{10}: ARRAY OF CHAR;
                               reqInfo{11}: ReqInfoPtr;
                               tag1{8}..: u.Tag): BOOLEAN;
PROCEDURE FontRequestA* {req, -96} (fontReq{9}: FontRequesterPtr;
                                    title{11}: ARRAY OF CHAR;
                                    tagList{8}: ARRAY OF u.TagItem): BOOLEAN  ;
PROCEDURE FontRequest* {req, -96} (fontReq{9}: FontRequesterPtr;
                                   title{11}: ARRAY OF CHAR;
                                   tag1{8}..: u.Tag):BOOLEAN  ;
PROCEDURE PaletteRequestA* {req, -102} (title{10}: ARRAY OF CHAR;
                                        reqInfo{11}: ReqInfoPtr;
                                        tagList{8}: ARRAY OF u.TagItem): LONGINT;
PROCEDURE PaletteRequest* {req, -102} (title{10}: ARRAY OF CHAR;
                                       reqInfo{11}: ReqInfoPtr;
                                       tag1{8}..: u.Tag): LONGINT;
PROCEDURE ReqHandlerA* {req, -108} (hinfo{9}: HandlerInfoPtr;
                                    sigs{0}: LONGSET;
                                    tagList{8}: ARRAY OF u.TagItem): LONGINT;
PROCEDURE ReqHandler* {req, -108} (hinfo{9}: HandlerInfoPtr;
                                   sigs{0}: LONGSET;
                                   tag1{8}..: u.Tag): LONGINT;
PROCEDURE SetWaitPointer* {req, -114} (window{8}: I.WindowPtr);
PROCEDURE GetVScreenSize* {req, -120} (screen{8}: I.ScreenPtr;
                                       VAR width{9},height{10}: LONGINT);
PROCEDURE SetReqPosition* {req, -126} (reqpos{0}: LONGINT;
                                       VAR nw{8}: I.NewWindow;
                                       screen{9}: I.ScreenPtr;
                                       window{10}: I.WindowPtr);
PROCEDURE Spread* {req, -132} (VAR posarray{8}: ARRAY OF LONGINT;
                               sizearray{9}: ARRAY OF LONGINT;
                               totalsize{0}, min{1}, max{2}, num{3}: LONGINT);
PROCEDURE ScreenToFrontSafely* {req, -138} (screen{8}: I.ScreenPtr);


PROCEDURE Assert* (c: BOOLEAN; txt: ARRAY OF CHAR);
BEGIN
  IF NOT c THEN
    vEZRequest (txt, "Abort", NIL, NIL);
    HALT (20);
  END;
END Assert;

BEGIN
  req := e.OpenLibrary (ReqToolsName, ReqToolsVersion);
  IF req = NIL THEN
    IF I.DisplayAlert (I.recoveryAlert,
         "\x00\x64\x14missing reqtools.library V37\o\o", 50) THEN END;
    HALT (20)
  END; (* IF *)
CLOSE
  IF req # NIL THEN
    e.CloseLibrary (req);
    req := NIL;
  END; (* IF *)
END ReqTools.
