program demo;

Uses Exec,reqtools,Init,Intuition,utility,AmigaDos;

const 	DISKINSERTED=$00008000;

var		filereq: prtFileRequester;
		fontreq: prtFontRequester;
		inforeq: prtReqInfo;
		scrnreq: prtScreenModeRequester;
		filterhook, font_filterhook: tHook;
		ret2,buffer2: String;
		buffer: Pointer;
		filename: String;
		files: String;
		ptr,longnum: Pointer;
		ret: LongInt;
		color: LongInt;
		name: String;
		mytag: preqtaglist;
		values: argarray;
		ff: tFileInfoBlock;
		tt: pTextAttr;
			
function filterfunc(Hook: tHook; filereq: prtFileRequester; fib: tFileInfoBlock): BOOL;
var naam:String;
begin
{	naam:=Char(@fib^.fib_FileName);}
{	writeln(naam);}
	filterfunc:=TRUE;
end;

function font_filterfunc(Hook: tHook; fontreq: prtFontRequester; textatt: pTextAttr): BOOL;
begin
{	writeln(textatt^.ta_Name^);}
	font_filterfunc:=TRUE;
end;

begin
	ReqToolsBase:=pReqToolsBase(OpenLibrary(REQTOOLSNAME,REQTOOLSVERSION));
	if(ReqToolsBase=NIL) then 
		begin
			writeln('You need reqtools.library V38 or higher!');
			writeln;
			writeln('Please install it in your Libs: directory.');
			exit;
		end;
	writeln('reqtools Demo');
	writeln;
	writeln('ŻŻŻŻŻŻŻŻŻŻŻŻŻ');
	writeln('This program demonstrates what ''reqtools.library'' ');
	writeln('has to offer.');

	Delay (60);
	ret:=rtEZRequestA('''reqtools.library'' offers several' + chr(10) + 'different types of requesters:',
					 'Let''s see them', NIL, NIL, NIL);

	ret:=rtEZRequestA('NUMBER 1:' + chr(10) + 'The larch',
					 'Be serious!', NIL, NIL, NIL);

	ret:=rtEZRequestA('NUMBER 1:' + chr(10) + 'String requester' + chr(10) + 'function: rtGetString'+'('+')',
					 'Show me', NIL, NIL, NIL);

	buffer:=CstrConstPtr('Type in anything');
	ret:=rtGetStringA (buffer, 127, 'Enter anything:', NIL, NIL);
	values[0]:=LongInt(buffer);
	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, @values[0], NIL);
		
	buffer:=CstrConstPtr('It is possible to have several responses');
	new(mytag);
	mytag^[0].ti_Tag:=RTGS_GadFmt;
	mytag^[0].ti_Data:=LongInt(CstrConstPtr(' OK | New 2.0 feature | Cancel '));
	mytag^[1].ti_Tag:=TAG_END;

	ret:=rtGetStringA (buffer, 127, '* New for ReqTools 2.0 *',
				NIL , mytag);

	ret:=rtEZRequestA ('NUMBER 2:' + chr(10) + 'Number requester' + chr(10) + 'function: rtGetLong' + '(' + ')',
					 'Show me', NIL, NIL, NIL);

	mytag^[0].ti_Tag:=RTGL_ShowDefault;
	mytag^[0].ti_Data:=LongInt(FALSE);
	mytag^[1].ti_Tag:=TAG_END;
	
	ret:=rtGetLongA (@longnum, 'Enter a number:', NIL, mytag);

	values[0]:=LongInt(longnum);

	if(ret=0) then 
		ret:=rtEZRequestA('You entered nothing','I''m sorry', NIL, NIL, NIL)
	else
		ret:=rtEZRequestA('The number You entered was: ' + chr(10) + '%ld' ,
					 'So it was', NIL, @values[0], NIL);

	mytag^[0].ti_Tag:=RTGL_ShowDefault;
	mytag^[0].ti_Data:=LongInt(FALSE);
	mytag^[1].ti_Tag:=RTGL_GadFmt;
	mytag^[1].ti_Data:=LongInt(CstrConstPtr('Ok|V38 feature|Cancel'));
	mytag^[2].ti_Tag:=TAG_END;

	ret:=rtGetLongA (@longnum, '* New for ReqTools 2.0 *', NIL, mytag);

	ret:=rtEZRequestA ('NUMBER 3:' + chr(10) + 'Notification requester, the requester' + chr(10) +
					 'you''ve been using all the time!' + chr(10) + 'function: rtEZRequestA'+'('+')',
					 'Show me more', NIL, NIL, NIL);

	ret:=rtEZRequestA ('Simplest usage: some body text and' + chr(10) + 'a single centered gadget.',
					 'Got it', NIL, NIL, NIL);

	ret:=rtEZRequestA ('You can also use two gadgets to' + chr(10) +
								'ask the user something.' + chr(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?' + chr(10) +
						 'We''ll try again...','Ok', NIL, NIL, NIL);
		ret:=rtEZRequestA ('You can also use two gadgets to' + chr(10) +
								'ask the user something.' + chr(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' + chr(10) +
								'three choices.' + chr(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' + chr(10) + 
									'would like it better.',
							 'So what', NIL, NIL, NIL);
		1:
			ret:=rtEZRequestA ('I''m glad you like it so much.','Fine', NIL, NIL, NIL);
		2:
			ret:=rtEZRequestA ('Maybe if you run the demo again' + chr(10) +
							 'you''ll REALLY like it.',
							 'Perhaps', NIL, NIL, NIL);
		end;
		
	mytag^[0].ti_Tag:=RTEZ_DefaultResponse;
	mytag^[0].ti_Data:=4;
	mytag^[1].ti_Tag:=TAG_END;

	ret :=rtEZRequestA ('The number of responses is not limited to three' + chr(10) +
								  'as you can see.  The gadgets are labeled with' + chr(10) +	
								  'the "Return" code from rtEZRequestA().' + chr(10) +
								  'Pressing "Return" will choose 4, note that' + chr(10) +
								  '4''s button text is printed in boldface.',
								  '1|2|3|4|5|0', NIL, NIL,
								  mytag);
	
	values[0]:=LongInt(ret);
	
	ret:=rtEZRequestA ('You picked ' + '%ld', 'How true', NIL, @values[0], NIL);

	mytag^[0].ti_Tag:=RT_Underscore;
	mytag^[0].ti_Data:=LongInt('_');
	mytag^[1].ti_Tag:=TAG_END;

	ret:=rtEZRequestA ('New for Release 2.0 of ReqTools (V38) is' + chr(10) +
						  'the possibility to define characters in the' + chr(10) +
						  'buttons as keyboard shortcuts.' + chr(10) + 
						  'As you can see these characters are underlined.' + chr(10) +
						  'Note that pressing shift while still holding' + chr(10) + 
						  'down the key will cancel the shortcut.',
						  '_Great|_Fantastic|_Swell|Oh _Boy',
						  NIL, NIL, mytag);

	values[0]:=5;
	values[1]:=LongInt(CstrConstPtr('five'));
	
	ret:=rtEZRequestA ('You may also use C-style formatting codes in the body text.' + chr(10) +
		'Like this:' + chr(10) + chr(10) + 
		'The number %%ld is written %%s. will give:' + chr(10) + chr(10) +
		'The number %ld is written %s.' + chr(10) + chr(10)+
		'if you also pass ''5'' and ''five'' to rtEZRequestA'+'('+')'+'.',
		'_Proceed', NIL, @values[0], mytag);	
	
		mytag^[0].ti_Tag:=RT_IDCMPFlags;
		mytag^[0].ti_Data:=DISKINSERTED;
		mytag^[1].ti_Tag:=RT_Underscore;
		mytag^[1].ti_Data:=LongInt('_');
		mytag^[2].ti_Tag:=TAG_END;

		ret:=rtEZRequestA ('It is also possible to pass extra IDCMP flags' + chr(10) +
							   'that will satisfy rtEZRequestA'+'('+')'+'. This requester' + chr(10) +
							   'has had DISKINSERTED passed to it.' + chr(10) +
							   '('+'Try inserting a disk'+')'+'.',
							   '_Continue', NIL, NIL, mytag);

	if ((ret=DISKINSERTED)) then
		ret:=rtEZRequestA ('You inserted a disk.', 'I did', NIL, NIL, NIL)
	else
		ret:=rtEZRequestA ('You used the ''Continue'' gadget' + chr(10) + 
						 'to satisfy the requester.', 'I did', NIL, NIL, NIL);

	mytag^[0].ti_Tag:=RT_ReqPos;
	mytag^[0].ti_Data:=LongInt(REQPOS_TOPLEFTSCR);
	mytag^[1].ti_Tag:=RT_Underscore;
	mytag^[1].ti_Data:=LongInt('_');
	mytag^[2].ti_Tag:=TAG_END;

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

	mytag^[0].ti_Tag:=RT_ReqPos;
	mytag^[0].ti_Data:=LongInt(REQPOS_CENTERSCR);
	mytag^[1].ti_Tag:=TAG_END;

	ret:=rtEZRequestA ('Alternatively, you can center the' + chr(10) +
						  'requester on the screen.' + chr(10) +
						  'Check out ''reqtools.doc'' for all the possibilities.',
						  'I''ll do that', NIL, NIL,
						  mytag);

	mytag^[0].ti_Tag:=RT_Underscore;
	mytag^[0].ti_Data:=LongInt('_');
	mytag^[1].ti_Tag:=TAG_END;

	ret:=rtEZRequestA ('NUMBER 4:' + chr(10) + 'File requester' + chr(10) +
						  'function: rtFileRequest'+'('+')',
						  '_Demonstrate', NIL, NIL, mytag);

	filereq:=Pointer(rtAllocRequestA (RT_FILEREQ, NIL));
	
	if (filereq<>NIL) then
	begin
{		filterhook.h_Entry^ := LongInt(filterfunc(filterhook,filereq,ff));
		mytag^[0].ti_Tag:=RTFI_FilterFunc;
		mytag^[0].ti_Data:=LongInt(@filterhook);
		mytag^[1].ti_Tag:=TAG_END;
}		
		filename := '';
		ret:=rtFileRequestA (filereq, @filename, 'Pick a file', NIL);
		if(ret<>0) then
			begin
				values[0]:=LongInt(@filename);
				values[1]:=LongInt(@filereq^.Dir^);
				ret:=rtEZRequestA ('You picked the file:' + #10 +
				'%s' + #10 + 'in directory:' + #10 + '%s','Right', NIL, @values[0], NIL)
			end
		else
			ret:=rtEZRequestA ('You didn''t pick a file.', 'No', NIL, NIL, NIL);

		ret:=rtFreeRequest(filereq)
	end
	else
		ret:=rtEZRequestA ('Out of memory!', 'Oh boy!', NIL, NIL, NIL);

	ret:=rtEZRequestA ('The file requester can be used' + chr(10) +
						  'as a directory requester as well.',
						  'Let''s _see that', NIL, NIL, mytag);

	filereq := Pointer(rtAllocRequestA (RT_FILEREQ, NIL));
	if (filereq<>NIL) then
		begin
			mytag^[0].ti_Tag:=RTFI_Flags;
			mytag^[0].ti_Data:=FREQF_NOFILES;
			mytag^[1].ti_Tag:=TAG_END;

			ret:=rtFileRequestA (filereq, @filename, 'Pick a directory',mytag);
			values[0]:=LongInt(@filereq^.Dir^);
			if(ret=1) then
				ret:=rtEZRequestA ('You picked the directory:' + chr(10) + '%s',
							 'Right', NIL, @values[0], NIL)
			else
				ret:=rtEZRequestA ('You didn''t pick a directory.', 'No', NIL, NIL, NIL);

			ret:=rtEZRequestA ('You can also change the Height of the requester', 'Wow', NIL, NIL, NIL);

			mytag^[0].ti_Tag:=RTFI_Flags;
			mytag^[0].ti_Data:=FREQF_NOFILES;
			mytag^[1].ti_Tag:=RTFI_Height;
			mytag^[1].ti_Data:=LongInt(250);
			mytag^[2].ti_Tag:=TAG_END;

			ret:=rtFileRequestA (filereq, @filename, 'Pick a directory',mytag);
			values[0]:=LongInt(@filereq^.Dir^);
			if(ret=1) then
				ret:=rtEZRequestA ('You picked the directory:' + chr(10) + '%s',
							 'Right', NIL, @values[0], NIL)
			else
				ret:=rtEZRequestA ('You didn''t pick a directory.', 'No', NIL, NIL, NIL);

			ret:=rtEZRequestA ('You can also change the OK_GADGET', 'Great', NIL, NIL, NIL);

			mytag^[0].ti_Tag:=RTFI_Flags;
			mytag^[0].ti_Data:=FREQF_NOFILES;
			mytag^[1].ti_Tag:=RTFI_OkText;
			mytag^[1].ti_Data:=LongInt(CstrConstPtr('_Remove'));
			mytag^[2].ti_Tag:=RT_UnderScore;
			mytag^[2].ti_Data:=LongInt('_');
			mytag^[3].ti_Tag:=TAG_END;

			ret:=rtFileRequestA (filereq, @filename, 'Remove a directory',mytag);
			values[0]:=LongInt(@filereq^.Dir^);
			if(ret=1) then
				ret:=rtEZRequestA ('You picked the directory:' + chr(10) + '%s',
							 'Right', NIL, @values[0], NIL)
			else
				ret:=rtEZRequestA ('You didn''t pick a directory.', 'No', NIL, NIL, NIL);

			ret:=rtFreeRequest(filereq);
			filereq := Pointer(rtAllocRequestA (RT_FILEREQ, NIL));			
			ret:=rtEZRequestA ('You can also use it as a Disk-requester', 'Perfect', NIL, NIL, NIL);

			mytag^[0].ti_Tag:=RTFI_VolumeRequest;
			mytag^[0].ti_Data:=VREQF_ALLDISKS|VREQF_NOASSIGNS;
			mytag^[1].ti_Tag:=RTFI_OkText;
			mytag^[1].ti_Data:=LongInt(CstrConstPtr('Un_Mount'));
			mytag^[2].ti_Tag:=RT_UnderScore;
			mytag^[2].ti_Data:=LongInt('_');
			mytag^[3].ti_Tag:=TAG_END;

			ret:=rtFileRequestA (filereq, @filename, 'Unmount a device',mytag);
			values[0]:=LongInt(@filereq^.Dir^);
			if(ret=1) then
				ret:=rtEZRequestA ('You picked the device:' + chr(10) + '%s',
							 'Right', NIL, @values[0], NIL)
			else
				ret:=rtEZRequestA ('You didn''t pick a device.', 'No', NIL, NIL, NIL);
		ret:=rtFreeRequest (filereq)
		end
	else
		ret:=rtEZRequestA ('Out of memory!', 'Oh boy!', NIL, NIL, NIL);

	ret:=rtEZRequestA ('NUMBER 5:' + chr(10) + 'Font requester' + chr(10) +
						  'function: rtFontRequest'+'('+')',
						  'Show', NIL, NIL, NIL);

	fontreq := Pointer(rtAllocRequestA (RT_FONTREQ, NIL));
	if (fontreq<>NIL) then
	begin
		fontreq^.Flags := FREQF_STYLE|FREQF_COLORFONTS;
{		font_filterhook.h_Entry^ := LongInt(font_filterfunc(font_filterhook,fontreq,tt));
		mytag^[0].ti_Tag:=RTFO_FilterFunc;
		mytag^[0].ti_Data:=LongInt(@font_filterhook);
		mytag^[1].ti_Tag:=TAG_END;
}		
		ret:=rtFontRequestA (fontreq, 'Pick a font', NIL);
		if(ret<>0) then
		begin
			values[0]:=LongInt(fontreq^.Attr.ta_Name);
			values[1]:=LongInt(fontreq^.Attr.ta_YSize);
			ret:=rtEZRequestA ('You picked the font:' + #10 +
					'%s' + #10 + 'with size:' + #10 +
					'%ld','Right', NIL, @values[0], NIL)
		end
		else
			ret:=rtEZRequestA ('You didn''t pick a font','I know', NIL, NIL, NIL);
		ret:=rtFreeRequest (fontreq);
	end
	else 		ret:=rtEZRequestA ('Out of memory!', 'Oh boy!', NIL, NIL, NIL);

	inforeq := Pointer(rtAllocRequestA (RT_REQINFO, NIL));
	if (inforeq<>NIL) then
	begin
		inforeq^.Flags := EZREQF_CENTERTEXT;
		ret:=rtEZRequestA ('With rtAllocRequestA'+' ('+' RT_REQINFO '+', NIL )'+ #10 +
						   'you can center the text in the requester', 'Got it', inforeq, NIL, NIL);
		ret:=rtFreeRequest (inforeq);
	end
	else 		ret:=rtEZRequestA ('Out of memory!', 'Oh boy!', NIL, NIL, NIL);

	ret:=rtEZRequestA ('NUMBER 6:' + chr(10) + 'ScreenMode requester' + chr(10) +
						  'function: rtScreenModeRequestA'+'('+')',
						  'Proceed', NIL, NIL, NIL);

	scrnreq := Pointer(rtAllocRequestA (RT_SCREENMODEREQ, NIL));
	if (scrnreq<>NIL) then
	begin
		mytag^[0].ti_Tag:=RTSC_Flags;
		mytag^[0].ti_Data:=SCREQF_DEPTHGAD|SCREQF_SIZEGADS|SCREQF_AUTOSCROLLGAD|SCREQF_OVERSCANGAD;
		mytag^[1].ti_Tag:=RT_UnderScore;
		mytag^[1].ti_Data:=LongInt('_');
		mytag^[2].ti_Tag:=TAG_END;

		ret:=rtScreenModeRequestA ( scrnreq, 'Pick a screenmode', mytag);
		values[0]:=LongInt(scrnreq^.DisplayID);
		values[1]:=LongInt(scrnreq^.DisplayWidth);
		values[2]:=LongInt(scrnreq^.DisplayHeight);
		values[3]:=LongInt(scrnreq^.DisplayDepth);
		values[4]:=LongInt(scrnreq^.OverscanType);
		if (Boolean(scrnreq^.AutoScroll)) then
			values[5]:=LongInt(CstrConstPtr('On'))
		else values[5]:=LongInt(CstrConstPtr('Off'));

		if(ret=1) 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, @values[0], NIL)
		else
			ret:=rtEZRequestA ('You didn''t pick a screen mode.', 'Sorry', NIL, NIL, NIL);
		ret:=rtFreeRequest (scrnreq);
	end
	else
		ret:=rtEZRequestA ('Out of memory!', 'Oh boy!', NIL, NIL, NIL);

	mytag^[0].ti_Tag:=RT_Underscore;
	mytag^[0].ti_Data:=LongInt('_');
	mytag^[1].ti_Tag:=TAG_END;

	ret:=rtEZRequestA ('NUMBER 7:' + chr(10) + 'Palette requester' + chr(10) +
						  'function: rtPaletteRequest'+'('+')',
						  '_Proceed', NIL, NIL, mytag);

	color := rtPaletteRequestA ('Change palette', NIL, NIL);
	if (color = -1) then
		ret:=rtEZRequestA ('You canceled.' + chr(10) + 'No nice colors to be picked ?',
						 'Nah', NIL, NIL, NIL)
	else
		ret:=rtEZRequestA ('You picked color number ' + '%ld.', 'Sure did',
						 NIL, @color, NIL);

	CloseLibrary (pLibrary(ReqToolsBase));
	writeln;
	writeln ('Finished, hope you enjoyed the demo');
	writeln;

	exit;

end.
