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

  1. #include <functions.h>
  2. #include <exec/types.h>
  3. #include <exec/io.h>
  4. #include <stdio.h>
  5. #include <exec/memory.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <graphics/gfxbase.h>
  9. #include "FileIO.h"
  10.  
  11. /* extern long GetMsg(), OpenWindow(), IoErr(), OpenLibrary(); */
  12.  
  13. /* === System Global Variables ========================================== */
  14. struct IntuitionBase *IntuitionBase = 0L;
  15. struct GfxBase       *GfxBase  = 0L;
  16. struct DosLibrary    *DosBase  = 0L;
  17. struct RequesterBase *RequesterBase = 0L;
  18. struct FileIO        *myFileIO  = 0L;
  19. struct FileIO        *myFileIO2 = 0L;
  20. struct Window        *myWindow  = 0L;
  21. struct Screen        *myScreen  = 0L;
  22. ULONG  argcount;  /* Saves argc from main(). argcount==0, then run from WB. */
  23.  
  24. struct TextAttr  topaz80_font;
  25.  
  26. BOOL TestFileIO();
  27.  
  28. struct NewScreen NewFileIOScreen =
  29.    {
  30.    0, 0,           /* LeftEdge, TopEdge */
  31.    640, 400,       /* Width, Height */
  32.    2,              /* Depth */
  33.    0, 1,           /* Detail/BlockPens */
  34.    HIRES | LACE,   /* ViewPort Modes (must set/clear HIRES as needed) */
  35.    CUSTOMSCREEN,
  36.    &topaz80_font,  /* Font */
  37.    (UBYTE *)"Example FileIO Program's Screen",
  38.    0L,             /* Gadgets */
  39.    0L,             /* CustomBitMap */
  40.    };
  41.  
  42. struct NewWindow NewFileIOWindow =
  43.    {
  44.    168, 30,            /* LeftEdge, TopEdge */
  45.    303, 145,          /* Width, Height */
  46.    -1, -1,            /* Detail/BlockPens */
  47.    MOUSEBUTTONS | CLOSEWINDOW | RAWKEY | DISKINSERTED,
  48.                       /* IDCMP Flags */
  49.    WINDOWDRAG | WINDOWDEPTH | SIZEBRIGHT | SMART_REFRESH |
  50.    WINDOWCLOSE | ACTIVATE | NOCAREREFRESH,
  51.                       /* Window Specification Flags */
  52.    0L,                /* FirstGadget */
  53.    0L,                /* Checkmark */
  54.    (UBYTE *)"FileIO Requester Window",  /* WindowTitle */
  55.    0L,                /* Screen */
  56.    0L,                /* SuperBitMap */
  57.    303, 145,          /* MinWidth, MinHeight */
  58.    600, 200,          /* MaxWidth, MaxHeight */
  59.    WBENCHSCREEN,
  60.    };
  61.  
  62.  
  63. /************************ MAIN ROUTINE *****************************/
  64.  
  65. VOID main(argc, argv)
  66. LONG argc;
  67. char **argv;
  68. {
  69.    LONG   class;
  70.    struct IntuiMessage *message;
  71.    BOOL   end;
  72.  
  73.    argcount = argc;
  74.  
  75.    if (!(IntuitionBase = (struct IntuitionBase *)
  76.       OpenLibrary("intuition.library", 0L)))
  77.       exit_program("FileIO Demo: No intuition library. \n", 1L);
  78.  
  79.    if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L)))
  80.       exit_program("FileIO Demo: No graphics library. \n", 2L);
  81.  
  82.    /* NOW OPEN THE REQUESTER LIBRARY */
  83.  
  84.    if (!(RequesterBase = (struct RequesterBase *)OpenLibrary("requester.library", 0L)))
  85.       exit_program("FileIO Demo: No requester library. \n", 4L);
  86.  
  87.    if (argv)
  88.       {
  89.       /* OK, we started from CLI */
  90.       if (argc > 1)
  91.          {
  92.          if (myScreen = OpenScreen(&NewFileIOScreen))
  93.             {
  94.             NewFileIOWindow.Screen = myScreen;
  95.             NewFileIOWindow.Type = CUSTOMSCREEN;
  96.             }
  97.          }
  98.       }
  99.  
  100.    if (!(myWindow = (struct Window *) OpenWindow( &NewFileIOWindow ) ))
  101.       exit_program("FileIO Demo: Null Window.\n", 5L);
  102.  
  103.  /* GET 2 FileIO STRUCTURES */
  104.  
  105.    if (!(myFileIO = GetFileIO() ))
  106.       exit_program("FileIO Demo: No FileIO 1.\n", 6L);
  107.  
  108.    if (!(myFileIO2 = GetFileIO() ))
  109.       exit_program("FileIO Demo: No FileIO 2.\n", 7L);
  110.  
  111.   /* Set up the XY co-ordinates where the requester should open */
  112.  
  113.   myFileIO->X = 6;
  114.   myFileIO->Y = 11;
  115.  
  116.   myFileIO2->X = 6;
  117.   myFileIO2->Y = 11;
  118.  
  119.  /* Set default colors and DrawMode */
  120.   myFileIO->DrawMode = JAM2;
  121.   myFileIO->PenA = 1;
  122.   myFileIO->PenB = 0;
  123.   myFileIO2->DrawMode = JAM2;
  124.   myFileIO2->PenA = 1;
  125.   myFileIO2->PenB = 0;
  126.  
  127.           /* pretty easy to set up, eh?  */
  128.  
  129.    end = FALSE;
  130.  
  131.    SetFlag(myFileIO2->Flags, WBENCH_MATCH | MATCH_OBJECTTYPE);
  132.    myFileIO2->MatchType = WBTOOL;
  133.    SetFlag(myFileIO2->Flags, USE_DEVICE_NAMES);
  134.  
  135.  
  136.    while (end == FALSE)
  137.     {
  138.       WaitPort(myWindow->UserPort);
  139.  
  140.       while (message = ( struct IntuiMessage *)GetMsg(myWindow->UserPort))
  141.        {
  142.          class = message->Class;
  143.          ReplyMsg(message);
  144.  
  145.          switch (class)
  146.           {
  147.             case CLOSEWINDOW:
  148.                end = TRUE;
  149.                break;
  150.             case DISKINSERTED:
  151.                /* You should clear the NO_CARE_REDRAW flag whenever you
  152.                 * detect that a new disk was inserted (if using this feature).
  153.                   We aren't using it, so comment it out.
  154.                ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
  155.                ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
  156.                 */
  157.                break;
  158.             case MOUSEBUTTONS:
  159.                if (TestFileIO(myFileIO, myWindow))
  160.                  {
  161.                   /*
  162.                   ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
  163.                   ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
  164.                   */
  165.                  }
  166.                break;
  167.             case RAWKEY:
  168.                if (TestFileIO(myFileIO2, myWindow))
  169.                 {
  170.                   /*
  171.                   ClearFlag(myFileIO->Flags, NO_CARE_REDRAW);
  172.                   ClearFlag(myFileIO2->Flags, NO_CARE_REDRAW);
  173.                   */
  174.                 }
  175.                break;
  176.             default:
  177.                break;
  178.           }
  179.        }
  180.     }
  181.   exit_program( 0L, 0L);
  182. }
  183.  
  184.  
  185.  
  186. exit_program( error_words, error_code )      /* All exits through here. */
  187. char  error_words;
  188. ULONG error_code;
  189. {
  190.    if( argcount && error_words ) puts( error_words );
  191.    if (myFileIO)  ReleaseFileIO(myFileIO);
  192.    if (myFileIO2) ReleaseFileIO(myFileIO2);
  193.  
  194.    if (myWindow) CloseWindow(myWindow);
  195.    if (myScreen) CloseScreen(myScreen);
  196.  
  197.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  198.    if (GfxBase)       CloseLibrary(GfxBase);
  199.    if (DosBase)       CloseLibrary(DosBase);
  200.    if (RequesterBase) CloseLibrary(RequesterBase);
  201.    exit( error_code );
  202. }
  203.  
  204.  
  205.  
  206. BOOL TestFileIO(fileio, wind)
  207. struct FileIO *fileio;
  208. struct Window *wind;
  209. {
  210.  UBYTE *address;
  211.  
  212. /* This guy calls DoFileIO(), displays the file name selected by the
  213.  * user, and returns TRUE if the user swapped disks during DoFileIO()
  214.  * (else returns FALSE) if an error, CANCEL, or no disk swap.
  215.  */
  216.    UBYTE buffer[80];
  217.  
  218.    fileio->Buffer = buffer;
  219.  
  220.    address = DoFileIO(fileio, wind);
  221.  
  222.    if( address == buffer )
  223.       {
  224.       /* If user was positive and no error, display the name */
  225.       AutoMessage( buffer, wind);
  226.       }
  227.  
  228.    if (!address)    AutoMessage("Error in operation", wind);
  229.    if (address==-1) AutoMessage("Cancelled operation", wind);
  230.  
  231.    if (FlagIsSet(fileio->Flags, DISK_HAS_CHANGED))
  232.       {
  233.       ClearFlag(fileio->Flags, DISK_HAS_CHANGED);
  234.       return(TRUE);
  235.       }
  236.    else
  237.      return(FALSE);
  238. }
  239.