home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / mmb_shift.lha / MMBShift / Source / MMBShift.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-28  |  4.1 KB  |  226 lines

  1. /*
  2. **  MMBShift.c  Version 37.1  (16. Januar 1994)
  3. **
  4. **  Ein Commodity-Programm um die mittlere Maustaste mit "Shift"
  5. **  zu belegen. Benötigt Amiga-OS 2.04 (37.175) oder höher.
  6. **
  7. **  (c) Copyright 1994 Ralf Seyfarth
  8. **    Alle Rechte vorbehalten
  9. **  
  10. **  Dieses Programm ist FREEWARE, es darf frei weitergegeben werden,
  11. **  solange alle Dateien im original Zustand enthalten sind.
  12. **
  13. **  Aufruf für DICE (2.07.56R) :
  14. **
  15. **  DCC MMBShift.c -o MMBShift -3.0 -mi
  16. */
  17.  
  18.  
  19. #include <clib/alib_protos.h>
  20. #include <dos/dos.h>
  21. #include <intuition/intuitionbase.h>
  22. #include <libraries/commodities.h>
  23. #include <workbench/startup.h>
  24. #include <workbench/workbench.h>
  25.  
  26. #define   CxBase_DECLARED
  27. #define   IntuitionBase_DECLARED
  28.  
  29. #include <proto/commodities.h>
  30. #include <proto/dos.h>
  31. #include <proto/exec.h>
  32. #include <proto/icon.h>
  33. #include <proto/intuition.h>
  34. #include <proto/utility.h>
  35.  
  36. #include <stdlib.h>
  37.  
  38. VOID _main(VOID);
  39. VOID _waitwbmsg(VOID);
  40. VOID HandleEvent(VOID);
  41. VOID MainLoop(VOID);
  42.  
  43. __geta4 VOID CxHandler(CxMsg *);
  44.  
  45. IMPORT struct IntuitionBase *IntuitionBase;
  46. IMPORT struct WBStartup        *_WBMsg;
  47.  
  48. #define LEFTSHIFT 0x60
  49.  
  50. struct Library *CxBase;
  51. struct MsgPort *BrokerMP;
  52.  
  53. struct NewBroker NewBroker =
  54. {
  55.     NB_VERSION,
  56.     "MMBShift",
  57.     "MMBShift 37.1 (16.1.94)",
  58.     "Copyright © 1994 Ralf Seyfarth",
  59.     NBU_NOTIFY | NBU_UNIQUE,
  60.     0,
  61.     0,
  62.     NULL,
  63.     0
  64. };
  65.  
  66. STATIC const UBYTE VersionsTag[] = "\0$VER: MMBShift 37.1 (16.1.94)";
  67.  
  68. CxObj *Broker;
  69. LONG  *ArgA[1];
  70.        Priority;
  71. UBYTE *PriStr;
  72. ULONG  CxSigFlag;
  73.  
  74.  
  75. VOID
  76. _main(VOID)
  77. {
  78.     if (IntuitionBase->LibNode.lib_Version < 37)
  79.     _exit(RETURN_FAIL);
  80.  
  81.     if (_WBMsg)
  82.     {
  83.     struct DiskObject *DObj;
  84.  
  85.     CurrentDir(_WBMsg->sm_ArgList[0].wa_Lock);
  86.  
  87.     if (DObj = GetDiskObject(_WBMsg->sm_ArgList[0].wa_Name))
  88.     {
  89.         if (PriStr = FindToolType(DObj->do_ToolTypes, "CX_PRIORITY"))
  90.         StrToLong(PriStr, &Priority);
  91.  
  92.         FreeDiskObject(DObj);
  93.     }
  94.     }
  95.     else
  96.     {
  97.     struct RDArgs *RDArgs;
  98.  
  99.     if (!(RDArgs = ReadArgs("CX_PRIORITY/N/K", ArgA, NULL)))
  100.     {
  101.         PrintFault(IoErr(), NULL);
  102.         _exit(RETURN_FAIL);
  103.     }
  104.  
  105.     if (ArgA[0])
  106.         Priority = *ArgA[0];
  107.  
  108.     FreeArgs(RDArgs);
  109.     }
  110.  
  111.     MainLoop();
  112. }
  113.  
  114.  
  115. VOID
  116. HandleEvent(VOID)
  117. {
  118.     FOREVER
  119.     {
  120.     ULONG SigRec = Wait(SIGBREAKF_CTRL_C | CxSigFlag);
  121.  
  122.     if (SigRec & SIGBREAKF_CTRL_C)
  123.         return;
  124.  
  125.     if (SigRec & CxSigFlag)
  126.     {
  127.         CxMsg *CxMsg;
  128.  
  129.         while (CxMsg = GetMsg(BrokerMP))
  130.         {
  131.            ULONG MsgID,
  132.              MsgType;
  133.  
  134.            MsgID   = CxMsgID(CxMsg);
  135.            MsgType = CxMsgType(CxMsg);
  136.  
  137.            ReplyMsg((struct Message *) CxMsg);
  138.  
  139.            if (MsgType == CXM_COMMAND)
  140.            {
  141.                switch (MsgID)
  142.                {
  143.                    case CXCMD_KILL    :
  144.                    case CXCMD_UNIQUE  : return;
  145.  
  146.                    case CXCMD_ENABLE  : ActivateCxObj(Broker, TRUE);
  147.                             break;
  148.  
  149.                    case CXCMD_DISABLE : ActivateCxObj(Broker, FALSE);
  150.                }
  151.            }
  152.         }
  153.     }
  154.     }
  155. }
  156.  
  157.  
  158. VOID
  159. MainLoop(VOID)
  160. {
  161.     CxObj *CxObj;
  162.     CxMsg *CxMsg;
  163.     ULONG  ECode = RETURN_FAIL;
  164.  
  165.     if (CxBase = OpenLibrary("commodities.library", 37L))
  166.     {
  167.     if (BrokerMP = CreateMsgPort())
  168.     {
  169.         NewBroker.nb_Pri  = (BYTE) Priority;
  170.             NewBroker.nb_Port = BrokerMP;
  171.  
  172.         if (Broker = CxBroker(&NewBroker, NULL))
  173.         {
  174.         if (CxObj = CxCustom(CxHandler, NULL))
  175.         {
  176.             AttachCxObj(Broker, CxObj);
  177.             CxSigFlag = 1L << BrokerMP->mp_SigBit;
  178.  
  179.             if (!CxObjError(Broker))
  180.             {
  181.             ActivateCxObj(Broker, TRUE);
  182.             HandleEvent();
  183.  
  184.             ECode = RETURN_OK;
  185.             }
  186.         }
  187.  
  188.         DeleteCxObjAll(Broker);
  189.         }
  190.         else
  191.         ECode = RETURN_OK;
  192.  
  193.         while (CxMsg = GetMsg(BrokerMP))
  194.            ReplyMsg((struct Message *) CxMsg);
  195.  
  196.         DeleteMsgPort(BrokerMP);
  197.     }
  198.  
  199.     CloseLibrary(CxBase);
  200.     }
  201.  
  202.     _exit(ECode);
  203.     _waitwbmsg();
  204. }
  205.  
  206.  
  207. __geta4 VOID
  208. CxHandler(CxMsg *CxMsg)
  209. {
  210.     struct InputEvent *IEvent;
  211.  
  212.     if (IEvent = (struct InputEvent *) CxMsgData(CxMsg))
  213.     {
  214.     if (IEvent->ie_Qualifier & IEQUALIFIER_MIDBUTTON)
  215.         IEvent->ie_Qualifier -= IEQUALIFIER_MIDBUTTON - IEQUALIFIER_LSHIFT;
  216.  
  217.     if (IEvent->ie_Class == IECLASS_RAWMOUSE)
  218.  
  219.         if ((IEvent->ie_Code & ~IECODE_UP_PREFIX) == IECODE_MBUTTON)
  220.         {
  221.         IEvent->ie_Code  -= IECODE_MBUTTON - LEFTSHIFT;
  222.         IEvent->ie_Class  = IECLASS_RAWKEY;
  223.         }
  224.     }
  225. }
  226.