
program reqtoolsdemo;

{------------------------------------------------------------------------}
{ This little proggy was written by J. Stötzer in 1994. It demonstrates
  what great features the new 'Reqtools.Library 2.0' by Nico Francois
  has to offer. Hope you like it.
  It's Public Domain. That means you can use the routs in your own Progs.

  Modified by PackMAN c/o Falk Zühlsdorff for OS2... (Unit Reqtools3)
  Greetings fly to: Janosh (Jan Stötzer C U) and Nico Francois .
  This Program needn`t the DOS Unit like the version of Janosh       }
{------------------------------------------------------------------------}

USES REQTOOLS3;

VAR     FileReq : p_rtFileRequester;
        FontReq : p_rtFontRequester;
        InfoReq : p_rtReqInfo;
        ScrnReq : p_rtScreenModeRequester;
        Buf     : str;
        FName   : str;
        Num     : long;
        Col     : long;
        Tags    : p_ReqTagList;
        Args    : ArgArray;
        HStr    : str;
        HStr2   : string[1000];
        ret     : long;
        ok      : boolean;

{------------------------------------------------------------------------}

BEGIN

  OpenLib(RTBase,REQTOOLSNAME,REQTOOLSVERSION);

  HStr2:="Reqtools.Library Demo"+chr(10)+
          "~~~~~~~~~~~~~~~~~~~~~"+chr(10)+chr(10)+
          "Written by Janosh and modified by PackMAN in KickPascal"+chr(10)+
          "from Maxon Computer. This Proggy demonstrates, what the"+chr(10)+
          "great 'reqtools.library' © by Nico Francois has to offer";
  ret:=rtEZRequestA(^HStr2,"Yeah !",Nil,Nil,Nil);

  ret:=rtEZRequestA("Reqtools.Library offers"\10"different types of requesters",
                    "Let's see them",Nil,Nil,Nil);

  ret:=rtEZRequestA('NUMBER 1:'\10'The larch :-)','Be serious!',Nil,Nil,Nil);

  ret:=rtEZRequestA("Ok, let's be serious..."\10"NUMBER 1:"\10"String requester function: rtGetString()",
                    "Show me",Nil,Nil,Nil);

  Buf:='A little bit of text';
  ret:=rtGetStringA(Buf,127,'Enter anything:',Nil,Nil);
  Args[0]:=long(Buf);
  IF ret=0 THEN
    ret:=rtEZRequestA("You entered nothing","I'm sorry",Nil,Nil,Nil)
  ELSE
    ret:=rtEZRequestA('You entered this string: '\10'%s','So I did',Nil,
                      ^Args[0],Nil);

  Buf:="Cool, heh ?";
  HStr:="It is possible to have several responses";
  Tags^[0]:=TagItem(RTGS_TextFmt,long(HStr));
  HStr:=' OK | New 2.0 feature | Fuck it !! ';
  Tags^[1]:=TagItem(RTGS_GadFmt,long(HStr));
  Tags^[2]:=TagItem(TAG_END,0);

  ret:=rtGetStringA(Buf,127,"* New for ReqTools 2.0 *",Nil,Tags);

  case ret of
    1 : ;
    2 : ret:=rtEZRequestA("Yeah! This is a new Reqtools 2.0 feature.",
                          "OK",Nil,Nil,Nil);
    0 : ret:=rtEZRequestA("Hey! Why don't you like it ???","Ooops",Nil,
                          Nil,Nil);
    otherwise
  END;

  ret:=rtEZRequestA ('NUMBER 2:'\10'Number requester'\10'function: rtGetLong()',
                     "Show me", Nil, Nil, Nil);

  Tags^[0]:=TagItem(RTGL_ShowDefault,long(false));
  Tags^[1]:=TagItem(TAG_END,0);

  ret:=rtGetLongA (^Num, "Enter a number:", Nil, Tags);
  Args[0]:= Num;

  IF ret=0 THEN
    ret:=rtEZRequestA("You entered nothing","I'm sorry", Nil, Nil, Nil)
  ELSE
    ret:=rtEZRequestA('The number You entered was: '\10'%ld' ,
                      'So it was', Nil, ^Args[0], Nil);

  Tags^[0]:=TagItem(RTGL_ShowDefault,long(false));
  HStr:="Some text above a Number Gadget";
  Tags^[1]:=TagItem(RTGL_TextFmt,long(HStr));
  HStr:='Ok|V38 feature|Cancel';
  Tags^[2]:=TagItem(RTGL_GadFmt,long(HStr));
  Tags^[3]:=TagItem(TAG_END,0);

  ret:=rtGetLongA (^Num, "* New for ReqTools 2.0 *", Nil, Tags);

  case ret of
    0 : ret:=rtEZRequestA("Don't you like it or why do you refuse"\10"to enter a number ??",
                          "Argh",Nil,Nil,Nil);
    2 : ret:=rtEZRequestA("Reqtools V38 makes it possible !","So is it",Nil,
                          Nil,Nil);
    otherwise
  END;

  HStr2:="New is also the ability to switch off"+chr(10)+
          "the backfill pattern.You can also center"+chr(10)+
          "the text above the entry gadget. It's also"+chr(10)+
          "possible to allow empty strings to be returned."+chr(10)+
          "These new features are also available in"+chr(10)+
          "the rtGetLong requester";
  Tags^[0]:=TagItem(RTGS_TextFmt,long(^HStr2));
  HStr:="_Great|_Abort";
  Tags^[1]:=TagItem(RTGS_GadFmt,long(HStr));
  Tags^[2]:=TagItem(RT_UnderScore,long('_'));;
  Tags^[3]:=TagItem(RTGS_BackFill,long(false));
  Tags^[4]:=TagItem(RTGS_Flags,GSREQF_CENTERTEXT or GSREQF_HIGHLIGHTTEXT);
  Tags^[5]:=TagItem(RTGS_AllowEmpty,long(true));
  Tags^[6]:=TagItem(TAG_END,0);

  Buf:="";
  ret:=rtGetStringA(Buf,127,"Enter anything",Nil,Tags);

  IF ret=0 THEN BEGIN
    HStr:="What's up?";
    Tags^[0]:=TagItem(RTEZ_ReqTitle,long(HStr));
    Tags^[1]:=TagItem(TAG_END,0);
    ret:=rtEZRequestA("You selected 'Abort'."\10"Sick in brain, eh??",
                      "Excuse me",Nil,Nil,Tags);
  END;

  ret:=rtEZRequestA ('NUMBER 3:'\10'Notification requester, the requester'\10'you have been using all the time!'\10'function: rtEZRequestA()',
                     "Show me more", Nil, Nil, Nil);

  ret:=rtEZRequestA ('Simplest usage: some body text and'\10'a single centered gadget.',
                     "Got it", Nil, Nil, Nil);

  ret:=rtEZRequestA ('You can also use two gadgets to'\10'ask the user something.'\10'Do you understand?',
                     "Of course|Not really", Nil, Nil, Nil);

  while ret=0 do BEGIN
    ret:=rtEZRequestA ('You are not one of the brightest, are you?'\10'We will try again...',
                       "Ok", Nil, Nil, Nil);
    ret:=rtEZRequestA ('You can also use two gadgets to'\10'ask the user something.'\10'Do you understand?',
                       "Of course|Not really...", Nil, Nil, Nil)
  END;

  ret:=rtEZRequestA ("Great, we'll continue THEN.", "Fine", Nil, Nil, Nil);

  ret:=rtEZRequestA ('You can also put up a requester with'\10'three choices.'\10'How do you like the demo so far ?',
                     "Great|So so|Rubbish", Nil, Nil, Nil);

  case ret of
    0: ret:=rtEZRequestA ('Too bad, I really hoped you'\10'would like it better.',
                          "So what", Nil, Nil, Nil);
    1: ret:=rtEZRequestA ('I am glad you like it so much.','Fine', Nil, Nil, Nil);
    2: ret:=rtEZRequestA ('Maybe IF you run the demo again'\10'you will REALLY like it.',
                          "Perhaps", Nil, Nil, Nil);
  END;

  HStr2:="The number of responses is not limited to three"+chr(10)+
          "as you can see. The gadget are labeled with the"+chr(10)+
          "Returncodes from rtEZRequestA()."+chr(10)+chr(10)+
          "The »3« is printed in bold face, that means that"+chr(10)+
          "it is default response which will be choosen by"+chr(10)+
          "pressing the »Return« key.";

  Tags^[0]:=TagItem(RTEZ_DefaultResponse,3);
  Tags^[1]:=TagItem(TAG_END,0);

  ret :=rtEZRequestA (^HStr2," 1 | 2 | 3 | 4 | 5 | 0 ", Nil, Nil,Tags);

  Args[0]:=long(ret);
  ret:=rtEZRequestA('You picked %ld',"How true",Nil,^Args[0],Nil);

  Tags^[0]:=TagItem(RT_Underscore,long('_'));;
  Tags^[1]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA('New for Rel. 2.0 of ReqTools(V38) is'\10'the possibility to define characters in the'\10'buttons as keyboard shortcuts.'\10'As you can see these characters are underlined.',
                    "_Great|_Fantastic|_Swell|Oh _Boy",Nil, Nil, Tags);

  ret:=rtEZRequestA('Note that pressing shift while still holding'\10'down the key will cancel the shortcut.',
                    "_Great|_Fantastic|_Swell|Oh _Boy",Nil, Nil, Tags);

  Tags^[1]:=TagItem(RTEZ_Flags,EZREQF_CENTERTEXT);
  Tags^[2]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA("Of cource you can also center"\10"the body text in the requester."\10"Simply by setting sum flags.",
                    "_Yeah|_Great",Nil,Nil,Tags);

  Tags^[1]:=TagItem(TAG_END,0);
  Args[0]:=5;
  HStr:="five";
  Args[1]:=long(HStr);

  ret:=rtEZRequestA ("You may also use C-style formatting codes in the body text."\10"Like this:"\10\10"The number %%ld is written %%s. will give:"\10\10"The number %ld is written %s."\10\10"IF you also pass '5' and 'five' to rtEZRequestA().",
                     "_Proceed", Nil, ^Args[0], Tags);

  Tags^[0]:=TagItem(RT_IDCMPFlags,DISKINSERTED);
  Tags^[1]:=TagItem(RT_Underscore,long('_'));
  Tags^[2]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA ("It is also possible to pass extra IDCMP flags"\10"that will satisfy rtEZRequestA(). This requester"\10"has had DISKINSERTED passed to it."\10"(Try inserting a disk).",
                     "_Continue", Nil, Nil, Tags);

  IF ret=DISKINSERTED THEN
    ret:=rtEZRequestA("You inserted a disk.","I did",Nil,Nil,Nil)
  ELSE
    ret:=rtEZRequestA("You used the 'Continue' gadget"\10"to satisfy the requester.",
                      "I did",Nil,Nil,Nil);

  Tags^[0]:=TagItem(RT_ReqPos,REQPOS_TOPLEFTSCR);
  Tags^[1]:=TagItem(RT_Underscore,long('_'));
  Tags^[2]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA("Finally, it is possible to specify the position"\10"of the requester."\10"E.g. at the top left of the screen, like this."\10"This works for all requesters, not just rtEZRequestA()!",
                    "_Amazing",Nil,Nil,Tags);

  Tags^[0]:=TagItem(RT_ReqPos,REQPOS_CENTERSCR);
  Tags^[2]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA("Alternatively, you can center the"\10"requester on the screen."\10"Check out 'reqtools.doc' for all the possibilities.",
                    "_Yo, I'll do that",Nil,Nil,Tags);

  Tags^[0]:=TagItem(RT_Underscore,long('_'));
  Tags^[1]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA("NUMBER 4:"\10"File requester"\10"function: rtFileRequest()",
                    "_Demonstrate",Nil,Nil,Tags);

{------------------------------------------------------------------------}
{                       *** File Requester ***                           }
{------------------------------------------------------------------------}


  FileReq:=ptr(rtAllocRequestA(RT_FileReq, Nil));

  IF FileReq<>Nil THEN BEGIN
    FName:="";
    ret:=0;
    ret:=rtFileRequestA(FileReq,FName,"Pick a file",Nil);
    IF ret<>0 THEN BEGIN
      Args[0]:=long(FName);
      Args[1]:=long(FileReq^.Dir);
      ret:=rtEZRequestA ("You picked the file:"\10"%s"\10"in directory:"\10"%s",
                         "Right", Nil, ^Args[0], Nil);
    END ELSE
      ret:=rtEZRequestA ("You didn't pick a file.", "No", Nil, Nil, Nil);
    rtFreeRequest(FileReq);
  END ELSE
    ret:=rtEZRequestA ("Out of memory!", "Oh boy!", Nil, Nil, Nil);

  ret:=rtEZRequestA("You can also change the height"\10"of the file requester",
                    "Wow",Nil,Nil,Nil);

  FileReq:=ptr(rtAllocRequestA(RT_FILEREQ,Nil));

  Tags^[0]:=TagItem(RTFI_Height,250);
  Tags^[1]:=TagItem(TAG_END,0);

  IF FileReq<>Nil THEN BEGIN
    FName:="";
    ret:=0;
    ret:=rtFileRequestA(FileReq,FName,"Pick a file",Tags);
    IF ret<>0 THEN BEGIN
      Args[0]:=long(FName);
      Args[1]:=long(FileReq^.Dir);
      ret:=rtEZRequestA ("You picked the file:"\10"%s"\10"in directory:"\10"%s",
                         "Right",Nil,^Args[0],Nil);
    END ELSE
      ret:=rtEZRequestA ("You didn't pick a file.","No",Nil,Nil,Nil);
    rtFreeRequest(FileReq);
  END ELSE
    ret:=rtEZRequestA("Out of memory!","Oh boy!",Nil,Nil,Nil);

  ret:=rtEZRequestA("The file requester can be used"\10"as a directory requester as well."\10"You can even change the text"\10"in the 'OK'-Gadget",
                    "Let's see that",Nil,Nil,Tags);

  FileReq:=ptr(rtAllocRequestA(RT_FileReq,Nil));

  Tags^[0]:=TagItem(RTFI_Flags,FREQF_NOFILES);
  HStr:="_Remove";
  Tags^[1]:=TagItem(RTFI_OkText,long(HStr));
  Tags^[2]:=TagItem(RT_UnderScore,long('_'));
  Tags^[3]:=TagItem(TAG_END,0);

  IF FileReq<>Nil THEN BEGIN
    ret:=0;
    ret:=rtFileRequestA(FileReq,FName,"Remove a directory",Tags);
    Args[0]:=long(FileReq^.Dir);
    IF ret=1 THEN
      ret:=rtEZRequestA ("You picked the directory: %s",
                         "Right",Nil,^Args[0],Nil)
    ELSE
      ret:=rtEZRequestA ("You didn't pick a directory.","No",Nil,Nil,Nil);
    rtFreeRequest(FileReq);
  END ELSE
    ret:=rtEZRequestA ("Out of memory!","Oh boy!",Nil,Nil,Nil);


  ret:=rtEZRequestA("You can also use it as a Disk-requester","Perfect",
                    Nil,Nil,Nil);
  FileReq:=ptr(rtAllocRequestA(RT_FILEREQ,Nil));

  Tags^[0]:=TagItem(RTFI_VolumeRequest,VREQF_ALLDISKS or VREQF_NOASSIGNS);
  HStr:="Un_mount";
  Tags^[1]:=TagItem(RTFI_OkText,long(HStr));
  Tags^[2]:=TagItem(RT_UnderScore,long('_'));
  Tags^[3]:=TagItem(TAG_END,0);

  IF FileReq<>Nil THEN BEGIN
    ret:=0;
    ret:=rtFileRequestA(FileReq, FName, "Unmount a device",Tags);
    Args[0]:=long(FileReq^.Dir);
    IF ret=1 THEN
      ret:=rtEZRequestA("You picked the device: %s","Right",Nil,^Args[0],Nil)
    ELSE
      ret:=rtEZRequestA("You didn't pick a device.","Ooops",Nil,Nil,Nil);
    rtFreeRequest (FileReq);
  END ELSE
    ret:=rtEZRequestA("Out of memory!","Oh boy!",Nil,Nil,Nil);


{------------------------------------------------------------------------}
{                       *** Font Requester ***                           }
{------------------------------------------------------------------------}

  ret:=rtEZRequestA("NUMBER 5:"\10"Font requester"\10"function: rtFontRequest()",
                    "Show me !",Nil,Nil,Nil);

  FontReq:=ptr(rtAllocRequestA(RT_FONTREQ,Nil));

  IF FontReq<>Nil THEN BEGIN
    FontReq^.Flags:=FREQF_STYLE or FREQF_COLORFONTS;
    ok:=rtFontRequestA(FontReq,"Selcet a font",Nil);
    IF ok THEN BEGIN
      Args[0]:=long(FontReq^.Attr.ta_Name);
      Args[1]:=long(FontReq^.Attr.ta_YSize);
      ret:=rtEZRequestA("You picked the font:"\10"%s"\10"with size:"\10"%ld Pixels",
                        "That's true",Nil,^Args[0],Nil);
    END ELSE
      ret:=rtEZRequestA("Wasn't there a font you liked ?","Nope",Nil,Nil,Nil);
    rtFreeRequest(FontReq);
  END ELSE
    ret:=rtEZRequestA("Out of memory!","Oh boy!",Nil,Nil,Nil);


{------------------------------------------------------------------------}
{                     *** Screenmode Requester ***                       }
{------------------------------------------------------------------------}

  ret:=rtEZRequestA("NUMBER 6:"\10"ScreenMode requester"\10"function: rtScreenModeRequestA()",
                    "Proceed",Nil,Nil,Nil);

  ScrnReq:=ptr(rtAllocRequestA(RT_SCREENMODEREQ,Nil));
  IF ScrnReq<>Nil THEN
   BEGIN
    Tags^[0]:=TagItem(RTSC_Flags,SCREQF_DEPTHGAD or SCREQF_SIZEGADS or
                          SCREQF_AUTOSCROLLGAD or SCREQF_OVERSCANGAD);
    Tags^[1]:=TagItem(RT_UnderScore,long('_'));
    Tags^[2]:=TagItem(TAG_END,0);

    ok:=rtScreenModeRequestA(ScrnReq,"Pick a screenmode",Tags);

    Args[0]:=long(ScrnReq^.DisplayID);
    Args[1]:=long(ScrnReq^.DisplayWidth);
    Args[2]:=long(ScrnReq^.DisplayHeight);
    Args[3]:=long(ScrnReq^.DisplayDepth);
    Args[4]:=long(ScrnReq^.OverscanType);
    IF (Boolean(ScrnReq^.AutoScroll)) THEN BEGIN
      HStr:="On";
      Args[5]:=long(HStr)
    END ELSE BEGIN
      HStr:="Off";
      Args[5]:=long(HStr);
    END;
    IF ok THEN
      ret:=rtEZRequestA("You picked this mode:"\10"ModeID   : 0x%lx"\10"Size     : %ld x %ld"\10"Depth    : %ld"\10"Overscan : %ld"\10"AutoScroll %s",
                        "Right",Nil,^Args[0],Nil)
    ELSE
      ret:=rtEZRequestA("You didn't pick a screen mode.","Sorry",Nil,Nil,Nil);
    rtFreeRequest(ScrnReq);
  END ELSE
    ret:=rtEZRequestA("Out of memory!","Oh boy!",Nil,Nil,Nil);


{------------------------------------------------------------------------}
{                      *** Palette Requester ***                         }
{------------------------------------------------------------------------}

  Tags^[0]:=TagItem(RT_Underscore,long('_'));
  Tags^[1]:=TagItem(TAG_END,0);

  ret:=rtEZRequestA ("NUMBER 7:"\10"Palette requester"\10"function: rtPaletteRequest()",
                     "_Proceed",Nil,Nil,Tags);

  Col:=rtPaletteRequestA("Change palette",Nil,Nil);
  IF Col=-1 THEN
    ret:=rtEZRequestA ("You canceled."\10"No nice colors to be picked ?",
                       "_Nah",Nil,Nil,Tags)
  ELSE
    ret:=rtEZRequestA ("You picked color number %ld.","_Sure did",
                       Nil,^Col,Tags);


  ret:=rtEZRequestA("Finishing the Demo... Hope ya enjoyed it.",
                    "Really _Great !",Nil,Nil,Tags);

  CloseSomeLibs;
END.

