home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-23 / boopsi1.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  12KB  |  285 lines

  1. ;/* boopsi1.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 boopsi1.c
  3. slink FROM LIB:c.o,boopsi1.o TO boopsi1 LIBRARY LIB:sc.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /* boopsi example showing simple creation of boopsi
  8. ** gadgets and using system images.
  9. */
  10. /*
  11. Copyright (c) 1991 Commodore-Amiga, Inc.
  12.  
  13. This example is provided in electronic form by Commodore-Amiga,
  14. Inc. for use with the Amiga Mail Volume II technical publication.
  15. Amiga Mail Volume II contains additional information on the correct
  16. usage of the techniques and operating system functions presented in
  17. these examples.  The source and executable code of these examples may
  18. only be distributed in free electronic form, via bulletin board or
  19. as part of a fully non-commercial and freely redistributable
  20. diskette.  Both the source and executable code (including comments)
  21. must be included, without modification, in any copy.  This example
  22. may not be published in printed form or distributed with any
  23. commercial product. However, the programming techniques and support
  24. routines set forth in these examples may be used in the development
  25. of original executable software products for Commodore Amiga
  26. computers.
  27.  
  28. All other rights reserved.
  29.  
  30. This example is provided "as-is" and is subject to change; no
  31. warranties are made.  All use is at your own risk. No liability or
  32. responsibility is assumed.
  33. */
  34.  
  35. #include <intuition/intuition.h>
  36. #include <intuition/classusr.h>
  37. #include <intuition/imageclass.h>
  38. #include <intuition/gadgetclass.h>
  39. #include <clib/exec_protos.h>
  40. #include <clib/intuition_protos.h>
  41. #include <clib/graphics_protos.h>
  42.  
  43. #ifdef LATTICE
  44. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  45. int chkabort(void) { return(0); }
  46. #endif
  47.  
  48. UBYTE *vers = "\0$VER: boopsi1 1.0";
  49.  
  50. void ProcessWindow(void);
  51.  
  52. #define MYPROP       1L
  53. #define MYSTRING     2L
  54. #define MYLEFTBUT    3L
  55. #define MYRIGHTBUT   4L
  56.  
  57. #define GADTOP      10L
  58. #define STRLEFT     20L
  59. #define STRWIDTH    30L
  60. #define STRHEIGHT   11L
  61. #define INITVALUE   25L
  62. #define PROPWIDTH   100L
  63. #define PROPVIS     10L
  64. #define BUTGADWID   11L
  65. #define BUTGADHEI   11L
  66.  
  67. struct Screen *screen;
  68. struct Window *window;
  69. struct DrawInfo *drinfo;
  70. struct Library *IntuitionBase;
  71. struct Gadget *prop, *string, *leftbut, *rightbut, *mygadgets;
  72. struct Image *rightbimage, *leftbimage;
  73.  
  74.  
  75.  
  76. void main(void)
  77. {
  78.     struct Gadget *tmpgad;
  79.     WORD gadtop;
  80.  
  81.     tmpgad = (struct Gadget *)&mygadgets;
  82.  
  83.     if (IntuitionBase = OpenLibrary("intuition.library", 36L))
  84.     {
  85.         if (screen = LockPubScreen(NULL))
  86.         {
  87.             /* need my screen's DrawInfo for the system gadget images */
  88.             drinfo = GetScreenDrawInfo(screen);
  89.  
  90.             gadtop = screen->Font->ta_YSize + GADTOP;
  91.             if (window = OpenWindowTags(NULL,
  92.                     WA_Title, (ULONG *)"AMail boopsi1",
  93.                     WA_Height, gadtop+STRHEIGHT+10L,
  94.                     WA_Width,  STRLEFT+STRWIDTH+PROPWIDTH+2*BUTGADWID+15,
  95.                     WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR | WFLG_CLOSEGADGET,
  96.                     WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  97.                             TAG_END))
  98.             {
  99.  
  100.                 /* Create a boopsi string gadget */
  101.                 if (string = (struct Gadget *)NewObject(NULL, "strgclass",
  102.                             /* All the normal Gadget fields */
  103.                             GA_ID,              MYSTRING,
  104.                             GA_Immediate,           TRUE,
  105.                             GA_RelVerify,           TRUE,
  106.                             GA_Top,             gadtop,
  107.                             GA_Left,            STRLEFT,
  108.                             GA_Width,           STRWIDTH,
  109.                             GA_Height,          STRHEIGHT,
  110.                             STRINGA_MaxChars,   3,
  111.                             STRINGA_LongVal,    INITVALUE,
  112.                             STRINGA_Justification, STRINGRIGHT,
  113.  
  114.                             /* Boopsi makes it easy to link gadgets together.
  115.                             ** The GA_Previous tag accepts a (struct Gadget **)
  116.                             ** to the previous gadget in the list, then changes
  117.                             ** this value to point to the gadget being
  118.                             ** created (in this case, "string").
  119.                             */
  120.                             GA_Previous,        tmpgad,
  121.                             TAG_END))
  122.                 {
  123.                     /* create the prop gadget */
  124.                     if (prop = (struct Gadget *)NewObject(NULL, "propgclass",
  125.                                 GA_Immediate,   TRUE,
  126.                                 GA_RelVerify,   TRUE,
  127.                                 PGA_Freedom,    FREEHORIZ,
  128.                                 PGA_Borderless, FALSE,
  129.                                 GA_Left,        STRLEFT + STRWIDTH,
  130.                                 GA_Top,         gadtop,
  131.                                 GA_Height,      BUTGADHEI,
  132.                                 PGA_Top,        INITVALUE,
  133.                                 PGA_Visible,    PROPVIS,
  134.                                 PGA_Total,      PROPWIDTH,
  135.                                 GA_ID,          MYPROP,
  136.  
  137.                                 /* link prop to string and
  138.                                 ** make tmpgad point to prop. */
  139.                                 GA_Previous,    tmpgad,
  140.                                 TAG_END))
  141.                     {
  142.                         /* Ask the system for a left arrow image
  143.                         ** for the left arrow gadget. */
  144.                         if (leftbimage = (struct Image *)NewObject(NULL,
  145.                             "sysiclass",
  146.  
  147.                             /* boopsi needs this screen's DrawInfo
  148.                             ** structure to get the right image.  */
  149.                             SYSIA_DrawInfo,   drinfo,
  150.                             SYSIA_Which,      LEFTIMAGE,
  151.  
  152.                             /* this will give us 11 x 11 buttons */
  153.                             SYSIA_Size,       SYSISIZE_MEDRES,
  154.                                   TAG_END))
  155.                         {
  156.                             /* Now ask for a right arrow */
  157.                             if (rightbimage = (struct Image *)NewObject(NULL,
  158.                                 "sysiclass",
  159.                                 SYSIA_DrawInfo,   drinfo,
  160.                                 SYSIA_Which,      RIGHTIMAGE,
  161.                                 SYSIA_Size,       SYSISIZE_MEDRES,
  162.                                               TAG_END))
  163.                             {
  164.                                 /* Create the left button */
  165.                                 if (leftbut = (struct Gadget *)NewObject(NULL,
  166.                                     "buttongclass",
  167.                                     GA_ID,        MYLEFTBUT,
  168.                                     GA_Immediate, TRUE,
  169.                                     GA_RelVerify, TRUE,
  170.                                     GA_Image,     leftbimage,
  171.                                     GA_Top,       gadtop,
  172.                                     GA_Left,      STRLEFT+STRWIDTH+PROPWIDTH-15,
  173.                                     GA_Width,     BUTGADWID,
  174.                                     GA_Height,    BUTGADHEI,
  175.                                     GA_Previous,  tmpgad,
  176.                                     TAG_END))
  177.                                 {
  178.                                     /* Create the right button */
  179.                                     if (rightbut = (struct Gadget *)NewObject(NULL,
  180.                                         "buttongclass",
  181.                                         GA_ID,        MYRIGHTBUT,
  182.                                         GA_Immediate, TRUE,
  183.                                         GA_RelVerify, TRUE,
  184.                                         GA_Image,     rightbimage,
  185.                                         GA_Top,       gadtop,
  186.                                         GA_Left,
  187.                                             STRLEFT+STRWIDTH+PROPWIDTH+BUTGADWID-10,
  188.                                         GA_Width,     BUTGADWID,
  189.                                         GA_Height,    BUTGADHEI,
  190.                                         GA_Previous,  tmpgad,
  191.                                         TAG_END))
  192.                                     {
  193.                                         /* All of the gadgets have been created
  194.                                         ** and linked together.  Add them to the
  195.                                         ** display and display them.
  196.                                         */
  197.                                         AddGList(window, mygadgets, -1, -1, NULL);
  198.                                         RefreshGList(mygadgets, window, NULL, -1);
  199.                                         ProcessWindow();
  200.                                         RemoveGList(window, mygadgets, -1);
  201.                                         DisposeObject(rightbut);
  202.                                     }
  203.                                     DisposeObject(leftbut);
  204.                                 }
  205.                                 DisposeObject(rightbimage);
  206.                             }
  207.                             DisposeObject(leftbimage);
  208.                         }
  209.                         DisposeObject(prop);
  210.                     }
  211.                     DisposeObject(string);
  212.                 }
  213.                 CloseWindow(window);
  214.             }
  215.             FreeScreenDrawInfo(screen, drinfo);
  216.             UnlockPubScreen(NULL, screen);
  217.         }
  218.         CloseLibrary(IntuitionBase);
  219.     }
  220. }
  221.  
  222. void ProcessWindow(void)
  223. {
  224.     struct IntuiMessage *imsg;
  225.     BOOL returnvalue = TRUE;
  226.     ULONG class;
  227.     LONG currval = INITVALUE;
  228.     struct Gadget *g;
  229.  
  230.  
  231.     while (returnvalue)
  232.     {
  233.         WaitPort(window->UserPort);
  234.         while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort))
  235.         {
  236.             g = (struct Gadget *)imsg->IAddress;
  237.             class = imsg->Class;
  238.             ReplyMsg((struct Message *)imsg);
  239.             switch (class)
  240.             {
  241.                 case IDCMP_CLOSEWINDOW:
  242.                     returnvalue = FALSE;
  243.                     break;
  244.                 case IDCMP_GADGETUP:
  245.                     switch (g->GadgetID)
  246.                     {
  247.                         case MYLEFTBUT:
  248.                             currval--;
  249.                             break;
  250.                         case MYRIGHTBUT:
  251.                             currval++;
  252.                             break;
  253.                         case MYPROP:
  254.                             /* read the prop gadget's value */
  255.                             GetAttr(PGA_TOP, prop, &currval);
  256.                             break;
  257.                         case MYSTRING:
  258.                             /* read the string gadget's value */
  259.                             GetAttr(STRINGA_LongVal, string, &currval);
  260.                             break;
  261.                     }
  262.                     /* make sure the value is between 0 and 90 */
  263.                     if (currval < 0L)
  264.                         currval = 0L;
  265.                     else
  266.                         if (currval > PROPWIDTH - PROPVIS)
  267.                             currval = PROPWIDTH - PROPVIS;
  268.  
  269.                     /* Update the values of the prop and string.
  270.                     ** gadgets (Intuition takes care of the  refresh). */
  271.  
  272.                     SetGadgetAttrs( prop, window, NULL,
  273.                                     PGA_TOP, currval,
  274.                                 TAG_END );
  275.  
  276.                     SetGadgetAttrs( string, window, NULL,
  277.                                 STRINGA_LongVal, currval,
  278.                                     TAG_END );
  279.  
  280.                     break;
  281.             }
  282.         }
  283.     }
  284. }
  285.