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

    :Program.  	 FileReqTest.mod
    :Contents.	 TestModule for FileRequest
    :CoFiles.	 FileRequest [bne]
    :Author.   	 Nicolas Benezan [bne]
    :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
    :Phone.      711/333679
    :Copyright.  Public Domain
    :Language. 	 Modula-2
    :Translator. M2Amiga AMSoft
    :Imports.	 FileRequest, SuperLists 1.3, IntuiStruct 1.3 [bne]
    :Imports.	 MemSystem [bne]
    :ModHistory. V1.0b [bne] 31.Oct.88
    
**********************************************************************)

MODULE FileReqTest;

FROM Intuition	IMPORT NewWindow,WindowPtr,WindowFlagSet,WindowFlags,
		IDCMPFlagSet,IDCMPFlags,OpenWindow,CloseWindow,Request,
                RequesterPtr,ScreenFlagSet,ScreenFlags,EndRequest,
                GadgetPtr;
FROM IntuiStruct IMPORT StructWindow;
FROM FileRequest IMPORT InitStdGadgets,InitList,BuildRequest,
		StdHandler,RequestFile,CreateStdEntry,StdReqWidth,
                StdReqHeight;
FROM MemSystem	IMPORT Allocate,AllocMem,Deallocate;
FROM Arts	IMPORT Assert,TermProcedure,BreakPoint;
FROM Dos	IMPORT FileLockPtr;
FROM Exec	IMPORT WaitPort;
FROM SYSTEM	IMPORT ADR;
IMPORT IntuiStruct;
IMPORT SuperLists;
IMPORT FileRequest;

VAR	MyWindow:NewWindow;
	MyWindowPtr:WindowPtr;
        MyRequester:RequesterPtr;
        Dir:FileLockPtr;
        FileName:ARRAY [0..255] OF CHAR;
        Gadgets:GadgetPtr;

PROCEDURE CleanUp;
BEGIN
  IF MyWindowPtr#NIL THEN
    IF MyWindowPtr^.firstRequest#NIL THEN
      EndRequest(MyRequester,MyWindowPtr);
    END;
    CloseWindow(MyWindowPtr);
  END;
END CleanUp;

BEGIN
  MyWindowPtr:=NIL;
  TermProcedure(CleanUp);
  IntuiStruct.AllocProc:=AllocMem;
  IntuiStruct.DeallocProc:=Deallocate;
  SuperLists.AllocProc:=Allocate;
  SuperLists.DeallocProc:=Deallocate;
  FileRequest.AllocProc:=Allocate;
  FileRequest.DeallocProc:=Deallocate;
  Dir:=NIL;
  StructWindow(MyWindow,64,100,512,100,0,1,IDCMPFlagSet{closeWindow},
    WindowFlagSet{windowDrag,windowDepth,windowClose,activate},
    ADR("File Select Requester Demo"),NIL,ScreenFlagSet{wbenchScreen});
  MyWindowPtr:=OpenWindow(MyWindow);
  Assert(MyWindowPtr#NIL,ADR("Can't open Window"));
  
  Gadgets:=InitStdGadgets(ADR("Ok     "),TRUE);
  MyRequester:=BuildRequest(50,16,StdReqWidth,StdReqHeight,Gadgets);
  IF Request(MyRequester,MyWindowPtr) THEN
    InitList(MyRequester^.reqLayer^.rp);
    IF RequestFile(Dir,FileName,MyWindowPtr,MyRequester,CreateStdEntry,
     StdHandler) THEN
       BreakPoint(ADR(FileName));
    END;
    EndRequest(MyRequester,MyWindowPtr);
  END;
  WaitPort(MyWindowPtr^.userPort);
END FileReqTest.
