moucalls.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. {Set tabsize to 4.}
  2. {****************************************************************************
  3. MOUCALLS interface unit
  4. FPK-Pascal Runtime Library for OS/2
  5. Copyright (c) 1993,94 by Florian Kl„mpfl
  6. Copyright (c) 1997 by Dani‰l Mantione
  7. Copyright (c) 1998 by Tomas Hajny
  8. The FPK-Pascal runtime library is distributed under the Library GNU Public
  9. License v2. So is this unit. The Library GNU Public License requires you to
  10. distribute the source code of this unit with any product that uses it.
  11. Because the EMX library isn't under the LGPL, we grant you an exception to
  12. this, and that is, when you compile a program with the FPK Pascal compiler,
  13. you do not need to ship source code with that program, AS LONG AS YOU ARE
  14. USING UNMODIFIED CODE! If you modify this code, you MUST change the next
  15. line:
  16. <This is an official, unmodified FPK Pascal source code file.>
  17. Send us your modified files, we can work together if you want!
  18. FPK-Pascal is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. Library GNU General Public License for more details.
  22. You should have received a copy of the Library GNU General Public License
  23. along with FPK-Pascal; see the file COPYING.LIB. If not, write to
  24. the Free Software Foundation, 59 Temple Place - Suite 330,
  25. Boston, MA 02111-1307, USA.
  26. ****************************************************************************}
  27. unit MouCalls;
  28. { Interface library to MOUCALLS.DLL (through EMXWRAP.DLL)
  29. Changelog:
  30. People:
  31. TH - Tomas Hajny
  32. Date: Description of change: Changed by:
  33. - First released version 0.50 TH
  34. Coding style:
  35. I have tried to use the same coding style as Dani‰l Mantione in unit
  36. DOSCALLS, although I can't say I would write it the same way otherwise
  37. (I would write much more spaces myself, at least). Try to use it as well,
  38. please. Original note by Dani‰l Mantione follows:
  39. It may be well possible that coding style feels a bit strange to you.
  40. Nevertheless I friendly ask you to try to make your changes not look all
  41. to different. To make life easier, set your IDE to use tab characters,
  42. turn optimal fill, autoindent and backspace unindents on and set a
  43. tabsize of 4.}
  44. {***************************************************************************}
  45. interface
  46. {***************************************************************************}
  47. uses strings;
  48. {$ifdef FPK}
  49. {$packrecords 1}
  50. {$endif FPK}
  51. const
  52. {return codes / error constants}
  53. ERROR_MOUSE_NO_DEVICE =385;
  54. ERROR_MOUSE_INV_HANDLE =386;
  55. ERROR_MOUSE_INV_PARMS =387;
  56. ERROR_MOUSE_CANT_RESET =388;
  57. ERROR_MOUSE_DISPLAY_PARMS =389;
  58. ERROR_MOUSE_INV_MODULE =390;
  59. ERROR_MOUSE_INV_ENTRY_PT =391;
  60. ERROR_MOUSE_INV_MASK =392;
  61. NO_ERROR_MOUSE_NO_DATA =393;
  62. NO_ERROR_MOUSE_PTR_DRAWN =394;
  63. ERROR_MOUSE_SMG_ONLY =412;
  64. ERROR_MOUSE_INVALID_ASCIIZ =413;
  65. ERROR_MOUSE_INVALID_MASK =414;
  66. ERROR_MOUSE_REGISTER =415;
  67. ERROR_MOUSE_DEREGISTER =416;
  68. ERROR_MOUSE_INVALID_IOWAIT =435;
  69. ERROR_MOU_DETACHED =466;
  70. ERROR_MOUSE_NO_CONSOLE =501;
  71. ERROR_MOUSE_INVALID_HANDLE =502;
  72. ERROR_MOU_EXTENDED_SG =505;
  73. ERROR_MOU_NOT_INITIALIZED =530;
  74. ERROR_MOUINITREAL_DONE =531;
  75. ERROR_MOUSE_CALLER_NOT_SUBSYS =533;
  76. {constants for FnMask in MouRegister}
  77. MR_MOUGETNUMBUTTONS =$00000001;
  78. MR_MOUGETNUMMICKEYS =$00000002;
  79. MR_MOUGETDEVSTATUS =$00000004;
  80. MR_MOUGETNUMQUEEL =$00000008;
  81. MR_MOUREADEVENTQUE =$00000010;
  82. MR_MOUGETSCALEFACT =$00000020;
  83. MR_MOUGETEVENTMASK =$00000040;
  84. MR_MOUSETSCALEFACT =$00000080;
  85. MR_MOUSETEVENTMASK =$00000100;
  86. MR_MOUOPEN =$00000800;
  87. MR_MOUCLOSE =$00001000;
  88. MR_MOUGETPTRSHAPE =$00002000;
  89. MR_MOUSETPTRSHAPE =$00004000;
  90. MR_MOUDRAWPTR =$00008000;
  91. MR_MOUREMOVEPTR =$00010000;
  92. MR_MOUGETPTRPOS =$00020000;
  93. MR_MOUSETPTRPOS =$00040000;
  94. MR_MOUINITREAL =$00080000;
  95. MR_MOUSETDEVSTATUS =$00100000;
  96. {constants for mouse hot key bits in MouGetHotKey/MouSetHotKey}
  97. MHK_BUTTON1 =1;
  98. MHK_BUTTON2 =2;
  99. MHK_BUTTON3 =4;
  100. {MouGetDevStatus/MouSetDevStatus device status constants}
  101. MOUSE_QUEUEBUSY =$0001;
  102. MOUSE_BLOCKREAD =$0002;
  103. MOUSE_FLUSH =$0004;
  104. MOUSE_UNSUPPORTED_MODE =$0008;
  105. MOUSE_DISABLED =$0100;
  106. MOUSE_MICKEYS =$0200;
  107. {constants for WaitFlag in MouReadEventQue}
  108. MOU_NOWAIT =$0000;
  109. MOU_WAIT =$0001;
  110. {constants for MouGetEventMask/MouSetEventMask events}
  111. MOUSE_MOTION =$0001;
  112. MOUSE_MOTION_WITH_BN1_DOWN =$0002;
  113. MOUSE_BN1_DOWN =$0004;
  114. MOUSE_MOTION_WITH_BN2_DOWN =$0008;
  115. MOUSE_BN2_DOWN =$0010;
  116. MOUSE_MOTION_WITH_BN3_DOWN =$0020;
  117. MOUSE_BN3_DOWN =$0040;
  118. {constants for Status in MouSetDevStatus}
  119. MOU_DRAW =0;
  120. MOU_NODRAW =1;
  121. MOU_PELS =0;
  122. MOU_MICKEYS =2;
  123. type
  124. (*This should be removed as soon as cardinal arithmetic in FPC works OK.*)
  125. cardinal=longint;
  126. {unnecessary, just FYI}
  127. THMOU=word;
  128. PHMOU=^THMOU;
  129. {record type for MouGetPos/SetPtrPos}
  130. TPtrLoc=record
  131. Row:word;
  132. Col:word;
  133. end;
  134. PPtrLoc=^TPtrLoc;
  135. {record type for MouGetShape/SetPtrShape}
  136. TPtrShape=record
  137. cb:word; {length of image buffer in bytes}
  138. Col:word; {pointer width in characters or pixels}
  139. Row:word; {pointer height in characters or pixels}
  140. ColHot:word; {hotspot offset from the left side}
  141. RowHot:word; {hotspot offset from the top}
  142. end;
  143. PPtrShape=^TPtrShape;
  144. {record type for MouReadEventQue}
  145. (* #pragma pack(2) ??? *)
  146. TMouEventInfo=record
  147. fs:word; {event bits}
  148. Time:cardinal; {event timestamp - unique number of milliseconds}
  149. Row:integer; {pointer current row position}
  150. Col:integer; {pointer current column position}
  151. end;
  152. PMouEventInfo=^TMouEventInfo;
  153. {record type for MouGetNumQueEl}
  154. TMouQueInfo=record
  155. cEvents:word; {number of elements in event queue}
  156. cmaxEvents:word; {maximum queue size in elements}
  157. end;
  158. PMouQueInfo=^TMouQueInfo;
  159. {record type for MouGetScaleFact/MouSetScaleFact}
  160. TScaleFact=record
  161. RowScale:word; {scaling factor of current row}
  162. ColScale:word; {scaling factor of current column}
  163. end;
  164. PScaleFact=^TScaleFact;
  165. {record type for MouRemovePtr}
  166. TNoPtrRect=record
  167. Row:word; {row of the top of the rectangle}
  168. Col:word; {column of the left edge}
  169. cRow:word; {row of the bottom}
  170. cCol:word; {column of the right edge}
  171. end;
  172. PNoPtrRect=^TNoPtrRect;
  173. TThreshold=record
  174. Length:word;
  175. Level1:word; {first movement level}
  176. Lev1Mult:word; {first level multiplier}
  177. Level2:word; {second movement level}
  178. Lev2Mult:word; {second level multiplier}
  179. end;
  180. PThreshold=^TThreshold;
  181. function MouRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word;
  182. function MouRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
  183. function MouDeRegister:word;
  184. function MouFlushQue(MouHandle:word):word;
  185. function MouGetPtrPos(var MouPtr:TPtrLoc;MouHandle:word):word;
  186. function MouSetPtrPos(var MouPtr:TPtrLoc;MouHandle:word):word;
  187. function MouSetPtrShape(ImageBuf:pointer;var ImageInfo:TPtrShape;
  188. MouHandle:word):word;
  189. function MouGetPtrShape(ImageBuf:pointer;var ImageInfo:TPtrShape;
  190. MouHandle:word):word;
  191. function MouGetDevStatus(var Status:word;MouHandle:word):word;
  192. function MouGetNumButtons(var ButtonCount:word;MouHandle:word):word;
  193. function MouGetNumMickeys(var MickeyCnt:word;MouHandle:word):word;
  194. function MouReadEventQue(var Event:TMouEventInfo;var WaitFlag:word;
  195. MouHandle:word):word;
  196. function MouGetNumQueEl(var MouseQInfo:TMouQueInfo;MouHandle:word):word;
  197. function MouGetEventMask(var EventMask:word;MouHandle:word):word;
  198. function MouSetEventMask(var EventMask:word;MouHandle:word):word;
  199. function MouGetScaleFact(var Scale:TScaleFact;MouHandle:word):word;
  200. function MouSetScaleFact(var Scale:TScaleFact;MouHandle:word):word;
  201. function MouOpen(DriverName:PChar;var MouHandle:word):word;
  202. function MouOpen(DriverName:string;var MouHandle:word):word;
  203. function MouClose(MouHandle:word):word;
  204. function MouRemovePtr(var ProtectArea:TNoPtrRect;MouHandle:word):word;
  205. function MouDrawPtr(MouHandle:word):word;
  206. function MouSetDevStatus(var Status:word;MouHandle:word):word;
  207. function MouInitReal(DriverName:PChar):word;
  208. function MouInitReal(DriverName:string):word;
  209. function MouSynch(WaitFlag:word):word;
  210. function MouGetThreshold(var MouThreshold:TThreshold;MouHandle:word):word;
  211. function MouSetThreshold(var MouThreshold:TThreshold;MouHandle:word):word;
  212. (*
  213. following two functions are undocumented and not present within C header files:
  214. function MouGetHotKey(var ButtonBits:word;MouHandle:word):word;
  215. function MouSetHotKey(var ButtonBits:word;MouHandle:word):word;
  216. *)
  217. (* Following routines are not supported
  218. (just have a look in some C header
  219. file - you probably won't find it there either).
  220. MouFree (index 4)
  221. MouShellInit (index 12)
  222. *)
  223. {***************************************************************************}
  224. implementation
  225. {***************************************************************************}
  226. function MouRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word;
  227. external 'EMXWRAP' index 324;
  228. {external 'MOUCALLS' index 24;}
  229. function MouRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
  230. begin
  231. if byte(ModuleName[0])>8 then byte(ModuleName[0]):=8;
  232. ModuleName[Succ(byte(ModuleName[0]))]:=#0;
  233. if byte(ProcName[0])>32 then byte(ProcName[0]):=32;
  234. ProcName[Succ(byte(ProcName[0]))]:=#0;
  235. MouRegister:=MouRegister(@ModuleName[1],@ProcName[1],FnMask);
  236. end;
  237. function MouDeRegister:word;
  238. external 'EMXWRAP' index 314;
  239. {external 'MOUCALLS' index 14;}
  240. function MouFlushQue(MouHandle:word):word;
  241. external 'EMXWRAP' index 307;
  242. {external 'MOUCALLS' index 7;}
  243. function MouGetPtrPos(var MouPtr:TPtrLoc;MouHandle:word):word;
  244. external 'EMXWRAP' index 319;
  245. {external 'MOUCALLS' index 19;}
  246. function MouSetPtrPos(var MouPtr:TPtrLoc;MouHandle:word):word;
  247. external 'EMXWRAP' index 321;
  248. {external 'MOUCALLS' index 21;}
  249. function MouSetPtrShape(ImageBuf:pointer;var ImageInfo:TPtrShape;
  250. MouHandle:word):word;
  251. external 'EMXWRAP' index 302;
  252. {external 'MOUCALLS' index 2;}
  253. function MouGetPtrShape(ImageBuf:pointer;var ImageInfo:TPtrShape;
  254. MouHandle:word):word;
  255. external 'EMXWRAP' index 301;
  256. {external 'MOUCALLS' index 1;}
  257. function MouGetDevStatus(var Status:word;MouHandle:word):word;
  258. external 'EMXWRAP' index 322;
  259. {external 'MOUCALLS' index 22;}
  260. function MouGetNumButtons(var ButtonCount:word;MouHandle:word):word;
  261. external 'EMXWRAP' index 308;
  262. {external 'MOUCALLS' index 8;}
  263. function MouGetNumMickeys(var MickeyCnt:word;MouHandle:word):word;
  264. external 'EMXWRAP' index 303;
  265. {external 'MOUCALLS' index 3;}
  266. function MouReadEventQue(var Event:TMouEventInfo;var WaitFlag:word;
  267. MouHandle:word):word;
  268. external 'EMXWRAP' index 320;
  269. {external 'MOUCALLS' index 20;}
  270. function MouGetNumQueEl(var MouseQInfo:TMouQueInfo;MouHandle:word):word;
  271. external 'EMXWRAP' index 313;
  272. {external 'MOUCALLS' index 13;}
  273. function MouGetEventMask(var EventMask:word;MouHandle:word):word;
  274. external 'EMXWRAP' index 315;
  275. {external 'MOUCALLS' index 15;}
  276. function MouSetEventMask(var EventMask:word;MouHandle:word):word;
  277. external 'EMXWRAP' index 316;
  278. {external 'MOUCALLS' index 16;}
  279. function MouGetScaleFact(var Scale:TScaleFact;MouHandle:word):word;
  280. external 'EMXWRAP' index 306;
  281. {external 'MOUCALLS' index 6;}
  282. function MouSetScaleFact(var Scale:TScaleFact;MouHandle:word):word;
  283. external 'EMXWRAP' index 311;
  284. {external 'MOUCALLS' index 11;}
  285. function MouOpen(DriverName:PChar;var MouHandle:word):word;
  286. external 'EMXWRAP' index 317;
  287. {external 'MOUCALLS' index 17;}
  288. function MouOpen(DriverName:string;var MouHandle:word):word;
  289. var B:byte;
  290. begin
  291. B:=byte(DriverName[0]);
  292. if B=0 then MouOpen:=MouOpen(nil,MouHandle) else
  293. begin
  294. if B<>255 then
  295. begin
  296. DriverName[Succ(B)]:=#0;
  297. MouOpen:=MouOpen(@DriverName[1],MouHandle);
  298. end else
  299. begin
  300. Move(DriverName[1],DriverName[0],B);
  301. DriverName[B]:=#0;
  302. MouOpen:=MouOpen(@DriverName,MouHandle);
  303. end;
  304. end;
  305. end;
  306. function MouClose(MouHandle:word):word;
  307. external 'EMXWRAP' index 309;
  308. {external 'MOUCALLS' index 9;}
  309. function MouRemovePtr(var ProtectArea:TNoPtrRect;MouHandle:word):word;
  310. external 'EMXWRAP' index 318;
  311. {external 'MOUCALLS' index 18;}
  312. function MouDrawPtr(MouHandle:word):word;
  313. external 'EMXWRAP' index 326;
  314. {external 'MOUCALLS' index 26;}
  315. function MouSetDevStatus(var Status:word;MouHandle:word):word;
  316. external 'EMXWRAP' index 326;
  317. {external 'MOUCALLS' index 26;}
  318. function MouInitReal(DriverName:PChar):word;
  319. external 'EMXWRAP' index 327;
  320. {external 'MOUCALLS' index 27;}
  321. function MouInitReal(DriverName:string):word;
  322. var B:byte;
  323. begin
  324. B:=byte(DriverName[0]);
  325. if B=0 then MouInitReal:=MouInitReal(nil) else
  326. begin
  327. if B<>255 then
  328. begin
  329. DriverName[Succ(B)]:=#0;
  330. MouInitReal:=MouInitReal(@DriverName[1]);
  331. end else
  332. begin
  333. Move(DriverName[1],DriverName[0],B);
  334. DriverName[B]:=#0;
  335. MouInitReal:=MouInitReal(@DriverName);
  336. end;
  337. end;
  338. end;
  339. function MouSynch(WaitFlag:word):word;
  340. external 'EMXWRAP' index 323;
  341. {external 'MOUCALLS' index 23;}
  342. function MouGetThreshold(var MouThreshold:TThreshold;MouHandle:word):word;
  343. external 'EMXWRAP' index 329;
  344. {external 'MOUCALLS' index 29;}
  345. function MouSetThreshold(var MouThreshold:TThreshold;MouHandle:word):word;
  346. external 'EMXWRAP' index 330;
  347. {external 'MOUCALLS' index 30;}
  348. (*
  349. following two functions are undocumented and not present within C header files:
  350. function MouGetHotKey(var ButtonBits:word;MouHandle:word):word;
  351. external 'MOUCALLS' index 4;
  352. function MouSetHotKey(var ButtonBits:word;MouHandle:word):word;
  353. external 'MOUCALLS' index 10;
  354. *)
  355. end.