home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 326.lha / requester.library_v1.3 / CustomList.c < prev    next >
C/C++ Source or Header  |  1989-12-30  |  7KB  |  264 lines

  1. /*************************************************************************
  2.  This program opens and utilizes the requester.library in order to use
  3.  the new SPECIAL_REQ flag. This flag allows us to display a list of
  4.  strings in a requester with all the features of the FileIO requester.
  5.  Because version 0 of the library did not support this feature, but version
  6.  1.4 now does, we must open the library with version #1. Old applications
  7.  that do not know about SPECIAL_REQ will still work with this version of
  8.  the library. It is backward compatible as far as the disk IO features are
  9.  concerned.
  10.  
  11.  If running this program from the CLI and you specify any argument on the
  12.  command (i.e.  1> TestFileIO blort ), then the window will open on a hires
  13.  screen. You can then see what the requester looks like in hires.
  14.  
  15.  Manx compile:
  16.  cc +p CustomList.c
  17.  ln CustomList.o -lcl32
  18.  
  19. **************************************************************************/
  20.  
  21. #include <functions.h>
  22. #include <exec/types.h>
  23. #include <exec/io.h>
  24. #include <stdio.h>
  25. #include <exec/memory.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/intuitionbase.h>
  28. #include <graphics/gfxbase.h>
  29. #include "FileIO.h"
  30.  
  31. /* extern long GetMsg(), OpenWindow(), IoErr(), OpenLibrary(); */
  32.  
  33. /* === System Global Variables ========================================== */
  34. struct IntuitionBase *IntuitionBase = 0L;
  35. struct GfxBase       *GfxBase  = 0L;
  36. struct DosLibrary    *DosBase  = 0L;
  37. struct RequesterBase *RequesterBase = 0L;
  38. struct FileIO        *myFileIO  = 0L;
  39. struct Window        *myWindow  = 0L;
  40. struct Screen        *myScreen  = 0L;
  41. ULONG  argcount;  /* Saves argc from main(). argcount==0, then run from WB. */
  42.  
  43. struct TextAttr  topaz80_font;
  44.  
  45. VOID TestFileIO();
  46.  
  47. struct NewScreen NewFileIOScreen =
  48.    {
  49.    0, 0,           /* LeftEdge, TopEdge */
  50.    640, 400,       /* Width, Height */
  51.    2,              /* Depth */
  52.    0, 1,           /* Detail/BlockPens */
  53.    HIRES | LACE,   /* ViewPort Modes (must set/clear HIRES as needed) */
  54.    CUSTOMSCREEN,
  55.    &topaz80_font,  /* Font */
  56.    (UBYTE *)"Example FileIO Program's Screen",
  57.    0L,             /* Gadgets */
  58.    0L,             /* CustomBitMap */
  59.    };
  60.  
  61. struct NewWindow NewFileIOWindow =
  62.    {
  63.    168, 30,            /* LeftEdge, TopEdge */
  64.    303, 145,          /* Width, Height */
  65.    -1, -1,            /* Detail/BlockPens */
  66.    MOUSEBUTTONS | CLOSEWINDOW,
  67.                       /* IDCMP Flags */
  68.    WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | SMART_REFRESH |
  69.    WINDOWCLOSE | ACTIVATE | NOCAREREFRESH,
  70.                       /* Window Specification Flags */
  71.    0L,                /* FirstGadget */
  72.    0L,                /* Checkmark */
  73.    (UBYTE *)"FileIO SPECIAL_REQ Example",  /* WindowTitle */
  74.    0L,                /* Screen */
  75.    0L,                /* SuperBitMap */
  76.    303, 145,          /* MinWidth, MinHeight */
  77.    600, 200,          /* MaxWidth, MaxHeight */
  78.    WBENCHSCREEN,
  79.    };
  80.  
  81.  
  82. VOID information();
  83.  
  84. UBYTE button_text[] = {"   About"};
  85.  
  86. /************************ MAIN ROUTINE *****************************/
  87.  
  88. VOID main(argc, argv)
  89. LONG argc;
  90. char **argv;
  91. {
  92.    LONG   class;
  93.    USHORT code;
  94.    struct IntuiMessage *message;
  95.    BOOL   end;
  96.  
  97.    argcount = argc;
  98.  
  99.    if (!(IntuitionBase = (struct IntuitionBase *)
  100.       OpenLibrary("intuition.library", 0L)))
  101.       exit_program("FileIO Demo: No intuition library. \n", 1L);
  102.  
  103.    if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L)))
  104.       exit_program("FileIO Demo: No graphics library. \n", 2L);
  105.  
  106.    /* NOW OPEN THE REQUESTER LIBRARY, Version 1 */
  107.  
  108.    if (!(RequesterBase = (struct RequesterBase *)OpenLibrary("requester.library", 1L)))
  109.       exit_program("FileIO Demo: No requester library. \n", 4L);
  110.  
  111.    if (argv)
  112.       {
  113.       /* OK, we started from CLI */
  114.       if (argc > 1)
  115.          {
  116.          if (myScreen = OpenScreen(&NewFileIOScreen))
  117.             {
  118.             NewFileIOWindow.Screen = myScreen;
  119.             NewFileIOWindow.Type = CUSTOMSCREEN;
  120.             }
  121.          }
  122.       }
  123.  
  124.    if (!(myWindow = (struct Window *) OpenWindow( &NewFileIOWindow ) ))
  125.       exit_program("FileIO Demo: Null Window.\n", 5L);
  126.  
  127.  
  128.    if (!(myFileIO = GetFileIO() ))
  129.       exit_program("FileIO Demo: No FileIO 1.\n", 6L);
  130.  
  131.   /* Set up the XY co-ordinates where the requester should open */
  132.  
  133.   myFileIO->X = 6;
  134.   myFileIO->Y = 11;
  135.  
  136.  /* Set default colors and DrawMode */
  137.   myFileIO->DrawMode = JAM2;
  138.   myFileIO->PenA = 1;
  139.   myFileIO->PenB = 0;
  140.   myFileIO->FileIOText = button_text;
  141.   myFileIO->FileIORoutine = (APTR)information;  /* pointer to function */
  142.   SetFlag(myFileIO->Flags, SPECIAL_REQ );
  143.  
  144.           /* pretty easy to set up, eh?  */
  145.  
  146.    end = FALSE;
  147.  
  148.  
  149.    while (end == FALSE)
  150.     {
  151.       WaitPort(myWindow->UserPort);
  152.  
  153.       while (message = ( struct IntuiMessage *)GetMsg(myWindow->UserPort))
  154.        {
  155.          class = message->Class;
  156.          code = message->Code;
  157.          ReplyMsg(message);
  158.  
  159.          switch (class)
  160.           {
  161.             case CLOSEWINDOW:
  162.                end = TRUE;
  163.                break;
  164.  
  165.             case MOUSEBUTTONS:
  166.                if( code == SELECTDOWN )
  167.                   TestFileIO(myFileIO, myWindow);
  168.                break;
  169.  
  170.             default:
  171.                break;
  172.           }
  173.        }
  174.     }
  175.   exit_program( 0L, 0L);
  176. }
  177.  
  178.  
  179.  
  180. exit_program( error_words, error_code )      /* All exits through here. */
  181. char  error_words;
  182. ULONG error_code;
  183. {
  184.    if( argcount && error_words ) puts( error_words );
  185.    if (myFileIO)  ReleaseFileIO(myFileIO);
  186.  
  187.    if (myWindow) CloseWindow(myWindow);
  188.    if (myScreen) CloseScreen(myScreen);
  189.  
  190.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  191.    if (GfxBase)       CloseLibrary(GfxBase);
  192.    if (DosBase)       CloseLibrary(DosBase);
  193.    if (RequesterBase) CloseLibrary(RequesterBase);
  194.    exit( error_code );
  195. }
  196.  
  197.  
  198.  
  199. UBYTE string[10][14] = {
  200.    {"This is One"},
  201.    {"This is Two"},
  202.    {"This is Three"},
  203.    {"This is Four"},
  204.    {"This is Five"},
  205.    {"This is Sex"},
  206.    {"This is Seven"},
  207.    {"This is Eight"},
  208.    {"This is Nine"},
  209.    {"This is Ten"},};
  210.  
  211.  
  212. VOID TestFileIO(fileio, wind)
  213. struct FileIO *fileio;
  214. struct Window *wind;
  215. {
  216.    UBYTE *address;
  217.    UBYTE c;
  218.    SHORT err;
  219.  
  220. /* This function makes the list of strings to display, and calls DoFileIO().
  221.    We have set the SPECIAL_REQ flag of FileIO. */
  222.  
  223.    NewEntryList( fileio );  /* frees any previous list */
  224.  
  225.    for( c=0; c<10; c++ )
  226.    {
  227.       err = AddEntry( c+1, string[c], fileio );
  228.       if( err < 0 )    AutoMessage("Out of memory for this string", wind );
  229.    }
  230.  
  231.    address = DoFileIO(fileio, wind);
  232.  
  233.    if( address == fileio->FileName )
  234.    {
  235.       /* If user was positive and no error, display the name */
  236.       AutoMessage( fileio->FileName, wind);
  237.       if( fileio->FileSize == -1 )
  238.       {
  239.           /* If user typed in string not in the list, indicate this */
  240.           AutoMessage( "string not in the list", wind);
  241.       }
  242.       if( fileio->Errno == ERR_APPGADG )
  243.       {
  244.           AutoMessage( "Cancelled by custom routine.", wind);
  245.       }
  246.    }
  247.  
  248.    if (!address)    AutoMessage("Error in operation", wind);
  249.    if (address==-1) AutoMessage("Cancelled operation", wind);
  250.    if (address==-2) AutoMessage("Library in use", wind);
  251.  
  252. }
  253.  
  254.  
  255. VOID information( req, wind, fileio )
  256. struct Requester *req;
  257. struct Window *wind;
  258. struct FileIO *fileio;
  259. {
  260.    AutoMessage("The north end of a south facing chicken", wind );
  261. }
  262.  
  263.  
  264.