home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 112.lha / IT1Demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-20  |  17.5 KB  |  860 lines

  1. /*    Demo.c        InovaTools 1 Demo Program         Lattice "C" version
  2.  
  3.     (c) 1988 Todor Fay
  4.  
  5.     This is a sample Inovatools 1 program.  It puts up
  6.     a window with gadgets for opening two different
  7.     types of file requester, one displays all files, the other
  8.     displays all files that end with ".c".
  9.     There's a gadget that opens the InovaTools color 
  10.     pallette editor.  And, there are two gadgets to create
  11.     and delete a reentrant window.
  12.      To keep track of all of the reentrant windows, 
  13.     a list is maintained in the main window.  This list can be
  14.     sized by changing the window size.
  15.     Each reentrant window has an example popup menu, two
  16.     Knob gadgets, and a drag gadget that can be dragged
  17.     to another window, where it stays!
  18.     There is no limit to the number of reentrant windows
  19.      created, and each is independant of the others.
  20. */
  21.  
  22. #include <intuition/intuition.h>
  23. #include <exec/memory.h>
  24. #include <graphics/gfxmacros.h>
  25. #include "itools1.h"
  26.  
  27. long GfxBase; 
  28. long IntuitionBase;
  29. long MathBase; 
  30. long LayersBase;
  31.  
  32. /*    We need a list structure to keep track of all of the
  33.     reentrant windows opened.  The ID number is for 
  34.     display purposes only.
  35. */
  36.  
  37. struct WindowListItem {
  38.     struct ListItem link;
  39.     struct Window *window;
  40.     short id;
  41. };
  42.  
  43. void updatelistitem(rp,item,x,y,highlighted)
  44.  
  45. /*    This is the update routine for a list item in the window
  46.     list.  When you create an InovaTools list, you must provide
  47.     a routine that will display one item in the list,
  48.     given that item, a rastport, x and y positions, and
  49.     a flag that indicates whether it is highlighted.
  50. */
  51.  
  52. register struct RastPort *rp;
  53. register struct WindowListItem *item;
  54. register long x,y,highlighted;
  55.  
  56. {
  57.     static struct IntuiText it = { 0,0,JAM2,0,0,0,0,0};
  58.     static char name[] = "Window #         ";
  59.     if (highlighted) {
  60.     it.FrontPen = 0;
  61.     it.BackPen = 1;
  62.     }
  63.     else {
  64.     it.FrontPen = 1;
  65.     it.BackPen = 0;
  66.     }
  67.     it.IText = name;
  68.     Itoa((long)item->id,&name[8],10l);
  69.     PrintIText(rp,&it,x,y);
  70. }
  71.  
  72. /*    The ListInfo structure for the window list: */
  73.  
  74. struct ListInfo windowlist = {
  75.     160,17,100,69,8,   /* Dimensions. */
  76.     10,11,12,13,       /* Gadget ID's. */
  77.     1,0,               /* Draw pens. */
  78.     0,0,0,             /* List pointers. */
  79.     0,                 /* Window. */
  80.     0,0,0,0,           /* The four gadgets. */
  81.     updatelistitem,    /* Draw routine. */
  82.     0,0,0,0,           /* Inovatools stuff. */
  83. };
  84.  
  85. void knobcode(window,knob)
  86.  
  87. /*    For a knob, you may provide a routine that is called
  88.     every time the knob is rotated.  This routine is
  89.     passed a pointer to the knob and the window it displays in.
  90. */
  91.  
  92. struct Window *window;
  93. register struct Knob *knob;
  94.  
  95. {
  96.     static struct IntuiText it = { 1,0,JAM2,0,0,0,0,0};
  97.     static char number[] = "    ";
  98.     it.IText = number;
  99.     if (knob->KnobID == 1) {
  100.     Itoa((long)knob->Value,number,10l);
  101.     PrintIText(window->RPort,&it,170,50);
  102.     }
  103.     else {
  104.     it.IText = "      ";
  105.     PrintIText(window->RPort,&it,270l,50l);
  106.     it.IText = number;
  107.     Itoa((long)knob->Value,number,10l);
  108.     PrintIText(window->RPort,&it,270l,50l);
  109.     }
  110. }
  111.  
  112. /*     The knob list for the reentrant window.  Copies of
  113.     this list will be made for each window, so
  114.     the knobs can be pointing at different angles.
  115. */
  116.     
  117. struct Knob firstknob = {
  118.     0,                 /* No next knob. */
  119.     300,30,            /* Center. */
  120.     KNOB_DRAW | KNOB_RANGED | KNOB_CALCVALUE,
  121.     0,100,0,32768,100,20,22,10000,55535,0,2,1,2,0,0,0,0,0,
  122.     knobcode,0
  123. };
  124.  
  125. struct Knob knoblist = {
  126.     &firstknob,                 /* Next knob. */
  127.     200,30,            /* Center. */
  128.     KNOB_DRAW | KNOB_RANGED | KNOB_CALCVALUE,
  129.     0,10,0,32768,10,20,22,10000,55535,0,3,1,1,0,0,0,0,0,
  130.     knobcode,0
  131. };
  132.  
  133. /*    The Drag Gadget declaration: */
  134.  
  135. struct DragInfo dragme = {
  136.     0,              /* Gadget Pointer - to be filled in later. */
  137.     -700,-300,1000,1000,  /* Bounding box. */
  138.     DRAG_OUTLINE | DRAG_MOVEGADGET,      /* Flags. */
  139.     0,0,
  140.     0,              /* No user supplied update routine. */
  141.     0
  142. };
  143.  
  144. /*    The PowerWindows declaration for the reentrant window: */
  145.  
  146. static USHORT dupeImageData1[] = {
  147.  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0000,0x0001,
  148.  0x8000,0x0000,0x0008,0x2001,0x8000,0x0000,0x000C,0x6001,
  149.  0x8000,0x0000,0x000E,0xE3C1,0x8000,0x0000,0x000F,0xE661,
  150.  0x8000,0x0000,0x000D,0x67E1,0x8000,0x0000,0x000C,0x6601,
  151.  0x8000,0x0000,0x000C,0x63C1,0x8000,0x0000,0x0000,0x0001,
  152.  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x0000,0x0000,0x0000,0x0000,
  153.  0x0000,0x0000,0x0000,0x0000,0x0F80,0x0000,0x0008,0x2000,
  154.  0x06C0,0x0000,0x000C,0x6000,0x066E,0xC3C3,0xB00E,0xE3C0,
  155.  0x0667,0x6066,0x600F,0xE660,0x0666,0x61E6,0x600D,0x67E0,
  156.  0x06C6,0x0663,0xC00C,0x6600,0x0F8F,0x03BC,0x600C,0x63C0,
  157.  0x0000,0x0007,0xC000,0x0000,0x0000,0x0000,0x0000,0x0000
  158. };
  159.  
  160. static struct Image dupeImage1 = {
  161.  0,0,
  162.  64,11,
  163.  2,
  164.  dupeImageData1,
  165.  0x0003,0x0000,
  166.  NULL
  167. };
  168.  
  169. static struct Gadget dupeGadget1 = {
  170.  NULL,
  171.  24,36,
  172.  64,11,
  173.  GADGHBOX+GADGHIMAGE+GADGIMAGE,
  174.  RELVERIFY+GADGIMMEDIATE,
  175.  BOOLGADGET,
  176.  (APTR)&dupeImage1,
  177.  NULL,
  178.  NULL,
  179.  NULL,
  180.  NULL,
  181.  2,
  182.  NULL
  183. };
  184.  
  185. static SHORT dupeBorderVectors1[] = {
  186.  0,0,
  187.  99,0,
  188.  99,10,
  189.  0,10,
  190.  0,0
  191. };
  192. static struct Border dupeBorder1 = {
  193.  -2,-1,
  194.  3,0,JAM1,
  195.  5,
  196.  dupeBorderVectors1,
  197.  NULL
  198. };
  199.  
  200. static struct IntuiText dupeIText1 = {
  201.  3,0,JAM2,
  202.  3,1,
  203.  NULL,
  204.  "Pop Up Menu",
  205.  NULL
  206. };
  207.  
  208. static struct Gadget dupeGadget2 = {
  209.  &dupeGadget1,
  210.  24,18,
  211.  96,9,
  212.  GADGHBOX+GADGHIMAGE,
  213.  RELVERIFY+GADGIMMEDIATE,
  214.  BOOLGADGET,
  215.  (APTR)&dupeBorder1,
  216.  NULL,
  217.  &dupeIText1,
  218.  NULL,
  219.  NULL,
  220.  1,
  221.  NULL
  222. };
  223.  
  224. static struct IntuiText dupeIText2 = {
  225.  3,1,COMPLEMENT,
  226.  0,0,
  227.  NULL,
  228.  "Another Menu Item",
  229.  NULL
  230. };
  231.  
  232. static struct MenuItem dupeMenuItem2 = {
  233.  NULL,
  234.  0,9,
  235.  136,8,
  236.  ITEMTEXT+ITEMENABLED+HIGHCOMP,
  237.  0,
  238.  (APTR)&dupeIText2,
  239.  NULL,
  240.  NULL,
  241.  NULL,
  242.  MENUNULL
  243. };
  244.  
  245. static USHORT dupeImageData2[] = {
  246.  0x0000,0x0000,0x3FFF,0xF800,0x3FFF,0xF800,0x3FFF,0xF800,
  247.  0x3FFF,0xF800,0x3FFF,0xF800,0x3FFF,0xF800,0x3FFF,0xF800,
  248.  0x3FFF,0xF800,0x3FFF,0xF800,0x0000,0x0000,0xFFFF,0xFE00,
  249.  0xC000,0x0600,0xC000,0x0600,0xC000,0x0600,0xC000,0x0600,
  250.  0xC000,0x0600,0xC000,0x0600,0xC000,0x0600,0xC000,0x0600,
  251.  0xC000,0x0600,0xFFFF,0xFE00
  252. };
  253.  
  254. static struct Image dupeImage2 = {
  255.  19,0,
  256.  23,11,
  257.  2,
  258.  dupeImageData2,
  259.  0x0003,0x0000,
  260.  NULL
  261. };
  262.  
  263. static struct MenuItem dupeSubItem3 = {
  264.  NULL,
  265.  121,3,
  266.  42,11,
  267.  CHECKIT+ITEMENABLED+HIGHCOMP+CHECKED,
  268.  3,
  269.  (APTR)&dupeImage2,
  270.  NULL,
  271.  NULL,
  272.  NULL,
  273.  MENUNULL
  274. };
  275.  
  276. static USHORT dupeImageData3[] = {
  277.  0x0000,0x0000,0x01FF,0x0000,0x0FFF,0xE000,0x3F01,0xF800,
  278.  0x7C00,0x7C00,0x7C00,0x7C00,0x7C00,0x7C00,0x3F01,0xF800,
  279.  0x0FFF,0xE000,0x01FF,0x0000,0x0000,0x0000,0x01FF,0x0000,
  280.  0x0FFF,0xE000,0x3F01,0xF800,0x7CFE,0x7C00,0xFBFF,0xBE00,
  281.  0xFBFF,0xBE00,0xFBFF,0xBE00,0x7CFE,0x7C00,0x3F01,0xF800,
  282.  0x0FFF,0xE000,0x01FF,0x0000
  283. };
  284.  
  285. static struct Image dupeImage3 = {
  286.  19,0,
  287.  23,11,
  288.  2,
  289.  dupeImageData3,
  290.  0x0003,0x0000,
  291.  NULL
  292. };
  293.  
  294. static struct MenuItem dupeSubItem2 = {
  295.  &dupeSubItem3,
  296.  163,-8,
  297.  42,11,
  298.  CHECKIT+ITEMENABLED+HIGHCOMP,
  299.  5,
  300.  (APTR)&dupeImage3,
  301.  NULL,
  302.  NULL,
  303.  NULL,
  304.  MENUNULL
  305. };
  306.  
  307. static USHORT dupeImageData4[] = {
  308.  0x03FE,0x0000,0x1FFF,0xC000,0x3FFF,0xE000,0x7BF8,0xF000,
  309.  0xF8FE,0xF800,0xFFFF,0xF800,0xFFFF,0xF800,0x7FFF,0xF000,
  310.  0x3E03,0xE000,0x1FFF,0xC000,0x03FE,0x0000,0x0000,0x0000,
  311.  0x03FE,0x0000,0x1FFF,0xC000,0x3CFF,0xE000,0x7FF9,0xF000,
  312.  0x7FFF,0xF000,0x7FAF,0xF000,0x3FFF,0xE000,0x1FFF,0xC000,
  313.  0x03FE,0x0000,0x0000,0x0000
  314. };
  315.  
  316. static struct Image dupeImage4 = {
  317.  19,0,
  318.  21,11,
  319.  2,
  320.  dupeImageData4,
  321.  0x0003,0x0000,
  322.  NULL
  323. };
  324.  
  325. static struct MenuItem dupeSubItem1 = {
  326.  &dupeSubItem2,
  327.  121,-8,
  328.  42,11,
  329.  CHECKIT+ITEMENABLED+HIGHCOMP,
  330.  6,
  331.  (APTR)&dupeImage4,
  332.  NULL,
  333.  NULL,
  334.  NULL,
  335.  MENUNULL
  336. };
  337.  
  338. static struct IntuiText dupeIText3 = {
  339.  3,1,COMPLEMENT,
  340.  0,0,
  341.  NULL,
  342.  "A Menu Item",
  343.  NULL
  344. };
  345.  
  346. static struct MenuItem dupeMenuItem1 = {
  347.  &dupeMenuItem2,
  348.  0,0,
  349.  136,8,
  350.  ITEMTEXT+ITEMENABLED+HIGHCOMP,
  351.  0,
  352.  (APTR)&dupeIText3,
  353.  NULL,
  354.  NULL,
  355.  &dupeSubItem1,
  356.  MENUNULL
  357. };
  358.  
  359. static struct Menu dupeMenu1 = {
  360.  NULL,
  361.  0,0,
  362.  57,0,
  363.  MENUENABLED,
  364.  "PopUp",
  365.  &dupeMenuItem1
  366. };
  367.  
  368. #define dupeMenuList1 dupeMenu1
  369.  
  370. static struct NewWindow dupeNewWindowStructure1 = {
  371.  81,28,
  372.  343,62,
  373.  0,1,
  374.  MOUSEBUTTONS+GADGETDOWN+GADGETUP+CLOSEWINDOW+NEWSIZE,
  375.  WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE,
  376.  &dupeGadget2,
  377.  NULL,
  378.  "Duped Window",
  379.  NULL,
  380.  NULL,
  381.  5,5,
  382.  640,200,
  383.  WBENCHSCREEN
  384. };
  385.  
  386. extern long AllocMem();
  387. extern long FindTask();
  388.  
  389. void dupewindowcode()
  390.  
  391. /*    This is the code for a task that opens its own reentrant window.
  392.     All of the structures for the window are created with calls to
  393.     DupeNewWindow, DupeKnobList, and DupeMenu.
  394. */
  395.  
  396. {
  397.     register struct Window *window;
  398.     register struct IntuiMessage *message;
  399.     register long class, code;
  400.     register struct Gadget *gadget;
  401.     static short globalid = 1;
  402.     short startx, starty;
  403.     struct Window *otherwindow;
  404.     struct NewWindow *newwindow;
  405.     struct Knob *knob;
  406.     struct Menu *menu;
  407.     struct WindowListItem *windowlistitem, *otheritem;
  408.     Forbid();
  409.     newwindow = DupeNewWindow(&dupeNewWindowStructure1);
  410.     if (!newwindow) {
  411.     Permit();
  412.     DeleteTask(FindTask((long)0));
  413.     }
  414.     knob = DupeKnobList(&knoblist);
  415.     if (!knob) {
  416.     Permit();
  417.     DeleteNewWindow(newwindow);
  418.     DeleteTask(FindTask((long)0));
  419.     }
  420.     menu = DupeMenu(&dupeMenuList1);
  421.     if (!menu) {
  422.     Permit();
  423.     DeleteNewWindow(newwindow);
  424.     DeleteKnobList(knob);
  425.     DeleteTask(FindTask((long)0));
  426.     }
  427.     window = FlashyOpenWindow(newwindow);
  428.     if (window) {
  429.  
  430. /*    Create a list item that points at this window and stick it in
  431.     the list in the main window. */
  432.  
  433.     windowlistitem = (struct WindowListItem *) 
  434.         AllocMem((long)sizeof(struct WindowListItem),MEMF_PUBLIC | MEMF_CLEAR);
  435.     if (windowlistitem) {
  436.         windowlistitem->window = window;
  437.         windowlistitem->id = globalid++;
  438.         InsertListItem(&windowlist,(struct ListItem *)windowlistitem);
  439.     }
  440.  
  441. /*    Install the knobs and call their display routines. */
  442.  
  443.     DrawKnobs(window,knob);
  444.     knobcode(window,knob);
  445.     knobcode(window,knob->NextKnob);
  446.     Permit();
  447.  
  448. /*    Main loop.  process messages and break with a CLOSEWINDOW. */
  449.  
  450.     for (;;) {
  451.  
  452. /*    Read an IntuiMessage and grab pertinent data before replying. */
  453.  
  454.         message = GetIntuiMessage(window);
  455.         class = message->Class;
  456.         code = message->Code;
  457.         gadget = (struct Gadget *) message->IAddress;
  458.         ReplyMsg(message);
  459.         if (class == CLOSEWINDOW) break;
  460.  
  461. /*    If window was resized, redraw knobs. */
  462.  
  463.         else if (class == NEWSIZE)     DrawKnobs(window,knob);
  464.  
  465. /*    If mouse was clicked, it may have been a knob, process it. */
  466.  
  467.         else if ((class == MOUSEBUTTONS) && (code == SELECTDOWN)) {
  468.         KnobGadgets(window,knob);
  469.         }
  470.         else if (class == GADGETDOWN) {
  471.         switch(gadget->GadgetID) {
  472.             case 1 :    /* PopUp menu selected. */
  473.             PopUpMenu(window,menu);
  474.             break;
  475.             case 2 :     /* Drag gadget selected. */
  476.             startx = gadget->LeftEdge;
  477.             starty = gadget->TopEdge;
  478.             dragme.Gadget = gadget;
  479.             DragGadget(window,&dragme);
  480.             otherwindow = 
  481.                 WhichWindow(window,(long)dragme.XPos,
  482.                 (long)dragme.YPos);
  483.  
  484. /*    If the gadget ended in another window, find it in the list. If
  485.     it is in the list and it isn't this window, stick the gadget
  486.     in that window.
  487. */
  488.             if (otherwindow != window) {
  489.                 Forbid();
  490.                 otheritem = 
  491.                 (struct WindowListItem *) windowlist.TopItem;
  492.                 for (;otheritem;) {
  493.                 if (otheritem->window == otherwindow) break;
  494.                 otheritem = (struct WindowListItem *)
  495.                     otheritem->link.Next;
  496.                 }
  497.                 if (otheritem) {
  498.                 RemoveGadget(window,gadget);
  499.                 gadget->LeftEdge = window->LeftEdge + 
  500.                     gadget->LeftEdge - otherwindow->LeftEdge;
  501.                 gadget->TopEdge = window->TopEdge + 
  502.                     gadget->TopEdge - otherwindow->TopEdge;
  503.                 gadget->NextGadget = 0;
  504.                 AddGadget(otherwindow,gadget,(long)-1);
  505.                 RefreshGadgets(otherwindow->FirstGadget,
  506.                     otherwindow,0);
  507.                 }
  508.                 else {
  509.                 gadget->LeftEdge = startx;
  510.                 gadget->TopEdge = starty;
  511.                 RefreshGadgets(window->FirstGadget,window,0);
  512.                 }
  513.                 Permit();
  514.             }
  515.             break;
  516.          }
  517.         }
  518.     }
  519.  
  520. /*    Done.  Pull out of the list in the main window.  */
  521.  
  522.     if (windowlistitem) {
  523.         windowlist.ActiveItem = (struct ListItem *) windowlistitem;
  524.         RemoveListItem(&windowlist);
  525.         FreeMem(windowlistitem,(long)sizeof(*windowlistitem));
  526.     }
  527.     FlashyCloseWindow(window);
  528.     }
  529.     else Permit();
  530.     DeleteNewWindow(newwindow);
  531.     DeleteKnobList(knob);
  532.     DeleteMenu(menu);
  533.     DeleteTask(FindTask(0l));
  534. }
  535.  
  536. /*    PowerWindow declarations for main window. */
  537.  
  538. static SHORT demoBorderVectors2[] = {
  539.  0,0,
  540.  123,0,
  541.  123,11,
  542.  0,11,
  543.  0,0
  544. };
  545. static struct Border demoBorder2 = {
  546.  -2,-1,
  547.  3,0,JAM1,
  548.  5,
  549.  demoBorderVectors2,
  550.  NULL
  551. };
  552.  
  553. static struct IntuiText demoIText4 = {
  554.  3,0,JAM2,
  555.  16,1,
  556.  NULL,
  557.  "Kill Window",
  558.  NULL
  559. };
  560.  
  561. static struct Gadget demoGadget7 = {
  562.  NULL,
  563.  23,77,
  564.  120,10,
  565.  NULL,
  566.  RELVERIFY,
  567.  BOOLGADGET,
  568.  (APTR)&demoBorder2,
  569.  NULL,
  570.  &demoIText4,
  571.  NULL,
  572.  NULL,
  573.  5,
  574.  NULL
  575. };
  576.  
  577. static SHORT demoBorderVectors3[] = {
  578.  0,0,
  579.  123,0,
  580.  123,11,
  581.  0,11,
  582.  0,0
  583. };
  584. static struct Border demoBorder3 = {
  585.  -2,-1,
  586.  3,0,JAM1,
  587.  5,
  588.  demoBorderVectors3,
  589.  NULL
  590. };
  591.  
  592. static struct IntuiText demoIText5 = {
  593.  3,0,JAM2,
  594.  20,1,
  595.  NULL,
  596.  "New Window",
  597.  NULL
  598. };
  599.  
  600. static struct Gadget demoGadget6 = {
  601.  &demoGadget7,
  602.  23,62,
  603.  120,10,
  604.  NULL,
  605.  RELVERIFY,
  606.  BOOLGADGET,
  607.  (APTR)&demoBorder3,
  608.  NULL,
  609.  &demoIText5,
  610.  NULL,
  611.  NULL,
  612.  4,
  613.  NULL
  614. };
  615.  
  616. static SHORT demoBorderVectors4[] = {
  617.  0,0,
  618.  123,0,
  619.  123,11,
  620.  0,11,
  621.  0,0
  622. };
  623. static struct Border demoBorder4 = {
  624.  -2,-1,
  625.  3,0,JAM1,
  626.  5,
  627.  demoBorderVectors4,
  628.  NULL
  629. };
  630.  
  631. static struct IntuiText demoIText6 = {
  632.  3,0,JAM2,
  633.  24,1,
  634.  NULL,
  635.  "'C' Files",
  636.  NULL
  637. };
  638.  
  639. static struct Gadget demoGadget5 = {
  640.  &demoGadget6,
  641.  23,32,
  642.  120,10,
  643.  NULL,
  644.  RELVERIFY,
  645.  BOOLGADGET,
  646.  (APTR)&demoBorder4,
  647.  NULL,
  648.  &demoIText6,
  649.  NULL,
  650.  NULL,
  651.  2,
  652.  NULL
  653. };
  654.  
  655. static SHORT demoBorderVectors5[] = {
  656.  0,0,
  657.  123,0,
  658.  123,11,
  659.  0,11,
  660.  0,0
  661. };
  662. static struct Border demoBorder5 = {
  663.  -2,-1,
  664.  3,0,JAM1,
  665.  5,
  666.  demoBorderVectors5,
  667.  NULL
  668. };
  669.  
  670. static struct IntuiText demoIText7 = {
  671.  3,0,JAM2,
  672.  5,1,
  673.  NULL,
  674.  "Color Pallette",
  675.  NULL
  676. };
  677.  
  678. static struct Gadget demoGadget4 = {
  679.  &demoGadget5,
  680.  23,47,
  681.  120,10,
  682.  NULL,
  683.  RELVERIFY,
  684.  BOOLGADGET,
  685.  (APTR)&demoBorder5,
  686.  NULL,
  687.  &demoIText7,
  688.  NULL,
  689.  NULL,
  690.  3,
  691.  NULL
  692. };
  693.  
  694. static SHORT demoBorderVectors6[] = {
  695.  0,0,
  696.  123,0,
  697.  123,11,
  698.  0,11,
  699.  0,0
  700. };
  701. static struct Border demoBorder6 = {
  702.  -2,-1,
  703.  3,0,JAM1,
  704.  5,
  705.  demoBorderVectors6,
  706.  NULL
  707. };
  708.  
  709. static struct IntuiText demoIText8 = {
  710.  3,0,JAM2,
  711.  24,1,
  712.  NULL,
  713.  "All Files",
  714.  NULL
  715. };
  716.  
  717. static struct Gadget demoGadget3 = {
  718.  &demoGadget4,
  719.  23,17,
  720.  120,10,
  721.  NULL,
  722.  RELVERIFY,
  723.  BOOLGADGET,
  724.  (APTR)&demoBorder6,
  725.  NULL,
  726.  &demoIText8,
  727.  NULL,
  728.  NULL,
  729.  1,
  730.  NULL
  731. };
  732.  
  733. #define demoGadgetList2 demoGadget3
  734.  
  735. static struct NewWindow demoNewWindowStructure2 = {
  736.  222,96,
  737.  314,95,
  738.  0,1,
  739.  GADGETDOWN+GADGETUP+CLOSEWINDOW+NEWSIZE,
  740.  WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE,
  741.  &demoGadget3,
  742.  NULL,
  743.  "InovaTools Demo",
  744.  NULL,
  745.  NULL,
  746.  314,95,
  747.  314,200,
  748.  WBENCHSCREEN
  749. };
  750.  
  751.  
  752. /*    Only ROM resident libraries are needed: */
  753.  
  754. extern long OpenLibrary();
  755.  
  756. void main()
  757.  
  758. /*    The main program.  Open the window and install the list.
  759.     There is no need to duplicate structures, since this is
  760.     not a reentrant window. 
  761. */
  762.  
  763. {
  764.     register struct Window *window;
  765.     register struct IntuiMessage *message;
  766.     register long class, code;
  767.     register struct Gadget *gadget;
  768.     struct WindowListItem *windowlistitem;
  769.     char blankstring[100];
  770.     LayersBase = OpenLibrary("layers.library",0l);
  771.     GfxBase = OpenLibrary("graphics.library",0l);
  772.     IntuitionBase = OpenLibrary("intuition.library",0l);
  773.     MathBase = OpenLibrary("mathffp.library",0l);
  774.     window = (struct Window *) FlashyOpenWindow(&demoNewWindowStructure2);
  775.     if (window) {
  776.     windowlist.Window = window;
  777.     InitListInfo(&windowlist);
  778.     for (;;) {
  779.         message = GetIntuiMessage(window);
  780.         class = message->Class;
  781.         code = message->Code;
  782.         gadget = (struct Gadget *) message->IAddress;
  783.         ReplyMsg(message);
  784.         if (class == CLOSEWINDOW) break;
  785.  
  786. /*    If the window size changes, redraw the list so it fits. */
  787.  
  788.         else if (class == NEWSIZE) {
  789.         windowlist.Height = window->Height - 26;
  790.         SizeList(&windowlist);
  791.         }
  792.         else if (class == GADGETDOWN) {
  793.         switch(gadget->GadgetID) {
  794.             case 12 :    /* Up arrow clicked in list. */
  795.             case 13 :    /* Down arrow clicked in list. */
  796.             ClickList(&windowlist,(long)gadget->GadgetID);
  797.             break;
  798.         }
  799.         }
  800.         else if (class == GADGETUP) {
  801.         switch(gadget->GadgetID) {
  802.             case 1 :    /* All files requester. */
  803.             FileName(blankstring,"All Files:",0l,0l,(long)
  804.                 FILES_DELETE | FILES_OPEN | FILES_TEST,0l,0l);
  805.             break;
  806.             case 2 :    /* C files requester. */
  807.             FileName(blankstring,"C Files:","c",0l,(long)
  808.                 FILES_DELETE | FILES_OPEN | FILES_TEST,0l,0l);
  809.             break;
  810.             case 3 :    /* Pallette Editor. */
  811.             EditColors(0l,10l,10l,80l);
  812.             break;
  813.             case 4 :    /* Create a window. */
  814.             CreateTask("Duplicate Window Handler",(long)0,
  815.                 dupewindowcode,(long)4000);
  816.             Delay((long)30);
  817.             break;
  818.             case 5 :    /* Delete currently activated window. */
  819.             if (windowlist.ActiveItem) {
  820.                 windowlistitem = (struct WindowListItem *) 
  821.                 windowlist.ActiveItem;
  822.                 SendCloseWindow(windowlistitem->window);
  823.                 Delay((long)30);
  824.             }
  825.             break;
  826.             case 10 :    /* List scroll bar. */
  827.             ScrollList(&windowlist);
  828.             break;
  829.             case 11 :    /* List box was clicked. */
  830.             GetListItem(&windowlist);
  831.             break;
  832.         }
  833.         }
  834.     }
  835.  
  836. /*    Tell all windows to close down.  SendCloseWindow sends
  837.     and Intuition CLOSEWINDOW event to the window, tricking it
  838.     into thinking the use shut it down.
  839. */
  840.  
  841.     for (;windowlist.TopItem;) {
  842.         windowlistitem = (struct WindowListItem *) windowlist.TopItem;
  843.         SendCloseWindow(windowlistitem->window);
  844.         Delay((long)20);
  845.     }
  846.     RemoveListInfo(&windowlist);
  847.     FlashyCloseWindow(window);
  848.     }
  849.  
  850. /*    Get rid of all duplicated structures that weren't freed.
  851.     And, get rid of the memory backup of file names. 
  852. */
  853.  
  854.     DeleteAll();
  855.     ReleaseFiles();
  856.     CloseLibrary(MathBase);
  857.     CloseLibrary(IntuitionBase);
  858.     CloseLibrary(GfxBase);
  859. }
  860.