home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / cxdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  6.5 KB  |  232 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/CXDemo.c,v 1.1.2.1 1998/02/28 17:45:09 mlemos Exp $
  3.  *
  4.  * CXDemo.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: CXDemo.c,v $
  12.  * Revision 1.1.2.1  1998/02/28 17:45:09  mlemos
  13.  * Ian sources
  14.  *
  15.  *
  16.  */
  17.  
  18. /* Execute me to compile with DICE V3.0.
  19. dcc CXDemo.c -proto -mi -ms -mRR -lbgui
  20. quit
  21. */
  22.  
  23. #include "DemoCode.h"
  24.  
  25. /*
  26. **      Key ID.
  27. **/
  28. #define CX_F1_PRESSED           1L
  29.  
  30. /*
  31. **      Gadget ID's.
  32. **/
  33. #define ID_HIDE                 1L
  34. #define ID_QUIT                 2L
  35.  
  36. /*
  37. **      Information text.
  38. **/
  39. UBYTE *InfoTxt = ISEQ_C ISEQ_B ISEQ_HIGHLIGHT
  40.                  "\33sCxDemo\n\n" ISEQ_TEXT ISEQ_N
  41.                  "This is a small \"do-nothing\" example of how\n"
  42.                  "to use the BGUI commodity class.\n"
  43.                  "In this example F1 is the Hotkey used to\n"
  44.                  "signal the broker to open the window.";
  45.  
  46. VOID StartDemo( void )
  47. {
  48.     Object    *CM_Broker, *WN_Window, *GA_Hide, *GA_Quit;
  49.     ULONG        signal = 0L, winsig = 0L, sigrec, type, id, rc;
  50.     BOOL        running = TRUE;
  51.  
  52.     /*
  53.     **      Setup a commodity object.
  54.     **/
  55.     CM_Broker = CommodityObject,
  56.         COMM_Name,              "CxDemo",
  57.         COMM_Title,             "Simple BGUI broker.",
  58.         COMM_Description,       "Does not do anything useful.",
  59.         COMM_ShowHide,          TRUE,
  60.     EndObject;
  61.  
  62.     /*
  63.     **      Object OK?
  64.     **/
  65.     if ( CM_Broker )
  66.     {
  67.         /*
  68.         **      Create a small window.
  69.         **/
  70.         WN_Window = WindowObject,
  71.             WINDOW_Title,           "CxDemo",
  72.             WINDOW_RMBTrap,         TRUE,
  73.             WINDOW_SizeGadget,      FALSE,  /* No use in this window. */
  74.             WINDOW_AutoAspect,      TRUE,
  75.             WINDOW_AutoKeyLabel,        TRUE,
  76.             WINDOW_MasterGroup,
  77.                 VGroupObject, HOffset(6), VOffset(6), Spacing(6), GROUP_BackFill, FILL_RASTER,
  78.                     StartMember,
  79.                         InfoObject, ButtonFrame,
  80.                             FRM_Flags,                FRF_RECESSED,
  81.                             INFO_TextFormat,        InfoTxt,
  82.                             INFO_FixTextWidth,    TRUE,
  83.                             INFO_MinLines,            6,
  84.                         EndObject,
  85.                     EndMember,
  86.                     StartMember,
  87.                         HGroupObject,
  88.                             StartMember, GA_Hide = FuzzButton( "_Hide", ID_HIDE ), EndMember,
  89.                             VarSpace(DEFAULT_WEIGHT),
  90.                             StartMember, GA_Quit = FuzzButton( "_Quit", ID_QUIT ), EndMember,
  91.                         EndObject, FixMinHeight,
  92.                     EndMember,
  93.                 EndObject,
  94.             EndObject;
  95.  
  96.         /*
  97.         **      Window OK?
  98.         **/
  99.         if ( WN_Window )
  100.         {
  101.             /*
  102.             **      Add F1 as hotkey.
  103.             **/
  104.             if ( AddHotkey( CM_Broker, "f1", CX_F1_PRESSED, 0L ))
  105.             {
  106.                 /*
  107.                 **        Obtain broker signal mask.
  108.                 **/
  109.                 GetAttr( COMM_SigMask, CM_Broker, &signal );
  110.                 /*
  111.                 **      Activate the broker.
  112.                 **/
  113.                 EnableBroker( CM_Broker );
  114.                 /*
  115.                 **      Open up the window.
  116.                 **/
  117.                 if ( WindowOpen( WN_Window ))
  118.                 {
  119.                     /*
  120.                     **      Obtain window sigmask.
  121.                     **/
  122.                     GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  123.                     /*
  124.                     **      Wait for messages.
  125.                     **/
  126.                     do {
  127.                         sigrec = Wait( signal | winsig | SIGBREAKF_CTRL_C );
  128.                         /*
  129.                         **      Broker signal?
  130.                         **/
  131.                         if ( sigrec & signal )
  132.                         {
  133.                             /*
  134.                             **      Obtain the messages from the broker.
  135.                             **/
  136.                             while ( MsgInfo( CM_Broker, &type, &id, NULL ) != CMMI_NOMORE )
  137.                             {
  138.                         /*
  139.                         **      Evaluate message.
  140.                         **/
  141.                         switch ( type ) {
  142.  
  143.                            case    CXM_IEVENT:
  144.                               switch ( id ) {
  145.  
  146.                                  case    CX_F1_PRESSED:
  147.                                     goto openUp;
  148.                               }
  149.                               break;
  150.  
  151.                            case    CXM_COMMAND:
  152.                               switch ( id ) {
  153.  
  154.                                  case    CXCMD_KILL:
  155.                                     Tell( "bye bye\n" );
  156.                                     running = FALSE;
  157.                                     break;
  158.  
  159.                                  case    CXCMD_DISABLE:
  160.                                     Tell( "broker disabled\n" );
  161.                                     DisableBroker( CM_Broker );
  162.                                     break;
  163.  
  164.                                  case    CXCMD_ENABLE:
  165.                                     Tell( "broker enabled\n" );
  166.                                     EnableBroker( CM_Broker );
  167.                                     break;
  168.  
  169.                                  case    CXCMD_UNIQUE:
  170.                                  case    CXCMD_APPEAR:
  171.                                     openUp:
  172.                                     if ( WindowOpen( WN_Window ))
  173.                                        GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  174.                                     break;
  175.  
  176.                                  case    CXCMD_DISAPPEAR:
  177.                                     WindowClose( WN_Window );
  178.                                     winsig = 0L;
  179.                                     break;
  180.                               }
  181.                               break;
  182.                         }
  183.                      }
  184.                   }
  185.  
  186.                   /*
  187.                   **      Window signal?
  188.                   **/
  189.                   if ( sigrec & winsig ) {
  190.                      while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
  191.                         switch ( rc ) {
  192.  
  193.                            case ID_HIDE:
  194.                            case WMHI_CLOSEWINDOW:
  195.                               /*
  196.                               **      Hide the window.
  197.                               **/
  198.                               WindowClose( WN_Window );
  199.                               winsig = 0L;
  200.                               break;
  201.  
  202.                            case ID_QUIT:
  203.                               /*
  204.                               **      The end.
  205.                               **/
  206.                               Tell( "bye bye\n" );
  207.                               running = FALSE;
  208.                               break;
  209.                         }
  210.                      }
  211.                   }
  212.  
  213.                   /*
  214.                   **      CTRL+C?
  215.                   **/
  216.                   if ( sigrec & SIGBREAKF_CTRL_C ) {
  217.                      Tell( "bye bye\n" );
  218.                      running = FALSE;
  219.                   }
  220.                } while ( running );
  221.             } else
  222.                Tell( "unable to open the window\n" );
  223.          } else
  224.             Tell( "unable to add the hotkey\n" );
  225.          DisposeObject( WN_Window );
  226.       } else
  227.          Tell( "unable to create a window object\n" );
  228.       DisposeObject( CM_Broker );
  229.    } else
  230.       Tell( "unable to create a commodity object\n" );
  231. }
  232.