DEFINITION MODULE ReqTools;

(*
**	$Filename: libraries/reqtools.h $
**	$Release: 1.0 $
**
**	(C) Copyright 1991 Nico François
**	    All Rights Reserved
*)

FROM SYSTEM        IMPORT ADDRESS, BYTE, STRPTR;
FROM DOS           IMPORT BPTR;
FROM DOSExtensions IMPORT DOSBaseRecPtr;
FROM GfxBase       IMPORT GfxBaseRecPtr;
FROM Hooks         IMPORT HookPtr;
FROM Intuition     IMPORT ScreenPtr, NewWindowPtr, WindowPtr;
FROM IntuitionBase IMPORT IntuitionBaseRecPtr;
FROM Libraries     IMPORT Library, LibraryPtr;
FROM Tasks         IMPORT SignalSet;
FROM Text          IMPORT TextAttr, TextFontPtr;
FROM TagItem       IMPORT TagItemPtr, TAGUSER;


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

TYPE
  ReqToolsBaseRecPtr = POINTER TO ReqToolsBaseRec;
  ReqToolsBaseRec =
   RECORD
     LibNode       : Library;
     Flags         : BYTE;
     pad           : ARRAY [0..3] OF BYTE;
     SegList       : BPTR;

     (* The following library bases may be read and used by your program *)
     IntuitionBase : IntuitionBaseRecPtr;
     GfxBase       : GfxBaseRecPtr;
     DOSBase       : DOSBaseRecPtr;

     (* 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  : LibraryPtr;
     UtilityBase   : LibraryPtr;
   END;

VAR
  ReqToolsBase : ReqToolsBaseRecPtr;  (* initialized by OpenReqToolsLib *)


(* types of requesters, for rtAllocRequestA() *)
CONST
  RTFILEREQ	= 0;
  RTREQINFO	= 1;
  RTFONTREQ	= 2;

(***************************************
* flags for RTFI_Flags and RTFO_Flags  *
* or filereq->Flags and fontreq->Flags *
***************************************)
TYPE
  FReqFlags = (MultiSelect, Save, NoBuffer, NoFiles, PadGad, FixedWidth,
               ColorFonts, ChangePalette, LeavePalette, Scale, Style,
               DoWildFunc, SelectDirs, FRTBD13, FRTBD14, FRTBD15, FRTBD16,
               FRTBD17, FRTBD18, FRTBD19, FRTBD20, FRTBD21, FRTBD22, FRTBD23,
               FRTBD24, FRTBD25, FRTBD26, FRTBD27, FRTBD28, FRTBD29, FRTBD30,
               FRTBD31);
  FReqFlagSet = SET OF FReqFlags;

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

(* structure _MUST_ be allocated with rtAllocRequest() *)
TYPE
  rtFileRequesterPtr = POINTER TO rtFileRequester;
  rtFileRequester =
    RECORD
      ReqPos      : LONGINT;
      LeftOffset  : INTEGER;
      TopOffset   : INTEGER;
      Flags       : FReqFlagSet;
      Hook        : HookPtr;
      Dir         : STRPTR;   (* READ ONLY! Change with rtChangeReqAttrA()! *)
      MatchPat    : STRPTR;   (* READ ONLY! Change with rtChangeReqAttrA()! *)
      DefaultFont : TextFontPtr;
      WaitPointer : LONGINT
      (* Lots of private data follows! HANDS OFF :-) *)
    END;

(* returned by rtFileRequestA() if multiselect is enabled,
   free list with rtFreeFileList() *)
  rtFileListPtr = POINTER TO rtFileList;
  rtFileList =
    RECORD
      Next   : rtFileListPtr;
      StrLen : LONGINT;             (* -1 for directories *)
      Name   : STRPTR;
    END;

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

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

  rtFontRequesterPtr = POINTER TO rtFontRequester;
  rtFontRequester =
    RECORD
      ReqPos      : LONGINT;
      LeftOffset  : INTEGER;
      TopOffset   : INTEGER;
      Flags       : FReqFlagSet;
      Hook        : HookPtr;
      Attr        : TextAttr;		(* READ ONLY! *)
      DefaultFont : TextFontPtr;
      WaitPointer : LONGINT
      (* Lots of private data follows! HANDS OFF :-) *)
    END;

(*****************************************
* flags for RTEZ_Flags or reqinfo->Flags *
*****************************************)
TYPE
  EZReqFlags = (NoReturnKey, LAmigaQual, CenterText,
                EZTBD3, EZTBD4, EZTBD5, EZTBD6, EZTBD7, EZTBD8, EZTBD9,
                EZTBD10, EZTBD11, EZTBD12, EZTBD13, EZTBD14, EZTBD15, EZTBD16,
                EZTBD17, EZTBD18, EZTBD19, EZTBD20, EZTBD21, EZTBD22, EZTBD23,
                EZTBD24, EZTBD25, EZTBD26, EZTBD27, EZTBD28, EZTBD29, EZTBD30,
                EZTBD31);
  EZReqFlagSet = SET OF EZReqFlags;

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

(* for rtEZRequest(), rtGetLong(), rtGetString() and rtPaletteRequest(),
   _MUST_ be allocated with rtAllocRequest() *)

  rtReqInfoPtr = POINTER TO rtReqInfo;
  rtReqInfo =
    RECORD
      ReqPos      : LONGINT;
      LeftOffset  : INTEGER;
      TopOffset   : INTEGER;
      Width       : LONGINT;       (* not for rtEZRequest() *)
      ReqTitle    : STRPTR;        (* currently only for rtEZRequest() *)
      Flags       : EZReqFlagSet;  (* only for rtEZRequest() *)
      DefaultFont : TextFontPtr;   (* currently only for rtPaletteRequest() *)
      WaitPointer : LONGINT
      (* structure may be extended in future *)
    END;

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

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

  rtHandlerInfoPtr = POINTER TO rtHandlerInfo;
  rtHandlerInfo =
    RECORD
      private1  : LONGINT;
      WaitMask  : LONGINT;
      DoNotWait : LONGINT
      (* Private data follows, HANDS OFF :-) *)
    END;

(* possible return codes from rtReqHandlerA() *)
CONST
  CallHandler = 80000000H;


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

  RTTagBase   = TAGUSER;

  (*** tags understood by most requester functions ***)
  (* optional pointer to window *)
  RTWindow		 = RTTagBase+1;

  (* idcmp flags requester should abort on (useful for IDCMP_DISKINSERTED) *)
  RTIDCMPFlags		 = RTTagBase+2;

  (* position of requester window (see below) - default REQPOS_POINTER *)
  RTReqPos		 = RTTagBase+3;

  (* signal mask to wait for abort signal *)
  RTLeftOffset		 = RTTagBase+4;

  (* topedge offset of requester relative to position specified by RTReqPos *)
  RTTopOffset		 = RTTagBase+5;

  (* name of public screen to put requester on (Kickstart 2.0 only!) *)
  RTPubScrName		 = RTTagBase+6;

  (* address of screen to put requester on *)
  RTScreen		 = RTTagBase+7;

  (* tagdata must hold the address of (!) an APTR variable *)
  RTReqHandler		 = RTTagBase+8;

  (* font to use when screen font is rejected, _MUST_ be fixed-width font!
   (struct TextFont *, not struct TextAttr - default GfxBase->DefaultFont *)
  RTDefaultFont		 = RTTagBase+9;

  (* boolean to set the standard wait pointer in window - default FALSE *)
  RTWaitPointer		 = RTTagBase+10;

  (*** tags specific to rtEZRequest ***)
  (* title of requester window - default "Request" or "Information" *)
  RTEZReqTitle		 = RTTagBase+20;

  (* (RTTagBase+21) reserved   *)
  (* various flags (see below) *)
  RTEZFlags		 = RTTagBase+22;

  (* default response (activated by pressing RETURN) - default TRUE *)
  RTEZDefaultResponse	 = RTTagBase+23;

  (*** tags specific to rtGetLongA ***)
  (* minimum allowed value - default MININT *)
  RTGLMin		 = RTTagBase+30;

  (* maximum allowed value - default MAXINT *)
  RTGLMax		 = RTTagBase+31;

  (* suggested width of requester window (in pixels) *)
  RTGLWidth		 = RTTagBase+32;

  (* boolean to show the default value - default TRUE *)
  RTGLShowDefault	 = RTTagBase+33;

  (*** tags specific to rtGetStringA ***)
  (* suggested width of requester window (in pixels) *)
  RTGSWidth		 = RTGLWidth;

  (* allow empty string to be accepted - default FALSE *)
  RTGSAllowEmpty	 = RTTagBase+80;

  (*** tags specific to rtFileRequestA ***)
  (* various flags (see below) *)
  RTFIFlags		 = RTTagBase+40;

  (* suggested height of file requester *)
  RTFIHeight		 = RTTagBase+41;

  (* replacement text for 'Ok' gadget (max 6 chars) *)
  RTFIOkText		 = RTTagBase+42;

  (*** tags specific to rtFontRequestA ***)
  (* various flags (see below) *)
  RTFOFlags		 = RTFIFlags;

  (* suggested height of font requester *)
  RTFOHeight		 = RTFIHeight;

  (* replacement text for 'Ok' gadget (max 6 chars) *)
  RTFOOkText		 = RTFIOkText;

  (* suggested height of font sample display - default 24 *)
  RTFOSampleHeight	 = RTTagBase+60;

  (* minimum height of font displayed *)
  RTFOMinHeight		 = RTTagBase+61;

  (* maximum height of font displayed *)
  RTFOMaxHeight		 = RTTagBase+62;

  (* [(RTTagBase+63) to (RTTagBase+66) used below] *)
  (*** tags for rtChangeReqAttrA ***)
  (* file requester - set directory *)
  RTFIDir		 = RTTagBase+50;

  (* file requester - set wildcard pattern *)
  RTFIMatchPat		 = RTTagBase+51;

  (* file requester - add a file or directory to the buffer *)
  RTFIAddEntry		 = RTTagBase+52;

  (* file requester - remove a file or directory from the buffer *)
  RTFIRemoveEntry	 = RTTagBase+53;

  (* font requester - set font name of selected font *)
  RTFOFontName		 = RTTagBase+63;

  (* font requester - set font size *)
  RTFOFontHeight	 = RTTagBase+64;

  (* font requester - set font style *)
  RTFOFontStyle		 = RTTagBase+65;

  (* font requester - set font flags *)
  RTFOFontFlags		 = RTTagBase+66;

  (*** tags for rtPaletteRequestA ***)
  (* initially selected color - default 1 *)
  RTPAColor		 = RTTagBase+70;

  (*** tags for rtReqHandlerA ***)
  (* end requester by software control, set tagdata to REQCANCEL, REQOK or
     in case of rtEZRequest to the return value *)
  RTRHEndRequest	 = RTTagBase+60;

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


(************
 * RTReqPos *
 ************)
  REQPOSPOINTER		= 0;
  REQPOSCENTERWIN	= 1;
  REQPOSCENTERSCR	= 2;
  REQPOSTOPLEFTWIN	= 3;
  REQPOSTOPLEFTSCR	= 4;

(******************
 * RTRHEndRequest *
 ******************)
  REQCANCEL		= 0;
  REQOK			= 1;

(********
 * hooks *
 ********)
  REQHOOKWILDFILE	= 0;
  REQHOOKWILDFONT	= 1;


(*
 *   reqtools.library   © 1991 Nico François
 *
 *   Modula-2 Interface © 1992 Michael Griebling
 *
 *)


PROCEDURE OpenReqToolsLib() : BOOLEAN;
(* Open the Requester Tools Library and return TRUE if successful. *)


PROCEDURE AllocRequestA(type : LONGINT; taglist : TagItemPtr) : ADDRESS;
INLINE(ReqToolsBase, -30, 0, 8);
(*
    Allocates a requester structure for you in a future compatible manner.
    This is the only way to properly allocate a rtFileRequester,
    rtFontRequester or rtReqInfo structure.  The structure will be
    initialized for you.

    Use rtFreeRequest() to free the requester structure when you no longer
    need it.

  INPUTS
    type    - type of structure to allocate, currently RT_REQINFO,
              RT_FILEREQ or RT_FONTREQ.
    taglist - pointer to array of tags (currently always NULL).

  RESULT
    req - pointer to the requester allocated or NULL if no memory.
*)

PROCEDURE AllocRequest(type : LONGINT) : ADDRESS;


PROCEDURE FreeRequest(req : ADDRESS);
INLINE(ReqToolsBase, -36, 9);
(*
    Free requester structure previously allocated by rtAllocRequest().
    This will also free all buffers associated with the requester, so there
    is no need to call rtFreeReqBuffer() first.

    req - pointer to requester (may be NULL).
*)


PROCEDURE FreeReqBuffer(req : ADDRESS);
INLINE(ReqToolsBase, -42, 9);
(*
    Frees the buffer associated with 'req'.  In case of a file requester this
    function will deallocate the directory buffer, in case of a font
    requester the font list.

    It is safe to call this function for requesters that have no buffer, so
    you may call this for all requesters to free as much memory as possible.

    req - pointer to requester.
*)


PROCEDURE ChangeReqAttrA(req : ADDRESS; taglist : TagItemPtr) : LONGINT;
INLINE(ReqToolsBase, -48, 9, 8);
(*
    Change requester attributes with supplied taglist.  This is the only
    correct way to change the attributes listed below.

    The return code from rtChangeReqAttr() should be ignored unless stated
    otherwise.

  INPUTS
    req     - pointer to requester.
    taglist - pointer to array of tags.

  TAGS
    for the file requester:
        RTFI_Dir         - STRPTR
                           Name of new directory to position file requester
                           in. The requester's buffer will be deallocated.
        RTFI_MatchPat    - STRPTR
                           New pattern string to match files on.
        RTFI_AddEntry    - (BPTR)
                           THIS *MUST* BE THE LAST TAG (just before TAG_END)!
                           Tagdata must hold a lock on a file or directory
                           you want to add to the file requester's buffer.
                           The lock should have been obtained using Lock(),
                           and you must unlock this lock yourself.
                           It is your responsability to make sure the file
                           or directory is indeed in the directory the file
                           requester is in.
                           If the entry is already in the file requester's
                           buffer it will simply be updated.
                           It is harmless to call this function if the
                           requester's buffer is not initialized.
                           rtChangeReqAttr() will return a boolean to
                           indicate success or failure (out of memory).
        RTFI_RemoveEntry - STRPTR
                           Name of file or directory you want to remove from
                           the file requester's buffer.
                           It is your responsability to make sure the file
                           or directory is indeed in the directory the file
                           requester is in.
                           It is harmless to call this function if the
                           requester's buffer is not initialized.
    for the font requester:
        RTFO_FontName    - STRPTR
                           Set the name of the currently selected font.
        RTFO_FontHeight  - (UWORD)
                           Set the fontsize of the currently selected font.
        RTFO_FontStyle   - (UBYTE)
                           Set the style of the current font.
        RTFO_FontFlags   - (UBYTE)
                           Set the flags of the current font.
*)

PROCEDURE ChangeReqAttr(req : ADDRESS) : LONGINT;


PROCEDURE FileRequestA(filereq : rtFileRequesterPtr;
                       VAR filename : ARRAY OF CHAR;
                       title : STRPTR; taglist : TagItemPtr) : BOOLEAN;
INLINE(ReqToolsBase, -54, 9, 10, 11, 8);
(*
    Get a directory and filename(s), or just a directory from the user.

    'filename' should point to an array of at least 108 chars.  The filename
    already in 'filename' will be displayed in the requester when it comes
    up.  When the requester returns 'filename' will probably have changed.

  INPUTS
    filereq  - pointer to a struct rtFileRequester allocated with
               rtAllocRequest().
    filename - pointer to an array of chars (must be 108 bytes big).
    title    - pointer to requester window title (null terminated).
    taglist  - pointer to a TagItem array.

  TAGS
    RT_Window      - see rtEZRequest()
    RT_ReqPos      - see rtEZRequest()
    RT_LeftOffset  - see rtEZRequest()
    RT_TopOffset   - see rtEZRequest()
    RT_PubScrName  - see rtEZRequest()
    RT_Screen      - see rtEZRequest()
    RT_ReqHandler  - see rtEZRequest()
    RT_WaitPointer - see rtEZRequest()
    RT_DefaultFont - TextFontPtr
                     This tag allows you to specify the font to be used in
                     the requester when the screen font is proportional.
                     Default is GfxBase->DefaultFont.
    RTFI_Flags     - (ULONG)
                     Several flags:
                       FREQF_NOBUFFER    - do _not_ use a buffer to remember
                                           directory contents for the next
                                           time rtFileRequest() is used.
                       FREQF_MULTISELECT - allow multiple files to be
                                           selected. rtFileRequest() will
                                           return a pointer to a rtFileList
                                           structure which will contain all
                                           selected files.
                                           Use rtFreeFileList() to free the
                                           memory used by this file list.
                       FREQF_SELECTDIRS  - set this flag if you wish to
                                           enable the selecting of dirs as
                                           well as files.  You *must* also
                                           set FREQF_MULTISELECT.
                                           Directories will be returned
                                           together with files in rtFileList,
                                           but with StrLen equal to -1.
                                           If you need the length of the
                                           directory's name use strlen().
                       FREQF_SAVE        - Set this if you are using the
                                           requester to save or delete
                                           something.  Double-clicking will
                                           be disabled so it is harder to
                                           make a mistake and select the
                                           wrong file.  If the user enters a
                                           non-existent directory in the
                                           string gadget, a requester will
                                           appear asking if the directory
                                           should be created.
                       FREQF_NOFILES     - Set this if you want to use the
                                           requester to allow the user to
                                           select a directory rather than a
                                           file.  Ideal for getting a
                                           destination directory.
                                           May be used with FREQF_MULTISELECT
                                           and FREQF_SELECTDIRS.
                       FREQF_PATGAD      - When this is set a pattern gadget
                                           will be added to the requester.
                       FREQF_DOWILDFUNC  - Call req->Hook for each entry in
                                           the directory.
                                           Note that there is no tag to set
                                           the hook.  You must initialize
                                           the req->Hook field with a pointer
                                           to a valid hook structure.
                                           See above for more information on
                                           the calling of hooks.
    RTFI_Height    - (ULONG)
                     Suggested height of file requester window.
    RTFI_OkText    - STRPTR
                     Replacement text for "Ok" gadget, max 6 characters long.

  RESULT
    ret - TRUE if the user selected a file (check 'filereq->Dir' for the
          directory and 'filename' for the filename) or FALSE if the
          requester was canceled -- or a pointer to a struct rtFileList
          (if FREQF_MULTISELECT was used).

  NOTE
    Automatically adjusts the requester to the screen's font.
    If the screen's font is proportional the default font will be used.

    If the requester got too big for the screen because of a very large font,
    the topaz.font will be used.

    rtFileRequest() checks the pr_WindowPtr of your process to find the
    screen to put the requester on.
*)

PROCEDURE FileRequest(filereq : rtFileRequesterPtr;
                      VAR filename : ARRAY OF CHAR;
                      VAR directory : ARRAY OF CHAR;
                      title : ARRAY OF CHAR) : BOOLEAN;


PROCEDURE FreeFileList(filelist : rtFileListPtr);
INLINE(ReqToolsBase, -60, 8);
(*
    Frees a filelist returned by rtFileRequest() when the FREQF_MULTISELECT
    flag was set.  Call this after you have scanned the filelist and you no
    longer need it.

  INPUTS
    filelist - pointer to rtFileList structure, returned by rtFileRequest()
               (may be NULL).
*)


PROCEDURE EZRequestA(bodyfmt, gadfmt : STRPTR; reqinfo : rtReqInfoPtr;
                     argarray : ADDRESS; taglist : TagItemPtr) : LONGINT;
INLINE(ReqToolsBase, -66, 9, 10, 11, 12, 8);
(*
    This function puts up a requester for you and waits for a response from
    the user. If the response is positive, this procedure returns 1.
    If the response is negative, this procedure returns 0.
    The function may also return an IDCMP flag or a value corresponding with
    one of other possible responses (see below).

    'gadfmt' may contain several possible responses.  Seperate these
    responses by a '|'.  For example: "Yes|No", or 'Yes|Maybe|No".  The
    responses should be typed in the same order as they will appear on
    screen, from left to right.  There is no limit to the number of responses
    other than the width of the screen the requester will appear on.

    'bodyfmt' can contain newlines ('\n', ASCII 10). This will cause a new
    line to be started (surprise, surprise :-).
    You may also include 'printf' style formating codes. The format arguments
    should be pointed to by 'argarray'.
    You can use formatting codes in 'gadfmt' as well.  The arguments for
    this format string should follow the ones for 'bodyfmt'.

    NOTE: The formatting is done by exec.library/RawDoFmt(), so be aware that
          to display a 32-bit integer argument you must use "%ld", not "%d",
          since RawDoFmt() is "word-oriented."

    The second and third function use a variable number of arguments. These
    functions can be found in 'reqtools[nb].lib'.
    The second function has the RawDoFmt arguments as variable args, the
    third the tags. If you need both this is what you can do:

    ...
       {
       ULONG tags[] = { RTEZ_ReqTitle, (ULONG)"mytitle", TAG_END };

       rtEZRequest ("String, num: %s, %ld", NULL, "Ok",
                                           TagItemPtrtags, "six", 6);
       }
    ...

    You can satisfy the requester with the following keyboard shortcuts:
      'Y' or 'V' for a positive response,
      ESC, 'N', 'R' or 'B' for a negative response.

    If EZREQF_NORETURNKEY is _not_ set (see RTEZ_Flags below) the RETURN key
    is also accepted as a shortcut for the positive response (can be changed
    using RTEZ_DefaultResponse, see below).  The response that will be
    selected when you press RETURN will be printed in bold.

    The EZREQF_LAMIGAQUAL flag should be used when you put up a requester
    for a destructive action (e.g. to delete something).  When it is set
    the keyboard shortcuts are limited to Left Amiga 'V' and 'B' so it is
    harder to accidently select something you will regret.
    Note that the RETURN and ESC key remain active!  To disable the RETURN
    key use the EZREQF_NORETURNKEY flag.  The ESC key cannot be disabled.

    You may pass a NULL for 'gadfmt', but make sure you know what you are
    doing.  Passing a NULL opens an EZRequester with NO responses, just a
    body text.  This implies the user has no means of "answering" this
    requester.  You must therefore use the RT_IDCMPFlags tag to allow some
    other events to end the requester (e.g. IDCMP_MOUSEBUTTONS,
    IDCMP_INACTIVEWINDOW,...) or you must make use of the ReqHandler feature.
    Using a requester handler you can end the requester by program control.
    This way you can e.g. put up a requester before you start loading a file
    and remove it after the file has been loaded.  Do not pass an empty
    string as 'gadfmt'!

    'reqinfo' can be used to customize the requester.  For greater control
    use the tags listed below.  The advantage of the rtReqInfo structure is
    that it is global, where tags have to be specified each function call.
    See libraries/reqtools.[hi] for a description of the rtReqInfo structure.

  INPUTS
    bodyfmt  - requester body text, can be format string a la RawDoFmt().
    gadfmt   - text for gadgets (left to right, seperated by '|') or NULL.
    argarray - pointer to array of arguments for format string(s).
    reqinfo  - pointer to a rtReqInfo structure allocated with
               rtAllocRequest() or NULL.
    taglist  - pointer to a TagItem array.

  TAGS
    RT_Window       - WindowPtr
                      Window that will be used to find the screen to put the
                      requester on.
                      You *MUST* supply this if you are a task calling this
                      function and not a process! This is because tasks
                      don't have a pr_WindowPtr.
    RT_IDCMPFlags   - (ULONG)
                      Extra idcmp flags to return on.  If one these IDCMP
                      flags causes the requester to abort the return code
                      will equal the flag in question.
    RT_ReqPos       - (ULONG)
                      One of the following:
                        REQPOS_POINTER    - requester appears where the mouse
                                            pointer is (default).
                        REQPOS_CENTERSCR  - requester is centered on the
                                            screen.
                        REQPOS_CENTERWIN  - requester is centered in the
                                            window (only works if the
                                            pr_WindowPtr of your process is
                                            valid or if you use RT_Window).
                                            If RT_Window is NULL the
                                            requester will be centered on
                                            the screen.
                        REQPOS_TOPLEFTSCR - requester appears at the top left
                                            of the screen.
                        REQPOS_TOPLEFTWIN - requester appears at the top left
                                            of the window (only works if the
                                            pr_WindowPtr of your process is
                                            valid or if you use RT_Window).
                      The requester will always remain in the visible part of
                      the screen, so if you use the Workbench 2.0 ScreenMode
                      preferences editor to enlarge your Workbench screen and
                      you scroll around, the requester will always appear in
                      the part you can see.
                      REQPOS_CENTERSCR and REQPOS_TOPLEFTSCR also apply to
                      the visible part of the screen. So if you use one of
                      these the requester will be appear in the center or the
                      top left off what you can see of the screen as opposed
                      to the entire screen.
                      REQPOS_CENTERWIN and REQPOS_TOPLEFTWIN fall back to
                      REQPOS_CENTERSCR or REQPOS_TOPLEFTSCR respectively
                      when there is no parent window.  So you can safely use
                      these without worrying about the existence of a window.
    RT_LeftOffset   - (ULONG)
                      Offset of left edge of requester relative to position
                      specified with RT_ReqPos (does not offset the requester
                      when RT_ReqPos is REQPOS_POINTER).
    RT_TopOffset    - (ULONG)
                      Offset of top edge of requester relative to position
                      specified with RT_ReqPos (does not offset the requester
                      when RT_ReqPos is REQPOS_POINTER).
    RT_PubScrName   - STRPTR
                      Name of public screen requester should appear on. When
                      this tag is used the RT_Window tag will be ignored.
                      If the public screen is not found the requester will
                      open on the default public screen.
                      Only works on Kickstart 2.0!  reqtools.library does
                      not check this, it is up to you *NOT* to use this tag
                      on Kickstart 1.3 or below!
                      Note that the 1.3 version of reqtools.library also
                      understands and supports this tag (on 2.0).
    RT_Screen       - ScreenPtr
                      Address of screen to put requester on.  You should
                      never use this, use RT_Window or RT_PubScrName.
    RT_ReqHandler   - rtHandlerInfoPtr
                      Using this tag you can start an "asynchronous"
                      requester. ti_TagData of the tag must hold the address
                      of a pointer variable to a rtHandlerInfo structure.
                      The requester will initialize this pointer and will
                      return immediately after its normal initialization.
                      The return code will not be what you would normally
                      expect.  If the return code is _not_ equal to
                      CALL_HANDLER an error occured and you should take
                      appropriate steps. If the return code was CALL_HANDLER
                      everything went ok and the requester will still be up!
                      See the explanation for rtReqHandler() below for the
                      following steps you have to take.
    RT_WaitPointer  - (BOOL)
                      If this is TRUE the window calling the requester will
                      get a standard wait pointer set while the requester is
                      up.  This will happen if you used the RT_Window tag or
                      if your process's pr_WindowPtr is valid.  Note that
                      after the requester has finished your window will be
                      ClearPointer()-ed.  If you used a custom pointer in
                      your window you will have to re-set it, or not use the
                      RT_WaitPointer tag and put up a wait pointer yourself.
                      Defaults to FALSE.  It is advised you use this tag as
                      much as possible.
    RTEZ_ReqTitle   - STRPTR
                      Title of requester window, default is "Request" unless
                      the requester has less than 2 responses, then the
                      default title is "Information".
    RTEZ_Flags      - (ULONG)
                      Flags for rtEZRequest():
                        EZREQF_NORETURNKEY - turn off the RETURN key as
                                             shorcut for positive response.
                        EZREQF_LAMIGAQUAL  - keyboard shortcuts are limited
                                             to Left Amiga 'V' and 'B', ESC
                                             and RETURN.
                        EZREQF_CENTERTEXT  - centers each line of body text
                                             in the requester window. Useful
                                             for about requesters.
    RTEZ_DefaultResponse - (ULONG)
                      Response value that will be returned when the user
                      presses the return key.  Will be ignored if the
                      EZREQF_NORETURNKEY flag is set.  The text for this
                      response will be printed in bold. Default is 1.

  RESULT
    ret - 1 (TRUE) for leftmost (positive) response, then each consecutive
          response will return 1 more, the rightmost (false) respons will
          return 0 (FALSE), so 1,2,3,...,num-1,0 -- or idcmp flag.

  NOTE
    Automatically adjusts the requester to the screen's font.

    rtEZRequest() checks the pr_WindowPtr of your process to find the
    screen to put the requester on.
*)

PROCEDURE EZRequest(bodyfmt : ARRAY OF CHAR;
                    gadfmt : ARRAY OF CHAR; reqinfo : rtReqInfoPtr;
                    argarray : ADDRESS) : LONGINT;

PROCEDURE EZRequestTags(bodyfmt : ARRAY OF CHAR;
                        gadfmt : ARRAY OF CHAR; reqinfo : rtReqInfoPtr;
                        argarray : ADDRESS; taglist : TagItemPtr) : LONGINT;

(* no return value versions of above routines *)
PROCEDURE vEZRequestA(bodyfmt : ARRAY OF CHAR;
                      gadfmt : ARRAY OF CHAR; reqinfo : rtReqInfoPtr;
                      taglist : TagItemPtr; argarray : ADDRESS);

PROCEDURE vEZRequest(bodyfmt : ARRAY OF CHAR;
                     gadfmt : ARRAY OF CHAR; reqinfo : rtReqInfoPtr;
                     argarray : ADDRESS);


PROCEDURE GetStringA(VAR buffer : ARRAY OF CHAR; maxchars : LONGINT;
                     title : STRPTR; reqinfo : rtReqInfoPtr;
                     taglist : TagItemPtr) : BOOLEAN;
INLINE(ReqToolsBase, -72, 9, 0, 10, 11, 8);
(*
    Puts up a string requester to get a line of text from the user.
    The string present in 'buffer' upon entry will be displayed, ready to
    be edited.

    'reqinfo' can be used to customize the requester.  For greater control
    use the tags listed below.  The advantage of the rtReqInfo structure is
    that it is global, where tags have to be specified each function call.
    See libraries/reqtools.[hi] for a description of the rtReqInfo structure.

  INPUTS
    buffer   - pointer to buffer to hold characters entered.
    maxchars - maximum number of characters that fit in buffer (EX-cluding
               the 0 to terminate the string !).
    title    - pointer to null terminated title of requester window.
    reqinfo  - pointer to a rtReqInfo structure allocated with
               rtAllocRequest() or NULL.
    taglist  - pointer to a TagItem array.

  TAGS
    RT_Window        - see rtEZRequest()
    RT_IDCMPFlags    - see rtEZRequest()
    RT_ReqPos        - see rtEZRequest()
    RT_LeftOffset    - see rtEZRequest()
    RT_TopOffset     - see rtEZRequest()
    RT_PubScrName    - see rtEZRequest()
    RT_Screen        - see rtEZRequest()
    RT_ReqHandler    - see rtEZRequest()
    RT_WaitPointer   - see rtEZRequest()
    RTGS_Width       - (ULONG)
                       Width of requester window in pixels.  This is only a
                       suggestion. rtGetString() will not go below a certain
                       width.
    RTGS_AllowEmpty  - (BOOL)
                       If RTGS_AllowEmpty is TRUE an empty string will also
                       be accepted and returned.  Defaults to FALSE, meaning
                       that if the user enters an empty string the requester
                       will be canceled.

  RESULT
    ret - TRUE if user entered something, FALSE if not. If one of your idcmp
          flags caused the requester to end 'ret' will hold this flag.

  NOTE
    The contents of the buffer will NOT change if the requester is aborted.

    Automatically adjusts the requester to the screen's font.

    rtGetString() checks the pr_WindowPtr of your process to find the
    screen to put the requester on.
*)

PROCEDURE GetString(VAR buffer : ARRAY OF CHAR; maxchars : LONGINT;
                    title : ARRAY OF CHAR; reqinfo : rtReqInfoPtr) : BOOLEAN;


PROCEDURE GetLongA(VAR longvar : LONGINT; title : STRPTR;
                   reqino : rtReqInfoPtr; taglist : TagItemPtr) : BOOLEAN;
INLINE(ReqToolsBase, -78, 9, 10, 11, 8);
(*
    Puts up a requester to get a signed long (32-bit) number from the user.

    'reqinfo' can be used to customize the requester.  For greater control
    use the tags listed below.  The advantage of the rtReqInfo structure is
    that it is global, where tags have to be specified each function call.
    See libraries/reqtools.[hi] for a description of the rtReqInfo structure.

  INPUTS
    &longvar - address of long (32 bit!) variable to hold result.
    title    - pointer to null terminated title of requester window.
    reqinfo  - pointer to a rtReqInfo structure allocated with
               rtAllocRequest() or NULL.
    taglist  - pointer to a TagItem array.

  TAGS
    RT_Window        - see rtEZRequest()
    RT_IDCMPFlags    - see rtEZRequest()
    RT_ReqPos        - see rtEZRequest()
    RT_LeftOffset    - see rtEZRequest()
    RT_TopOffset     - see rtEZRequest()
    RT_PubScrName    - see rtEZRequest()
    RT_Screen        - see rtEZRequest()
    RT_ReqHandler    - see rtEZRequest()
    RT_WaitPointer   - see rtEZRequest()
    RTGL_Min         - (ULONG)
                       Minimum allowed value. If the user tries to enter a
                       smaller value the requester will refuse to accept it.
    RTGL_Max         - (ULONG)
                       Maximum allowed value, higher values are refused.
    RTGL_Width       - (ULONG)
                       Width if requester window in pixels.  This is only a
                       suggestion. rtGetLong() will not go below a
                       certain width.
    RTGL_ShowDefault - (BOOL)
                       If this is TRUE (default) the value already in
                       'longvar' will be displayed in the requester when it
                       comes up. If set to FALSE the requester will be empty.

  RESULT
    ret - TRUE if user entered a number, FALSE if not. If one of your idcmp
          flags caused the requester to end 'ret' will hold this flag.

  NOTE
    'longvar' will NOT change if the requester is aborted.

    Automatically adjusts the requester to the screen's font.

    rtGetLong() checks the pr_WindowPtr of your process to find the
    screen to put the requester on.
*)

PROCEDURE GetLong(VAR longvar : LONGINT; title : ARRAY OF CHAR;
                  reqino : rtReqInfoPtr) : BOOLEAN;


PROCEDURE FontRequestA(fontreq : rtFontRequesterPtr; title : STRPTR;
                       taglist : TagItemPtr) : BOOLEAN;
INLINE(ReqToolsBase, -96, 9, 11, 8);
(*
    Let the user select a font and a style (optional).

    Setting certain flags may result in the calling of a caller-supplied
    hook. See rtFileRequest() for more information on the calling of this
    hook.

    Hook types ('param[0]') currently implemented for rtFontRequest():

        REQHOOK_WILDFONT:
            Set the FREQF_DOWILDFUNC flag to activate. The requester will
            call your hook for each font in the system's font list.
            'param[1]' will hold the address of a struct TextAttr. If your
            hook returns TRUE the font will be skipped.

    Finally note that when you change your hook or your hook's behaviour
    you _MUST_ purge the requester's buffer (using rtFreeReqBuffer())!

  INPUTS
    fontreq  - pointer to a struct rtFontRequester allocated with
               rtAllocRequest().
    title    - pointer to requester window title (null terminated).
    taglist  - pointer to a TagItem array.

  TAGS
    RT_Window         - see rtEZRequest()
    RT_ReqPos         - see rtEZRequest()
    RT_LeftOffset     - see rtEZRequest()
    RT_TopOffset      - see rtEZRequest()
    RT_PubScrName     - see rtEZRequest()
    RT_Screen         - see rtEZRequest()
    RT_ReqHandler     - see rtEZRequest()
    RT_WaitPointer    - see rtEZRequest()
    RT_DefaultFont    - TextFontPtr
                        This tag allows you to specify the font to be used in
                        the requester when the screen font is proportional.
                        Default is GfxBase->DefaultFont.
    RTFO_Flags        - (ULONG)
                        Several flags:
                          FREQF_NOBUFFER      - do not buffer the font list
                                                for subsequent calls to
                                                rtFontRequest().
                          FREQF_FIXEDWIDTH    - only display fixed-width fonts.
                          FREQF_COLORFONTS    - display color fonts also.
                          FREQF_CHANGEPALETTE - change the screen's palette
                                                to match that of a selected
                                                color font.
                          FREQF_LEAVEPALETTE  - leave the palette as it is
                                                when exiting rtFontRequest()
                                                Useful in combination with
                                                FREQF_CHANGEPALETTE.
                          FREQF_SCALE         - allow fonts to be scaled
                                                when they don't exist in the
                                                requested size.
                                                (works on Kickstart 2.0 only,
                                                 has no effect on 1.2/1.3).
                          FREQF_STYLE         - include gadgets so the user
                                                may select the font's style.
                          FREQF_DOWILDFUNC    - Call req->Hook for each font.
                                                Note that there is no tag to
                                                set the hook.  You must
                                                initialize the req->Hook
                                                field with a pointer to a
                                                valid hook structure.
                                                See rtFileRequest() for more
                                                information on the calling of
                                                this hook.
    RTFO_Height       - (ULONG)
                        Suggested height of font requester window.
    RTFO_OkText       - STRPTR
                        Replacement text for "Ok" gadget.  Maximum 6 chars.
                        (7 is still ok, but not esthetically pleasing)
    RTFO_SampleHeight - (ULONG)
                        Height of font sample display in pixels (default 24).
    RTFO_MinHeight    - (ULONG)
                        Minimum font size displayed.
    RTFO_MaxHeight    - (ULONG)
                        Maximum font size displayed.

  RESULT
    bool - TRUE if the user selected a font (freq->Attr holds the font),
           FALSE if the requester was canceled.
*)

PROCEDURE FontRequest(fontreq : rtFontRequesterPtr;
                      title : ARRAY OF CHAR) : BOOLEAN;


PROCEDURE PaletteRequestA(title : STRPTR; reqinfo : rtReqInfoPtr;
                           taglist : TagItemPtr) : LONGINT;
INLINE(ReqToolsBase, -102, 10, 11, 8);
(*
    Put up a palette requester so the user can change the screen's colors.

    The colors are changed in the viewport of the screen the requester will
    appear on, so that is where you will find them after the palette
    requester returns.

    The selected color is returned, so you can also use this requester to let
    the user select a color.

    'reqinfo' can be used to customize the requester.  For greater control
    use the tags listed below.  The advantage of the rtReqInfo structure is
    that it is global, where tags have to be specified each function call.
    See libraries/reqtools.[hi] for a description of the rtReqInfo structure.

  INPUTS
    title   - pointer to requester window title (null terminated).
    reqinfo - pointer to a rtReqInfo structure allocated with
              rtAllocRequest() or NULL.
    taglist - pointer to a TagItem array.

  TAGS
    RT_Window        - see rtEZRequest()
    RT_ReqPos        - see rtEZRequest()
    RT_LeftOffset    - see rtEZRequest()
    RT_TopOffset     - see rtEZRequest()
    RT_PubScrName    - see rtEZRequest()
    RT_Screen        - see rtEZRequest()
    RT_ReqHandler    - see rtEZRequest()
    RT_WaitPointer   - see rtEZRequest()
    RT_DefaultFont   - TextFontPtr
                       This tag allows you to specify the font to be used in
                       the requester when the screen font is proportional.
                       Default is GfxBase->DefaultFont.
    RTPA_Color       - (ULONG)
                       Initially selected color of palette.  Default is 1.

  RESULT
    color - the color number of the selected color or -1 if the user
            canceled the requester.

  NOTE
    Automatically adjusts the requester to the screen's font.
    If the screen's font is proportional the default font will be used.

    If the requester got too big for the screen because of a very large font,
    the topaz.font will be used.

    rtPaletteRequest() checks the pr_WindowPtr of your process to find the
    screen to put the requester on.
*)

PROCEDURE PaletteRequest(title : ARRAY OF CHAR; reqinfo : rtReqInfoPtr) : LONGINT;


PROCEDURE ReqHandlerA(handlerinfo : rtHandlerInfoPtr; sigs : SignalSet;
                      taglist : TagItemPtr) : LONGINT;
INLINE(ReqToolsBase, -108, 9, 0, 8);
(*
    This function should be called if you used the RT_ReqHandler tag with a
    requester function.

    The requester you used the tag with will have returned immediately after
    its initialization and will have initialized a pointer to a rtHandlerInfo
    structure for you.
    You should now do the following:

    Check the DoNotWait field. If it is FALSE you have to wait for the
    signals in the WaitMask field (plus your own signals if you like).
    If any of the signals in WaitMask are received or DoNotWait was not FALSE
    you have to call rtReqHandler() and check its return value for one of
    the following values:

      CALL_HANDLER    - Check DoNotWait again, Wait() if you have to
                        and call rtReqHandler() again. In other words, loop.
      everything else - normal return value, requester has finished. This
                        return value will be the same as if the requester
                        had run normally.

    You must pass the signals you received to rtReqHandler().

    NOTE: if you want to wait for your own signals do not do so if
          DoNotWait is TRUE.  Call rtReqHandler() and if you must know
          if one of your signals arrived use SetSignal() to find this out.
          If you are waiting for a message to arrive at a message port you
          can simple call GetMsg and check if it is non-null.
          DoNotWait will naturally only be TRUE when it absolutely,
          positively has to be.  A multitasking machine as the Amiga should
          use Wait() as much as possible.

    This is an example of a "requester loop":

    ...
    struct rtHandlerInfo *hinfo;
    ULONG ret, mymask, sigs;

    ...
       /* calculate our mask */
       mymask = 1 << win->UserPort->mp_SigBit;

       /* We use the RT_ReqHandler tag to cause the requester to return
          after initializing.
          Check the return value to see if this setup went ok. */
       if (rtFontRequest (req, "Font", RT_ReqHandler, &hinfo, TAG_END)
                                                           == CALL_HANDLER) {
          do {
            /* Wait() if we can */
            if (!hinfo->DoNotWait)
               sigs = Wait (hinfo->WaitMask | mymask);

            /* check our own message port */
            while (msg = GetMsg (win->UserPort)) {
               ...
               /* here we handle messages received at our windows IDCMP               ...
                  port */
               ...
               }

            /* let the requester do its thing (remember to pass 'sigs') */
            ret = rtReqHandler (hinfo, sigs, TAG_END);

            /* continue this loop as long as the requester is up */
            } while (ret == CALL_HANDLER)

          /* when we get here we know the requester has finished, 'ret'
             is the return code. */
          ...
          }
       else notify ("Error opening requester!");
    ...

  INPUTS
    handlerinfo - pointer to handler info structure initialized by using
                  the RT_ReqHandler tag when calling a requester function.
    sigs        - the signals received by previous wait, will be ignored if
                  hinfo->DoNotWait was TRUE.
    taglist     - pointer to a TagItem array.

  TAGS
    RTRH_EndRequest - supplying this tag will end the requester. The return
                      code from rtReqHandler() will _not_ be CALL_HANDLER,
                      but the requester return code.  If the tagdata of this
                      tag is REQ_CANCEL the requester will be canceled, if it
                      is REQ_OK the requester will be ok-ed.
                      In case of an EZRequest tagdata should be the return
                      code of the requester (TRUE, FALSE or 2,3,4,...).

  RESULT
    ret - CALL_HANDLER if you have to call rtReqHandler() again,
          or the normal return value from the requester.
*)

PROCEDURE ReqHandler(handlerinfo : rtHandlerInfoPtr; sigs : SignalSet) : LONGINT;


PROCEDURE SetWaitPointer(window : WindowPtr);
INLINE(ReqToolsBase, -114, 8);
(*
    Change the window's pointer image to that of a wait pointer.  Call this
    function whenever your program will be busy doing something for a lengthy
    period of time.

    It is recomended you call this function before calling any of the
    requester functions.  This way if the user clicks in your window he will
    know he must respond to the requester before doing anything else.  See
    also the RT_WaitPointer tag for an automatic way of setting the wait
    pointer.

  INPUTS
    window - pointer to the window to receive the wait pointer.
*)


(*
 * the following functions are for the advanced reqtools user
 * who whishes to write his/her own (complementary) requesters
 *)
PROCEDURE GetVScreenSize(screen : ScreenPtr; VAR width, height : LONGINT);
INLINE(ReqToolsBase, -120, 8, 9, 10);
(*
    Use this function to get the size of the visible portion of a screen.

    The value returned by rtGetVScreenSize() can be used for vertical
    spacing.  It will be larger for interlaced and productivity screens.
    Using this number for spacing will assure your requester will look
    good on an interlaced and a non-interlaced screen.

    Current return codes are 2 for non-interlaced and 4 for interlaced.
    These values may change in the future, don't depend on them too much.
    They will in any case remain of the same magnitude.

  INPUTS
    screen    - pointer to the screen.
    widthptr  - address of an ULONG variable to hold the width.
    heightptr - address of an ULONG variable to hold the height.
*)


PROCEDURE SetReqPosition(reqpos : LONGINT; newwindow : NewWindowPtr;
                         screen : ScreenPtr; window : WindowPtr);
INLINE(ReqToolsBase, -126, 0, 8, 9, 10);
(*
    Sets newwindow->LeftEdge and newwindow->TopEdge according to reqpos.

    Except for the left- and topedge 'newwindow' must already be completely
    initialized.

    The newwindow->LeftEdge and newwindow->TopEdge already in the NewWindow
    structure will be used as offsets to the requested position.  If you'd
    like a window at position (25,18) from the top left of the screen you
    would fill newwindow->LeftEdge with 25, newwindow->TopEdge with 18 and
    call rtSetReqPosition() with reqpos equal to REQPOS_TOPLEFTSCR.

    Don't forget to make sure newwindow->LeftEdge and newwindow->TopEdge
    are 0 if you don't want to offset your window.

    In case of REQPOS_POINTER you can use them to point to your window's
    hotspot, where the pointer should point.  If you call rtSetReqPosition()
    with the left- and topedge equal to 0 you'd get a window appearing with
    its top- and leftedge equal to the current pointer position.

    Note that the screen pointer may _NOT_ be NULL.  If you have your own
    window open you can supply yourwindow->WScreen to this function.

    The window pointer is only required if reqpos is REQPOS_CENTERWIN or
    REQPOS_TOPLEFTWIN.  Even in this case you may call rtSetReqPosition()
    with a NULL window pointer.  The positions will simply fall back to
    REQPOS_CENTERSCR and REQPOS_TOPLEFTSCR respectively.

  INPUTS
    reqpos    - one of the REQPOS_... constants usable with RT_ReqPos.
    newwindow - pointer to your (already initialized) NewWindow structure.
    screen    - pointer to screen the requester will appear on.
    window    - pointer to parent window or NULL.
*)


PROCEDURE Spread(VAR posarray  : ARRAY OF LONGINT;
                 VAR sizearray : ARRAY OF LONGINT;
                 totalsize, min, max, num : LONGINT);
INLINE(ReqToolsBase, -132, 8, 9, 0, 1, 2, 3);
(*
    Evenly spread a number of objects over a certain length.
    Primary use is for arrangement of gadgets in a window.

    Example:

    'sizearray' holds following values: 4, 6, 4, 2 and 8,
    'totalsize' is 24 (= 4 + 6 + 4 + 2 + 8),
    'min' is 3, 'max' is 43,
    and finally, 'num' is 5.

    After calling rtSpread() 'posarray' would hold the following
    values: 3, 11, 19, 26 and 31.

    My attempt at a visual representation:

        |                                            |
        |  |                                      |  |
        |  OOOO    OOOOOO    OOOO    OO    OOOOOOOO  |
        |  |                                      |  |
        |         1    1    2    2    3    3    4    4
        0----5----0----5----0----5----0----5----0----5

  INPUTS
    posarray  - pointer to array to be filled with positions.
    sizearray - pointer to array of sizes.
    totalsize - total size of all objects (sum of all values in sizearray).
    min       - first position to use.
    max       - last position, first _NOT_ to use.
    num       - number of objects (size of posarray and sizearray).
*)


PROCEDURE ScreenToFrontSafely(screen : ScreenPtr);
INLINE(ReqToolsBase, -138, 8);
(*
    Brings the specified screen to the front of the display, but only after
    checking it is still in the list of currently open screens.

    This function can be used to bring a screen back to the front of the
    display after bringing another screen to the front.  If the first screen
    closed while you where busy it is harmless to call this function, unlike
    calling the normal ScreenToFront().

  INPUTS
    screen - pointer to the screen.
*)


END ReqTools.