MOUSE.DEF 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. FOREIGN DEFINITION MODULE Mouse;
  2. (*
  3. Mouse Driver Interface for GPM Modula-2
  4. Michael McCarthy : Semester2, 1991
  5. The functions implemented in this module provide a
  6. GPM Modula-2 interface for Microsoft compatible Mouse Drivers.
  7. 13-Jun-92 jrh Dot cursor restored
  8. *)
  9. IMPORT IMPLEMENTATION FROM "Mouse.obj";
  10. FROM SYSTEM IMPORT BYTE,ADDRESS;
  11. FROM Types IMPORT SHORTCARD;
  12. TYPE
  13. Button = (LeftButton,
  14. RightButton, (* not available on some mice *)
  15. MiddleButton (* not available on some mice *)
  16. );
  17. ButtonSet = SET OF Button;
  18. GraphicCursor = RECORD
  19. screenMask,
  20. cursorMask: ARRAY [0..15] OF SHORTCARD;
  21. hotX, hotY: [-16..16];
  22. END;
  23. (* The screenMask is first ANDed into the display,
  24. then the cursorMask is XORed into the display.
  25. The hot spot coordinates are relative to the
  26. upper-left corner of the cursor image, and define
  27. where the cursor actually 'points to'.
  28. *)
  29. VAR
  30. (* Some common mouse cursors for graphics modes. Read only !
  31. Pass as parameter in SetGraphicCursor. *)
  32. dot,stdArrow,upArrow,checkMark,hand,
  33. crossX,crossHair,hourGlass: GraphicCursor;
  34. PROCEDURE InitMouse() : INTEGER;
  35. (*
  36. Initializes mouse and resets all driver variables.
  37. MUST BE CALLED BEFORE USING ANY OF THE PROCEDURES, OR ACCESSING
  38. ANY OF THE OBJECTS IN THIS MODULE !!!
  39. Returns the number of mouse buttons if the mouse driver is loaded
  40. (some drivers also check for the existence of a mouse), or 0
  41. otherwise.
  42. The driver variables are reset as follows :
  43. Cursor position : screen centre
  44. Cursor visibility : hidden
  45. graphics cursor : arrow
  46. text cursor : reverse video
  47. event handler disabled
  48. light pen emulation mode enabled
  49. horizontal mickey/pixel ratio : 8 to 8
  50. vertical mickey/pixel ratio : 16 to 8
  51. horiz range : 0 .. maxcols-1
  52. vert range : 0 .. maxrows-1
  53. CRT page no. 0
  54. *)
  55. PROCEDURE ResetMouse();
  56. (* Should be called prior to exiting any program that has
  57. used SetMEventHandler or SwapMEventHandler *)
  58. PROCEDURE ShowCursor();
  59. (* Increment the current cursor visibility level. Cursor only actually
  60. becomes visible when visibility level is non-negative *)
  61. PROCEDURE HideCursor();
  62. (* Decrement visibility level *)
  63. PROCEDURE GetPosBut(VAR buttonStatus: ButtonSet;
  64. VAR horizontal, vertical:INTEGER);
  65. (* Return the state of the mouse buttons and the screen coordinates of
  66. the mouse cursor *)
  67. PROCEDURE SetCursorPos(horizontal, vertical: INTEGER);
  68. (* Set the screen position of the mouse cursor *)
  69. PROCEDURE GetButPres(button: Button;
  70. VAR buttonStatus: ButtonSet;
  71. VAR buttonPressCount: CARDINAL;
  72. VAR horizontal, vertical: INTEGER);
  73. (* Get button press information for specified button. This includes
  74. - current status of button
  75. - number of times this button has been pressed since this function
  76. was last called
  77. - screen coordinates of mouse cursor last time this button was
  78. pressed
  79. *)
  80. PROCEDURE GetButRel(button: Button;
  81. VAR buttonStatus: ButtonSet;
  82. VAR buttonReleaseCount: CARDINAL;
  83. VAR horizontal ,vertical: INTEGER);
  84. (* Get button release information for specified button. This includes
  85. - current status of button
  86. - number of times this button has been released since this function
  87. was last called
  88. - screen coordinates of mouse cursor last time this button was
  89. released
  90. *)
  91. PROCEDURE SetHorizontalLimits(minPos, maxPos: INTEGER);
  92. (* Set minimum and maximum horizontal screen coordinates for the mouse
  93. cursor. All cursor movement will be restricted to the specified
  94. horizontal interval.
  95. *)
  96. PROCEDURE SetVerticalLimits(minPos, maxPos: INTEGER);
  97. (* Set minimum and maximum vertical screen coordinates for the mouse
  98. cursor. All cursor movement will be restricted to the specified
  99. vertical interval.
  100. *)
  101. PROCEDURE SetGraphicCursor(VAR cursor: GraphicCursor);
  102. (* Define the shape, colour and "centre" of the graphics cursor *)
  103. PROCEDURE SetTextCursor(selectedCursor,
  104. screenMaskORscanStart,
  105. cursorMaskORscanStop: CARDINAL);
  106. (* Inputs :
  107. selectedCursor <-- cursor select
  108. 0: Software text cursor
  109. 1: Hardware text cursor
  110. screenMaskORscanStart <-- screen mask value or
  111. scan line start
  112. cursorMaskORscanStop <-- cursor mask value or
  113. scan line stop
  114. For the software text cursor, the second two
  115. parameters specify the screen and cursor masks.
  116. The screen mask is first ANDed into the display,
  117. then the cursor mask is XORed into the display.
  118. For the hardware text cursor, the second two
  119. parameters contain the line numbers of the first
  120. and last scan line in the cursor to be shown on
  121. the screen.
  122. *)
  123. PROCEDURE ReadMotionCounters(VAR horizontal,
  124. vertical:INTEGER);
  125. (* Return the horizontal and vertical mickey count since the last call
  126. to this function. *)
  127. TYPE
  128. MEvent = (Motion,
  129. LeftDown,
  130. LeftUp,
  131. RightDown, (* not available on some mice *)
  132. RightUp, (* " " " " " *)
  133. MiddleDown, (* " " " " " *)
  134. MiddleUp (* " " " " " *)
  135. );
  136. MEventSet = SET OF MEvent;
  137. MEventHandler =
  138. PROCEDURE (SHORTCARD, (* MEventSet condition mask *)
  139. SHORTCARD, (* button state *)
  140. SHORTCARD, (* horizontal cursor pos *)
  141. SHORTCARD (* vertical cursor pos *)
  142. );
  143. PROCEDURE SetMEventHandler(mask: SHORTCARD (* MEventSet *);
  144. handler: MEventHandler);
  145. (* Emulates mouse system call 12.
  146. Establish conditions and handler for mouse events.
  147. After this, when an event occurs that is in the
  148. mask, the handler is called, passing the current event set,
  149. the current button status, and the cursor x and y coordinates
  150. as parameters.
  151. N.B. Use with caution !!
  152. (i) Do NOT use calls to Inout or Terminal, or other procedures that
  153. use DOS function calls, inside a mouse event handler. This is
  154. on account of the "non reentrant" nature of DOS.
  155. (ii) When it comes to file I/O, program defensively! I strongly
  156. recommend disabling any event handler prior to accessing disk
  157. files. This is because it is not always possible to know whether
  158. or not you are observing (i), especially during program
  159. development and debugging.
  160. If you need to perform file I/O, and you have a mouse event
  161. handler installed, play it safe and disable it first. This will
  162. cost at most two lines of code (one if you don't need to
  163. reenable it afterwards).
  164. (iii) The quickest way to disable a mouse event handler is to call
  165. InitMouse or ResetMouse. Another way is to set the event mask
  166. to 0, as in SetMEVentHandler(0, handler). Alternatively you
  167. can employ a "null handler and mask" and use SwapMEventHandler.
  168. *)
  169. PROCEDURE LightPenOn;
  170. (* Allow mouse to emulate a light pen. *)
  171. PROCEDURE LightPenOff;
  172. (* Turn light pen emulation off *)
  173. PROCEDURE SetMickeysPerPixel(horPix, verPix: CARDINAL);
  174. (* Set the ratio of mickeys per 8 screen pixels. The default ratios are
  175. 8 and 16 for horizontal and vertical movement respectively. This
  176. roughly translates to having to move the mouse 6.4 inches to traverse
  177. the screen horizontally, and 4 inches for a vertical traversal.
  178. Thus the (horizontal/vertical) sensitivity of the mouse is in
  179. inverse proportion to the mickey/pixel ratios.
  180. *)
  181. PROCEDURE ConditionalOff(left, top,
  182. right, bottom: INTEGER);
  183. (* Define a region of the screen for updating. If mouse cursor is in
  184. defined region it will be hidden. After calling this procedure,
  185. ShowCursor must be called to make cursor visible again.
  186. Used when saving and restoring regions of the screen.
  187. *)
  188. PROCEDURE SetSpeedThreshold(threshold: CARDINAL);
  189. (* Sets the threshold speed for doubling the cursor's motion on the
  190. screen. If the mouse moves faster than the threshold, the cursor
  191. speed goes into overdrive.
  192. *)
  193. PROCEDURE SwapMEventHandler(newmask: SHORTCARD (* MEventSet *);
  194. newhandler: MEventHandler;
  195. VAR oldmask : SHORTCARD;
  196. VAR oldhandler : MEventHandler);
  197. (* Emulates Microsoft Mouse Driver System Call 20.
  198. Establish new conditions and new handler for mouse events.
  199. After this, when an event occurs that is in the mask, the handler
  200. is called, passing the current event set, the current button status,
  201. and the cursor x and y coordinates as parameters.
  202. The address of the previous handler that was set VIA THIS MODULE will
  203. be returned along with the mask. This procedure WILL NOT WORK if a
  204. handler has been installed externally.
  205. For other restrictions, see the above comments on the use of
  206. SetMEventHandler.
  207. *)
  208. PROCEDURE GetStateSize() : INTEGER;
  209. (* Returns size in bytes of storage required to save the current Mouse
  210. driver state using SaveMouseState *)
  211. PROCEDURE SaveMouseState( buffer : ADDRESS) ;
  212. (* Assumes that buffer has been allocated enough space to store the
  213. current mouse driver state. The amount of space required is returned
  214. by GetStateSize *)
  215. PROCEDURE RestoreMouseState( buffer : ADDRESS) ;
  216. (* Restores the mouse driver to a previous state that has been saved via
  217. SaveMouseState. The buffer holds the required data. *)
  218. END Mouse.