home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / bgui-1.1a.lha / BGUI / demos / PopupCycle.c < prev    next >
C/C++ Source or Header  |  1994-09-15  |  7KB  |  237 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc PopupCycle.c -mi -ms -proto -lbgui -lpopupmenuclass.o
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: PopupCycle.c,v $
  7. **      Description: Simple BGUI external class demonstration.
  8. **        Copyright: (C) Copyright 1994 Paul Weterings.
  9. **                   All Rights Reserved.
  10. **
  11. **          $Author: Paul Weterings $
  12. **        $Revision: 1.2 $
  13. **            $Date: 1994/08/03 11:38:53 $
  14. */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/libraries.h>
  18. #include <dos/dos.h>
  19. #include <libraries/bgui.h>
  20. #include <libraries/bgui_macros.h>
  21.  
  22. #include <clib/macros.h>
  23. #include <clib/alib_protos.h>
  24.  
  25. #include <proto/exec.h>
  26. #include <proto/intuition.h>
  27. #include <proto/bgui.h>
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <stdlib.h>
  32. #include <math.h>
  33.  
  34. /*
  35. ** Keep in mind that you need Markus Aalto's PopUpMenu Class
  36. ** his archive is called 'pppmnc11.lha'
  37. **
  38. ** Note from Jan to DICE users:
  39. **      Since the DICE linker DLink does not seem to know how to
  40. **      handle HUNK_LIB hunks like in the .lib file supplied with the
  41. **      PopupMenuClass you will have to link with the supplied
  42. **      popupmenuclass.o file. This file is compiled without registered
  43. **      args (-mRR).
  44. */
  45.  
  46. #include <BoopsiObjects/PopUpMenuClass.h>
  47.  
  48. /*
  49. **      Library base pointers.
  50. */
  51. struct Library *BGUIBase = NULL;
  52.  
  53. /*
  54. **      Object ID's
  55. */
  56. #define ID_QUIT                 1
  57. #define ID_POPUP                2
  58.  
  59. /*
  60. ** Version checking
  61. */
  62. extern struct Library *SysBase;
  63.  
  64. Class *PopUpMenuClass;
  65. struct DrawInfo *dri;
  66. UBYTE *names[] = {
  67.     "Paul Weterings",
  68.     "supplied this",
  69.     "little class demo",
  70.     "Thanks to",
  71.     "Markus Aalto",
  72.     "for the",
  73.     "freely",
  74.     "Distributable",
  75.     "PopUpMenu class",
  76.     "Markus: s37732v@vipunen.hut.fi",
  77.     "Paul  : Paul@grafix.wlink.nl",
  78.     NULL
  79. };
  80.  
  81.  
  82. int main( int argc, char *argv[] )
  83. {
  84.    Object          *WN_Window, *GA_Quit, *GA_Master, *GA_Popup;
  85.    struct Window   *win;
  86.    struct Screen   *scr;
  87.    ULONG            winsig = 0L, sigrec, rc;
  88.    BOOL             running = TRUE;
  89.  
  90.    /*
  91.    ** Needed for the class
  92.    */
  93.    struct Node *node;
  94.    struct List labels;
  95.    UBYTE **strings = names;
  96.    UWORD Height;
  97.  
  98.  
  99.    /*
  100.    **      Need al least OS 2.0.
  101.    */
  102.    if ( SysBase->lib_Version < 37 ) {
  103.       puts( "> OS 2.0 required!" );
  104.       exit( 0 );
  105.    }
  106.  
  107.    /*
  108.    **      Open the libraries.
  109.    */
  110.    if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION ))
  111.    {
  112.       if ( scr = LockPubScreen( NULL ))
  113.       {
  114.          /*
  115.          ** Create the PopUpMenu class
  116.          */
  117.          if (PopUpMenuClass = CreatePopUpMenuClass())
  118.          {
  119.  
  120.             /*
  121.             ** Create the list with items
  122.             */
  123.             NewList( &labels );
  124.             while( *strings )
  125.             {
  126.                node = (struct Node *)AllocVec( sizeof(struct Node), MEMF_ANY|MEMF_CLEAR );
  127.                if( node )
  128.                {
  129.                   node->ln_Name = *strings;
  130.                   AddTail( &labels, node );
  131.                }
  132.                else
  133.                {
  134.                   puts( "Not enough memory for nodes in List" );
  135.                   goto nolist;
  136.                }
  137.                strings++;
  138.             }
  139.  
  140.             /*
  141.             **       I guess this variable can be filled better by BGUI
  142.             */
  143.             if( dri = GetScreenDrawInfo( scr ) )
  144.                Height = MAX(dri->dri_Font->tf_YSize + INTERHEIGHT, PUMG_MinHeight );
  145.             else
  146.                goto noscrdrwinf;
  147.             /*
  148.             **      Create a small window.
  149.             */
  150.             WN_Window = WindowObject,
  151.                WINDOW_Title,           "PopUpCycle",
  152.                WINDOW_Screen,          scr,
  153.                WINDOW_SmartRefresh,    TRUE,
  154.                WINDOW_MasterGroup,
  155.                GA_Master = VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  156.                   StartMember,
  157.                      GA_Popup = ExternalObject,
  158.                         EXT_MinWidth,           130,
  159.                         EXT_MinHeight,          Height+2,
  160.                         EXT_Class,              PopUpMenuClass,
  161.                         EXT_TrackAttr,          PUMG_Active,
  162.                         PUMG_Labels,            &labels,
  163.                         PUMG_TextFont,          dri->dri_Font, /* Not really needed */
  164.                         PUMG_NewLook,           TRUE,          /* Play with this!   */
  165.                         GA_RelVerify,           TRUE,
  166.                         GA_ID,                  ID_POPUP,
  167.                      EndObject,
  168.                      FixMinHeight,
  169.                   EndMember,
  170.                   StartMember,
  171.                      GA_Quit = KeyButton( "_Quit", ID_QUIT ), FixMinHeight,
  172.                   EndMember,
  173.                EndObject, /* VGroupObject */
  174.             EndObject; /* WindowObject */
  175.  
  176.             if ( WN_Window ) {
  177.                /*
  178.                **      Make button selectable by the keyboard.
  179.                */
  180.                GadgetKey( WN_Window, GA_Quit, "q" );
  181.                /*
  182.                **      Open up the window.
  183.                */
  184.                if ( win = WindowOpen( WN_Window )) {
  185.                   /*
  186.                   **      Obtain window sigmask.
  187.                   */
  188.                   GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  189.                   /*
  190.                   **      Wait for messages.
  191.                   */
  192.                   do {
  193.                      sigrec = Wait( winsig );
  194.  
  195.                      /*
  196.                      **      Window signal?
  197.                      */
  198.                      if ( sigrec & winsig ) {
  199.                         while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
  200.                            switch ( rc ) {
  201.  
  202.                               case    WMHI_CLOSEWINDOW:
  203.                               case    ID_QUIT:
  204.                               /*
  205.                               **      The end.
  206.                               */
  207.                               running = FALSE;
  208.                               break;
  209.                            }
  210.                         }
  211.                      }
  212.                   }
  213.                   while ( running );
  214.                }
  215.                DisposeObject( WN_Window );
  216.             }
  217. noscrdrwinf:
  218.             DisposePopUpMenuClass( PopUpMenuClass );
  219.  
  220.             while( node = RemHead( &labels ) )
  221.               FreeVec( (void *)node );
  222. nolist:
  223.             FreeScreenDrawInfo( scr, dri );
  224.          }
  225.          UnlockPubScreen( NULL, scr );
  226.       }
  227.       CloseLibrary( BGUIBase );
  228.    }
  229. }
  230.  
  231. #ifdef _DCC
  232. int wbmain( struct wbStartup *wbs )
  233. {
  234.    return( main( 0, NULL ));
  235. }
  236. #endif
  237.