commodities.pas 7.8 KB

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