MODULE ExtProcDemo;

(*======================================================================*)
(*                    Amiga M2Sprint Support Routines                   *)
(*======================================================================*)
(*         © Copyright 1989 Robert Salesas, All Rights Reserved         *)
(*        Re-Distribute as you wish but DO NOT alter the contents       *)
(*            of this file.  Moral Rights remain my property.           *)
(*======================================================================*)
(*      Version: 1.02           Author : Robert Salesas                 *)
(*      Date   : 04-Dec-89      Changes: Original                       *)
(*======================================================================*)

FROM SYSTEM           IMPORT  ADR;
FROM TPInterface      IMPORT  TPFound, TPMsg;
FROM TPExtDefs        IMPORT  DrawerFlags;
FROM RSAlerts         IMPORT  CreateAlert;
FROM EasyWindows      IMPORT  CreateWindow;
FROM Intuition        IMPORT  IDCMPFlagSet, WindowFlagSet, WindowPtr,
                              CloseWindow;
FROM DOSProcess       IMPORT  Delay;
FROM Pens             IMPORT  Move;
FROM Text             IMPORT  Text;
FROM Strings          IMPORT  LengthStr;

VAR
  Succ  :  BOOLEAN;
  Wp    :  WindowPtr;


BEGIN
  IF TPFound THEN   (*  IF run FROM withing TP  *)
    WITH TPMsg^ DO
      (*  Let's try posting an error through TP's routines  *)
      (*  NOTE:  error message should fit on LoRes screen   *)
      TP_ErrMessage := ADR("We are now making an error!");
      TP_ErrNotice;

      (*  Let's try a YES | NO requester  *)
      TP_QueryMessage := ADR("Would you like to quit?");
      TP_Query;

      IF (TP_QueryBool = 0) THEN
        (*  Let's open a window on the screen  *)
        Wp := CreateWindow((TP_Sp^.Width - 200) DIV 2, (TP_Sp^.Height - 100) DIV 2, 200, 100,
                           "Test window", IDCMPFlagSet{}, WindowFlagSet{},
                           TP_Sp, NIL);
        IF (Wp # NIL) THEN  (* If all is well  *)
          (*  Now let's get a filename  *)
          TP_Drawer := Current;
          TP_FileReqRd;
          IF (TP_PathBuff^[0] # 0C) THEN  (*  IF NOT an empty string  *)
            (*  Print it TO the window  *)
            Move(Wp^.RPort, 20, 20);
            Text(Wp^.RPort, TP_PathBuff, LengthStr(TP_PathBuff^));
          ELSE
            (*  Tell them no slection was made.  *)
            Move(Wp^.RPort, 20, 20);
            Text(Wp^.RPort, ADR("Nothing was selected"), 20);
          END;

          Move(Wp^.RPort, 20, 40);
          Text(Wp^.RPort, ADR("The full External path."), 20);
          TP_ReturnDrawer;
          Move(Wp^.RPort, 20, 54);
          Text(Wp^.RPort, TP_PathBuff, LengthStr(TP_PathBuff^));


          (*  Pause FOR a WHILE  *)
          Delay(100);

          (*  Close the window  *)
          CloseWindow(Wp);

          (*  AND we are done!!!  *)
        ELSE          (*  Tell user of problem  *)
          TP_ErrMessage := ADR("Unable to open window.");
          TP_ErrNotice;
        END;
      END;
    END;
  ELSE              (*  ELSE advice the user  *)
    Succ := CreateAlert("This program can only be run", "from within Title Page.");
  END;
END ExtProcDemo.
