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