home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / findfiles.lha / FindFile / FFSource.lha / CX.c next >
Encoding:
C/C++ Source or Header  |  1993-04-03  |  3.4 KB  |  167 lines

  1. /************************************************************************
  2.  CX.c        FindFile's Commodities exchange routines
  3.  
  4.  CX.c 1.2 1993/02/28 00:56:13 RUSS Exp
  5.  
  6.  1.2
  7.  
  8.  CX.c
  9.  * Revision 1.2  1993/02/28  00:56:13  RUSS
  10.  * Added #include "FindFile.h"
  11.  *
  12.  * Revision 1.1  1993/02/27  18:49:15  RUSS
  13.  * Initial revision
  14.  *
  15. ************************************************************************/
  16. #include "FindFile.h"
  17.  
  18. extern struct Library *IntuitionBase;
  19. extern struct Library *GadToolsBase;
  20. extern struct Library *CxBase;
  21. extern struct Library *IconBase;
  22.  
  23. extern char *cxTitle;
  24.  
  25. /******************************** Commodities Exchange Handling Routines *********/
  26.  
  27. void
  28. OpenCxInterface( struct controlPanel *cp )
  29. {
  30.   struct NewBroker nb = {
  31.     NB_VERSION,
  32.     ( BYTE *)NAME,
  33.     NULL,
  34.     ( BYTE *)"Searches a volume for a file",
  35.     NBU_UNIQUE | NBU_NOTIFY,
  36.     COF_SHOW_HIDE,
  37.     0,
  38.     NULL,
  39.     0
  40.   };
  41.  
  42.   nb.nb_Title = (BYTE *)cxTitle;
  43.   nb.nb_Pri = cp->cxInterface.cxPriority;
  44.  
  45.  
  46.   /******* Allocate And Initialize MessagePort *********/
  47.   if( !( cp->cxInterface.cxPort = CreateMsgPort() ) )
  48.     Shutdown( cp, 20 );
  49.  
  50.   DB("Got MP.")
  51.  
  52.  
  53.   nb.nb_Port = cp->cxInterface.cxPort;
  54.  
  55.   /******* Create Main Broker CxObj ********************/
  56.  
  57.   if( !( cp->cxInterface.ffBroker = CxBroker( &nb, NULL ) ) )
  58.   {
  59.     DB("Deleteing Msgport")
  60.  
  61.     DeleteMsgPort( cp->cxInterface.cxPort );
  62.  
  63.     DB("Cleaning up")
  64.  
  65.     cp->cxInterface.cxPort = NULL;
  66.     cp->cxInterface.ffBroker = NULL;
  67.  
  68.     DB("Shutting Down")
  69.  
  70.     Shutdown( cp, 20 );
  71.   }
  72.  
  73.   DB("Created Broker object")
  74.  
  75.   /******* Create HotKey CxObj *************************/
  76.  
  77.   AttachCxObj( cp->cxInterface.ffBroker, HotKey( cp->cxInterface.cxHotKeyString,
  78.                          cp->cxInterface.cxPort,
  79.                          OPEN_WINDOW ));
  80.  
  81.   DB("Hot Key attached")
  82.  
  83.   /******* If all went well, activate the Broker *******/
  84.  
  85.   if( ! CxObjError( cp->cxInterface.ffBroker ) )
  86.     ActivateCxObj( cp->cxInterface.ffBroker , TRUE );
  87.   else
  88.     Shutdown( cp , 20 );
  89.  
  90.   DB("Broker activated.")
  91.  
  92. }
  93.  
  94. void
  95. CloseCxInterface( struct controlPanel *cp )
  96. {
  97.   if( cp->cxInterface.cxPort )
  98.   {
  99.     struct Message *msg;
  100.  
  101.     if( cp->cxInterface.ffBroker )
  102.       DeleteCxObjAll( cp->cxInterface.ffBroker );
  103.     cp->cxInterface.ffBroker = NULL;
  104.  
  105.     if( cp->cxInterface.cxPort )
  106.     {
  107.     while( msg = GetMsg( cp->cxInterface.cxPort ) )
  108.     ReplyMsg( msg );
  109.  
  110.     DeleteMsgPort( cp->cxInterface.cxPort );
  111.     cp->cxInterface.cxPort = NULL;
  112.     }
  113.  
  114.   }
  115. }
  116.  
  117. void
  118. HandleCxCommand( struct controlPanel *cp )
  119. {
  120.   CxMsg      *msg;
  121.  
  122.   while( msg = ( CxMsg *)GetMsg( cp->cxInterface.cxPort ) )
  123.   {
  124.     ULONG        messageID;
  125.     ULONG        messageType;
  126.  
  127.     messageID = CxMsgID( msg );
  128.     messageType = CxMsgType( msg );
  129.  
  130.     ReplyMsg( ( struct Message *)msg );
  131.  
  132.     switch( messageType )
  133.     {
  134.       case CXM_IEVENT : switch( messageID )
  135.             {
  136.               case OPEN_WINDOW : CMD_Show( cp );
  137.                          break;
  138.             }
  139.             break;
  140.  
  141.       case CXM_COMMAND :  switch( messageID )
  142.               {
  143.                 case CXCMD_DISABLE : ActivateCxObj( cp->cxInterface.ffBroker,
  144.                                 FALSE );
  145.                          break;
  146.                 case CXCMD_ENABLE :  ActivateCxObj( cp->cxInterface.ffBroker,
  147.                                 TRUE );
  148.                          break;
  149.  
  150.                 case CXCMD_APPEAR :
  151.                 case CXCMD_UNIQUE :  CMD_Show( cp );
  152.                          break;
  153.  
  154.                 case CXCMD_DISAPPEAR : CMD_Hide( cp );
  155.                            break;
  156.  
  157.                 case CXCMD_KILL : CMD_Quit( cp );
  158.                           break;
  159.               }
  160.               break;
  161.     }
  162.   }
  163. }
  164.  
  165. /**********************************************************************************/
  166.  
  167.