home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / BGUI / bgui_e / sources / examples / PopButton.e < prev    next >
Encoding:
Text File  |  1999-08-26  |  9.6 KB  |  240 lines

  1. /*
  2. **         File: PopButton.e
  3. **    Copyright: Copyright © 1995 Jaba Development.
  4. **               Copyright © 1995 Jan van den Baard.
  5. **               Copyright © 1996 Dominique Dutoit
  6. **               All Rights Reserved.
  7. **
  8. */
  9.  
  10. OPT OSVERSION=37
  11. OPT PREPROCESS
  12.  
  13. MODULE  'libraries/bgui',
  14.         'libraries/bguim',
  15.         'intuition/intuition',
  16.         'intuition/gadgetclass',
  17.         'utility/tagitem',
  18.         'bgui',
  19.         'bgui/bgui_image',
  20.         'tools/boopsi',
  21.         'intuition/screens'
  22.  
  23. CONST ID_QUIT = 1, ID_POPMENU1 = 2, ID_POPMENU2 = 3, ID_POPMENU3 = 4, ID_POPMENU4 = 5
  24.  
  25. DEF project:popMenu, edit:popMenu, exclude:popMenu, able:popMenu
  26. /*
  27. **  Put up a simple requester.
  28. **/
  29. PROC req( win:PTR TO window, gadgets, body:PTR TO CHAR, args )
  30.     DEF flags
  31.     flags   := BREQF_LOCKWINDOW OR BREQF_CENTERWINDOW OR BREQF_AUTO_ASPECT OR BREQF_FAST_KEYS
  32. ENDPROC BgUI_RequestA( win, [ flags, NIL, gadgets, body, NIL, NIL, "_", 0, NIL, 0], args)
  33.  
  34. PROC main()
  35.      DEF window
  36.      DEF wo_window, go_quit, go_pmb, go_pmb1, go_pmb2, go_pmb3
  37.      DEF signal = 0, rc, tmp=0, txt:PTR TO CHAR
  38.      DEF running = TRUE, about:PTR TO CHAR
  39.  
  40.      about :=  ISEQ_C + 'This demonstrates the usage of the ' + ISEQ_B + 'PopButtonClass\n' + ISEQ_N +
  41.                'When you click inside the above popmenu buttons a small\n'+
  42.                'popup-menu will appear which you can choose from.\n\n'+
  43.                'You can also key-activate the menus and browse though the\n'+
  44.                'items using the cursor up and down keys. Return or Enter\n'+
  45.                'acknowledges the selection and escape cancels it.'
  46.  
  47.      /*
  48.       * Menu entries.
  49.       */
  50.      project := [ 'New',          0, 0,
  51.                   'Open...',      0, 0,
  52.                   PMB_BARLABEL,  0, 0,
  53.                   'Save',         0, 0,
  54.                   'Save As...',   0, 0,
  55.                   PMB_BARLABEL,  0, 0,
  56.                   'Print',        0, 0,
  57.                   'Print As...',  0, 0,
  58.                   PMB_BARLABEL,  0, 0,
  59.                   'About...',     0, 0,
  60.                   PMB_BARLABEL,  0, 0,
  61.                   'Quit',         0, 0,
  62.                   NIL,    0, 0 ]:popMenu
  63.  
  64.      edit := [    'Cut',          0, 0,
  65.                   'Copy',         0, 0,
  66.                   'Paste',        0, 0,
  67.                   PMB_BARLABEL,  0, 0,
  68.                   'Erase',        0, 0,
  69.                   NIL,    0, 0 ]:popMenu
  70.  
  71.      /*
  72.       * This menu has checkable items and mutual exclusion.
  73.       *
  74.       * The first item will mutually-exclude the last
  75.       * four items and any of the last four items will
  76.       * mutually-exclude the first item.
  77.       */
  78.      exclude := [   'Uncheck below',        PMF_CHECKIT,                    Shl(1,2) OR Shl(1,3) OR Shl(1,4) OR Shl(1,5),
  79.                     PMB_BARLABEL,     0,          0,
  80.                     'Item 1',               PMF_CHECKIT OR PMF_CHECKED,        Shl(1,0),
  81.                     'Item 2',               PMF_CHECKIT OR PMF_CHECKED,        Shl(1,0),
  82.                     'Item 3',               PMF_CHECKIT OR PMF_CHECKED,        Shl(1,0),
  83.                     'Item 4',               PMF_CHECKIT OR PMF_CHECKED,        Shl(1,0),
  84.                     NIL,       0,          0]:popMenu
  85.      /*
  86.       * This menu has two items that enable the other
  87.       * when selected. (NMC)
  88.       */
  89.      able := [  'Enable below',      0,    0,
  90.                 'Enable above',      PMF_DISABLED,  0,
  91.                 NIL,       0,    0 ]:popMenu
  92.  
  93.      /*
  94.      **      Open BGUI.
  95.      **/
  96.  
  97.      IF ( bguibase := OpenLibrary( BGUINAME, BGUIVERSION ))
  98.         /*
  99.         * Create the popmenu buttons.
  100.         */
  101.         go_pmb  := PopButtonObject,
  102.                    PMB_MenuEntries,  project,
  103.                    /*
  104.                     *         Let this one activate
  105.                     *         the About item.
  106.                     */
  107.                    PMB_PopPosition,  9,
  108.                    LAB_Label,        '_Project',
  109.                    LAB_Underscore,   "_",
  110.                    GA_ID,            ID_POPMENU1,
  111.                 EndObject;
  112.  
  113.         go_pmb1 := PopButtonObject,
  114.                    PMB_MenuEntries,  edit,
  115.                    LAB_Label,        '_Edit',
  116.                    LAB_Underscore,   "_",
  117.                    GA_ID,            ID_POPMENU2,
  118.                 EndObject;
  119.  
  120.         go_pmb2 := PopButtonObject,
  121.                    PMB_MenuEntries,  exclude,
  122.                    LAB_Label,        'E_xclude',
  123.                    LAB_Underscore,   "_",
  124.                    GA_ID,            ID_POPMENU3,
  125.                 EndObject;
  126.  
  127.         go_pmb3 := PopButtonObject,
  128.                    PMB_MenuEntries,  able,   /* NMC */
  129.                    /*
  130.                     *         Make this menu always
  131.                     *         appear below the label
  132.                     */
  133.                    PMB_PopPosition,  -1,
  134.                    LAB_Label,        'E_nable',
  135.                    LAB_Underscore,   "_",
  136.                    GA_ID,            ID_POPMENU4,
  137.                 EndObject;
  138.  
  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_AutoKeyLabel, TRUE,
  148.            WINDOW_MasterGroup,
  149.               VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  150.                  GROUP_BackFill,         SHINE_RASTER,
  151.                  StartMember,
  152.                     HGroupObject, Spacing( 4 ), HOffset( 6 ), VOffset( 4 ),
  153.                        NeXTFrame,
  154.                        FRM_BackDriPen,         FILLPEN,
  155.                        StartMember, go_pmb, FixMinWidth, EndMember,
  156.                        StartMember, VertSeparator, EndMember,
  157.                        StartMember, go_pmb1, FixMinWidth, EndMember,
  158.                        StartMember, VertSeparator, EndMember,
  159.                        StartMember, go_pmb2, FixMinWidth, EndMember,
  160.                        StartMember, VertSeparator, EndMember,
  161.                        StartMember, go_pmb3, FixMinWidth, EndMember,   /* NMC */
  162.                        StartMember, VertSeparator, EndMember,    /* NMC */
  163.                     EndObject, FixMinHeight,
  164.                  EndMember,
  165.                  StartMember,
  166.                     InfoFixed( NIL, about, NIL, 7 ),
  167.                  EndMember,
  168.  
  169.                  StartMember,
  170.                     HGroupObject,
  171.                        VarSpace( DEFAULT_WEIGHT ),
  172.                        StartMember, go_quit := PrefButton('_Quit', ID_QUIT), EndMember,
  173.                        VarSpace( DEFAULT_WEIGHT ),
  174.                     EndObject, FixMinHeight,
  175.                  EndMember,
  176.               EndObject,
  177.         EndObject
  178.         /*
  179.         **      Object created OK?
  180.         **/
  181.         IF ( wo_window )
  182.            IF ( window := WindowOpen( wo_window ) )
  183.               GetAttr( WINDOW_SigMask, wo_window, {signal} )
  184.                   WHILE running = TRUE
  185.                         Wait( signal )
  186.                         WHILE ( rc := HandleEvent( wo_window )) <> WMHI_NOMORE
  187.                               SELECT rc
  188.                                      CASE    WMHI_CLOSEWINDOW
  189.                                              running := FALSE
  190.                                      CASE    ID_QUIT
  191.                                              running := FALSE
  192.  
  193.                                      CASE    ID_POPMENU4
  194.                                              GetAttr( PMB_MenuNumber, go_pmb3, {tmp} )
  195.                                              domethod( go_pmb3, [ PMBM_ENABLE_ITEM, Eor(tmp,1), TAG_END ])
  196.                                              domethod( go_pmb3, [ PMBM_DISABLE_ITEM, tmp, TAG_END ])
  197.                                              txt := able[ tmp ].label
  198.                                              def( window, txt, tmp )
  199.  
  200.                                      CASE    ID_POPMENU3
  201.                                              GetAttr( PMB_MenuNumber, go_pmb2, {tmp} )
  202.                                              txt := exclude[ tmp ].label
  203.                                              def( window, txt, tmp )
  204.  
  205.                                      CASE    ID_POPMENU2
  206.                                              GetAttr( PMB_MenuNumber, go_pmb1, {tmp} )
  207.                                              txt := edit[ tmp ].label
  208.                                              def( window, txt, tmp )
  209.  
  210.                                      CASE    ID_POPMENU1
  211.                                              GetAttr( PMB_MenuNumber, go_pmb, {tmp} )
  212.                                              SELECT tmp
  213.                                                 CASE  9
  214.                                                    req( window, '_OK', ISEQ_C +  ISEQ_B + 'PopButtonClass DEMO\n' + ISEQ_N + '(C) Copyright 1995 Jaba Development.', NIL )
  215.  
  216.                                                 CASE  11
  217.                                                    running := FALSE
  218.  
  219.                                                 DEFAULT
  220.                                                    txt := project[ tmp ].label
  221.                                                    def( window, txt, tmp )
  222.                                              ENDSELECT
  223.                               ENDSELECT
  224.                         ENDWHILE
  225.                   ENDWHILE
  226.            ELSE
  227.               WriteF( 'Unable to open the window\n' )
  228.            ENDIF
  229.            DisposeObject( wo_window )
  230.         ELSE
  231.            WriteF( 'Unable to create a window object\n' )
  232.         ENDIF
  233.         CloseLibrary(bguibase)
  234.      ELSE
  235.          WriteF( 'Unable to open the bgui.library\n' )
  236.      ENDIF
  237. ENDPROC NIL
  238.  
  239. PROC def( window, txt, tmp ) IS req( window, '_OK', ISEQ_C + 'Selected Item \d <' + ISEQ_B + '\s' + ISEQ_N + '>', [ tmp, txt, NIL ] )
  240.