home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / misc / MMB_Shift-2.0.lha / MMB_Shift.c < prev    next >
C/C++ Source or Header  |  1994-08-29  |  6KB  |  188 lines

  1. /*
  2.  * MMB_Shift
  3.  * ---------
  4.  *
  5.  * Copyright ⌐ 1994 by Andreas M. Kirchwitz, Seesener Str. 69, D-10709 Berlin
  6.  *                                   E-Mail: amk@zikzak.in-berlin.de, Germany
  7.  */
  8.  
  9. #include <exec/libraries.h>
  10. #include <libraries/commodities.h>
  11. #include <dos/dos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/alib_protos.h>
  14. #include <clib/alib_stdio_protos.h>
  15. #include <clib/commodities_protos.h>
  16. #include <devices/inputevent.h>
  17.  
  18. static const char version[] = "$VER: MMB_Shift 2.0 " __AMIGADATE__;
  19.  
  20. #ifdef __SASC
  21. __regargs int _CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  22. __regargs void __chkabort(void) { return; }  /* really */
  23. #endif
  24.  
  25. void main(int, char **);
  26. void ProcessMsg(void);
  27. void CxFunction(CxMsg *, CxObj *);
  28.  
  29. struct Library *CxBase, *IconBase;
  30. struct MsgPort *broker_mp;
  31. CxObj *broker, *cocustom;
  32.  
  33. struct NewBroker newbroker =
  34. {
  35.     NB_VERSION,
  36.     "MMB_Shift",        /* string to identify this broker */
  37.     "MMB_Shift 2.0 ⌐ 1994 A. M. Kirchwitz",
  38.     "map MMB+LMB to LSHIFT+MMB+LMB",
  39.     NBU_UNIQUE | NBU_NOTIFY,    /* don't want any new commodities starting with this name. */
  40.     0, 0, 0, 0            /* if someone tries it, let me know                        */
  41. };
  42.  
  43. ULONG cxsigflag;
  44.  
  45. IX middleix = {
  46.    IX_VERSION,                /* required                      */
  47.    IECLASS_RAWMOUSE,
  48.    IECODE_LBUTTON,            /* Code                          */
  49.    0x00FF & (~IECODE_UP_PREFIX),    /* CodeMask                      */
  50.    IEQUALIFIER_MIDBUTTON,        /* qualifier I am interested in  */
  51.    IEQUALIFIER_MIDBUTTON,        /* QualMask                      */
  52.    0                    /* synonyms irrelevant           */
  53. };
  54.  
  55. void main(int argc, char **argv)
  56. {
  57.     UBYTE **ttypes;
  58.     CxMsg *msg;
  59.     CxObj *mfilter;
  60.  
  61.     if (CxBase = OpenLibrary("commodities.library", 37L))
  62.     {
  63.         /* open the icon.library for support library functions, ArgArrayInit() and ArgArrayDone() */
  64.         if (IconBase = OpenLibrary("icon.library", 36L))
  65.         {
  66.             if (broker_mp = CreateMsgPort())
  67.             {
  68.                 newbroker.nb_Port = broker_mp;
  69.                 cxsigflag = 1L << broker_mp->mp_SigBit;
  70.  
  71.                 /* ArgArrayInit() is a support library function (in the 2.0 version of amiga.lib) */
  72.                 /* that makes it easy to read arguments from either a CLI or from Workbench's     */
  73.                 /* ToolTypes. Because it uses icon.library, the library has to be open before     */
  74.                 /* before calling this function.  ArgArrayDone() cleans up after this function.   */
  75.                 ttypes = ArgArrayInit((long)argc, argv);
  76.  
  77.                 /* ArgInt() (in amiga.lib) searches through the array set up by ArgArrayInit()    */
  78.                 /* for a specific ToolType.  If it finds one, it returns the numeric value of the */
  79.                 /* number that followed the ToolType (i.e., CX_PRIORITY=7).  If it  doesn't find  */
  80.                 /* the ToolType, it returns the default value (the third argument)                */
  81.                 newbroker.nb_Pri = (BYTE)ArgInt(ttypes, "CX_PRIORITY", 0);
  82.  
  83.                 if (broker = CxBroker(&newbroker, NULL))
  84.                 {
  85.                     if (mfilter = CxFilter(NULL))
  86.                     {
  87.                         SetFilterIX(mfilter, &middleix);
  88.  
  89.                         if (!CxObjError(mfilter))
  90.                         {
  91.                             AttachCxObj(broker, mfilter);
  92.  
  93.                             /* CxCustom() takes two arguments, a pointer to the custom function           */
  94.                             /* and an ID. Commodities Exchange will assign that ID to any CxMsg           */
  95.                             /* passed to the custom  function.                                            */
  96.  
  97.                             if (cocustom = CxCustom(CxFunction, 0L))
  98.                             {
  99.                                 AttachCxObj(mfilter, cocustom);
  100.                                 ActivateCxObj(broker, 1L);
  101.                                 ProcessMsg();
  102.                             }
  103.                         }
  104.                         else
  105.                         {
  106.                             DeleteCxObj(mfilter);
  107.                         }
  108.                     }
  109.  
  110.                     /* DeleteCxObjAll() is a commodities.library function that not only deletes   */
  111.                     /* the CxObject pointed to in its argument, but it deletes all of the         */
  112.                     /* CxObjects that are attached to it.                                         */
  113.                     DeleteCxObjAll(broker);
  114.  
  115.                     /* Empty the port of all CxMsgs */
  116.                     while(msg = (CxMsg *)GetMsg(broker_mp))
  117.                         ReplyMsg((struct Message *)msg);
  118.                 }
  119.                 DeletePort(broker_mp);
  120.             }
  121.             ArgArrayDone();   /* this amiga.lib function cleans up after ArgArrayInit()           */
  122.             CloseLibrary(IconBase);
  123.         }
  124.         CloseLibrary(CxBase);
  125.     }
  126. }
  127.  
  128. void ProcessMsg(void)
  129. {
  130.     extern struct MsgPort *broker_mp;
  131.     extern CxObj *broker;
  132.     extern ULONG cxsigflag;
  133.     CxMsg *msg;
  134.     ULONG sigrcvd, msgid;
  135.     LONG returnvalue = 1L;
  136.  
  137.     while (returnvalue)
  138.     {
  139.         sigrcvd = Wait(SIGBREAKF_CTRL_C | cxsigflag);
  140.  
  141.         while(msg = (CxMsg *)GetMsg(broker_mp))
  142.         {
  143.             msgid = CxMsgID(msg);
  144.             ReplyMsg((struct Message *)msg);
  145.  
  146.             switch(msgid)
  147.             {
  148.                 case CXCMD_DISABLE:
  149.                     ActivateCxObj(broker, 0L);
  150.                     break;
  151.                 case CXCMD_ENABLE:
  152.                     ActivateCxObj(broker, 1L);
  153.                     break;
  154.                 case CXCMD_KILL:
  155.                     returnvalue = 0L;
  156.                     break;
  157.                 case CXCMD_UNIQUE:
  158.                     returnvalue = 0L;
  159.                     break;
  160.             }
  161.         }
  162.  
  163.         if (sigrcvd & SIGBREAKF_CTRL_C) returnvalue = 0L;
  164.     }
  165. }
  166.  
  167.  
  168. /*
  169.  *  The custom function for the custom CxObject.  Any code for a
  170.  *  custom CxObj must be short and sweet because it runs as part
  171.  *  of the input.device task.
  172.  */
  173. void CxFunction(register CxMsg *cxm, CxObj *co)
  174. {
  175.     struct InputEvent *ie;
  176.  
  177.     ie = (struct InputEvent *)CxMsgData(cxm);
  178.     ie->ie_Qualifier |= IEQUALIFIER_LSHIFT;
  179.  
  180. #if 0
  181.     ie->ie_Qualifier &= ~(IEQUALIFIER_MIDBUTTON);
  182.     ie->ie_Code &= ~(IECODE_MBUTTON);
  183. #endif
  184.  
  185.     /* DisplayBeep(NULL); */
  186. }
  187.  
  188.