home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / Talk2boopsi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  7.6 KB  |  148 lines

  1. ;/* Talk2boopsi.c - Execute me to compile me with SAS/C 5.10b
  2. LC -b1 -cfistq -v -y -j73 Talk2boopsi.c
  3. Blink FROM LIB:c.o,Talk2boopsi.o TO Talk2boopsi LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit ;*/
  5. /* This example creates a Boopsi prop gadget and integer string gadget, connecting them so they */
  6. /* update each other when the user changes their value.  The example program only initializes   */
  7. /* the gadgets and puts them on the window; it doesn't have to interact with them to make them  */
  8. /* talk to each other.                                                                          */
  9.  
  10. #include <exec/types.h>
  11. #include <utility/tagitem.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/gadgetclass.h> /* contains IDs for gadget attributes */
  14. #include <intuition/icclass.h>     /* contains ICA_MAP, ICA_TARGET       */
  15. #include <clib/exec_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #ifdef LATTICE                     /* Disable SAS/C CTRL/C handling    */
  19. int CXBRK(void) { return(0); }
  20. int chkabort(void) { return(0); }
  21. #endif
  22.  
  23. UBYTE *vers = "\0$VER: Talk2boopsi 37.1";
  24.  
  25. struct Library *IntuitionBase;
  26. struct Window *w;
  27. struct IntuiMessage *msg;
  28. struct Gadget *prop, *integer;
  29.  
  30. /* The attribute mapping lists */
  31. struct TagItem prop2intmap[] =    /* This tells the prop gadget to */
  32. {                                 /* map its PGA_Top attribute to  */
  33.     {PGA_Top,   STRINGA_LongVal}, /* STRINGA_LongVal when it       */
  34.     {TAG_END,}                    /* issues an update about the    */
  35. };                                /* change to its PGA_Top value.  */
  36.  
  37. struct TagItem int2propmap[] =    /* This tells the string gadget */
  38. {                                 /* to map its STRINGA_LongVal   */
  39.     {STRINGA_LongVal,   PGA_Top}, /* attribute to PGA_Top when it */
  40.     {TAG_END,}                    /* issues an update.            */
  41. };
  42.  
  43. #define PROPGADGET_ID       1L
  44. #define INTGADGET_ID        2L
  45. #define PROPGADGETWIDTH     10L
  46. #define PROPGADGETHEIGHT    80L
  47. #define INTGADGETHEIGHT     18L
  48. #define VISIBLE             10L
  49. #define TOTAL               100L
  50. #define INITIALVAL          25L
  51. #define MINWINDOWWIDTH      80
  52. #define MINWINDOWHEIGHT     (PROPGADGETHEIGHT + 70)
  53. #define MAXCHARS            3L
  54.  
  55.  
  56. void main(void)
  57. {
  58.     BOOL done = FALSE;
  59.  
  60.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  61.     {                                /* Open the window--notice that the window's IDCMP port     */
  62.                                      /* does not listen for GADGETUP messages.                   */
  63.         if (w = OpenWindowTags(NULL,
  64.                  WA_Flags,       WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  65.                                      WFLG_CLOSEGADGET | WFLG_SIZEGADGET,
  66.                  WA_IDCMP,       IDCMP_CLOSEWINDOW,
  67.                  WA_MinWidth,    MINWINDOWWIDTH,
  68.                  WA_MinHeight,   MINWINDOWHEIGHT,
  69.                  TAG_END))
  70.         {                                 /* Create a new propgclass object */
  71.             if (prop = (struct Gadget *)NewObject(NULL, "propgclass",
  72.                 GA_ID,     PROPGADGET_ID,        /* These are defined by gadgetclass and         */
  73.                 GA_Top,    (w->BorderTop) + 5L,  /* correspond to similarly named fields in      */
  74.                 GA_Left,   (w->BorderLeft) + 5L, /* the Gadget structure.                        */
  75.                 GA_Width,  PROPGADGETWIDTH,
  76.                 GA_Height, PROPGADGETHEIGHT,
  77.  
  78.                 ICA_MAP,      prop2intmap, /* The prop gadget's attribute map */
  79.  
  80.              /* The rest of this gadget's attributes are defined by propgclass. */
  81.                 PGA_Total,     TOTAL,          /* This is the integer range of the prop gadget.  */
  82.                 PGA_Top,       INITIALVAL,     /* The initial integer value of the prop gadget.  */
  83.  
  84.                 PGA_Visible,   VISIBLE, /* This determines how much of the prop gadget area is   */
  85.                                         /* covered by the prop gadget's knob, or how much of     */
  86.                                         /* the gadget's TOTAL range is taken up by the prop      */
  87.                                         /* gadget's knob.                                        */
  88.  
  89.                 PGA_NewLook,   TRUE,    /* Use new-look prop gadget imagery */
  90.                 TAG_END))
  91.             {                           /* create the integer string gadget.                     */
  92.                 if (integer = (struct Gadget *)NewObject(NULL, "strgclass",
  93.                     GA_ID,      INTGADGET_ID,         /* Parameters for the Gadget structure     */
  94.                     GA_Top,     (w->BorderTop) + 5L,
  95.                     GA_Left,    (w->BorderLeft) + PROPGADGETWIDTH + 10L,
  96.                     GA_Width,   MINWINDOWWIDTH -
  97.                                   (w->BorderLeft + w->BorderRight +
  98.                                   PROPGADGETWIDTH + 15L),
  99.                     GA_Height,  INTGADGETHEIGHT,
  100.  
  101.                     ICA_MAP,    int2propmap,           /* The attribute map */
  102.                     ICA_TARGET, prop,                  /* plus the target.  */
  103.  
  104.                             /* Th GA_Previous attribute is defined by gadgetclass and is used to */
  105.                             /* wedge a new gadget into a list of gadget's linked by their        */
  106.                             /* Gadget.NextGadget field.  When NewObject() creates this gadget,   */
  107.                             /* it inserts the new gadget into this list behind the GA_Previous   */
  108.                             /* gadget. This attribute is a pointer to the previous gadget        */
  109.                             /* (struct Gadget *).  This attribute cannot be used to link new     */
  110.                             /* gadgetsinto the gadget list of an open window or requester,       */
  111.                     GA_Previous, prop,  /* use AddGList() instead.                               */
  112.  
  113.                     STRINGA_LongVal,  INITIALVAL, /* These attributes are defined by strgclass.  */
  114.                     STRINGA_MaxChars, MAXCHARS,   /* The first contains the value of the         */
  115.                     TAG_END))                     /* integer string gadget. The second is the    */
  116.                                                   /* maximum number of characters the user is    */
  117.                                                   /* allowed to type into the gadget.            */
  118.                  {
  119.                     SetGadgetAttrs(prop, w, NULL, /* Because the integer string gadget did not   */
  120.                         ICA_TARGET, integer,      /* exist when this example created the prop    */
  121.                         TAG_END);                 /* gadget, it had to wait to set the           */
  122.                                                   /* ICA_Target of the prop gadget.              */
  123.  
  124.                     AddGList(w, prop, -1, -1, NULL);  /* Add the gadgets to the                  */
  125.                     RefreshGList(prop, w, NULL, -1);  /* window and display them.                */
  126.  
  127.                     while (done == FALSE)     /* Wait for the user to click */
  128.                     {                         /* the window close gadget.   */
  129.                         WaitPort((struct MsgPort *)w->UserPort);
  130.                         while (msg = (struct IntuiMessage *)
  131.                            GetMsg((struct MsgPort *)w->UserPort))
  132.                         {
  133.                             if (msg->Class == IDCMP_CLOSEWINDOW)
  134.                                 done = TRUE;
  135.                             ReplyMsg(msg);
  136.                         }
  137.                     }
  138.                     RemoveGList(w, prop, -1);
  139.                     DisposeObject(integer);
  140.                  }
  141.                 DisposeObject(prop);
  142.             }
  143.             CloseWindow(w);
  144.         }
  145.         CloseLibrary(IntuitionBase);
  146.     }
  147. }
  148.