home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 361b.lha / CManual_v1.0_disk3 / FileWindow / Example.c.pp / Example.c
C/C++ Source or Header  |  1990-04-07  |  10KB  |  409 lines

  1. /* Name: Example.c
  2.  
  3.  
  4.   FFFFF III L     EEEEE     W     W III N   N DDD    OOO  W     W
  5.   F      I  L     E         W     W  I  NN  N D  D  O   O W     W
  6.   FFFF   I  L     EEE       W  W  W  I  N N N D   D O   O W  W  W
  7.   F      I  L     E          W W W   I  N  NN D  D  O   O  W W W
  8.   F     III LLLLL EEEEE       W W   III N   N DDD    OOO    W W
  9.  
  10.   
  11.               EEEEE X   X  AAA  M   M PPPP  L     EEEEE
  12.               E      X X  A   A MM MM P   P L     E
  13.               EEEE    X   AAAAA M M M PPPP  L     EEEE
  14.               E      X X  A   A M   M P     L     E
  15.               EEEEE X   X A   A M   M P     LLLLL EEEEE
  16.  
  17.  
  18.   
  19.   FILE WINDOW EXAMPLE   VERSION 1.20   90-01-30
  20.  
  21.   Yet another program dedicated to Sioe-Lin Kwik.
  22.  
  23.  
  24.   FILE WINDOW was created by Anders Bjerin, and is distributed as
  25.   public domain with NO RIGHTS RESERVED. That means that you can do
  26.   what ever you want with the program.
  27.   
  28.   You may use FILE WINDOW in your own programs, commercial or not, and 
  29.   do not even need to mention that you have used it. You may alter the
  30.   source code to fit your needs, and you may spread it to anyone.
  31.  
  32.  
  33.  
  34.   This is an example on how to call FileWindow(). For more information 
  35.   please read the file "FileWindow.c".
  36.  
  37.  
  38.  
  39.  
  40.   ENJOY YOUR AMIGA, AND MAKE EVERYONE ELSE ENJOY IT TOO!
  41.  
  42.   Anders Bjerin  
  43.  
  44. */
  45.  
  46.  
  47.  
  48.  
  49.  
  50. /* ********************************************************************* */
  51. /* * FILE WINDOW   EXAMPLE    Version 1.20    Anders Bjerin   90-01-30 * */
  52. /* ********************************************************************* */
  53.  
  54.  
  55. #include <intuition/intuition.h>
  56. #include <string.h>
  57.  
  58. /* Remember to include this file if you use FileWindow(): */
  59. #include "FileWindow.h"
  60.  
  61.  
  62.  
  63. /* Declare what FileWindow will return: */
  64. extern USHORT FileWindow();
  65.  
  66.  
  67.  
  68. /* Declare the functions: */
  69. void _main();
  70. USHORT press_continue();
  71. void quit();
  72.  
  73.  
  74.  
  75. struct IntuitionBase *IntuitionBase;
  76. struct IntuiMessage *your_message;
  77. struct Window *your_window;
  78.  
  79.  
  80. /* 80-Characters ROM font: */
  81. struct TextAttr your_font=
  82. {
  83.   "topaz.font", /* Font Name */
  84.   TOPAZ_EIGHTY, /* Font Height */
  85.   FS_NORMAL,    /* Style */
  86.   FPF_ROMFONT   /* Preferences */
  87. };
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /* ********************************************************************* */
  94. /* * Information for the boolean gadget "CONTINUE"                     * */
  95. /* ********************************************************************* */
  96.  
  97.  
  98. /* Values for a 8-letter box: */
  99. SHORT points8[]=
  100. {
  101.    0,  0,
  102.   76,  0,
  103.   76, 14,
  104.    0, 14,
  105.    0,  0
  106. };
  107.  
  108.  
  109. /* A border for a 8-letter box: */
  110. struct Border border8=
  111. {
  112.   0, 0,         /* LeftEdge, TopEdge */
  113.   1, 2, JAM1,   /* FrontPen, BackPen, DrawMode */
  114.   5,            /* Count */
  115.   points8,      /* *XY */
  116.   NULL          /* *NextBorder */
  117. };
  118.  
  119.  
  120. struct IntuiText text_continue=
  121. {
  122.   3, 0,       /* FrontPen, BackPen */
  123.   JAM1,       /* DrawMode */
  124.   7,4,        /* LeftEdge, TopEdge */
  125.   &your_font, /* *ITextFont, (Topaz, 80) */
  126.   "CONTINUE", /* *IText */
  127.   NULL        /* *NextText */
  128. };
  129.  
  130.  
  131. struct Gadget gadget_continue=
  132. {
  133.   NULL,            /* *NextGadget */
  134.   16, 177, 78, 15, /* LeftEdge, TopEdge, Width, Height */
  135.   GADGHNONE,       /* Flags */
  136.   GADGIMMEDIATE,   /* Activation */
  137.   BOOLGADGET,      /* GadgetType */
  138.   (APTR) &border8, /* GadgetRender */
  139.   NULL,            /* SelectRender */
  140.   &text_continue,  /* *GadgetText */
  141.   NULL,            /* MutualExclude */
  142.   NULL,            /* SpecialInfo */
  143.   NULL,            /* GadgetID */
  144.   NULL             /* UserData */
  145. };
  146.  
  147.  
  148.  
  149.  
  150.  
  151. /* ********************************************************************* */
  152. /* * YOUR WINDOW                                                       * */
  153. /* ********************************************************************* */
  154.  
  155.  
  156. struct NewWindow your_new_window=
  157. {
  158.   0,0,              /* LeftEdge, TopEdge */
  159.   640, 200,         /* Width, Height */
  160.   0,1,              /* DetailPen, BlockPen */
  161.  
  162.   CLOSEWINDOW|      /* IDCMPFlags */
  163.   GADGETDOWN,
  164.  
  165.   ACTIVATE|         /* Flags */
  166.   WINDOWDEPTH|
  167.   WINDOWDRAG|
  168.   WINDOWCLOSE|
  169.   SMART_REFRESH,
  170.  
  171.   &gadget_continue,        /* *FirstGadget */
  172.   NULL,                    /* *CheckMark */
  173.   (STRPTR) "YOUR PROGRAM", /* *Title */
  174.   NULL,                    /* *Screen */
  175.   NULL,                    /* *BitMap */
  176.   0,0,                     /* MinWidth, MinHeight */
  177.   0,0,                     /* MaxWidth, MaxHeight */
  178.   WBENCHSCREEN             /* Type */
  179. };
  180.  
  181.  
  182.  
  183.  
  184.  
  185. /* ********************************************************************* */
  186. /* * TEXT:                                                             * */
  187. /* ********************************************************************* */
  188.  
  189.  
  190. struct IntuiText int_text=
  191. {
  192.   1, 0,       /* FrontPen, BackPen */
  193.   JAM2,       /* DrawMode */
  194.   16, 9,      /* LewftEdge, TopEdge */
  195.   &your_font, /* *ITextFont */
  196.   NULL,       /* *IText */
  197.   NULL        /* *NextText */
  198. };
  199.  
  200.  
  201. char *text_string[19]=
  202. {
  203.   "                                                                     ",
  204.   "FILE WINDOW EXAMPLE   VERSION 1.20   90-01-30",
  205.   "",
  206.   "FILE WINDOW was created by Anders Bjerin, and is distributed as",
  207.   "public domain with NO RIGHTS RESERVED. That means that you can do",
  208.   "what ever you want with the program.",
  209.   "",
  210.   "You may use FILE WINDOW in your own programs, commercial or not, and",
  211.   "do not even need to mention that you have used it. You may alter the",
  212.   "source code to fit your needs, and you may spread it to anyone.",
  213.   "",
  214.   "If you have any questions, ideas, programs (PD or your own) etc etc,",
  215.   "or just want to say hello, PLEASE WRITE TO ME:",
  216.   "",
  217.   "AMIGA C CLUB (ACC)",
  218.   "Anders Bjerin",
  219.   "Tulevagen 22",
  220.   "181 41  LIDINGO",
  221.   "SWEDEN"
  222. };
  223.  
  224.  
  225.  
  226.  
  227.  
  228. void _main()
  229. {
  230.   USHORT operation;
  231.   UBYTE file[TOTAL_LENGTH];
  232.   int temp;
  233.  
  234.  
  235.  
  236.   /* Open IntuitionBase: */
  237.   if( (IntuitionBase=(struct IntuitionBase *)
  238.       OpenLibrary("intuition.library", 33))==NULL )
  239.   {
  240.     /* Could NOT open IntuitionBase! */
  241.     exit();
  242.   }
  243.  
  244.  
  245.  
  246.   /* Open your window: */
  247.   if( (your_window = (struct Window *) 
  248.     OpenWindow(&your_new_window)) == NULL )
  249.   {
  250.     /* Could NOT open the window! */
  251.  
  252.     /* Close IntuitionBase: */
  253.     CloseLibrary((struct Library *) IntuitionBase);
  254.  
  255.     exit();
  256.   }
  257.  
  258.  
  259.  
  260.   /* Copy some text into file. This is optional, but very handy if you   */
  261.   /* want the FileWindow() to start to look in a specific directory, or  */
  262.   /* device:                                                             */
  263.   /* (If there is a file name in the string it will automatically appear */
  264.   /* in the "File:" gadget, and the path in the "Drawer:" gadget.)       */
  265.   strcpy(file, "df0:");
  266.  
  267.  
  268.  
  269.   /* Fill your_window with text: */
  270.   for(temp=1; temp < 19; temp++)
  271.   {
  272.     int_text.IText=text_string[temp];
  273.     PrintIText(your_window->RPort, &int_text, 0, temp*8);
  274.   }
  275.     
  276.  
  277.  
  278.   /* Wait: */
  279.   press_continue();
  280.  
  281.  
  282.  
  283.   /* Clicking on the CLOSE WINDOW gadget to leave the while loop: */
  284.   while(TRUE)
  285.   {
  286.     /* Clear your_window: */
  287.     int_text.IText=text_string[0];
  288.     for(temp=1; temp < 23; temp++)
  289.       PrintIText(your_window->RPort, &int_text, 0, temp*8);
  290.  
  291.  
  292.  
  293.     /* FILE WINDOW!!! */
  294.     operation=FileWindow
  295.               (
  296.                 "FILE WINDOW  V1.20", /* Title            */
  297.                 NULL,                 /* Extension (none) */
  298.                 0, 0,                 /* x, y position    */
  299.                 NULL,                 /* Screen    (none) */
  300.                 file                  /* file with path.  */
  301.               );
  302.  
  303.  
  304.  
  305.  
  306.     int_text.IText="File name plus path:";
  307.     int_text.FrontPen=1; /* Normal colour. */
  308.     PrintIText(your_window->RPort, &int_text, 0, 8 );
  309.  
  310.  
  311.  
  312.  
  313.     /* Write the filename and the path: */
  314.     int_text.IText=file; /* file name and path. */
  315.     int_text.FrontPen=3; /* Highlighted. */
  316.     PrintIText(your_window->RPort, &int_text, 16, 16 );
  317.   
  318.   
  319.  
  320.     int_text.IText="Operation:";
  321.     int_text.FrontPen=1; /* Normal colour. */
  322.     PrintIText(your_window->RPort, &int_text, 0, 24 );
  323.       
  324.  
  325.  
  326.     switch(operation)
  327.     {
  328.       case LOAD:   int_text.IText="LOAD"; break;
  329.       case SAVE:   int_text.IText="SAVE"; break;
  330.       case CANCEL: int_text.IText="CANCEL"; break;
  331.       case QUIT:   int_text.IText="QUIT"; break;
  332.       case PANIC:  int_text.IText="PANIC"; break;
  333.       default:     int_text.IText="Something went terrible WRONG!";
  334.     }
  335.     int_text.FrontPen=3; /* Highlighted. */
  336.     PrintIText(your_window->RPort, &int_text, 16, 32 );
  337.   
  338.  
  339.  
  340.     /* Draw the gadget again: */
  341.     RefreshGadgets(&gadget_continue, your_window, NULL);
  342.  
  343.  
  344.  
  345.     /* Wait: */
  346.     press_continue();
  347.   }
  348. }
  349.  
  350.  
  351.  
  352. /* Clean up before we leave: */
  353. void quit()
  354. {
  355.   /* Close the window: */
  356.   if(your_window)
  357.     CloseWindow(your_window);
  358.  
  359.  
  360.  
  361.   /* Close IntuitionBase: */
  362.   if(IntuitionBase)
  363.     CloseLibrary((struct Library *) IntuitionBase);
  364.  
  365.  
  366.  
  367.   exit();
  368. }
  369.  
  370.  
  371.  
  372. /* This function simply waits for someone to click on the CONTINUE */
  373. /* or CLOSEWINDOW gadget: */
  374. USHORT press_continue()
  375. {
  376.   ULONG class;
  377.   
  378.  
  379.  
  380.   while(TRUE)
  381.   {
  382.     Wait(1 << your_window->UserPort->mp_SigBit);
  383.   
  384.     if(your_message = (struct IntuiMessage *)
  385.       GetMsg(your_window->UserPort))
  386.     {
  387.       /* Collect some interesting values: */
  388.       class = your_message->Class;
  389.  
  390.       /* We have now saved some important values, and can now reply: */
  391.       /* (Do NEVER try to get some values after you have replied!) */
  392.       ReplyMsg((struct Message *)your_message);
  393.  
  394.  
  395.  
  396.       /* What has actually happened? */
  397.       switch(class)
  398.       {
  399.         case CLOSEWINDOW:
  400.                quit();    /* CLOSEWINDOW */
  401.                
  402.         case GADGETDOWN:
  403.                return(1); /* CONTINUE */
  404.       
  405.       }
  406.     }
  407.   }
  408. }
  409.