home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* DropMenu - Drop Down Menu Commodity */
- /* */
- /* Public Domain - Written 1992 by Paul Wilkinson */
- /* See DropMenu.doc for more information */
- /* */
- /* Contact the author at: */
- /* 24 Armstrong Ave */
- /* Mt. Warrigal NSW */
- /* 2528 */
- /* Australia */
- /* */
- /*****************************************************************************/
-
- #include "DropMenu.h" /* Get all the support thingies */
-
- main(int argc,char *argv[])
- {
- int rc;
-
- if ((rc=Initialise(argc,argv)) == 0) /* Initialise everything */
- {
- Process(); /* If all OK then do main processing */
-
- }
- else
- {
- if (rc > 1)
- EasyRequest(NULL,&TerminalRQ,NULL,errortxt[rc]); /* Complain if did not initialise */
- }
-
- CloseAll(); /* Clean everything up */
-
- }
-
- /*
- * Initialise - Initialise everything necessary for DropMenu.
- * Returns 0 if all OK otherwise returns fail code.
- */
- long Initialise(int argc,char *argv[])
- {
-
- LONG error;
-
- UBYTE *pop;
- int rc=0;
-
- UBYTE **ToolTypes=NULL;
-
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37);
-
- if (!IntuitionBase)
- return(1);
-
- CxBase = (struct CxBase *)OpenLibrary("commodities.library",37);
-
- if (!CxBase)
- return(2);
-
- IconBase = (struct IconBase *)OpenLibrary("icon.library",36);
-
- if (!IconBase)
- return(3);
-
- ToolTypes = ArgArrayInit(argc,(UBYTE **)argv);
-
- if (!SetupCx(ToolTypes,&error))
- {
- if (error==CBERR_DUP) /* Duplicate, not an error, but do not allow */
- return(-1); /* initialisation to complete */
- else
- return(4);
- }
-
- ArgArrayDone();
-
- stdout=Output();
-
- return(rc);
-
- }
-
-
-
- void CloseAll()
- {
-
- ShutdownCx();
-
-
- if (IntuitionBase)
- CloseLibrary((struct Library *)IntuitionBase);
-
- if (CxBase)
- CloseLibrary((struct Library *)CxBase);
-
- if (IconBase)
- CloseLibrary((struct Library *)IconBase);
-
- }
-
-
- void Process()
- {
- long SignalSet;
-
- int done=FALSE;
-
- while (!done)
-
- {
-
- SignalSet = (1 << CxPort -> mp_SigBit) | SIGBREAKF_CTRL_C ;
-
- SignalSet = Wait(SignalSet);
-
- /* There are messages pending at the
- * Commodities reply port.
- */
-
- if(SignalSet & (1 << CxPort -> mp_SigBit))
- {
- CxMsg *Message;
-
- while(Message = (CxMsg *)GetMsg(CxPort))
- done = HandleCxMsg(Message);
- }
-
-
- /* ^C tells the program to quit. */
-
- if(SignalSet & SIGBREAKF_CTRL_C)
- done = TRUE;
- }
-
-
- }
-
-
- VOID
- ShutdownCx()
- {
- if(CxPort)
- {
- struct Message *Message;
-
- /* Remove the broker. */
-
- if(Broker)
- DeleteCxObjAll(Broker);
-
- /* Remove the MsgPort from the public list. */
-
- RemPort(CxPort);
-
- /* Remove all pending messages. */
-
- while(Message = GetMsg(CxPort))
- ReplyMsg(Message);
-
- /* Delete the MsgPort. */
-
- DeleteMsgPort(CxPort);
-
- CxPort = NULL;
- Broker = NULL;
- }
- }
-
- /* SetupCx(UBYTE **ToolTypes):
- *
- * Set up the Commodities interface.
- */
-
- BYTE
- SetupCx(UBYTE **ToolTypes,LONG *error)
- {
- /* Cancel any previously made assignments. */
-
- ShutdownCx();
-
- /* Create a reply port. */
-
- if(CxPort = CreateMsgPort())
- {
- /* Fill in a unique name. */
-
- CxPort -> mp_Node . ln_Name = NewBroker . nb_Name;
-
- /* Add the reply port to the public list. */
-
- AddPort(CxPort);
-
- /* Set the Commodity priority if possible. */
-
- NewBroker . nb_Pri = ArgInt(ToolTypes,"CX_PRIORITY",0);
- NewBroker . nb_Port = CxPort;
-
- /* Create the broker. */
-
- if(Broker = CxBroker(&NewBroker,error))
- {
-
- CxObj *ObjectList;
-
- /* Install the plain InputEvent handler. */
-
- AttachCxObj(Broker,CxFilter("rawmouse"));
-
- ObjectList = CxCustom(CXEventHandler,NULL);
-
- /* Any accumulated errors? */
-
- if(!CxObjError(ObjectList))
- {
- /* Add the custom object. */
-
- AttachCxObj(Broker,ObjectList);
-
- /* Any errors? */
-
- if(!CxObjError(Broker))
- {
- /* Activate the broker. */
-
- ActivateCxObj(Broker,TRUE);
-
- return(TRUE);
- }
- }
- }
- }
-
- ShutdownCx();
-
- return(FALSE);
- }
-
- /* HandleCxMsg(CxMsg *Message):
- *
- * Handle incoming Commodities messages.
- */
-
- long
- HandleCxMsg(CxMsg *Message)
- {
- long done = FALSE;
-
- ULONG MessageType = CxMsgID(Message),MessageID = CxMsgType(Message);
-
- ReplyMsg((struct Message *)Message);
-
- /* Take a look at the message type. */
-
- switch(MessageID)
- {
- /* It's a hotkey. */
-
- case CXM_IEVENT:
-
- break;
- /* It's an internal Commodities command. */
-
- case CXM_COMMAND:
- switch(MessageType)
- {
- /* Disable the Commodity. */
- case CXCMD_DISABLE:
- Active = FALSE;
- ActivateCxObj(Broker,FALSE);
- break;
-
- /* Enable the Commodity. */
- case CXCMD_ENABLE:
- Active = TRUE;
- ActivateCxObj(Broker,TRUE);
- break;
-
- /* Create the control panel. */
-
- case CXCMD_APPEAR:
-
- break;
- /* Close the control panel. */
-
- case CXCMD_DISAPPEAR:
- break;
- /* Remove this Commodity. */
-
- case CXCMD_KILL:
- case CXCMD_UNIQUE:
- done=TRUE;
- break;
- }
-
- break;
- }
-
- return(done);
- }
-
- /* CXEventHandlerAction(CxMsg *CxMessage,CxObj *CxObject):
- *
- * Commodities support routine, handles the Commodities
- * custom actions (in this case: filter the InputEvents
- * coming in and swallow rmb ups every now and then).
- */
-
- VOID
- CXEventHandler(CxMsg *CxMessage,CxObj *CxObject)
- {
-
- struct InputEvent *ie;
-
- int_start();
-
- ie = (struct InputEvent *)CxMsgData(CxMessage);
-
- if ((ie->ie_Class & IECLASS_RAWMOUSE)==IECLASS_RAWMOUSE)
- {
- if ((swallowed) && (ie->ie_X != xpos || ie->ie_Y != ypos))
- {
- swallowed=!swallowed; /*If mouse moved then don't drop menus */
- }
-
- if ((ie->ie_Code & IECODE_RBUTTON)==IECODE_RBUTTON) /* Is it a RMB? */
- {
- if (ie->ie_Code & IECODE_UP_PREFIX) /* RMB Up? */
- {
- if (swallowed)
- {
- ie->ie_Code = ie->ie_Code & ~(IECODE_UP_PREFIX); /* Kill it if swallowing */
- }
- }
- else
- {
- xpos=ie->ie_X; /* Save mouse position for later comparison */
- ypos=ie->ie_Y;
- swallowed=!swallowed; /* Otherwise toggle swallowing state */
- }
-
- }
-
- }
-
- int_end();
-
- }
-