(*
**	Cyclone Modula-2 Interface module:
**	$VER: commodities.h 38.4 (24.2.93)
**	Includes Release 40.15
**
**	Commodities definitions
**
**	(C) Copyright 1990-1993 Commodore-Amiga Inc.
**	All Rights Reserved
**
**      Interface module by Marcel Timmermans
**      (C) Copyright 1995-1996 Marcel Timmermans
**      All Rights Reserved
*)

DEFINITION MODULE CommoditiesD;

(*$ Implementation- *)

FROM SYSTEM IMPORT ADDRESS;
IMPORT ed:ExecD,Reg,ie:InputEvent;


CONST
 commoditiesName = "commodities.library";

TYPE
(* Fake data types for system private objects *)
  CxObjPtr; 
  CxMsgPtr;

CONST

(* constant for NewBroker.nb_Version *)
 nbVersion = 5;	    (* Version of NewBroker structure *)

(* Sizes for various buffers *)
 cbdNamelen  = 24;
 cbdTitlelen = 40;
 cbdDescrlen = 40;


TYPE
 UniqueFlags = (
  unique,notify,uf2,uf3,uf4,uf5,uf6,uf7, 
  uf8,uf9,uf10,uf11,uf12,uf13,uf14,uf15
 );

 UniqueFlagSet=SET OF UniqueFlags;

 NewBrokerFlags = (
  nbf0,nbf1,showHide,nbf3,nbf4,nbf5,nbf6,nbf7,
  nbf8,nbf9,nbf10,nbf11,nbf12,nbf13,nbf14,nbf15
 );

 NewBrokerFlagSet = SET OF NewBrokerFlags;

 NewBroker = RECORD
  version         : SHORTINT;  (* Must be set to NB_VERSION *)
  name            : ADDRESS;
  title           : ADDRESS;
  descr           : ADDRESS;
  unique          : UniqueFlagSet;
  flags           : NewBrokerFlagSet;
  pri             : SHORTINT;
  port            : ed.MsgPortPtr;
  reservedChannel : CARDINAL;
 END;
 NewBrokerPtr=POINTER TO NewBroker;

 PFL=POINTER TO PROCEDURE():LONGINT;


CONST
(* Flags for NewBroker.nb_Unique *)
 nbuDuplicate=UniqueFlagSet{};
 nbuUnique=UniqueFlagSet{unique};       (* will not allow duplicates	      *)
 nbuNotify=UniqueFlagSet{notify};       (* sends CXM_UNIQUE to existing broker *)

(* Flags for NewBroker.nb_Flags *)
 cofShowHide=NewBrokerFlagSet{showHide};



(* Commodities Object Types *)
  cxInvalid     = 0;  (* not a valid object (probably null)  *)
  cxFilter      = 1;  (* input event messages only           *)
  cxTypeFilter  = 2;  (* obsolete, do not use                *)
  cxSend        = 3;  (* sends a message                     *)
  cxSignal      = 4;  (* sends a signal                      *)
  cxTranslate   = 5;  (* translates input event into chain   *)
  cxBroker      = 6;  (* application representative          *)
  cxDebug       = 7;  (* dumps info to serial port           *)
  cxCustom      = 8;  (* application provides function       *)
  cxZero        = 9;  (* system terminator node              *)



(*****************************************************************************)


(* Commodities message types *)
  cxmIEvent   = 5;
  cxmCommand  = 6;

(* Only CXM_IEVENT messages are passed through the input network. Other types
 * of messages are sent to an optional port in your broker. This means that
 * you must test the message type in your message handling, if input messages
 * and command messages come to the same port.
 *
 * CXM_IEVENT: Messages of this type rattle around the Commodities input
 *             network. They are sent to you by a Sender object, and passed
 *             to you as a synchronous function call by a Custom object.
 *
 *             The message port or function entry point is stored in the
 *             object, and the ID field of the message will be set to what
 *             you arrange issuing object.
 *
 *             The data section of the message will point to the input event
 *             triggering the message.
 *
 * CXM_COMMAND: These messages are sent to a port attached to your Broker.
 *              They are sent to you when the controller program wants your
 *              program to do something. The ID value identifies the command.
 *)

(* ID values associated with a message of type CXM_COMMAND *)
  cxcmdDisable   = 15;  (* please disable yourself       *)
  cxcmdEnable    = 17;  (* please enable yourself        *)
  cxcmdAppear    = 19;  (* open your window, if you can  *)
  cxcmdDisappear = 21;  (* go dormant                    *)
  cxcmdKill      = 23;  (* go away for good              *)
  cxcmdListChg   = 27;  (* Someone changed the broker list *)
  cxcmdUnique    = 25;  (* someone tried to create a broker
                         * with your name. Suggest you appear.
                         *)

(*****************************************************************************)
TYPE

  InputXpressionPtr = POINTER TO InputXpression;
  InputXpression = RECORD
    version  : SHORTCARD;       (* must be set to IX_VERSION  *)
    class    : ie.Class;        (* class must match exactly   *)

    code     : CARDINAL;        (* Bits that we want          *)
    codeMask : CARDINAL;        (* Set bits here to indicate  *)
                                (* which bits in ix_Code are  *)
                                (* don't care bits.           *)
    qualifier: ie.QualifierSet; (* Bits that we want          *)
    qualMask : ie.QualifierSet; (* Set bits here to indicate  *)
                                (* which bits in ix_Qualifier *)
                                (* are don't care bits        *)
    qualSame : CARDINAL         (* synonyms in qualifier      *)
  END;

  IX = InputXpression;
  IXPtr = POINTER TO IX;

CONST
(* constant for InputXpression.ix_Version *)
  ixVersion = 2;

(* constants for InputXpression.ix_QualSame *)
  ixSymShift   = 0;     (* left- and right- shift are equivalent     *)
  ixSymCaps    = 1;     (* either shift or caps lock are equivalent  *)
  ixSymAlt     = 2;     (* left- and right- alt are equivalent       *)

  ixSymShiftMask = ie.QualifierSet{ie.lShift,ie.rShift};
  ixSymCapsMask  = ixSymShiftMask + ie.QualifierSet{ie.capsLock};
  ixSymAltMask   = ie.QualifierSet{ie.lAlt,ie.rAlt};

(* constant for InputXpression.ix_QualMask *)
  ixNormalQuals = ie.QualifierSet{ie.lShift..ie.leftButton};

(*****************************************************************************)


(* Error returns from CxBroker() *)
  errOk       = 0;  (* No error                             *)
  errSysErr   = 1;  (* System error, no memory, etc         *)
  errDup      = 2;  (* uniqueness violation                 *)
  errVersion  = 3;  (* didn't understand NewBroker.version  *)


(*****************************************************************************)


(* Return values from CxObjError() *)
  coErrIsNull      = 0;  (* you called CxError(NULL)            *)
  coErrNullAttach  = 1;  (* someone attached NULL to my list    *)
  coErrBadFilter   = 2;  (* a bad filter description was given  *)
  coErrBadType     = 3;  (* unmatched type-specific operation   *)

END CommoditiesD.
