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 / demotextb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.1 KB  |  170 lines

  1. /* demotextb.c -- demonstration of         :ts=8
  2.  * Basic Object Oriented Programming System for Intuition
  3.  *
  4.  * Demonstrates use of a text button object (from class "textbclass").
  5.  */
  6.  
  7. /*
  8. Copyright (c) 1989 Commodore-Amiga, Inc.
  9.  
  10. Executables based on this information may be used in software
  11. for Commodore Amiga computers. All other rights reserved.
  12. This information is provided "as is"; no warranties are made.
  13. All use is at your own risk, and no liability or responsibility
  14. is assumed.
  15. */
  16.  
  17. #include "sysall.h"
  18.  
  19. #define D(x)    ;
  20.  
  21. struct  IntuitionBase   *IntuitionBase;
  22. struct  GfxBase         *GfxBase;
  23. struct  Library         *UtilityBase;
  24.  
  25. Object    *NewObject();
  26.  
  27. ULONG    myiflags = GADGETDOWN | GADGETUP | CLOSEWINDOW;
  28.  
  29. /* objects to be created    */
  30. void        *initTextBClass();
  31. void        *TextBClass = NULL;
  32. struct Gadget    *textbutton = NULL;
  33.  
  34. void        *initFrame1Class();
  35. void        *Frame1Class = NULL;
  36. struct Image    *frameimage = NULL;
  37.  
  38. main()
  39. {
  40.     struct DrawInfo    *GetScreenDrawInfo();
  41.     struct DrawInfo    *drinfo;
  42.  
  43.     struct Window     *OpenWindowTags();
  44.     struct Window    *w;
  45.  
  46.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  47.     { cleanup("no V36 utility library\n"); }
  48.  
  49.     if (!(IntuitionBase = 
  50.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  51.     { cleanup("no V36 intuition library\n"); }
  52.  
  53.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  54.     { cleanup("no V36 graphics library\n"); }
  55.  
  56.     D( printf("about to openwindow\n") );
  57.     w = OpenWindowTags( NULL, 
  58.         WA_Title,    "boopsi Test Window",
  59.         WA_SimpleRefresh, TRUE,
  60.         WA_NoCareRefresh, TRUE,
  61.         WA_DepthGadget,    TRUE,
  62.         WA_DragBar,    TRUE,
  63.         WA_Left,    300,
  64.         WA_Top,        50,
  65.         WA_Width,    280,
  66.         WA_Height,    120,
  67.         WA_IDCMP,    myiflags,
  68.         WA_CloseGadget,    TRUE,
  69.             TAG_END );
  70.     D( printf("window at %lx\n ", w ) );
  71.  
  72.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  73.     drinfo = GetScreenDrawInfo( w->WScreen );
  74.  
  75.     /* create a frame image which can be shared by contents
  76.      * of different sizes
  77.      */
  78.     Frame1Class = initFrame1Class();
  79.     frameimage =  (struct Image *) NewObject( Frame1Class, NULL, TAG_END );
  80.  
  81.     /* create a text button gadget using
  82.      * a "simple ascii string" as a label
  83.      */
  84.     TextBClass = initTextBClass();
  85.     textbutton =  (struct Gadget *) NewObject( TextBClass, NULL, 
  86.         GA_LEFT,    30,
  87.         GA_TOP,        20,
  88.         GA_TEXT,    "My Gadget",
  89.         GA_IMAGE,    frameimage,
  90.         GA_ID,        0xf00d,
  91.         GA_DRAWINFO,    drinfo,        /* textbuttons need this now */
  92.             TAG_END );
  93.  
  94.     D(printf("objects initialized\n"));
  95.  
  96.     /* make it a little bigger, but want to see centered text */
  97.     SetGadgetAttrs( textbutton, NULL, NULL, 
  98.                 GA_WIDTH, textbutton->Width + 20,
  99.             GA_DRAWINFO,    drinfo,        /* since no window */
  100.             TAG_END );
  101.  
  102.     AddGList( w, textbutton, -1, -1, NULL );
  103.     RefreshGList( textbutton, w, NULL, -1 );
  104.  
  105.     D( printf("gadgets added and refreshed \n") );
  106.  
  107.     goHandleWindow( w );
  108.  
  109.     RemoveGList( w, textbutton, -1 );
  110.     FreeScreenDrawInfo( w->WScreen, drinfo );
  111.     CloseWindow( w );
  112.  
  113.     D( printf("dispose\n") );
  114.     DisposeObject( textbutton );
  115.     DisposeObject( frameimage);
  116.     freeTextBClass( TextBClass );
  117.     freeFrame1Class( Frame1Class );
  118.  
  119.     cleanup( "all done" );
  120. }
  121.  
  122. cleanup( str )
  123. char    *str;
  124. {
  125.     if (str) printf("%s\n", str);
  126.  
  127.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  128.     if (GfxBase) CloseLibrary(GfxBase);
  129.     if (UtilityBase) CloseLibrary(UtilityBase);
  130.  
  131.     exit (0);
  132. }
  133.  
  134. /* this variable holds the integer "current value" of the
  135.  * whole little system of gadgets
  136.  */
  137. LONG        currval = 0;
  138.  
  139. goHandleWindow( w )
  140. struct Window    *w;
  141. {
  142.     struct IntuiMessage *imsg;
  143.     struct Gadget    *g;
  144.  
  145.     for(;;)
  146.     {
  147.     WaitPort( w->UserPort );
  148.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  149.     {
  150.         switch ( imsg->Class )
  151.         {
  152.         case CLOSEWINDOW:
  153.             ReplyMsg( (struct Message *) imsg );
  154.         return;
  155.  
  156.         case GADGETDOWN:
  157.         D( printf("gadget down, %lx\n", imsg->IAddress ) );
  158.         break;
  159.  
  160.         case GADGETUP:
  161.         g = (struct Gadget *) imsg->IAddress;
  162.         D( printf("gadget up, %lx, id %lx\n",
  163.             imsg->IAddress, g->GadgetID ) );
  164.         break;
  165.         }
  166.         ReplyMsg( (struct Message *) imsg );
  167.     }
  168.     }
  169. }
  170.