|##########|
|#MAGIC   #|CLABLNIN
|#PROJECT #|"IMPORTALL"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx-x-x--x---x-x-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|xx---xxxxx-xx---
|##########|
(* $A- *)
DEFINITION MODULE Commodities;

FROM Exec   IMPORT LibraryPtr, MsgPortPtr, TaskPtr, TaskSignals;

FROM Input  IMPORT Qualifiers, QualifierSet, InputEventPtr;
FROM System IMPORT SysStringPtr, Regs, PROC;

TYPE
  KeyMapPtr       = DEFERRED POINTER KeyMap.KeyMapPtr;

  CxBrokerErr     = (ok, sysErr, dup, version, makeMeLong = $10000);

CONST
  NBVersion       = 5;

TYPE
  UniqueFlags     = (unique, notify, dummy = 15);
  UniqueFlagSet   = SET OF UniqueFlags;

  NewBrokerFlags  = (showHide = 2, dummy = 15);
  NewBrokerFlagSet= SET OF NewBrokerFlags;

  NewBrokerPtr    = POINTER TO NewBroker;
  NewBroker       = RECORD
                      version            :  SHORTINT;       | := NBVersion
                      name               :  SysStringPtr;
                      title              :  SysStringPtr;
                      descr              :  SysStringPtr;
                      unique             :  UniqueFlagSet;
                      flags              :  NewBrokerFlagSet;
                      pri                :  SHORTINT;
                      port               :  MsgPortPtr;
                      reservedChannel    :  INTEGER;
                    END;


  CxObjPtr        = HIDDEN;
  CxMsgPtr        = POINTER TO RECORD OF Exec.Message END;

  PFL             = PROCEDURE():LONGINT;


  CxObjType       =  (invalid, filter, typefilter,
                      sender, signal, translate,
                      broker, debug, custom, zero);

 | invalid    : not a valid object (probably null)
 | filter     : input event messages only
 | typefilter : filter on message type
 | send       : sends a message
 | signal     : sends a signal
 | translate  : translates IE into chain
 | broker     : application representative
 | debug      : dumps kprintf to serial port
 | custom     : application provids function
 | zero       : system terminator node

  CxMsg           = (unique=4, iEvent, command);
  CxMsgTypes      = SET OF CxMsg;

  CxMsgCommands = (disable   = 15,  | disable yourself
                   enable    = 17,  | enable yourself
                   appear    = 19,  | open your window
                   disappear = 21,  | close the window
                   kill      = 23,  | terminate yourself
                   unique    = 25,  | someone tried to create
                                    | a unique broker
                   listChg   = 27); | someone changed broker list

  BrokerCommandErr= (noMem = -3, noPort, noBroker, ok);

  CxObjErrs       = (isNull, nullAttach, badFilter, badType);
  CxObjErrSet     = SET OF CxObjErrs;

  | isNull     : you called CxError(NULL)
  | nullAttach : someone attached NULL to my list
  | badFilter  : a bad filter description was given
  | badType    : unmatched type-specific operation



CONST
  IXVersion       =  2;

TYPE
  QualSameId      = (shift, caps, alt);
  QualSameSet     = SET OF QualSameId;

  InputXpressionPtr
                  = POINTER TO InputXpression;
  InputXpression  = RECORD
                      version    :  SHORTCARD; | must be set to IX_VERSION
                      class      :  SHORTCARD; | class must match exactly
                      code       :  CARDINAL;
                      codeMask   :  CARDINAL;  | normally used for UPCODE
                      qualifier  :  CARDINAL;
                      qualMask   :  CARDINAL;
                      qualSame   :  QualSameSet;| synonyms in qualifier
                    END;
  IX              = InputXpression;
  IXPtr           = InputXpressionPtr;

  IXErr           = (noDescription = -2, tokensAfterEnd, ok);

CONST
  shiftMask       = QualifierSet:{lShift,rShift};
  capsMask        = shiftMask + QualifierSet:{capsLock};
  altMask         = QualifierSet:{lAlt, rAlt};
  normalquals     = QualifierSet:{lShift..leftButton};


VAR
  CxBase :  LibraryPtr;


LIBRARY CxBase BY -30
  PROCEDURE CreateCxObj(type IN D0: CxObjType;
                        arg1 IN A0: ANYPTR;
                        arg2 IN A1: ANYPTR) : CxObjPtr;

LIBRARY CxBase BY -36
  PROCEDURE CxBroker(REF nb    IN A0: NewBroker;
                     VAR error IN D0: CxBrokerErr) : CxObjPtr;

LIBRARY CxBase BY -42
  PROCEDURE ActivateCxObj(co   IN A0: CxObjPtr;
                          true IN D0: LONGBOOL): LONGBOOL;
        (* TRUE: active, FALSE inactive *)


LIBRARY CxBase BY -48
  PROCEDURE DeleteCxObj(co IN A0: CxObjPtr);

LIBRARY CxBase BY -54
  PROCEDURE DeleteCxObjAll(co IN A0: CxObjPtr);

LIBRARY CxBase BY -60
  PROCEDURE GetCxObjType(co IN A0: CxObjPtr) : CxObjType;

LIBRARY CxBase BY -66
  PROCEDURE CxObjError(co IN A0: CxObjPtr): CxObjErrSet;

LIBRARY CxBase BY -72
  PROCEDURE ClearCxObjError(co IN A0: CxObjPtr);

LIBRARY CxBase BY -78
  PROCEDURE SetCxObjPri(co  IN A0: CxObjPtr;
                        pri IN D0: LONGINT) (*** Should be SHORTINT***);

LIBRARY CxBase BY -84
  PROCEDURE AttachCxObj(headObj IN A0: CxObjPtr;
                        co      IN A1: CxObjPtr);

LIBRARY CxBase BY -90
  PROCEDURE EnqueueCxObj(headObj IN A0: CxObjPtr;
                         co      IN A1: CxObjPtr);

LIBRARY CxBase BY -96
  PROCEDURE InsertCxObj(headObj IN A0: CxObjPtr;
                        co      IN A1: CxObjPtr;
                        pred    IN A2: CxObjPtr);

LIBRARY CxBase BY -102
  PROCEDURE RemoveCxObj(co IN A0: CxObjPtr);


LIBRARY CxBase BY -114
  PROCEDURE SetTranslate(translator IN A0: CxObjPtr;
                         events     IN A1: InputEventPtr);

LIBRARY CxBase BY -120
  PROCEDURE SetFilter(    filter IN A0: CxObjPtr;
                      REF text   IN A1: STRING);

LIBRARY CxBase BY -126
  PROCEDURE SetFilterIX(filter IN A0: CxObjPtr;
                        ix     IN A1: IXPtr);

LIBRARY CxBase BY -132
  PROCEDURE ParseIX(REF description IN A0: STRING;
                        ix          IN A1: IXPtr) :IXErr;

LIBRARY CxBase BY -138
  PROCEDURE CxMsgType(cxm IN A0: CxMsgPtr) : CxMsgTypes;

LIBRARY CxBase BY -144
  PROCEDURE CxMsgData(cxm IN A0: CxMsgPtr) : ANYPTR;

LIBRARY CxBase BY -150
   PROCEDURE CxMsgID(cxm IN A0: CxMsgPtr) : LONGINT;

LIBRARY CxBase BY -150
  PROCEDURE CxMsgCommand(cxm IN A0: CxMsgPtr) : CxMsgCommands;

LIBRARY CxBase BY -156
  PROCEDURE DivertCxMsg(cxm     IN A0: CxMsgPtr;
                        headobj IN A1: CxObjPtr;
                        ret     IN A2: CxObjPtr);

LIBRARY CxBase BY -162
  PROCEDURE RouteCxMsg(cxm IN A0: CxMsgPtr;
                       co  IN A1: CxObjPtr);

LIBRARY CxBase BY -168
  PROCEDURE DisposeCxMsg(cxm IN A0: CxMsgPtr);

LIBRARY CxBase BY -174
  PROCEDURE InvertKeyMap(ansicode IN D0: LONGCARD;
                         event    IN A0: InputEventPtr;
                         km       IN A1: KeyMapPtr) : BOOLEAN;

LIBRARY CxBase BY -180
  PROCEDURE AddIEvents(events IN A0: InputEventPtr);



PROCEDURE CxFilter(REF des : STRING):CxObjPtr;

PROCEDURE CxSender(port : MsgPortPtr;id : LONGINT):CxObjPtr;

PROCEDURE CxSignal(task : TaskPtr;sig : TaskSignals):CxObjPtr;

PROCEDURE CxTranslate(ie : InputEventPtr):CxObjPtr;

PROCEDURE CxCustom(action : PROC;id : LONGINT):CxObjPtr;


END Commodities.
