home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / bgui-1.1a.lha / BGUI / demos / cxdemo.c < prev    next >
C/C++ Source or Header  |  1994-08-03  |  15KB  |  259 lines

  1. ;/* Execute me to compile with DICE V3.0.
  2. dcc cxdemo.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: cxdemo.c,v $
  7. **      Description: Small BGUI commodity class demonstration.
  8. **        Copyright: (C) Copyright 1994 Jaba Development.
  9. **                   (C) Copyright 1994 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **
  12. **          $Author: jaba $
  13. **        $Revision: 1.2 $
  14. **            $Date: 1994/08/03 11:19:36 $
  15. **/
  16.  
  17. #include <exec/types.h>
  18. #include <libraries/gadtools.h>
  19. #include <dos/dos.h>
  20. #include <libraries/bgui.h>
  21. #include <libraries/bgui_macros.h>
  22.  
  23. #include <clib/alib_protos.h>
  24.  
  25. #include <proto/exec.h>
  26. #include <proto/intuition.h>
  27. #include <proto/bgui.h>
  28.  
  29. #include <stdio.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **/
  34. struct Library  *BGUIBase       = NULL;
  35.  
  36. /*
  37. **      Key ID.
  38. **/
  39. #define CX_F1_PRESSED           1L
  40.  
  41. /*
  42. **      Gadget ID's.
  43. **/
  44. #define ID_HIDE                 1L
  45. #define ID_QUIT                 2L
  46.  
  47. /*
  48. **      Information text.
  49. **/
  50. UBYTE *InfoTxt = ISEQ_C ISEQ_B ISEQ_HIGHLIGHT
  51.                  "CxDemo\n\n" ISEQ_TEXT ISEQ_N
  52.                  "This is a small \"do-nothing\" example of how\n"
  53.                  "to use the BGUI commodity class.\n"
  54.                  "In this example F1 is the Hotkey used to\n"
  55.                  "signal the broker to open the window.";
  56.  
  57. int main( int argc, char *argv[] )
  58. {
  59.         Object          *CM_Broker, *WN_Window, *GA_Hide, *GA_Quit;
  60.         ULONG            signal = 0L, winsig = 0L, sigrec, type, id, rc;
  61.         BOOL             running = TRUE;
  62.  
  63.         /*
  64.         **      Open the library.
  65.         **/
  66.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  67.                 /*
  68.                 **      Setup a commodity object.
  69.                 **/
  70.                 CM_Broker = CommodityObject,
  71.                         COMM_Name,              "CxDemo",
  72.                         COMM_Title,             "Simple BGUI broker.",
  73.                         COMM_Description,       "Does not do anything usefull.",
  74.                         COMM_ShowHide,          TRUE,
  75.                 EndObject;
  76.  
  77.                 if ( CM_Broker ) {
  78.                         /*
  79.                         **      Create a small window.
  80.                         **/
  81.                         WN_Window = WindowObject,
  82.                                 WINDOW_Title,           "CxDemo",
  83.                                 WINDOW_RMBTrap,         TRUE,
  84.                                 WINDOW_SizeGadget,      FALSE,  /* No use in this window. */
  85.                                 WINDOW_MasterGroup,
  86.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  87.                                                 StartMember,
  88.                                                         InfoObject, ButtonFrame,
  89.                                                                 FRM_Flags,              FRF_RECESSED,
  90.                                                                 INFO_TextFormat,        InfoTxt,
  91.                                                                 INFO_FixTextWidth,      TRUE,
  92.                                                                 INFO_MinLines,          6,
  93.                                                         EndObject,
  94.                                                 EndMember,
  95.                                                 StartMember,
  96.                                                         HGroupObject, Spacing( 4 ),
  97.                                                                 StartMember, GA_Hide = KeyButton( "_Hide", ID_HIDE ), EndMember,
  98.                                                                 VarSpace( DEFAULT_WEIGHT ),
  99.                                                                 StartMember, GA_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  100.                                                         EndObject, FixMinHeight,
  101.                                                 EndMember,
  102.                                         EndObject,
  103.                         EndObject;
  104.  
  105.                         if ( WN_Window ) {
  106.                                 /*
  107.                                 **      Add F1 as hotkey.
  108.                                 **/
  109.                                 if ( AddHotkey( CM_Broker, "f1", CX_F1_PRESSED, 0L )) {
  110.                                         /*
  111.                                         **      Add gadget keys.
  112.                                         **/
  113.                                         GadgetKey( WN_Window, GA_Hide, "h" );
  114.                                         GadgetKey( WN_Window, GA_Quit, "q" );
  115.                                         /*
  116.                                         **      Obtain broker signal mask.
  117.                                         **/
  118.                                         GetAttr( COMM_SigMask, CM_Broker, &signal );
  119.                                         /*
  120.                                         **      Activate the broker.
  121.                                         **/
  122.                                         EnableBroker( CM_Broker );
  123.                                         /*
  124.                                         **      Open up the window.
  125.                                         **/
  126.                                         if ( WindowOpen( WN_Window )) {
  127.                                                 /*
  128.                                                 **      Obtain window sigmask.
  129.                                                 **/
  130.                                                 GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  131.                                                 /*
  132.                                                 **      Wait for messages.
  133.                                                 **/
  134.                                                 do {
  135.                                                         sigrec = Wait( signal | winsig | SIGBREAKF_CTRL_C );
  136.                                                         /*
  137.                                                         **      Broker signal?
  138.                                                         **/
  139.                                                         if ( sigrec & signal ) {
  140.                                                                 /*
  141.                                                                 **      Obtain the messages from the
  142.                                                                 **      broker.
  143.                                                                 **/
  144.                                                                 while ( MsgInfo( CM_Broker, &type, &id, NULL ) != CMMI_NOMORE ) {
  145.                                                                         /*
  146.                                                                         **      Evaluate message.
  147.                                                                         **/
  148.                                                                         switch ( type ) {
  149.  
  150.                                                                                 case    CXM_IEVENT:
  151.                                                                                         switch ( id ) {
  152.  
  153.                                                                                                 case    CX_F1_PRESSED:
  154.                                                                                                         goto openUp;
  155.                                                                                         }
  156.                                                                                         break;
  157.  
  158.                                                                                 case    CXM_COMMAND:
  159.                                                                                         switch ( id ) {
  160.  
  161.                                                                                                 case    CXCMD_KILL:
  162.                                                                                                         puts( "bye bye" );
  163.                                                                                                         running = FALSE;
  164.