home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / OB3.2D3.DMS / in.adf / Interfaces / Commodities.mod < prev    next >
Encoding:
Text File  |  1993-05-22  |  11.6 KB  |  308 lines

  1. (*-------------------------------------------------------------------------*)
  2. (*                                                                         *)
  3. (*  Amiga Oberon Interface Module:                    Date: 21-May-93      *)
  4. (*                                                                         *)
  5. (*   © 1992 by Fridtjof Siebert                                            *)
  6. (*   updated for V39 by hartmut Goebel                                     *)
  7. (*                                                                         *)
  8. (*-------------------------------------------------------------------------*)
  9.  
  10. MODULE Commodities;
  11.  
  12. IMPORT e  * := Exec,
  13.        ie * := InputEvent,
  14.        km * := KeyMap,
  15.        sys  := SYSTEM,
  16.        I    := Intuition;
  17.  
  18. (*****************************************************************************)
  19. CONST
  20.   commoditiesName * = "commodities.library";
  21.  
  22. (* Sizes for various buffers *)
  23.   nameLen   * = 24;
  24.   titleLen  * = 40;
  25.   descrLen  * = 40;
  26.  
  27. TYPE
  28.   NameStr * = ARRAY nameLen OF CHAR;
  29.   TitleStr * = ARRAY titleLen OF CHAR;
  30.   DescrStr * = ARRAY descrLen OF CHAR;
  31.  
  32.   NewBrokerPtr * = UNTRACED POINTER TO NewBroker;
  33.   NewBroker * = STRUCT;
  34.     version * : SHORTINT;                  (* must be set to NB_VERSION *)
  35.     name  * : UNTRACED POINTER TO NameStr;
  36.     title * : UNTRACED POINTER TO TitleStr;
  37.     descr * : UNTRACED POINTER TO DescrStr;
  38.     unique * : SET;
  39.     flags  * : SET;
  40.     pri    * : SHORTINT;
  41.     (* new in V5   *)
  42.     port * : e.MsgPortPtr;
  43.     reservedChannel * : INTEGER;
  44.   END;
  45.  
  46. CONST
  47.  
  48. (* constant for NewBroker.version *)
  49.   nbVersion * = 5;        (* Version of NewBroker structure   *)
  50.  
  51. (* Flags for NewBroker.unique *)
  52.   duplicate  * = 0;
  53.   unique     * = 1;        (* will not allow duplicates           *)
  54.   notify     * = 2;        (* sends CXM_UNIQUE to existing broker *)
  55.  
  56. (* Flags for NewBroker.flags *)
  57.   showHide * = 2;
  58.  
  59. (*****************************************************************************)
  60. TYPE
  61.  
  62. (* Fake data types for system private objects  *)
  63.   CxObj * = STRUCT END;
  64.   CxMsg * = STRUCT END;
  65.   CxObjPtr * = UNTRACED POINTER TO CxObj;
  66.   CxMsgPtr * = UNTRACED POINTER TO CxMsg;
  67.  
  68. (* Pointer to a function returning a LONG *)
  69.   PFT * = PROCEDURE(): LONGINT;
  70.  
  71. (*****************************************************************************)
  72. CONST
  73.  
  74. (* Commodities Object Types *)
  75.   invalid     * = 0;  (* not a valid object (probably null)  *)
  76.   filter      * = 1;  (* input event messages only           *)
  77.   typeFilter  * = 2;  (* obsolete, do not use                *)
  78.   send        * = 3;  (* sends a message                     *)
  79.   signal      * = 4;  (* sends a signal                      *)
  80.   translate   * = 5;  (* translates input event into chain   *)
  81.   broker      * = 6;  (* application representative          *)
  82.   debug       * = 7;  (* dumps info to serial port           *)
  83.   custom      * = 8;  (* application provides function       *)
  84.   zero        * = 9;  (* system terminator node              *)
  85.  
  86.  
  87. (*****************************************************************************)
  88.  
  89.  
  90. (* Commodities message types *)
  91.   cxmIEvent   * = 5;
  92.   cxmCommand  * = 6;
  93.  
  94. (* Only CXM_IEVENT messages are passed through the input network. Other types
  95.  * of messages are sent to an optional port in your broker. This means that
  96.  * you must test the message type in your message handling, if input messages
  97.  * and command messages come to the same port.
  98.  *
  99.  * CXM_IEVENT: Messages of this type rattle around the Commodities input
  100.  *             network. They are sent to you by a Sender object, and passed
  101.  *             to you as a synchronous function call by a Custom object.
  102.  *
  103.  *             The message port or function entry point is stored in the
  104.  *             object, and the ID field of the message will be set to what
  105.  *             you arrange issuing object.
  106.  *
  107.  *             The data section of the message will point to the input event
  108.  *             triggering the message.
  109.  *
  110.  * CXM_COMMAND: These messages are sent to a port attached to your Broker.
  111.  *              They are sent to you when the controller program wants your
  112.  *              program to do something. The ID value identifies the command.
  113.  *)
  114.  
  115. (* ID values associated with a message of type CXM_COMMAND *)
  116.   cmdDisable   * = 15;  (* please disable yourself       *)
  117.   cmdEnable    * = 17;  (* please enable yourself        *)
  118.   cmdAppear    * = 19;  (* open your window, if you can  *)
  119.   cmdDisappear * = 21;  (* go dormant                    *)
  120.   cmdKill      * = 23;  (* go away for good              *)
  121.   cmdListChg   * = 27;  (* Someone changed the broker list *)
  122.   cmdUnique    * = 25;  (* someone tried to create a broker
  123.                          * with your name. Suggest you appear.
  124.                          *)
  125.  
  126. (*****************************************************************************)
  127. TYPE
  128.  
  129.   InputXpressionPtr * = UNTRACED POINTER TO InputXpression;
  130.   InputXpression * = STRUCT
  131.     version * : SHORTINT;     (* must be set to IX_VERSION  *)
  132.     class   * : SHORTINT;     (* class must match exactly   *)
  133.  
  134.     code     * : SET;         (* Bits that we want          *)
  135.     codeMask * : INTEGER;     (* Set bits here to indicate  *)
  136.                               (* which bits in ix_Code are  *)
  137.                               (* don't care bits.           *)
  138.     qualifier * : SET;        (* Bits that we want          *)
  139.     qualMask  * : SET;        (* Set bits here to indicate  *)
  140.                               (* which bits in ix_Qualifier *)
  141.                               (* are don't care bits        *)
  142.     qualSame * : SET;         (* synonyms in qualifier      *)
  143.   END;
  144.  
  145.   IX * = InputXpression;
  146.   IXPtr * = UNTRACED POINTER TO IX;
  147.  
  148. CONST
  149. (* constant for InputXpression.ix_Version *)
  150.   ixVersion * = 2;
  151.  
  152. (* constants for InputXpression.ix_QualSame *)
  153.   ixSymShift   * = 0;     (* left- and right- shift are equivalent     *)
  154.   ixSymCaps    * = 1;     (* either shift or caps lock are equivalent  *)
  155.   ixSymAlt     * = 2;     (* left- and right- alt are equivalent       *)
  156.  
  157.   ixSymShiftMask * = {ie.lShift,ie.rShift};
  158.   ixSymCapsMask  * = ixSymShiftMask + {ie.capsLock};
  159.   ixSymAltMask   * = {ie.lAlt,ie.rAlt};
  160.  
  161. (* constant for InputXpression.ix_QualMask *)
  162.   ixNormalQuals * = -{ie.relativeMouse}; (* avoid RELATIVEMOUSE *)
  163.  
  164. (*****************************************************************************)
  165.  
  166.  
  167. (* Error returns from CxBroker() *)
  168.   errOk       * = 0;  (* No error                             *)
  169.   errSysErr   * = 1;  (* System error, no memory, etc         *)
  170.   errDup      * = 2;  (* uniqueness violation                 *)
  171.   errVersion  * = 3;  (* didn't understand NewBroker.version  *)
  172.  
  173.  
  174. (*****************************************************************************)
  175.  
  176.  
  177. (* Return values from CxObjError() *)
  178.   coErrIsNull      * = 0;  (* you called CxError(NULL)            *)
  179.   coErrNullAttach  * = 1;  (* someone attached NULL to my list    *)
  180.   coErrBadFilter   * = 2;  (* a bad filter description was given  *)
  181.   coErrBadType     * = 3;  (* unmatched type-specific operation   *)
  182.  
  183. TYPE
  184.   LONGBOOL * = e.LONGBOOL;
  185.  
  186. CONST
  187.   LTRUE * = e.LTRUE;
  188.   LFALSE * = e.LFALSE;
  189.  
  190.  
  191. VAR
  192.   base * : e.LibraryPtr;
  193.  
  194. (*--- functions in V36 or higher (distributed as Release 2.0) ---*)
  195. (*
  196.  *  OBJECT UTILITIES
  197.  *)
  198. PROCEDURE CreateCxObj    *{base,- 30}(type{0}      : LONGINT;
  199.                                       arg1{8}      : e.APTR;
  200.                                       arg2{9}      : e.APTR): CxObjPtr;
  201. PROCEDURE CxBroker       *{base,- 36}(VAR nb{8}    : NewBroker;
  202.                                       VAR error{9} : LONGINT): CxObjPtr;
  203. PROCEDURE ActivateCxObj  *{base,- 42}(co{8}        : CxObjPtr;
  204.                                       true{0}      : LONGBOOL): LONGBOOL;
  205. PROCEDURE DeleteCxObj    *{base,- 48}(co{8}        : CxObjPtr);
  206. PROCEDURE DeleteCxObjAll *{base,- 54}(co{8}        : CxObjPtr);
  207. PROCEDURE CxObjType      *{base,- 60}(co{8}        : CxObjPtr): LONGINT;
  208. PROCEDURE CxObjError     *{base,- 66}(co{8}        : CxObjPtr): LONGSET;
  209. PROCEDURE ClearCxObjError*{base,- 72}(co{8}        : CxObjPtr);
  210. PROCEDURE SetCxObjPri    *{base,- 78}(co{8}        : CxObjPtr;
  211.                                       pri{0}       : LONGINT): LONGINT;
  212. (*
  213.  *  OBJECT ATTACHMENT
  214. *)
  215. PROCEDURE AttachCxObj    *{base,- 84}(headobj{8}   : CxObjPtr;
  216.                                       co{9}        : CxObjPtr);
  217. PROCEDURE EnqueueCxObj   *{base,- 90}(headobj{8}   : CxObjPtr;
  218.                                       co{9}        : CxObjPtr);
  219. PROCEDURE InsertCxObj    *{base,- 96}(headobj{8}   : CxObjPtr;
  220.                                       co{9}        : CxObjPtr;
  221.                                       pred{10}     : CxObjPtr);
  222. PROCEDURE RemoveCxObj    *{base,-102}(co{8}        : CxObjPtr);
  223. (*
  224.  *  TYPE SPECIFIC
  225.  *)
  226. PROCEDURE SetTranslate   *{base,-114}(translator{8}: CxObjPtr;
  227.                                       VAR ie{9}    : IX);
  228. PROCEDURE SetFilter      *{base,-120}(filter{8}    : CxObjPtr;
  229.                                       text{9}      : ARRAY OF CHAR);
  230. PROCEDURE SetFilterIX    *{base,-126}(filter{8}    : CxObjPtr;
  231.                                       VAR ix{9}    : IX);
  232. PROCEDURE ParseIX        *{base,-132}(descr{8}     : ARRAY OF CHAR;
  233.                                       VAR ix{9}    : IX): LONGINT;
  234. (*
  235.  *  COMMON MESSAGE
  236.  *)
  237. PROCEDURE CxMsgType      *{base,-138}(cxm{8}       : CxMsgPtr): LONGSET;
  238. PROCEDURE CxMsgData      *{base,-144}(cxm{8}       : CxMsgPtr): e.APTR;
  239. PROCEDURE CxMsgID        *{base,-150}(cxm{8}       : CxMsgPtr): LONGINT;
  240. (*
  241.  *  MESSAGE ROUTING
  242.  *)
  243. PROCEDURE DivertCxMsg    *{base,-156}(cxm{8}       : CxMsgPtr;
  244.                                       headObj{9}   : CxObjPtr;
  245.                                       returnObj{10}: CxObjPtr);
  246. PROCEDURE RouteCxMsg     *{base,-162}(cxm{8}       : CxMsgPtr;
  247.                                       co{9}        : CxObjPtr);
  248. PROCEDURE DisposeCxMsg   *{base,-168}(cxm{8}       : CxMsgPtr);
  249. (*
  250.  *  INPUT EVENT HANDLING
  251.  *)
  252. PROCEDURE InvertKeyMap   *{base,-174}(ansiCode{0}  : LONGINT;
  253.                                       ie{8}        : ie.InputEventPtr;
  254.                                       km{9}        : km.KeyMapPtr): BOOLEAN;
  255. PROCEDURE AddIEvents     *{base,-180}(ie{8}        : ie.InputEventPtr);
  256.  
  257. (*--- functions in V38 or higher (distributed as Release 2.1) ---*)
  258. (*
  259.  * MORE INPUT EVENT HANDLING
  260.  *)
  261. PROCEDURE  MatchIX       *{base,-204}(event{8}     : ie.InputEventPtr;
  262.                                       ix{9}        : IXPtr): BOOLEAN;
  263.  
  264. (* $OvflChk- $RangeChk- $StackChk- $NilChk- $ReturnChk- $CaseChk- *)
  265.  
  266. (*************************
  267.  * object creation macros
  268.  *************************)
  269.  
  270. PROCEDURE CxFilter*(d: e.APTR): CxObjPtr;
  271. BEGIN RETURN CreateCxObj(filter,d, NIL); END CxFilter;
  272.  
  273. (*  obsolete since V38, so do not use *)
  274. PROCEDURE CxTypeFilter*(type: e.APTR): CxObjPtr;
  275. BEGIN RETURN CreateCxObj(typeFilter,type, NIL); END CxTypeFilter;
  276.  
  277. PROCEDURE CxSender*(port: e.MsgPortPtr; id: e.APTR): CxObjPtr;
  278. BEGIN RETURN CreateCxObj(send,port,id); END CxSender;
  279.  
  280. PROCEDURE CxSignal*(task: e.TaskPtr; sig: INTEGER): CxObjPtr;
  281. BEGIN RETURN CreateCxObj(signal,task,sys.VAL(e.APTR,LONG(sig))); END CxSignal;
  282.  
  283. PROCEDURE CxTranslate*(ie: ie.InputEventPtr): CxObjPtr;
  284. BEGIN RETURN CreateCxObj(translate,ie,NIL); END CxTranslate;
  285.  
  286. PROCEDURE CxDebug*(id: e.APTR): CxObjPtr;
  287. BEGIN RETURN CreateCxObj(debug,id, NIL); END CxDebug;
  288.  
  289. TYPE
  290.   CustomProcType * = PROCEDURE(obj: CxObjPtr; msg: CxMsgPtr);
  291.  
  292. PROCEDURE CxCustom*(action: CustomProcType; id: e.APTR): CxObjPtr;
  293. BEGIN RETURN CreateCxObj(custom,sys.VAL(e.APTR,action),id); END CxCustom;
  294.  
  295. (* matches nothing   *)
  296. PROCEDURE NullIx*(VAR i: IX): BOOLEAN;
  297. BEGIN RETURN i.class = ie.null; END NullIx;
  298.  
  299.  
  300. BEGIN
  301.   base :=  e.OpenLibrary(commoditiesName,37);
  302.  
  303. CLOSE
  304.   IF base#NIL THEN e.CloseLibrary(base) END;
  305.  
  306. END Commodities.
  307.  
  308.