home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / addbuttons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  5.0 KB  |  198 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/AddButtons.c,v 1.1.2.1 1998/02/28 17:44:45 mlemos Exp $
  3.  *
  4.  * AddButtons.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994 Paul Weterings.
  8.  * All Rights Reserved.
  9.  *
  10.  * Modified by Ian J. Einman, 4/26/96
  11.  *
  12.  * $Log: AddButtons.c,v $
  13.  * Revision 1.1.2.1  1998/02/28 17:44:45  mlemos
  14.  * Ian sources
  15.  *
  16.  *
  17.  */
  18.  
  19. /*
  20. dcc AddButtons.c -mi -ms -mRR -proto -lbgui
  21. quit
  22. */
  23.  
  24. #include "DemoCode.h"
  25.  
  26. /*
  27.  *      Object ID's. Please note that the ID's are shared
  28.  *      between the menus and the gadget objects.
  29.  */
  30. #define ID_ADD          21
  31. #define ID_QUIT         22
  32. #define ID_INS          23
  33. #define ID_REM          24
  34.  
  35. /*
  36.  *      Simple menu strip.
  37.  */
  38. struct NewMenu SimpleMenu[] = {
  39.    Title( "Project" ),
  40.       Item( "Add",        "A", ID_ADD ),
  41.       Item( "Insert",     "I", ID_INS ),
  42.       Item( "Remove all", "R", ID_REM ),
  43.       ItemBar,
  44.       Item( "Quit",       "Q", ID_QUIT ),
  45.    End
  46. };
  47.  
  48. /*
  49.  *      Simple button creation macros.
  50.  */
  51. #define AddButton\
  52.    ButtonObject,\
  53.       LAB_Label,              "Added",\
  54.       LAB_Style,              FSF_BOLD,\
  55.       FuzzButtonFrame,\
  56.    EndObject
  57.  
  58. #define InsButton\
  59.    ButtonObject,\
  60.       LAB_Label,              "Inserted",\
  61.       LAB_Style,              FSF_BOLD,\
  62.       FuzzButtonFrame,\
  63.    EndObject
  64.  
  65.  
  66. VOID StartDemo( void )
  67. {
  68.    struct Window           *window;
  69.    Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
  70.    ULONG                    signal = 0, rc;
  71.    BOOL                     running = TRUE, ok = FALSE;
  72.    int                      x = 0, xx;
  73.  
  74.    /*
  75.     *      Create window object.
  76.     */
  77.    WO_Window = WindowObject,
  78.       WINDOW_Title,           "Add/Insert Demo",
  79.       WINDOW_MenuStrip,       SimpleMenu,
  80.       WINDOW_LockHeight,      TRUE,
  81.       WINDOW_AutoAspect,      TRUE,
  82.       WINDOW_AutoKeyLabel,    TRUE,
  83.       WINDOW_MasterGroup,
  84.          base = HGroupObject,
  85.             StartMember, GO_Add  = FuzzButton( "_Add",        ID_ADD  ), EndMember,
  86.             StartMember, GO_Ins  = FuzzButton( "_Insert",     ID_INS  ), EndMember,
  87.             StartMember, GO_Rem  = FuzzButton( "_Remove all", ID_REM  ), EndMember,
  88.             StartMember, GO_Quit = FuzzButton( "_Quit",       ID_QUIT ), EndMember,
  89.          EndObject,
  90.       EndObject;
  91.  
  92.         /*
  93.          *      OK?
  94.          */
  95.    if ( WO_Window )
  96.    {
  97.       /*
  98.        *      Open window.
  99.        */
  100.       if ( window = WindowOpen( WO_Window ))
  101.       {
  102.          /*
  103.           *      Get signal mask.
  104.           */
  105.          GetAttr( WINDOW_SigMask, WO_Window, &signal );
  106.          do {
  107.             /*
  108.              *      Poll messages.
  109.              */
  110.             Wait( signal );
  111.             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  112.             {
  113.                switch ( rc )
  114.                {
  115.                case WMHI_CLOSEWINDOW:
  116.                case ID_QUIT:
  117.                   /*
  118.                    *      Bye now.
  119.                    */
  120.                   running = FALSE;
  121.                   break;
  122.  
  123.                case ID_ADD:
  124.                   if ( x == 19 )
  125.                   {
  126.                      Tell( "Max Nr. of gadgets\n" );
  127.                      break;
  128.                   }
  129.                   x++;
  130.  
  131.                   addobj[x]  = AddButton;
  132.  
  133.                   ok = DoMethod( base, GRM_ADDMEMBER, addobj[ x ],
  134.                      LGO_FixMinHeight, FALSE,
  135.                      LGO_Weight,       DEFAULT_WEIGHT,
  136.                      TAG_END );
  137.  
  138.                   if (!ok)
  139.                   {
  140.                      DoMethod( base, GRM_REMMEMBER, addobj[ x ] );
  141.                      x--;
  142.                      Tell( "Last object did not fit!\n" );
  143.                   }
  144.  
  145.                   if ( ! window )
  146.                      goto error;
  147.                   break;
  148.  
  149.                case ID_REM:
  150.                   if ( x > 0 )
  151.                   {
  152.                      for ( xx = 1; xx <= x; xx++ )
  153.                      DoMethod( base, GRM_REMMEMBER, addobj[ xx ] );
  154.                      x = 0;
  155.                   }
  156.                   else
  157.                      Tell("Were out of gadgets!\n");
  158.                   break;
  159.  
  160.                case ID_INS:
  161.                   if ( x == 19 )
  162.                   {
  163.                      Tell( "Max Nr. of gadgets\n" );
  164.                      break;
  165.                   }
  166.                   x++;
  167.  
  168.                   addobj[x]  = InsButton;
  169.  
  170.                   ok = DoMethod( base, GRM_INSERTMEMBER, addobj[ x ], GO_Rem,
  171.                      LGO_FixMinHeight, FALSE,
  172.                      LGO_Weight,       DEFAULT_WEIGHT,
  173.                      TAG_END );
  174.  
  175.                   if (!ok)
  176.                   {
  177.                      DoMethod( base, GRM_REMMEMBER, addobj[ x ] );
  178.                      x--;
  179.                      Tell( "Last object did not fit!\n" );
  180.                   }
  181.  
  182.                   if ( ! window )
  183.                      goto error;
  184.                   break;
  185.  
  186.                }
  187.             }
  188.          } while ( running );
  189.       }
  190.       else
  191.          Tell( "Could not open the window\n" );
  192.       error:
  193.       DisposeObject( WO_Window );
  194.    }
  195.    else
  196.       Tell( "Could not create the window object\n" );
  197. }
  198.