home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / demo5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  5.1 KB  |  207 lines

  1. /* demo5.c -- demonstration of         :ts=8
  2.  * Basic Object Oriented Programming System for Intuition
  3.  *
  4.  * This demo shows the simple use of a composite gadget
  5.  * class; as simple as creating one boopsi gadget and
  6.  * using it, with either IDCMPUPDATE or GADGETUP.
  7.  */
  8.  
  9. /*
  10. Copyright (c) 1989 Commodore-Amiga, Inc.
  11.  
  12. Executables based on this information may be used in software
  13. for Commodore Amiga computers. All other rights reserved.
  14. This information is provided "as is"; no warranties are made.
  15. All use is at your own risk, and no liability or responsibility
  16. is assumed.
  17. */
  18.  
  19. #include "sysall.h"
  20. #include <intuition/icclass.h>
  21. #include "mymodel.h"
  22.  
  23. #define D(x)    x
  24.  
  25. struct  IntuitionBase   *IntuitionBase;
  26. struct  GfxBase         *GfxBase;
  27. struct  Library         *UtilityBase;
  28.  
  29. Object    *NewObject();
  30.  
  31. ULONG    myiflags =  CLOSEWINDOW | GADGETUP | IDCMPUPDATE;
  32.  
  33. void    *MyGroupClass = NULL;
  34. void    *initMyGroupClass();
  35.  
  36. struct Gadget    *mygadget = NULL;
  37. struct Window    *w = NULL;
  38.  
  39. #define PROPRANGE    (20)
  40. #define INITVAL        (0)    /* initial value of string and slider    */
  41.  
  42. /****************************************************************/
  43. /*  mapping tag list                        */
  44. /****************************************************************/
  45.  
  46. /* for IDCMPUPDATE    */
  47. struct TagItem    gadget2me[] = {
  48.     {MYMODA_CURRVAL, ICSPECIAL_CODE },
  49.     /* put (16 bits of) currval into IntuiMessage.Code    */
  50.     { TAG_END, }
  51. };
  52.  
  53. #define MYWINDOWTITLE    "boopsi Demo 5"
  54.  
  55. main()
  56. {
  57.     struct DrawInfo    *GetScreenDrawInfo();
  58.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  59.  
  60.     struct DrawInfo    *drinfo;
  61.  
  62.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  63.     { cleanup("no V36 utility library\n"); }
  64.  
  65.     if (!(IntuitionBase = 
  66.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  67.     { cleanup("no V36 intuition library\n"); }
  68.  
  69.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  70.     { cleanup("no V36 graphics library\n"); }
  71.  
  72.     /* initialize my private class    */
  73.     if ( ! ( MyGroupClass = initMyGroupClass() ) )
  74.     {
  75.     cleanup( "can't initialize gadget group" );
  76.     }
  77.  
  78.     D( printf(" my group class is at %lx\n", MyGroupClass ) );
  79.  
  80.     w = OpenWindowTags( NULL, 
  81.         WA_Title,    MYWINDOWTITLE,
  82.         WA_SimpleRefresh, TRUE,
  83.         WA_NoCareRefresh, TRUE,
  84.         WA_DepthGadget,    TRUE,
  85.         WA_DragBar,    TRUE,
  86.         WA_Left,    300,
  87.         WA_Top,        50,
  88.         WA_Width,    280,
  89.         WA_Height,    120,
  90.         WA_IDCMP,    myiflags,
  91.         WA_CloseGadget,    TRUE,
  92.             TAG_END );
  93.     D( printf("window at %lx\n", w ) );
  94.  
  95.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  96.     drinfo = GetScreenDrawInfo( w->WScreen );
  97.  
  98.     /* Go get the big guy.
  99.      * Note that I pass the DrawInfo to this *gadget*,
  100.      * using GA_DRAWINFO (not SYSIA_DrawInfo).  Sorry.
  101.      */
  102.     mygadget = (struct Gadget *) NewObject( MyGroupClass, NULL,
  103.                 GA_LEFT,    4 * w->BorderLeft,
  104.                 GA_TOP,        3 * w->BorderTop,
  105.                 GA_ID,        99,
  106.                 GA_DRAWINFO,    drinfo,
  107.  
  108.                 ICA_TARGET,    ICTARGET_IDCMP,
  109.                 ICA_MAP,    gadget2me,
  110.  
  111.                     TAG_END );
  112.     if ( ! mygadget ) cleanup( "can't get composite gadget" );
  113.     D( printf("group gadget at %lx\n", mygadget ) );
  114.  
  115.     /* 
  116.      * Now that the model and gadget are packaged together,
  117.      * I just talk to the gadget.  I pass NULL window
  118.      * since the gadget is not yet attached.
  119.      */
  120.      SetGadgetAttrs( mygadget, NULL, NULL,
  121.         MYMODA_RANGE, PROPRANGE,
  122.         MYMODA_CURRVAL, PROPRANGE/2,
  123.         TAG_END );
  124.  
  125.     /* And here's the nice part:
  126.      * you add just the ONE gadget
  127.      * to the window.
  128.      */
  129.     AddGList( w, mygadget, -1, 1, NULL );
  130.     RefreshGList( mygadget, w, NULL, -1 );
  131.  
  132.     D( printf("gadgets added and refreshed \n") );
  133.  
  134.     goHandleWindow( w );
  135.  
  136.     RemoveGList( w, mygadget, 1 );    /* just one    */
  137.  
  138.     FreeScreenDrawInfo( w->WScreen, drinfo );
  139.     cleanup( "all done" );
  140. }
  141.  
  142. cleanup( str )
  143. char    *str;
  144. {
  145.     if (str) printf("%s\n", str);
  146.  
  147.     /* the only thing I have to clean up is the gadget. */
  148.     DisposeObject( mygadget );
  149.  
  150.     if ( MyGroupClass )
  151.     {
  152.     int freesuccess;
  153.  
  154.     freesuccess = freeMyGroupClass( MyGroupClass );
  155.     D( if ( ! freesuccess ) printf("!!! MyGroupClass refused to free!\n");)
  156.     }
  157.  
  158.     if ( w ) CloseWindow( w );
  159.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  160.     if (GfxBase) CloseLibrary(GfxBase);
  161.     if (UtilityBase) CloseLibrary(UtilityBase);
  162.  
  163.     exit (0);
  164. }
  165.  
  166. goHandleWindow( w )
  167. struct Window    *w;
  168. {
  169.     struct TagItem    *FindTagItem();
  170.  
  171.     struct IntuiMessage *imsg;
  172.     struct TagItem    *tags;
  173.     ULONG        currval;
  174.     /* struct TagItem    *ti; */
  175.  
  176.     for(;;)
  177.     {
  178.     WaitPort( w->UserPort );
  179.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  180.     {
  181.         switch ( imsg->Class )
  182.         {
  183.         case CLOSEWINDOW:
  184.             ReplyMsg( (struct Message *) imsg );
  185.         return;
  186.  
  187.        case GADGETUP:
  188.            D( printf("GADGETUP GadgetID: %lx\n",
  189.             ((struct Gadget *) imsg->IAddress)->GadgetID ) );
  190.         break;
  191.  
  192.         case IDCMPUPDATE:
  193.         tags = (struct TagItem *) imsg->IAddress;
  194.             D( printf("IDCMPUPDATE, quals %lx code (decimal) %ld\n",
  195.             imsg->Qualifier, imsg->Code ));
  196.  
  197.         GetAttr( MYMODA_CURRVAL, mygadget, &currval );
  198.         D( printf("Current value now %ld\n", currval ) );
  199.  
  200.         break;
  201.         }
  202.         ReplyMsg( (struct Message *) imsg );
  203.     }
  204.     }
  205. }
  206.  
  207.