commodities.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 by Free Pascal development team
  4. commodities.library functions
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$PACKRECORDS 2}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit commodities;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$IFDEF FPC_DOTTEDUNITS}
  17. uses
  18. Amiga.Core.Exec, Amiga.Core.Inputevent, Amiga.Core.Keymap;
  19. {$ELSE FPC_DOTTEDUNITS}
  20. uses
  21. exec, inputevent, keymap;
  22. {$ENDIF FPC_DOTTEDUNITS}
  23. type
  24. CxObj = LongInt;
  25. PCxObj = ^CxObj;
  26. CxMsg = LongInt;
  27. PCXMsg = ^CxMsg;
  28. PNewBroker = ^TNewBroker;
  29. TNewBroker = record
  30. nb_Version: Shortint; // NB_VERSION see below
  31. nb_Name: STRPTR;
  32. nb_Title: STRPTR;
  33. nb_Descr: STRPTR;
  34. nb_Unique: SmallInt; // see below NBU_*
  35. nb_Flags: SmallInt; // see below COF_*
  36. nb_Pri: Shortint;
  37. nb_Port: PMsgPort;
  38. nb_ReservedChannel: SmallInt;
  39. end;
  40. const
  41. // nb_Version
  42. NB_VERSION = 5; // Version of NewBroker structure
  43. // buffer sizes
  44. CBD_NAMELEN = 24; // length of nb_Name
  45. CBD_TITLELEN = 40; // length of nb_Title
  46. CBD_DESCRLEN = 40; // length of nb_Descr
  47. // nb_Unique
  48. NBU_DUPLICATE = 0;
  49. NBU_UNIQUE = 1; // will not allow duplicates
  50. NBU_NOTIFY = 2; // sends CXM_UNIQUE to existing broker
  51. // nb_Flags
  52. COF_SHOW_HIDE = 4;
  53. // Commodities Object Types
  54. CX_INVALID = 0; // not a valid object (probably null)
  55. CX_FILTER = 1; // input event messages only
  56. CX_TYPEFILTER = 2; // filter on message type
  57. CX_SEND = 3; // sends a message
  58. CX_SIGNAL = 4; // sends a signal
  59. CX_TRANSLATE = 5; // translates IE into chain
  60. CX_BROKER = 6; // application representative
  61. CX_DEBUG = 7; // dumps kprintf to serial port
  62. CX_CUSTOM = 8; // application provides function
  63. CX_ZERO = 9; // system terminator node
  64. CXM_IEVENT = 1 shl 5;
  65. CXM_COMMAND = 1 shl 6;
  66. // ID values
  67. CXCMD_DISABLE = 15; // please disable yourself
  68. CXCMD_ENABLE = 17; // please enable yourself
  69. CXCMD_APPEAR = 19; // open your window, if you can
  70. CXCMD_DISAPPEAR = 21; // go dormant
  71. CXCMD_KILL = 23; // go away for good
  72. CXCMD_LIST_CHG = 27; // Used by Exchange program. Someone has changed the broker list
  73. CXCMD_UNIQUE = 25; // someone tried to create a broker with your name. Suggest you Appear.
  74. type
  75. PInputXpression = ^TInputXpression;
  76. TInputXpression = record
  77. ix_Version: Byte; // must be set to IX_VERSION
  78. ix_Class: Byte; // class must match exactly
  79. ix_Code: Word; // Bits that we want
  80. ix_CodeMask: Word; // Set bits here to indicate which bits in ix_Code are don't care bits.
  81. ix_Qualifier: Word; // Bits that we want
  82. ix_QualMask : Word; // Set bits here to indicate which bits in ix_Qualifier are don't care bits
  83. ix_QualSame : Word; // synonyms in qualifier
  84. end;
  85. IX = TInputXpression;
  86. PIX = ^IX;
  87. const
  88. // ix_Version
  89. IX_VERSION = 2;
  90. // ix_QualSame
  91. IXSYM_SHIFT = 1; // left- and right- shift are equivalent
  92. IXSYM_CAPS = 2; // either shift or caps lock are equivalent
  93. IXSYM_ALT = 4; // left- and right- alt are equivalent
  94. // corresponding QualSame masks
  95. IXSYM_SHIFTMASK = IEQUALIFIER_LSHIFT or IEQUALIFIER_RSHIFT;
  96. IXSYM_CAPSMASK = IXSYM_SHIFTMASK or IEQUALIFIER_CAPSLOCK;
  97. IXSYM_ALTMASK = IEQUALIFIER_LALT or IEQUALIFIER_RALT;
  98. // ix_QualMask
  99. IX_NORMALQUALS = $7FFF; // avoid RELATIVEMOUSE
  100. // Return Values of CxBroker()
  101. CBERR_OK = 0; // No error
  102. CBERR_SYSERR = 1; // System error , no memory, etc
  103. CBERR_DUP = 2; // uniqueness violation
  104. CBERR_VERSION = 3; // didn't understand nb_VERSION
  105. // Return Values of CxObjError()
  106. COERR_ISNULL = 1; // you called CxError(NULL)
  107. COERR_NULLATTACH = 2; // someone attached NULL to my list
  108. COERR_BADFILTER = 4; // a bad filter description was given
  109. COERR_BADTYPE = 8; // unmatched type-specific operation
  110. var
  111. CxBase: PLibrary = nil;
  112. const
  113. COMMODITIESNAME: PAnsiChar = 'commodities.library';
  114. function CreateCxObj(Typ: LongWord location 'd0'; Arg1: LongInt location 'a0'; Arg2: LongInt location 'a1'): PCxObj; syscall CxBase 30;
  115. function CxBroker(Nb: PNewBroker location 'a0'; var Error: LongInt location 'd0'): PCxObj; syscall CxBase 36;
  116. function ActivateCxObj(Co: PCxObj location 'a0'; Tru: LongInt location 'd0'): LongInt; syscall CxBase 42;
  117. procedure DeleteCxObj(Co: PCxObj location 'a0'); syscall CxBase 48;
  118. procedure DeleteCxObjAll(Co: PCxObj location 'a0'); syscall CxBase 54;
  119. function CxObjType(Co: PCxObj location 'a0'): LongWord; syscall CxBase 60;
  120. function CxObjError(Co: PCxObj location 'a0'): LongInt; syscall CxBase 66;
  121. procedure ClearCxObjError(Co: PCxObj location 'a0'); syscall CxBase 72;
  122. function SetCxObjPri(Co: PCxObj location 'a0'; Pri: LongInt location 'd0'): LongInt; syscall CxBase 78;
  123. procedure AttachCxObj(HeadObj: PCxObj location 'a0'; Co: PCxObj location 'a1'); syscall CxBase 84;
  124. procedure EnqueueCxObj(HeadObj: PCxObj location 'a0'; Co: PCxObj location 'a1'); syscall CxBase 90;
  125. procedure InsertCxObj(HeadObj: PCxObj location 'a0'; Co: PCxObj location 'a1'; Pred: PCxObj location 'a2'); syscall CxBase 96;
  126. procedure RemoveCxObj(Co: PCxObj location 'a0'); syscall CxBase 102;
  127. procedure SetTranslate(Translator: PCxObj location 'a0'; Events: PInputEvent location 'a1'); syscall CxBase 114;
  128. procedure SetFilter(Filter: PCxObj location 'a0'; Text: STRPTR location 'a1'); syscall CxBase 120;
  129. procedure SetFilterIX(Filter: PCxObj location 'a0'; Ix: PInputXpression location 'a1'); syscall CxBase 126;
  130. function ParseIX(Description: STRPTR location 'a0'; Ix: PInputXpression location 'a1'): LongInt; syscall CxBase 132;
  131. function CxMsgType(Cxm: PCxMsg location 'a0'): LongWord; syscall CxBase 138;
  132. function CxMsgData(Cxm: PCxMsg location 'a0'): APTR; syscall CxBase 144;
  133. function CxMsgID(Cxm: PCxMsg location 'a0'): LongInt; syscall CxBase 150;
  134. procedure DivertCxMsg(Cxm: PCxMsg location 'a0'; HeadObj: PCxObj location 'a1'; ReturnObj: PCxObj location 'a2'); syscall CxBase 156;
  135. procedure RouteCxMsg(Cxm: PCxMsg location 'a0'; Co: PCxObj location 'a1'); syscall CxBase 162;
  136. procedure DisposeCxMsg(Cxm: PCxMsg location 'a0'); syscall CxBase 168;
  137. function InvertKeyMap(AnsiCode: LongWord location 'd0'; Event: PInputEvent location 'a0'; Km: PKeyMap location 'a1'): LongBool; syscall CxBase 174;
  138. procedure AddIEvents(Events: PInputEvent location 'a0'); syscall CxBase 180;
  139. function MatchIX(Event: PInputEvent location 'a0'; Ix: PInputXpression location 'a1'): LongBool; syscall CxBase 204;
  140. // macros
  141. function CxFilter(D: STRPTR): PCxObj; inline;
  142. function CxSender(Port: PMsgPort; Id: longint): PCxObj; inline;
  143. function CxSignal(Task: pTask; Sig: Byte): PCxObj; inline;
  144. function CxTranslate(Ie: PInputEvent): PCxObj; inline;
  145. function CxDebug(Id: LongInt): PCxObj; inline;
  146. function CxCustom(Action: Pointer; Id: LongInt): PCxObj; inline;
  147. function Null_IX(ix: PIX): Boolean; inline;
  148. implementation
  149. function CxFilter(D: STRPTR): PCxObj; inline;
  150. begin
  151. CxFilter := CreateCxObj(CX_FILTER, IPTR(d), 0)
  152. end;
  153. function CxSender(Port: PMsgPort; Id: longint): PCxObj; inline;
  154. begin
  155. CxSender := CreateCxObj(CX_SEND, IPTR(Port), Id);
  156. end;
  157. function CxSignal(Task: pTask; Sig: Byte): PCxObj;
  158. begin
  159. CxSignal:= CreateCxObj(CX_SIGNAL, IPTR(task), Sig);
  160. end;
  161. function CxTranslate(Ie: PInputEvent): PCxObj;
  162. begin
  163. CxTranslate := CreateCxObj(CX_TRANSLATE, IPTR(Ie), 0);
  164. end;
  165. function CxDebug(Id: LongInt): PCxObj;
  166. begin
  167. CxDebug := CreateCxObj(CX_DEBUG, Id, 0)
  168. end;
  169. function CxCustom(Action: Pointer; Id: LongInt): PCxObj;
  170. begin
  171. CxCustom := CreateCxObj(CX_CUSTOM, IPTR(Action), Id);
  172. end;
  173. function Null_IX(Ix: PIX): Boolean;
  174. begin
  175. Null_IX := Ix^.ix_Class = IECLASS_NULL;
  176. end;
  177. const
  178. // Change LIBVERSION to proper values
  179. LIBVERSION: longword = 0;
  180. initialization
  181. CxBase := OpenLibrary(COMMODITIESNAME, LIBVERSION);
  182. finalization
  183. if Assigned(CxBase) then
  184. CloseLibrary(CxBase);
  185. end.