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

    :Program.  	 FileRequest.def
    :Contents.	 supports file selection requesters
    :Reamrk.     similar to the DPaint(tm) "Load" function
    :Author.   	 Nicolas Benezan [bne]
    :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
    :Phone.      711/333679
    :Copyright.  Shareware (see Copyright File !)
    :Language. 	 Modula-2
    :Translator. M2Amiga AMSoft
    :Imports.	 IntuiStruct1.3, SuperLists1.3, DosSopport, IDCMP [bne]
    :ModHistory. V1.0c [bne] 01.Nov.88
    
**********************************************************************)

DEFINITION MODULE FileRequest;

FROM Intuition	IMPORT GadgetPtr,Gadget,StringInfo,PropInfo,Image,
		WindowPtr,RequesterPtr,IDCMPFlags;
FROM Exec	IMPORT MsgPortPtr;
FROM SuperLists	IMPORT SuperListPtr,EntryPtr;
FROM Graphics	IMPORT RastPortPtr;
FROM SYSTEM	IMPORT ADDRESS;
FROM Dos	IMPORT FileLockPtr,FileInfoBlockPtr,DeviceListType;
FROM InputEvent	IMPORT QualifierSet;

CONST	StdReqWidth=400;(* Requester/Window *)
	StdReqHeight=81;
        StdBoxLeft=9;	(* File Select List - ResizeList() *)
        StdBoxTop=16;
        StdBoxWidth=273;
        StdBoxHeight=57;
        file=0;		(* userFlags *)
        dir=1;
        dev=2;
        CancelID=0;	(* GadgetIDs *)
	VolumeID=1;
	RootID=2;
        ParentID=3;
        OkID=4;
        PropID=5;
        UpID=6;
        DownID=7;
        BoxID=8;
        PathID=9;
TYPE	MsgHandler=PROCEDURE((* Class *)IDCMPFlags,(* Code *)CARDINAL,
		(* Qualifier *)QualifierSet,(* iAddress *)ADDRESS,
                (* mouseX,Y *)INTEGER,INTEGER);
        CreateEntryProc=PROCEDURE(FileInfoBlockPtr):EntryPtr;
        DeviceListTypeSet=SET OF DeviceListType;
VAR	RootGadg,ParentGadg,VolumeGadg,OkGadg,CancelGadg:Gadget;
	BoxGadg,PathGadg,ScrollGadg,UpGadg,DownGadg:Gadget;
        PathInfo:StringInfo;
        ScrollInfo:PropInfo;
        GadgetStrip:GadgetPtr;
        UpImage,DownImage:Image;
        SelectList:SuperListPtr;
        AllocProc:PROCEDURE(VAR ADDRESS,LONGINT);
        DeallocProc:PROCEDURE(VAR ADDRESS);

PROCEDURE InitStdGadgets(ActionText:ADDRESS;Requester:BOOLEAN):GadgetPtr;
(*:Input.	ActionText: Pointer to the text of the Ok-Gadget
  :Input.	Requester: should I set the regGadget flag ?
  :Result.	Pointer to the first gadget of a linked list
  :Semantic.	Initialises the gadget structures with standard values *)

PROCEDURE InitList(RastPort:RastPortPtr);
(*:Input.	RastPort: Pointer to the RastPort in which the SuperList
  :Input.	will be displayed
  :Semantic.	Initialises the SuperList structure required for the
  :Semantic.	file requester *)

PROCEDURE ResizeList(Left,Top,Width,Height:INTEGER);
(*:Input.	Left,Top: Coordinates of the List's upper left Corner
  :Input.	Width,Height: X and Y dimensions of the SuperList
  :Semantic.	Changes the position and size of the List's display area
*)
PROCEDURE BuildRequest(Left,Top,Width,Height:INTEGER;
		GadgetStrip:GadgetPtr):RequesterPtr;
(*:Input.	Left,Top: Coordinates of the Requesters's upper left Corner
  :Input.	Width,Height: X and Y dimensions of the Requester
  :Input.	GadgetStrip: Pointer to the first gadget of a linked list
  :Result.	Pointer to the requester structure
  :Semantic.	Initialises the Requester structure *)

PROCEDURE StdHandler(Class:IDCMPFlags;Code:CARDINAL;Qualifier:QualifierSet;
		iAddress:ADDRESS;X,Y:INTEGER);
(*:Input.	Class,Code,Qualifier,iAddress: IDCMP Message Parameters
  :Input.	X,Y: Mouse pointer coordinates
  :Semantic.	Dummy procedure if no OtherMsgHandler is needed
  :Semantic.	as parameter of the RequestFile() procedure *)

PROCEDURE RequestFile(VAR Dir:FileLockPtr;VAR Name:ARRAY OF CHAR;
		Window:WindowPtr;Requester:RequesterPtr;CreateEntry:
                CreateEntryProc;OtherMsgHandler:MsgHandler):BOOLEAN;
(*:Input.	Dir: Directory which is loaded first
  :Output.	Dir: Directory in which the last selection has been done
  :Output.	Name: Name of the selected file (if any) without path
  :Input.	Window: Pointer to the requester's window
  :Input.	Requester: Pointer to the Requester or NIL if no
  :Input.	requester is used
  :Input.	CreateEntry: Procedure creating the SuperList directory
  :Input.	entries (default is CreateStdEntry() )
  :Input.	OtherMsgHandler: Procedure responsible for all Messages
  :Input.	RequestFile() does not process
  :Result.	TRUE: valid selection FALSE: Cancel or error
  :Semantic.	Main Procedure of RequestFile, handles the file requester
*)
PROCEDURE GetPath(File:FileLockPtr;VAR Path:ARRAY OF CHAR);
(*:Input.	File: FileLock structure of the file to be examined
  :Output.	Path: Path of the directory containing the file *)

PROCEDURE ReadDeviceList(List:SuperListPtr;Types:DeviceListTypeSet);
(*:Input.	List: Pointer to an initialised SuperList structure
  :Input.	Types: Flag set to enable volumes, directories or devices
  :Semantic.	Reads the DOS device list and writes it into a SuperList
*)
PROCEDURE CreateStdEntry(Info:FileInfoBlockPtr):EntryPtr;
(*:Input.	Info: Pointer to an InfoBlock of a file Examine()d
  :Input.	by RequestFile()
  :Result.	Pointer to the initialised SuperList entry
  :Semantic.	Allocates a SuperList entry, initialises it and
  :Semantic.	sets its text field to the filename or dir-name +(dir)
  :Note.	Important: The flags "dir" or "file" in Entry.userFlags
  :Note.	are set depending on the entry type. Entry.userData is
  :Note.	set to the length of the file name. Do not forget this
  :Note.	if you use your own CreateEntry procedure ! *) 

PROCEDURE ReadDirectory(List:SuperListPtr;InsertAt:INTEGER;Dir:FileLockPtr;
		CreateEntry:CreateEntryProc);
(*:Input.	List: Pointer to a properly initialised SuperList structure
  :Input.	InsertAt: Position at which the Entries should be inserted
  :Input.	 0: Iserts always at Position 0 (list grows backward)
  :Input.	 n>0: Inserts at n, n+1, n+2 ...
  :Input.	 -1: Inserts always at the last Position
  :Input.	Dir: Pointer to the FileLock of the directory to be read
  :Input.	CreateEntry: Procedure converting the FileInfoBlock into
  :Input.	a SuperList entry (default is CreateStdEntry() )
  :Semantic.	Reads a directory into a SuperList
  :Note.	CreateEntry() can call ReadDirectory() recursively to
  :Note.	read nested directories *)

END FileRequest.
