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

  1. ;/* simplegad.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 simplegad.c
  3. Blink FROM LIB:c.o,simplegad.o TO simplegad LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. **
  6. ** The example below demonstrates a simple application gadget.  The
  7. ** program declares a Gadget structure set up as a boolean gadget with
  8. ** complement mode highlighting.  The gadget is attached to the window
  9. ** when it is opened by using the WA_Gadgets tag in the OpenWindowTags()
  10. ** call.
  11. **
  12. ** simplegad.c - show the use of a button gadget.
  13. */
  14.  
  15. #define INTUI_V36_NAMES_ONLY
  16.  
  17. #include <exec/types.h>
  18. #include <intuition/intuition.h>
  19. #include <intuition/intuitionbase.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23.  
  24. #include <stdio.h>
  25.  
  26. #ifdef LATTICE
  27. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  28. int chkabort(void) { return(0); }  /* really */
  29. #endif
  30.  
  31. struct Library *IntuitionBase;
  32.  
  33. #define BUTTON_GAD_NUM   (3)
  34. #define MYBUTTONGADWIDTH (100)
  35. #define MYBUTTONGADHEIGHT (50)
  36.  
  37. /* NOTE that the use of constant size and positioning values are
  38. ** not recommended; it just makes it easy to show what is going on.
  39. ** The position of the gadget should be dynamically adjusted depending
  40. ** on the height of the font in the title bar of the window.
  41. */
  42.  
  43. UWORD buttonBorderData[] =
  44.     {
  45.     0,0, MYBUTTONGADWIDTH + 1,0, MYBUTTONGADWIDTH + 1,MYBUTTONGADHEIGHT + 1,
  46.     0,MYBUTTONGADHEIGHT + 1, 0,0,
  47.     };
  48.  
  49. struct Border buttonBorder =
  50.     {
  51.     -1,-1,1,0,JAM1,5,buttonBorderData,NULL,
  52.     };
  53.  
  54. struct Gadget buttonGad =
  55.     {
  56.     NULL, 20,20, MYBUTTONGADWIDTH,MYBUTTONGADHEIGHT,
  57.     GFLG_GADGHCOMP, GACT_RELVERIFY | GACT_IMMEDIATE,
  58.     GTYP_BOOLGADGET, &buttonBorder, NULL, NULL,0,NULL,BUTTON_GAD_NUM,NULL,
  59.     };
  60.  
  61. /*
  62. ** routine to show the use of a button (boolean) gadget.
  63. */
  64. VOID main(int argc, char **argv)
  65. {
  66. struct Window *win;
  67. struct IntuiMessage *msg;
  68. struct Gadget *gad;
  69. ULONG  class;
  70. BOOL done;
  71.  
  72. /* make sure to get intuition version 37, for OpenWindowTags() */
  73. IntuitionBase = OpenLibrary("intuition.library", 37);
  74. if (IntuitionBase)
  75.     {
  76.     if (win = OpenWindowTags(NULL,
  77.                             WA_Width, 400,
  78.                             WA_Height, 100,
  79.                             WA_Gadgets, &buttonGad,
  80.                             WA_Activate, TRUE,
  81.                             WA_CloseGadget, TRUE,
  82.                             WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_GADGETUP |
  83.                                       IDCMP_CLOSEWINDOW,
  84.                             TAG_END))
  85.         {
  86.         done = FALSE;
  87.         while (done == FALSE)
  88.             {
  89.             Wait(1L << win->UserPort->mp_SigBit);
  90.             while ( (done == FALSE) &&
  91.                     (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  92.                 {
  93.                 /* Stash message contents and reply, important when message
  94.                 ** triggers some lengthy processing
  95.                 */
  96.                 class = msg->Class;
  97.  
  98.                 /* gadget address is ONLY valid for gadget messages! */
  99.                 if ((class == IDCMP_GADGETUP) || (class == IDCMP_GADGETDOWN))
  100.                     gad = (struct Gadget *)(msg->IAddress);
  101.  
  102.                 ReplyMsg((struct Message *)msg);
  103.  
  104.                 /* switch on the type of the event */
  105.                 switch (class)
  106.                     {
  107.                     case IDCMP_GADGETUP:
  108.                         /* caused by GACT_RELVERIFY */
  109.                         printf("received an IDCMP_GADGETUP, gadget number %d\n",
  110.                                gad->GadgetID);
  111.                         break;
  112.                     case IDCMP_GADGETDOWN:
  113.                         /* caused by GACT_IMMEDIATE */
  114.                         printf("received an IDCMP_GADGETDOWN, gadget number %d\n",
  115.                                gad->GadgetID);
  116.                         break;
  117.                     case IDCMP_CLOSEWINDOW:
  118.                         /* set a flag that we are done processing events... */
  119.                         printf("received an IDCMP_CLOSEWINDOW\n");
  120.                         done = TRUE;
  121.                         break;
  122.                     }
  123.                 }
  124.             }
  125.         CloseWindow(win);
  126.         }
  127.     CloseLibrary(IntuitionBase);
  128.     }
  129. }
  130.