home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / ansicdemo.lha / ANSI-C / Intuition / gadgethelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  5.8 KB  |  231 lines

  1. /*
  2.  * gadgethelp.c - shows help and bounds on a prop gadget
  3.  *
  4.  * NB: If using GadTools, the correct bounds and help-properties
  5.  * are already set in GadTools gadgets.
  6.  *
  7.  * (c) Copyright 1992 Commodore-Amiga, Inc.  All Rights Reserved.
  8.  * 
  9.  * This demo shows off the gadget help feature of V39.  With this
  10.  * feature, an application can be notified when the user stops the
  11.  * mouse over a gadget.  The intent is that the application would
  12.  * then offer help (perhaps using AmigaGuide) on that gadget.
  13.  * Gadget help can be set selectively for any user gadget.  The
  14.  * application shows the correct handling of the IDCMP_GADGETHELP
  15.  * message, including decisions about when the mouse is not in
  16.  * the window, or when it's in the window but not over any help-reporting
  17.  * gadget.
  18.  *
  19.  * Note that all GadTools gadgets correctly set their bounds and
  20.  * the gadget help property.
  21.  * 
  22.  */
  23.  
  24. /*------------------------------------------------------------------------*/
  25. #include <stdio.h>
  26. #include <intuition/intuition.h>
  27. #include <pragma/exec_lib.h>
  28. #include <pragma/intuition_lib.h>
  29.  
  30. /*------------------------------------------------------------------------*/
  31.  
  32. void bail_out(int code);
  33.  
  34. /*------------------------------------------------------------------------*/
  35.  
  36. struct Image im =
  37. {
  38.     0,0,0,0,0,
  39.     0,
  40. };
  41.  
  42. struct PropInfo mypinfo =
  43. {
  44.     AUTOKNOB|FREEVERT,
  45.     0, 2730,    /*  VPot represents 1 on scale 0..28 with 5 visible */
  46.     0, 9362,    /*  VBody represents 0..28 with 5 visible */
  47.     0, 0, 0, 0, 0, 0,
  48. };
  49.  
  50.  
  51. struct ExtGadget myGad =
  52. {
  53.     NULL,    /*  NextGadget */
  54.     20,12,    /*  LeftEdge, TopEdge */
  55.     80,100,    /*  Width, Height */
  56.     GFLG_EXTENDED | GADGHNONE | GADGIMAGE,        /*  Flags */
  57.     GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY,    /*  Activation */
  58.     PROPGADGET,    /*  GadgetType */
  59.     &im,    /*  GadgetRender */
  60.     NULL,    /*  SelectRender */
  61.     NULL,    /*  GadgetText */
  62.     NULL,    /*  MutualExclude */
  63.     &mypinfo,    /*  SpecialInfo */
  64.     NULL,    /*  GadgetID */
  65.     NULL,    /*  UserData */
  66.     GMORE_BOUNDS|GMORE_GADGETHELP,
  67.     10,10,    /*  LeftEdge, TopEdge */
  68.     100,120,    /*  Width, Height */
  69. };
  70.  
  71. struct NewWindow testnewwindow =
  72. {
  73.     0,0,        /*  LeftEdge, TopEdge */
  74.     320,150,            /*  Width, Height */
  75.     -1, -1,             /*  DetailPen, BlockPen */
  76.     IDCMP_GADGETHELP | IDCMP_RAWKEY | CLOSEWINDOW | MOUSEMOVE | GADGETUP | GADGETDOWN,    /*  IDCMPFlags */
  77.     WINDOWDRAG | WINDOWSIZING | WINDOWDEPTH | WINDOWCLOSE |
  78.     NOCAREREFRESH | SMART_REFRESH,    /* Flags */
  79.     NULL,        /*  FirstGadget */
  80.     NULL,        /*  CheckMark */
  81.     (UBYTE *) "Gadget Help Demo",    /*  Title */
  82.     NULL,        /*  Screen */
  83.     NULL,        /*  BitMap */    
  84.     100,50,        /*  MinWidth, MinHeight */
  85.     640,200,        /*  MaxWidth, MaxHeight */
  86.     WBENCHSCREEN,    /*  Type */
  87. };
  88.  
  89. /*------------------------------------------------------------------------*/
  90.  
  91. struct IntuitionBase *IntuitionBase;
  92. struct Window *mywin;
  93.  
  94. /*------------------------------------------------------------------------*/
  95.  
  96. main()
  97. {
  98.     BOOL terminated;
  99.     struct IntuiMessage *imsg;
  100.  
  101.     terminated = FALSE;
  102.     mywin = NULL;
  103.  
  104.     if (!(IntuitionBase = (struct IntuitionBase *)
  105.     OpenLibrary("intuition.library",39L)))
  106.     bail_out(20);
  107.  
  108.     if (!(mywin = OpenWindowTags(&testnewwindow,
  109.     TAG_DONE)))
  110.     bail_out(20);
  111.  
  112.     myGad.TopEdge += mywin->WScreen->Font->ta_YSize;
  113.     AddGadget( mywin, ( struct Gadget *)&myGad, ~0 );
  114.     RefreshGList( ( struct Gadget *)&myGad, mywin, NULL, 1 );
  115.  
  116.     printf("Window at %lx, gadget at %lx\n", mywin, &myGad);
  117.  
  118.     /* Turn on Gadget Help */
  119.     HelpControl( mywin, HC_GADGETHELP );
  120.  
  121.     while (!terminated)
  122.     {
  123.     Wait (1 << mywin->UserPort->mp_SigBit);
  124.     while (imsg = (struct IntuiMessage *) GetMsg(mywin->UserPort))
  125.     {
  126.         switch ( imsg->Class )
  127.         {
  128.         case IDCMP_MOUSEMOVE:
  129.         printf("MouseMove (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  130.         break;
  131.  
  132.         case IDCMP_CLOSEWINDOW:
  133.         terminated = TRUE;
  134.         break;
  135.  
  136.         case IDCMP_RAWKEY:
  137.         printf("RAWKEY %lx\n", imsg->Code);
  138.         break;
  139.  
  140.         case IDCMP_GADGETUP:
  141.         printf("Gadget Up (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  142.         break;
  143.  
  144.         case IDCMP_GADGETDOWN:
  145.         printf("Gadget Down (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  146.         break;
  147.  
  148.         case IDCMP_GADGETHELP:
  149.         if ( imsg->IAddress == NULL )
  150.         {
  151.             printf("Gadget Help: Mouse not over window\n");
  152.         }
  153.         else if ( imsg->IAddress == (APTR) mywin )
  154.         {
  155.             printf("Gadget Help: Mouse in window, not over a gadget\n");
  156.         }
  157.         else
  158.         {
  159.             /* Detect system gadgets.  Figure out by looking at
  160.              * system-gadget-type bits in GadgetType field:
  161.              */
  162.             LONG sysgtype =
  163.             ((struct Gadget *)imsg->IAddress)->GadgetType & 0xF0;
  164.             switch ( sysgtype )
  165.             {
  166.             case GTYP_SIZING:
  167.             printf("Gadget Help for window sizing gadget\n");
  168.             break;
  169.  
  170.             case GTYP_WDRAGGING:
  171.             printf("Gadget Help for window drag-bar\n");
  172.             break;
  173.  
  174.             case GTYP_WUPFRONT:
  175.             printf("Gadget Help for window depth gadget\n");
  176.             break;
  177.  
  178.             case GTYP_WDOWNBACK:
  179.             printf("Gadget Help for window zoom gadget\n");
  180.             break;
  181.  
  182.             case GTYP_CLOSE:
  183.             printf("Gadget Help for window close gadget\n");
  184.             break;
  185.  
  186.             case 0:
  187.             /* In this example, we only have one gadget,
  188.              * so we know which one it is.  Normally, you'd
  189.              * have to figure that out here, using the
  190.              * usual techniques you already use for other
  191.              * gadget messages.
  192.              */
  193.             printf("Gadget Help for proportional gadget, code %ld\n",
  194.                 imsg->Code);
  195.             break;
  196.  
  197.             default:
  198.                 printf("Gadget Help on some other system gadget\n");
  199.                 break;
  200.             }
  201.         }
  202.         }
  203.     }
  204.     }
  205.     bail_out(0);
  206. }
  207.  
  208.  
  209. /*------------------------------------------------------------------------*/
  210.  
  211. /*/ bail_out()
  212.  *
  213.  * Close any allocated or opened stuff.
  214.  *
  215.  */
  216.  
  217. void bail_out(code)
  218.  
  219. int code;
  220. {
  221.     if (mywin)
  222.     CloseWindow(mywin);
  223.  
  224.     if (IntuitionBase)
  225.     CloseLibrary( ( struct Library *)IntuitionBase);
  226.  
  227.     exit(code);
  228. }
  229.  
  230. /*------------------------------------------------------------------------*/
  231.