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

  1. /*
  2. **      CXDEMO.E
  3. **
  4. **      (C) Copyright 1996 Marco Talamelli.
  5. **          All Rights Reserved.
  6. **
  7. **      On 22 May 96: A dead-loop bug corrected by Dominique Dutoit.
  8. **      On 25 May 96: A big bad bug fixed in libraries/bgui.m so
  9. **                    this example now works.
  10. **
  11. **      Updated on 10-Aug-96
  12. **/
  13.  
  14. OPT OSVERSION=37
  15. OPT PREPROCESS
  16.  
  17. MODULE  'libraries/bgui',
  18.         'libraries/bguim',
  19.         'libraries/gadtools',
  20.         'libraries/commodities',
  21.         'bgui',
  22.         'bgui/bgui_image',
  23.         'bgui/bgui_cx',
  24.         'dos/dos',
  25.         'tools/boopsi',
  26.         'utility/tagitem',
  27.         'intuition/screens',
  28.         'intuition/intuition',
  29.         'intuition/classes',
  30.         'intuition/classusr',
  31.         'intuition/gadgetclass'
  32.  
  33. /*
  34. **      Key ID.
  35. **/
  36. #define CX_F1_PRESSED           1
  37.  
  38. /*
  39. **      Gadget ID's.
  40. **/
  41. #define ID_HIDE                 1
  42. #define ID_QUIT                 2
  43.  
  44. PROC main()
  45.  
  46. DEF cm_broker:PTR TO object, wn_window, ga_hide, ga_quit,
  47.         signal = 0, winsig = 0, sigrec, type, id, rc,
  48.         running = TRUE,infotxt:PTR TO CHAR
  49.  
  50. /*
  51. **      Information text.
  52. **/
  53.     infotxt := '\ec\eb\ed8'+
  54.                  'CxDemo\n\n\ed2\en'+
  55.                  'This is a small "do-nothing" example of how\n'+
  56.                  'to use the BGUI commodity class.\n'+
  57.                  'In this example F1 is the Hotkey used to\n'+
  58.                  'signal the broker to open the window.'
  59.  
  60.         /*
  61.         **      Open the library.
  62.         **/
  63.     IF bguibase := OpenLibrary( 'bgui.library', 37 )
  64.  
  65.         /*
  66.         **      Setup a commodity object.
  67.         **/
  68.         cm_broker := CommodityObject,
  69.                 COMM_Name,              'CxDemo',
  70.                 COMM_Title,             'Simple BGUI broker.',
  71.                 COMM_Description,       'Does not do anything usefull.',
  72.                 COMM_ShowHide,          TRUE,
  73.         EndObject
  74.  
  75.         /*
  76.         **      Object OK?
  77.         **/
  78.         IF cm_broker
  79.                 /*
  80.                 **      Create a small window.
  81.                 **/
  82.                 wn_window := WindowObject,
  83.                         WINDOW_Title,           'CxDemo',
  84.                         WINDOW_RMBTrap,         TRUE,
  85.                         WINDOW_SizeGadget,      FALSE,  /* No use in this window. */
  86.                         WINDOW_AutoAspect,      TRUE,
  87.                         WINDOW_AutoKeyLabel,    TRUE,
  88.                         WINDOW_MasterGroup,
  89.                                 VGroupObject, HOffset( 6 ), VOffset( 6 ), Spacing( 6 ), GROUP_BackFill, SHINE_RASTER,
  90.                                         StartMember,
  91.                                                 InfoObject, ButtonFrame,
  92.                                                         FRM_Flags,              FRF_RECESSED,
  93.                                                         INFO_TextFormat,        infotxt,
  94.                                                         INFO_FixTextWidth,      TRUE,
  95.                                                         INFO_MinLines,          6,
  96.                                                 EndObject,
  97.                                         EndMember,
  98.                                         StartMember,
  99.                                                 HGroupObject, Spacing( 4 ),
  100.                                                         StartMember, ga_hide := KeyButton( '_Hide', ID_HIDE ), EndMember,
  101.                                                         VarSpace( DEFAULT_WEIGHT ),
  102.                                                         StartMember, ga_quit := KeyButton( '_Quit', ID_QUIT ), EndMember,
  103.                                                 EndObject, FixMinHeight,
  104.                                         EndMember,
  105.                                 EndObject,
  106.                 EndObject
  107.  
  108.                 /*
  109.                 **      Window OK?
  110.                 **/
  111.                 IF wn_window
  112.                         /*
  113.                         **      Add F1 as hotkey.
  114.                         **/
  115.                         IF AddHotkey( cm_broker, 'f1', CX_F1_PRESSED, 0 )
  116.                                 /*
  117.                                 **      Obtain broker signal mask.
  118.                                 **/
  119.                                 GetAttr( COMM_SigMask, cm_broker, {signal} )
  120.                                 /*
  121.                                 **      Activate the broker.
  122.                                 **/
  123.                                 EnableBroker( cm_broker )
  124.                                 /*
  125.                                 **      Open up the window.
  126.                                 **/
  127.                                 IF WindowOpen( wn_window )
  128.                                         /*
  129.                                         **      Obtain window sigmask.
  130.                                         **/
  131.                                         GetAttr( WINDOW_SigMask, wn_window, {winsig} )
  132.                                         /*
  133.                                         **      Wait for messages.
  134.                                         **/
  135.                                         WHILE running = TRUE
  136.                                                 sigrec := Wait( signal OR winsig OR SIGBREAKF_CTRL_C )
  137.                                                 /*
  138.                                                 **      Broker signal?
  139.                                                 **/
  140.                                                 IF ( sigrec AND signal )
  141.                                                         /*
  142.                                                         **      Obtain the messages from the
  143.                                                         **      broker.
  144.                                                         **/
  145.                                                         WHILE ( MsgInfo( cm_broker, {type}, {id}, NIL ) <> CMMI_NOMORE )
  146.                                                                 /*
  147.                                                                 **      Evaluate message.
  148.                                                                 **/
  149.                                                                 SELECT type
  150.  
  151.                                                                         CASE    CXM_IEVENT
  152.                                                                                 SELECT id
  153.  
  154.                                                                                         CASE    CX_F1_PRESSED
  155.                                                                                                 IF WindowOpen( wn_window )
  156.                                                                                                    GetAttr( WINDOW_SigMask, wn_window, {winsig} )
  157.                                                                                                 ENDIF
  158.                                                                                 ENDSELECT
  159.  
  160.                                                                         CASE    CXM_COMMAND
  161.                                                                                 SELECT id
  162.  
  163.                                                                                         CASE    CXCMD_KILL
  164.                                                                                                 WriteF( 'bye bye\n' )
  165.                                                                                                 running := FALSE
  166.  
  167.                                                                                         CASE    CXCMD_DISABLE
  168.                                                                                                 WriteF( 'broker disabled\n' )
  169.                                                                                                 DisableBroker( cm_broker )
  170.  
  171.                                                                                         CASE    CXCMD_ENABLE
  172.                                                                                                 WriteF( 'broker enabled\n' )
  173.                                                                                                 EnableBroker( cm_broker )
  174.  
  175.                                                                                         CASE    CXCMD_UNIQUE
  176.                                                                                                 IF WindowOpen( wn_window )
  177.                                                                                                         GetAttr( WINDOW_SigMask, wn_window, {winsig} )
  178.                                                                                                 ENDIF
  179.                                                                                         CASE    CXCMD_APPEAR
  180.                                                                                                   IF WindowOpen( wn_window )
  181.                                                                                                         GetAttr( WINDOW_SigMask, wn_window, {winsig} )
  182.                                                                                                   ENDIF
  183.  
  184.                                                                                         CASE    CXCMD_DISAPPEAR
  185.                                                                                                 WindowClose( wn_window )
  186.                                                                                                 winsig := 0
  187.                                                                                 ENDSELECT
  188.                                                                 ENDSELECT
  189.                                                         ENDWHILE
  190.                                                 ENDIF
  191.  
  192.                                                 /*
  193.                                                 **      Window signal?
  194.                                                 **/
  195.                                                 IF ( sigrec AND winsig )
  196.                                                         WHILE ( wn_window AND (( rc := HandleEvent( wn_window )) <> WMHI_NOMORE ))
  197.                                                                 SELECT rc
  198.  
  199.                                                                         CASE    ID_HIDE
  200.                                                                                 WindowClose( wn_window )
  201.                                                                                 winsig := 0
  202.                                                                         CASE    WMHI_CLOSEWINDOW
  203.                                                                                 /*
  204.                                                                                 **      Hide the window.
  205.                                                                                 **/
  206.                                                                                 WindowClose( wn_window )
  207.                                                                                 winsig := 0
  208.  
  209.                                                                         CASE    ID_QUIT
  210.                                                                                 /*
  211.                                                                                 **      The end.
  212.                                                                                 **/
  213.                                                                                 running := FALSE
  214.                                                                 ENDSELECT
  215.                                                         ENDWHILE
  216.                                                 ENDIF
  217.  
  218.                                                 /*
  219.                                                 **      CTRL+C?
  220.                                                 **/
  221.                                                 IF ( sigrec AND SIGBREAKF_CTRL_C )
  222.                                                         running := FALSE
  223.                                                 ENDIF
  224.                                         ENDWHILE
  225.                                 ELSE
  226.                                         WriteF( 'unable to open the window\n' )
  227.                                 ENDIF
  228.                         ELSE
  229.                                 WriteF( 'unable to add the hotkey\n' )
  230.                         ENDIF
  231.                         DisposeObject( wn_window )
  232.                 ELSE
  233.                         WriteF( 'unable to create a window object\n' )
  234.                 ENDIF
  235.                 DisposeObject( cm_broker )
  236.         ELSE
  237.             WriteF( 'unable to create a commodity object\n' )
  238.         ENDIF
  239.         CloseLibrary(bguibase)
  240.     ELSE
  241.         WriteF('Could not open the bgui.library\n')
  242.     ENDIF
  243. ENDPROC
  244.