home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
libraries
/
fileio_463
/
c
/
customlist.c
next >
Wrap
C/C++ Source or Header
|
1991-02-08
|
9KB
|
335 lines
/*************************************************************************
This program opens and utilizes the requester.library in order to use
the new SPECIAL_REQ flag. This flag allows us to display a list of
strings in a requester with all the features of the FileIO requester.
Because version 0 of the library did not support this feature, but version
1.5 now does, we must open the library with version #1. Old applications
that do not know about SPECIAL_REQ will still work with this version of
the library. It is backward compatible as far as the disk IO features are
concerned.
NOTE: Under version 1.B of the requester.library, custom strings are now
limited to 191 characters instead of 29.
If running this program from the CLI and you specify any argument on the
command (i.e. 1> TestFileIO blort ), then the window will open on a hires
screen. You can then see what the requester looks like in hires.
Manx compile:
cc +p CustomList.c
ln CustomList.o -lcl32
**************************************************************************/
#include <functions.h>
#include <exec/types.h>
#include <exec/io.h>
#include <stdio.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include "FileIO.h"
/* extern long GetMsg(), OpenWindow(), IoErr(), OpenLibrary(); */
/* === System Global Variables ========================================== */
struct IntuitionBase *IntuitionBase = 0L;
struct GfxBase *GfxBase = 0L;
struct DosLibrary *DosBase = 0L;
struct RequesterBase *RequesterBase = 0L;
struct FileIO *myFileIO = 0L;
struct Window *myWindow = 0L;
struct Screen *myScreen = 0L;
ULONG argcount; /* Saves argc from main(). argcount==0, then run from WB. */
struct TextAttr topaz80_font;
VOID TestFileIO();
struct NewScreen NewFileIOScreen =
{
0, 0, /* LeftEdge, TopEdge */
640, 400, /* Width, Height */
2, /* Depth */
0, 1, /* Detail/BlockPens */
HIRES | LACE, /* ViewPort Modes (must set/clear HIRES as needed) */
CUSTOMSCREEN,
&topaz80_font, /* Font */
(UBYTE *)"Example FileIO Program's Screen",
0L, /* Gadgets */
0L, /* CustomBitMap */
};
struct NewWindow NewFileIOWindow =
{
168, 30, /* LeftEdge, TopEdge */
303, 145, /* Width, Height */
-1, -1, /* Detail/BlockPens */
MENUPICK | MOUSEBUTTONS | CLOSEWINDOW,
/* IDCMP Flags */
WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | SMART_REFRESH |
WINDOWCLOSE | ACTIVATE | NOCAREREFRESH,
/* Window Specification Flags */
0L, /* FirstGadget */
0L, /* Checkmark */
(UBYTE *)"FileIO SPECIAL_REQ Example", /* WindowTitle */
0L, /* Screen */
0L, /* SuperBitMap */
303, 145, /* MinWidth, MinHeight */
600, 200, /* MaxWidth, MaxHeight */
WBENCHSCREEN,
};
struct IntuiText itxt[] = {
{0,1,JAM1,19,1,NULL,(UBYTE *)"Multiple"},
{0,1,JAM1,19,1,NULL,(UBYTE *)"Handler"}, };
struct MenuItem mi[] = {
{&mi[1],0, 0,91,10,CHECKIT | MENUTOGGLE | ITEMTEXT | ITEMENABLED | HIGHCOMP,\
NULL,(APTR)&itxt[0],NULL,NULL},
{NULL,0, 10,91,10,CHECKIT | MENUTOGGLE | ITEMTEXT | ITEMENABLED | HIGHCOMP,\
NULL,(APTR)&itxt[1],NULL,NULL},};
struct Menu myMenu = {NULL,0,0,72,0,MENUENABLED, "Project",&mi[0]};
BOOL myFunc();
struct HandlerBlock hblock = {
/* APTR StartUpCode; */ (APTR)myFunc,
/* APTR DiskInsertedCode; */ 0,
/* APTR GadgetCode; */ 0,
/* APTR KeyCode; */ 0,
/* APTR MouseMoveCode; */ 0 };
BOOL information();
UBYTE button_text[] = {" About"};
/************************ MAIN ROUTINE *****************************/
VOID main(argc, argv)
LONG argc;
char **argv;
{
LONG class;
USHORT code;
struct IntuiMessage *message;
BOOL end;
argcount = argc;
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", 0L)))
exit_program("FileIO Demo: No intuition library. \n", 1L);
if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L)))
exit_program("FileIO Demo: No graphics library. \n", 2L);
/* NOW OPEN THE REQUESTER LIBRARY, Version 1 */
if (!(RequesterBase = (struct RequesterBase *)OpenLibrary("requester.library", 1L)))
exit_program("FileIO Demo: No requester library. \n", 4L);
if (argv)
{
/* OK, we started from CLI */
if (argc > 1)
{
if (myScreen = OpenScreen(&NewFileIOScreen))
{
NewFileIOWindow.Screen = myScreen;
NewFileIOWindow.Type = CUSTOMSCREEN;
}
}
}
if (!(myWindow = (struct Window *) OpenWindow( &NewFileIOWindow ) ))
exit_program("FileIO Demo: Null Window.\n", 5L);
if (!(myFileIO = GetFileIO() ))
exit_program("FileIO Demo: No FileIO 1.\n", 6L);
/* Set up the XY co-ordinates where the requester should open */
myFileIO->X = 6;
myFileIO->Y = 11;
/* Set default colors and DrawMode */
myFileIO->DrawMode = JAM2;
myFileIO->PenA = 1;
myFileIO->PenB = 0;
myFileIO->FileIOText = button_text;
myFileIO->FileIORoutine = (APTR)information; /* pointer to function */
SetFlag(myFileIO->Flags, SPECIAL_REQ );
/* pretty easy to set up, eh? */
SetMenuStrip( myWindow, &myMenu );
/* These 2 lines are to demo using the CUSTOM_HANDLERS */
myFileIO->Custom = &hblock;
SetFileIOHandlers( &hblock );
end = FALSE;
while (end == FALSE)
{
WaitPort(myWindow->UserPort);
while (message = ( struct IntuiMessage *)GetMsg(myWindow->UserPort))
{
class = message->Class;
code = message->Code;
ReplyMsg(message);
switch (class)
{
case CLOSEWINDOW:
end = TRUE;
break;
case MENUPICK:
switch( ITEMNUM( code ) )
{
case 0:
ToggleFlag( myFileIO->Flags, MULTIPLE_FILES );
TestFileIO(myFileIO, myWindow);
break;
case 1:
ToggleFlag( myFileIO->Flags, CUSTOM_HANDLERS );
TestFileIO(myFileIO, myWindow);
break;
}
break;
case MOUSEBUTTONS:
if( code == SELECTDOWN )
TestFileIO(myFileIO, myWindow);
break;
default:
break;
}
}
}
exit_program( 0L, 0L);
}
exit_program( error_words, error_code ) /* All exits through here. */
char * error_words;
ULONG error_code;
{
if( argcount && error_words ) puts( error_words );
if (myWindow) CloseWindow(myWindow);
if (myScreen) CloseScreen(myScreen);
if (IntuitionBase) CloseLibrary(IntuitionBase);
if (GfxBase) CloseLibrary(GfxBase);
if (DosBase) CloseLibrary(DosBase);
if (RequesterBase)
{
ReleaseFileIO(myFileIO);
CloseLibrary(RequesterBase);
}
exit( error_code );
}
UBYTE string[10][14] = {
{"This is One"},
{"This is Two"},
{"This is Three"},
{"This is Four"},
{"This is Five"},
{"This is Sex"},
{"This is Seven"},
{"This is Eight"},
{"This is Nine"},
{"This is Ten"},};
VOID TestFileIO(fileio, wind)
struct FileIO *fileio;
struct Window *wind;
{
struct FileEntry *fentry1 = 0, *fentry2 = 0;
UBYTE *address;
UBYTE c;
SHORT err;
/* This function makes the list of strings to display, and calls DoFileIO().
We have set the SPECIAL_REQ flag of FileIO. */
NewEntryList( fileio ); /* frees any previous list */
for( c=0; c<10; c++ )
{
err = AddEntry( c+1, string[c], fileio );
if( err < 0 ) AutoMessage("Out of memory for this string", wind );
}
address = DoFileIO(fileio, wind);
if( address == fileio->FileName )
{
/* If user was positive and no error, display the name */
fileio->FileName[75] = 0; /* Let's clip it to MAX 75 chars before display */
AutoMessage( fileio->FileName, wind);
if( fileio->FileSize == -1 )
{
/* If user typed in string not in the list, indicate this */
AutoMessage( "string not in the list", wind);
}
if( fileio->Errno == ERR_APPGADG )
{
AutoMessage( "Cancelled by custom routine.", wind);
}
if( fileio->Flags & MULTIPLE_FILES )
{
while( fentry2 = RetrieveEntry( &fentry1, fileio ) )
{
AutoMessage( fentry2->filePart->EntryString, wind );
}
}
}
if (!address) AutoMessage("Error in operation", wind);
if (address==-1) AutoMessage("Cancelled operation", wind);
if (address==-2) AutoMessage("Library in use", wind);
}
/*------- This is the for SPECIAL_REQ's "NextDisk" gadget replacement ------*/
/* Returning a 1 ends the requester with ERR_APPGADG. A 0 just returns control
to the requester lib. Also note that we can change the FileIOText and
even FileIORoutine, which will be set accordingly when we return(0) */
BOOL information( req, wind, fileio )
struct Requester *req;
struct Window *wind;
struct FileIO *fileio;
{
return(AutoPrompt3("This is the extra gadget routine",0,0, wind ));
}
/* -------- This is the CUSTOM_HANDLERS StartHandler routine ---------- */
BOOL myFunc( extra,seconds,micros,mouseX,mouseY,fileio,xwind,iaddress )
ULONG extra;
APTR iaddress;
struct Window *xwind;
struct FileIO *fileio;
SHORT mouseY, mouseX;
ULONG micros,seconds;
{
return(AutoPrompt3( "This is a custom StartHandler",0,0, xwind ));
}