home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / CBMDevKit3.dms / CBMDevKit3.adf / intuition / gadgethelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  5.9 KB  |  235 lines

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