home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / bgui.lzx / bgui / Classes / PopButtonClass / testpopbutton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-08  |  6.5 KB  |  251 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc testpopbutton.c -3.0 -mi -ms -proto -lpopbuttonclass.o -lbgui -ldebug
  3. quit
  4. */
  5. /*
  6.  *    TESTPOPBUTTON.C
  7.  *
  8.  *    (C) Copyright 1995 Jaba Development.
  9.  *    (C) Copyright 1995 Jan van den Baard.
  10.  *        All Rights Reserved.
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <libraries/bgui.h>
  15. #include <libraries/bgui_macros.h>
  16.  
  17. #include <clib/alib_protos.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/bgui.h>
  22. #include <proto/dos.h>
  23. #include <proto/utility.h>
  24.  
  25. #include "popbuttonclass.h"
  26.  
  27. /*
  28.  *    Object ID.
  29.  */
  30. #define ID_QUIT                 1
  31. #define ID_POPMENU1        2
  32. #define ID_POPMENU2        3
  33. #define ID_POPMENU3        4
  34.  
  35. /*
  36.  *    Menu entries.
  37.  */
  38. struct PopMenu Project[] = {
  39.     "New",          0, 0,
  40.     "Open...",      0, 0,
  41.     PMB_BARLABEL,    0, 0,
  42.     "Save",         0, 0,
  43.     "Save As...",   0, 0,
  44.     PMB_BARLABEL,    0, 0,
  45.     "Print",        0, 0,
  46.     "Print As...",  0, 0,
  47.     PMB_BARLABEL,    0, 0,
  48.     "About...",     0, 0,
  49.     PMB_BARLABEL,    0, 0,
  50.     "Quit",         0, 0,
  51.     NULL,        0, 0 };
  52.  
  53. struct PopMenu    Edit[] = {
  54.     "Cut",          0, 0,
  55.     "Copy",         0, 0,
  56.     "Paste",        0, 0,
  57.     PMB_BARLABEL,    0, 0,
  58.     "Erase",        0, 0,
  59.     NULL,        0, 0 };
  60.  
  61. /*
  62.  *    This menu has checkable items and mutual exclusion.
  63.  *
  64.  *    The first item will mutually-exclude the last
  65.  *    four items and any of the last four items will
  66.  *    mutually-exclude the first item.
  67.  */
  68. struct PopMenu    Exclude[] = {
  69.     "Uncheck below",        PMF_CHECKIT,                    (1<<2)|(1<<3)|(1<<4)|(1<<5),
  70.     PMB_BARLABEL,        0,                0,
  71.     "Item 1",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  72.     "Item 2",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  73.     "Item 3",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  74.     "Item 4",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  75.     NULL,            0,                0
  76. };
  77.  
  78. /*
  79.  *    Library base and class base.
  80.  */
  81. struct Library *BGUIBase;
  82. Class           *PMBClass;
  83.  
  84. /*
  85.  *    Put up a simple requester.
  86.  */
  87. ULONG Req( struct Window *win, UBYTE *gadgets, UBYTE *body, ... )
  88. {
  89.     struct bguiRequest    req = { NULL };
  90.  
  91.     req.br_GadgetFormat    = gadgets;
  92.     req.br_TextFormat    = body;
  93.     req.br_Flags        = BREQF_CENTERWINDOW|BREQF_AUTO_ASPECT|BREQF_LOCKWINDOW|BREQF_FAST_KEYS;
  94.  
  95.     return( BGUI_RequestA( win, &req, ( ULONG * )( &body + 1 )));
  96. }
  97.  
  98. int main( int argc, char **argv )
  99. {
  100.     struct Window        *window;
  101.     Object            *WO_Window, *GO_Quit, *GO_PMB, *GO_PMB1, *GO_PMB2;
  102.     ULONG             signal, rc, tmp = 0;
  103.     UBYTE            *txt;
  104.     BOOL             running = TRUE;
  105.  
  106.     /*
  107.      *    Open BGUI.
  108.      */
  109.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  110.         /*
  111.          *    Initialize the popbuttonclass.
  112.          */
  113.         if ( PMBClass = InitPMBClass()) {
  114.             /*
  115.              *    Create the popmenu buttons.
  116.              */
  117.             GO_PMB    = NewObject( PMBClass, NULL, PMB_MenuEntries,     Project,
  118.                                  /*
  119.                                   *         Let this one activate
  120.                                   *         the About item.
  121.                                   */
  122.                                  PMB_PopPosition,     9,
  123.                                  LAB_Label,          "_Project",
  124.                                  LAB_Underscore,     '_',
  125.                                  GA_ID,         ID_POPMENU1,
  126.                                  TAG_END );
  127.  
  128.             GO_PMB1 = NewObject( PMBClass, NULL, PMB_MenuEntries,     Edit,
  129.                                  LAB_Label,          "_Edit",
  130.                                  LAB_Underscore,     '_',
  131.                                  GA_ID,         ID_POPMENU2,
  132.                                  TAG_END );
  133.  
  134.             GO_PMB2 = NewObject( PMBClass, NULL, PMB_MenuEntries,     Exclude,
  135.                                  LAB_Label,          "E_xclude",
  136.                                  LAB_Underscore,     '_',
  137.                                  GA_ID,         ID_POPMENU3,
  138.                                  TAG_END );
  139.             /*
  140.              *    Create the window object.
  141.              */
  142.             WO_Window = WindowObject,
  143.                 WINDOW_Title,        "PopButtonClass Demo",
  144.                 WINDOW_AutoAspect,    TRUE,
  145.                 WINDOW_SmartRefresh,    TRUE,
  146.                 WINDOW_RMBTrap,         TRUE,
  147.                 WINDOW_MasterGroup,
  148.                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  149.                         GROUP_BackFill,         SHINE_RASTER,
  150.                         StartMember,
  151.                             HGroupObject, Spacing( 4 ), HOffset( 6 ), VOffset( 4 ),
  152.                                 NeXTFrame,
  153.                                 FRM_BackDriPen,         FILLPEN,
  154.                                 StartMember, GO_PMB, FixMinWidth, EndMember,
  155.                                 StartMember, VertSeparator, EndMember,
  156.                                 StartMember, GO_PMB1, FixMinWidth, EndMember,
  157.                                 StartMember, VertSeparator, EndMember,
  158.                                 StartMember, GO_PMB2, FixMinWidth, EndMember,
  159.                                 StartMember, VertSeparator, EndMember,
  160.                             EndObject, FixMinHeight,
  161.                         EndMember,
  162.                         StartMember,
  163.                             InfoFixed( NULL, ISEQ_C
  164.                                      "This demonstrates the usage of the \"PopButtonClass\"\n"
  165.                                      "When you click inside the above popmenu buttons a small\n"
  166.                                      "popup-menu will appear which you can choose from.\n\n"
  167.                                      "You can also key-activate the menus and browse though the\n"
  168.                                      "items using the cursor up and down keys. Return or Enter\n"
  169.                                      "acknowledges the selection and escape cancels it.",
  170.                                      NULL, 7 ),
  171.                         EndMember,
  172.                         StartMember,
  173.                             HGroupObject,
  174.                                 VarSpace( DEFAULT_WEIGHT ),
  175.                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  176.                                 VarSpace( DEFAULT_WEIGHT ),
  177.                             EndObject, FixMinHeight,
  178.                         EndMember,
  179.                     EndObject,
  180.             EndObject;
  181.  
  182.             /*
  183.              *    Object created OK?
  184.              */
  185.             if ( WO_Window ) {
  186.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  187.                 tmp += GadgetKey( WO_Window, GO_PMB,   "p" );
  188.                 tmp += GadgetKey( WO_Window, GO_PMB1,  "e" );
  189.                 tmp += GadgetKey( WO_Window, GO_PMB2,  "x" );
  190.                 if ( tmp == 4 ) {
  191.                     if ( window = WindowOpen( WO_Window )) {
  192.                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  193.                         do {
  194.                             Wait( signal );
  195.                             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  196.                                 switch ( rc ) {
  197.  
  198.                                     case    WMHI_CLOSEWINDOW:
  199.                                     case    ID_QUIT:
  200.                                         running = FALSE;
  201.                                         break;
  202.  
  203.                                     case    ID_POPMENU3:
  204.                                         GetAttr( PMB_MenuNumber, GO_PMB2, &tmp );
  205.                                         txt = Exclude[ tmp ].pm_Label;
  206.                                         goto def;
  207.  
  208.                                     case    ID_POPMENU2:
  209.                                         GetAttr( PMB_MenuNumber, GO_PMB1, &tmp );
  210.                                         txt = Edit[ tmp ].pm_Label;
  211.                                         goto def;
  212.  
  213.                                     case    ID_POPMENU1:
  214.                                         GetAttr( PMB_MenuNumber, GO_PMB, &tmp );
  215.                                         switch ( tmp ) {
  216.                                             case    9:
  217.                                                 Req( window, "*OK", ISEQ_C ISEQ_B "PopButtonClass DEMO\n" ISEQ_N "(C) Copyright 1995 Jaba Development." );
  218.                                                 break;
  219.  
  220.                                             case    11:
  221.                                                 running = FALSE;
  222.                                                 break;
  223.  
  224.                                             default:
  225.                                                 txt = Project[ tmp ].pm_Label;
  226.                                                 def:
  227.                                                 Req( window, "*OK", ISEQ_C "Selected Item %ld <" ISEQ_B "%s" ISEQ_N ">", tmp, txt );
  228.                                                 break;
  229.                                         }
  230.                                         break;
  231.                                 }
  232.                             }
  233.                         } while ( running );
  234.                     }
  235.                 }
  236.                 DisposeObject( WO_Window );
  237.             }
  238.             FreePMBClass( PMBClass );
  239.         }
  240.         CloseLibrary( BGUIBase );
  241.     }
  242. }
  243.  
  244. #ifdef _DCC
  245. int wbmain( struct WBStartup *wbs )
  246. {
  247.     return( main( 0, wbs ));
  248. }
  249. #endif
  250.  
  251.