home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / Split_GUI.lha / Split_v1.0 / Sources.lha / Sources / commodity.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-04  |  2.6 KB  |  151 lines

  1. #include <intuition/intuition.h>
  2. #include <libraries/commodities.h>
  3. #include "split.h"
  4.  
  5. #include <clib/alib_protos.h>
  6. #include <proto/intuition.h>
  7. #include <proto/commodities.h>
  8. #include <proto/exec.h>
  9.  
  10. /* for debug purposes */
  11. #include <stdio.h>
  12.  
  13. /* in split.c */
  14. extern BOOL stay;
  15.  
  16. /* in window.c */
  17. extern void openGUI( void );
  18. extern void closeGUI( void );
  19. extern void quit( void );
  20.  
  21. /* end of external definitions */
  22.  
  23. struct NewBroker newbroker = {
  24.     NB_VERSION,
  25.     "Split",
  26.     "Split v1.0 © 1995 by Stefano Reksten",
  27.     NULL,
  28.     NBU_UNIQUE | NBU_NOTIFY,
  29.     COF_SHOW_HIDE, 0, 0, 0 };
  30.  
  31. struct Library *CxBase;
  32.  
  33. char *hotkey = "ctrl lalt f";
  34.  
  35. CxObj *broker, *keyfilter, *keysender, *keykiller;
  36. struct MsgPort *mport;
  37. ULONG brokerSig;
  38.  
  39.  
  40. BOOL setUpCommodity( int argc, char **argv )
  41. {
  42. struct Library *IconBase;
  43.  
  44. if ( IconBase = OpenLibrary( "icon.library", 37L ) )
  45.     {
  46.     char **ttypes;
  47.  
  48.     ttypes = ArgArrayInit( argc, argv );
  49.     newbroker.nb_Pri = ArgInt( ttypes, "CX_PRIORITY", 0 );
  50.     hotkey = ArgString( ttypes, "CX_POPKEY", hotkey );
  51.     CloseLibrary( IconBase );
  52.     }
  53.  
  54. if ( CxBase = OpenLibrary( "commodities.library", 0L ) )
  55.     {
  56.     if ( mport = CreateMsgPort() )
  57.         {
  58.         newbroker.nb_Port = mport;
  59.  
  60.         if ( broker = CxBroker( &newbroker, NULL ) )
  61.             {
  62.             brokerSig = 1L<<mport->mp_SigBit;
  63.  
  64.             if ( keyfilter = CxFilter( hotkey ) )
  65.                 {
  66.                 AttachCxObj( broker, keyfilter );
  67.  
  68.                 if ( keysender = CxSender( mport, EVT_POPKEY ) )
  69.                     {
  70.                     AttachCxObj( keyfilter, keysender );
  71.  
  72.                     if ( keykiller = CxTranslate( NULL ) )
  73.                         {
  74.                         AttachCxObj( keyfilter, keykiller );
  75.  
  76.                         if ( !( CxObjError( keyfilter ) ) )
  77.                             {
  78.                             ActivateCxObj( broker, 1L );
  79.                             return TRUE;
  80.                             }
  81.                         else
  82.                             {
  83.                             DeleteCxObjAll( broker );
  84.                             return FALSE;
  85.                             }
  86.                         }
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.     }
  92. }
  93.  
  94.  
  95. void removeCommodity( void )
  96. {
  97. CxMsg *cxm;
  98.  
  99. DeleteCxObjAll( broker );
  100. while( cxm = (CxMsg *)GetMsg( mport ) )
  101.     ReplyMsg( (struct Message *)cxm );
  102. DeleteMsgPort( mport );
  103. }
  104.  
  105.  
  106. void handleBrokerSig( void )
  107. {
  108. CxMsg *msg;
  109. ULONG msgid, msgtype;
  110.  
  111. while( stay && ( msg = (CxMsg *)GetMsg( mport ) ) )
  112.     {
  113.     msgid = CxMsgID( msg );
  114.     msgtype = CxMsgType( msg );
  115.     ReplyMsg( (struct Message *)msg );
  116.  
  117.     switch( msgtype )
  118.         {
  119.         case CXM_IEVENT:
  120.             switch( msgid )
  121.                 {
  122.                 case EVT_POPKEY:
  123.                     openGUI();
  124.                     break;
  125.                 }
  126.             break;
  127.         case CXM_COMMAND:
  128.             switch( msgid )
  129.                 {
  130.                 case CXCMD_DISABLE:
  131.                     ActivateCxObj( broker, 0L );
  132.                     break;
  133.                 case CXCMD_ENABLE:
  134.                     ActivateCxObj( broker, 1L );
  135.                     break;
  136.                 case CXCMD_KILL:
  137.                     quit();
  138.                     break;
  139.                 case CXCMD_UNIQUE:
  140.                 case CXCMD_APPEAR:
  141.                     openGUI();
  142.                     break;
  143.                 case CXCMD_DISAPPEAR:
  144.                     closeGUI();
  145.                     break;
  146.                 }
  147.             break;
  148.         }
  149.     }
  150. }
  151.