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

  1. /*
  2. **      AddButtons.e
  3. **
  4. **      (C) Copyright 1994 Paul Weterings.
  5. **          All Rights Reserved.
  6. **
  7. **      Modified by Ian J. Einman, 26-Apr-96
  8. **      Modified by Dominique Dutoit, 1-May-96
  9. **      Updated on 31-Aug-96 !!Bug!! if the window is going to be greater than the screen
  10. **                           width, all buttons freeze but you can still close safely the
  11. **                           window. It's a BGUI bug.
  12. */
  13.  
  14. OPT OSVERSION=37
  15. OPT PREPROCESS
  16.  
  17. MODULE 'libraries/bgui',
  18.        'libraries/bguim',
  19.        'libraries/gadtools',
  20.        'bgui',
  21.        'bgui/bgui_image',
  22.        'bgui/bgui_obsolete',
  23.        'tools/boopsi',
  24.        'utility/tagitem',
  25.        'intuition/classes',
  26.        'intuition/classusr',
  27.        'intuition/gadgetclass',
  28.        'graphics/text'
  29. /*
  30.  *      Object ID's. Please note that the ID's are shared
  31.  *      between the menus and the gadget objects.
  32.  */
  33. CONST   ID_ADD = 21,
  34.         ID_QUIT= 22,
  35.         ID_INS=23,
  36.         ID_REM=24
  37. /*
  38.  *      Simple button creation macros.
  39.  */
  40. #define AddButton\
  41.     ButtonObject,\
  42.         LAB_Label,              'Added',\
  43.         LAB_Style,              FSF_BOLD,\
  44.         FuzzButtonFrame,\
  45.     EndObject
  46.  
  47. #define InsButton\
  48.     ButtonObject,\
  49.         LAB_Label,              'Inserted',\
  50.         LAB_Style,              FSF_BOLD,\
  51.         FuzzButtonFrame,\
  52.     EndObject
  53.  
  54. PROC main()
  55.         DEF window
  56.         DEF wo_window, go_add, go_quit, go_ins, go_rem
  57.         DEF addobj[20]:ARRAY OF LONG, base:PTR TO object
  58.         DEF signal = 0, rc
  59.         DEF running = TRUE, ok = FALSE
  60.         DEF x = 0, xx
  61.         DEF simplemenu
  62.  
  63.         /*
  64.         *      Simple menu strip.
  65.         */
  66.         simplemenu :=   StartMenu,
  67.                             Title( 'Project' ),
  68.                                 Item( 'Add',        'A',    ID_ADD ),
  69.                                 Item( 'Insert',     'I',    ID_INS ),
  70.                                 Item( 'Remove All', 'R',    ID_REM ),
  71.                                 ItemBar,
  72.                                 Item( 'Quit',       'Q',    ID_QUIT),
  73.                         End
  74.  
  75.         /*
  76.         **      Open the library.
  77.         **/
  78.         IF bguibase := OpenLibrary( 'bgui.library', BGUIVERSION )
  79.                 /*
  80.                 **      Create a window object.
  81.                 **/
  82.                 wo_window := WindowObject,
  83.                         WINDOW_Title,           'Add/Insert Demo',
  84.                         WINDOW_MenuStrip,       simplemenu,
  85.                         WINDOW_LockHeight,      TRUE,
  86.                         WINDOW_AutoAspect,      TRUE,
  87.                         WINDOW_AutoKeyLabel,    TRUE,
  88.                         WINDOW_MasterGroup,
  89.                                 base := HGroupObject,
  90.                                     StartMember, go_add  := PrefButton( '_Add',        ID_ADD  ), EndMember,
  91.                                     StartMember, go_ins  := PrefButton( '_Insert',     ID_INS  ), EndMember,
  92.                                     StartMember, go_rem  := PrefButton( '_Remove all', ID_REM  ), EndMember,
  93.                                     StartMember, go_quit := PrefButton( '_Quit',       ID_QUIT ), EndMember,
  94.                                 EndObject,
  95.                         EndObject
  96.  
  97.                 /*
  98.                 **      Object created OK?
  99.                 **/
  100.                 IF ( wo_window )
  101.                         /*
  102.                         **      Open up the window.
  103.                         **/
  104.                         IF ( window := WindowOpen( wo_window ) )
  105.                                 /*
  106.                                 **      Obtain signal mask.
  107.                                 **/
  108.                                 GetAttr( WINDOW_SigMask, wo_window, {signal} )
  109.                                 /*
  110.                                 **      Poll messages.
  111.                                 **/
  112.                                 WHILE running = TRUE
  113.                                         /*
  114.                                         **      Wait for the signal.
  115.                                         **/
  116.                                         Wait( signal )
  117.                                         /*
  118.                                         **      Call uppon the event handler.
  119.                                         **/
  120.                                         WHILE ( rc := HandleEvent( wo_window )) <> WMHI_NOMORE
  121.                                                 SELECT rc
  122.                                                         CASE    WMHI_CLOSEWINDOW
  123.                                                                 running := FALSE
  124.                                                         CASE    ID_QUIT
  125.                                                                 running := FALSE
  126.                                                         CASE    ID_ADD
  127.                                                                 IF ( x = 19 )
  128.                                                                     WriteF( 'Max Nr. of gadgets\n' )
  129.                                                                 ELSE
  130.                                                                     INC x
  131.  
  132.                                                                     addobj[ x ] := AddButton
  133.  
  134.                                                                     ok := domethod( base, [ GRM_ADDMEMBER,      addobj[ x ],
  135.                                                                                             LGO_FixMinHeight,   FALSE,
  136.                                                                                             LGO_Weight,         DEFAULT_WEIGHT,
  137.                                                                                             TAG_END ] )
  138.  
  139.                                                                     IF ( ok=0 )
  140.                                                                         domethod( base, [ GRM_REMMEMBER, addobj[ x ], TAG_END ] )
  141.                                                                         DEC x
  142.                                                                         WriteF( 'Last object did not fit!\n' )
  143.                                                                     ENDIF
  144.  
  145.                                                                 ENDIF
  146.                                                         CASE    ID_REM
  147.                                                                 IF ( x > 0 )
  148.                                                                     FOR xx := 1 TO x
  149.                                                                         domethod( base, [ GRM_REMMEMBER, addobj[ xx ], TAG_END ] )
  150.                                                                     ENDFOR
  151.  
  152.                                                                     x := 0
  153.                                                                 ELSE
  154.                                                                     WriteF( 'Were out of gadgets!\n' )
  155.                                                                 ENDIF
  156.                                                         CASE    ID_INS
  157.                                                                 IF ( x = 19 )
  158.                                                                     WriteF( 'Max Nr. of gadgets\n' )
  159.                                                                 ELSE
  160.                                                                     INC x
  161.  
  162.                                                                     addobj[ x ] := InsButton
  163.  
  164.                                                                     ok := domethod( base, [ GRM_INSERTMEMBER,   addobj[ x ], go_rem,
  165.                                                                                             LGO_FixMinHeight,   FALSE,
  166.                                                                                             LGO_Weight,         DEFAULT_WEIGHT,
  167.                                                                                             TAG_END ] )
  168.  
  169.                                                                     IF ( ok=0 )
  170.                                                                         domethod( base, [ GRM_REMMEMBER, addobj[ x ], TAG_END ] )
  171.                                                                         DEC x
  172.                                                                         WriteF( 'Last object did not fit!\n' )
  173.                                                                     ENDIF
  174.  
  175.                                                                 ENDIF
  176.                                                 ENDSELECT
  177.                                         ENDWHILE
  178.                                 ENDWHILE
  179.                         ELSE
  180.                             WriteF( 'Unable to open the window\n' )
  181.                         ENDIF
  182.                         /*
  183.                         **      Disposing of the object
  184.                         **      will automatically close the window
  185.                         **      and dispose of all objects that
  186.                         **      are attached to the window.
  187.                         **/
  188.                     error:
  189.                         DisposeObject( wo_window )
  190.                 ELSE
  191.                         WriteF( 'Unable to create a window object\n' )
  192.                 ENDIF
  193.                 CloseLibrary(bguibase)
  194.         ELSE
  195.                 WriteF( 'Unable to open the bgui.library\n' )
  196.         ENDIF
  197. ENDPROC NIL
  198.