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