/**
*
*  BMOUSE.H   Header file for Turbo C TOOLS Mouse Functions
*
*  Version 6.00 (C) Copyright Blaise Computing Inc. 1988
*
**/

#ifndef DEF_BMOUSE		      /* Prevent second reading of    */
#define DEF_BMOUSE 1		      /* these definitions.	      */

#include <bkeybrd.h>	      /* For KEYSTATUS. 		      */
#include <bintrupt.h>	      /* For ISRCTRL.			      */

    /* General symbols. 					      */

#define MO_LEFT        1      /* Left	mouse button.		      */
#define MO_RIGHT       2      /* Right	mouse button.		      */
#define MO_MIDDLE      4      /* Center mouse button, if any.	      */
			      /* (MO_LEFT, MO_RIGHT and MO_MIDDLE     */
			      /*  must not conflict with MO_PRESS and */
			      /*  MO_RELEASE.)			      */
#define MO_ALLBUTTONS  (MO_LEFT | MO_RIGHT | MO_MIDDLE)

#define MO_INSTALL	0
#define MO_REMOVE	1

    /* Error codes.						      */

#define MO_OK		  0   /* Successful operation.		      */
#define MO_NOLINK	(-3)  /* Mouse functions not linked.	      */
#define MO_ABSENT	(-2)  /* Mouse driver not installed.	      */
#define MO_BAD_OPT	  1   /* Unknown option.		      */
#define MO_RANGE	  2   /* Value(s) out of range. 	      */
#define MO_BAD_COMBO	  3   /* Bad combination of options.	      */
#define MO_ALREADY	  4   /* Can't do operation twice.            */
#define MO_NOT_INSTALLED  5   /* MOCATCH not installed. 	      */

    /* Symbol for b_mouse.					      */

#define MO_UNKNOWN   (-1)     /* Mouse state not yet tested.	      */

    /* Symbols for MORANGE.					      */

#define MO_HORIZ       0      /* Horizontal.			      */
#define MO_VERT        3      /* Vertical.			      */

    /* Symbols for MOHIDE.					      */

#define MO_HIDE        1
#define MO_SHOW        0

    /* Symbols for MOLITPEN.					      */

#define MO_PEN	       1      /* Emulate light pen.  (Default	      */
			      /*  condition when mouse is reset.)     */
#define MO_NO_PEN      0      /* Don't emulate light pen.             */

    /* Symbols for MOBUTTON and MOCHECK.			      */

#define MO_PRESS       8      /* Button events (must not conflict     */
#define MO_RELEASE  0x10      /*  with MO_LEFT, MO_RIGHT, and	      */
			      /*  MO_MIDDLE).			      */

#define MO_CLEAR       0x0010
#define MO_NOCLEAR     0x0020

#define MO_CLICK      0x0040
#define MO_DCLICK     0x0080

#define MO_HOLD       0x0800

#define MO_RSHIFT     0x1000
#define MO_LSHIFT     0x2000
#define MO_CSHIFT     0x4000
#define MO_ASHIFT     0x8000

    /* Mouse event masks for MOHANDLR.				      */

#define MO_MOVE       0x0001	      /* Mouse moved.		      */
#define MO_L_PRESS    0x0002	      /* Left	button depressed.     */
#define MO_L_RELEASE  0x0004	      /* Left	button released.      */
#define MO_R_PRESS    0x0008	      /* Right	button depressed.     */
#define MO_R_RELEASE  0x0010	      /* Right	button released.      */
#define MO_M_PRESS    0x0020	      /* Middle button depressed.     */
#define MO_M_RELEASE  0x0040	      /* Middle button released.      */

    /* Internal symbols.					      */

#define MO_HIST_LIMIT	5     /* Number of recent events recorded.    */
			      /* Need at least 5 for double clicks.   */
			      /* Must match MOCATCH.ASM.	      */

			      /* Mouse events handled by MOCATCH.     */
#define MOCATCH_MASK   (MO_L_PRESS | MO_L_RELEASE		       \
		      | MO_R_PRESS | MO_R_RELEASE		       \
		      | MO_M_PRESS | MO_M_RELEASE)

    /* Data types.						      */

typedef struct		      /* MO_EVENT:  Mouse event in history    */
{			      /*  array.  This must match MOCATCH.ASM */
			      /*				      */
    int       event;	      /* MO_PRESS or MO_RELEASE.	      */
    long      time;	      /* BIOS clock ticks since midnight.     */
    unsigned  c_vert,c_horiz; /* Mouse cursor location in pixels.     */
    int       vert,horiz;     /* Mouse location in mickeys.	      */
    KEYSTATUS kstat;	      /* Shift key status at time of event.   */
    int       relevant;       /* Bits to prevent rereading same event */
			      /*  (MO_CLICK, MO_DCLICK, MO_PRESS,     */
			      /*   MO_RELEASE). 		      */
} MO_EVENT;

			      /* PMOHANDLER:  Address of mouse	      */
			      /*   interrupt handler function.	      */
typedef void cdecl (*PMOHANDLER)(const ALLREG *);

    /* Global variables.					      */

extern int b_mouse;	      /* Mouse presence:  MO_UNKNOWN,	      */
			      /*   0 if absent, or number of buttons. */

extern long b_clicklimit;     /* Time limits for clicks and double    */
extern long b_dclicklimit;    /* clicks (measured in clock ticks).    */

			      /* History of recent mouse events       */
			      /*  maintained by MOCATCH.	      */
			      /*  First subscript is for each button  */
			      /*   (0 = left, 1 = right, 2 = middle); */
			      /*  second is for event number	      */
			      /*   (0 is most recent).		      */
extern volatile MO_EVENT b_mohist[3][MO_HIST_LIMIT];

extern void (far *b_mocatch)(void);   /* Pointer to MOCATCH if	      */
				      /*  installed, or 0 if not.     */
				      /*			      */
extern unsigned     b_momask;	      /* Current MOCATCH event mask   */
				      /*  (0 or MOCATCH_MASK).	      */
				      /*			      */
extern ISRCTRL far *b_modispat;       /* Address of dispatcher that   */
				      /*  invokes user interrupt      */
				      /*  handler, or 0 if no handler */
				      /*  installed.		      */
				      /*			      */
extern unsigned     b_mohanmask;      /* Call mask for user mouse     */
				      /*  interrupt handler (0 if     */
				      /*  none).		      */

    /* Routines implemented as macros.				      */

#define moreset()		      /* Reset mouse driver.	      */ \
      ((b_mouse=MO_UNKNOWN),moequip())

    /* Function declarations.					      */

			      /* General mouse setup.		      */

int cdecl moequip(void);	      /* Mouse driver presence test.  */
				      /*			      */
int cdecl mogate(const DOSREG *,      /* General gateway.	      */
		       DOSREG *);     /*			      */
				      /*			      */
int far cdecl mopreclk(int);	      /* Install MOCATCH (so MOCHECK  */
				      /*  can work).		      */
				      /*			      */
int cdecl mohandlr(PMOHANDLER,	      /* Install user's mouse         */
    unsigned,char *,int,int);	      /*  interrupt handler.	      */
				      /*			      */
int cdecl mospeed(unsigned,unsigned); /* Set mouse sensitivity (speed */
				      /*  of cursor motion).	      */
				      /*			      */
int cdecl mojump(unsigned);	      /* Set speed-jump threshold.    */
				      /*			      */
int cdecl molitpen(int);	      /* Enable or disable light pen  */
				      /*  emulation.		      */

			      /* Mouse cursor appearance.	      */

int far cdecl mohide(int);	      /* Hide or show mouse cursor.   */
				      /*			      */
int far cdecl moavoid(unsigned,       /* Hide mouse cursor when in    */
	 unsigned,unsigned,unsigned); /*  specified region.	      */
				      /*			      */
int cdecl mosoft(unsigned,unsigned);  /* Set software text cursor.    */
				      /*			      */
int cdecl mohard(int,int);	      /* Set hardware text cursor.    */
				      /*			      */
int cdecl mograph(const unsigned *,   /* Set graphics-mode cursor.    */
    int,int);			      /*			      */

			      /* Controlling mouse cursor movement.   */

int cdecl mocurmov(unsigned,unsigned);/* Move mouse cursor.	      */
				      /*			      */
int cdecl morange(int,unsigned,       /* Set range limit (horizontal  */
		      unsigned);      /*  or vertical). 	      */
				      /*			      */

			      /* Querying mouse status. 	      */

int cdecl mostat(unsigned *,	      /* Report mouse position and    */
	     unsigned *,unsigned *);  /*  button status.	      */
				      /*			      */
int cdecl mobutton(int,unsigned *,    /* Report mouse button press/   */
   unsigned *,unsigned *,unsigned *); /*  release history.	      */
				      /*			      */
int cdecl mogetmov(int *,int *);      /* Report relative physical     */
				      /*  mouse motion since last     */
				      /*  inquiry.		      */
				      /*			      */
int far cdecl mocheck(unsigned long,  /* Check for recent mouse event.*/
  unsigned long,int,		      /*			      */
  unsigned long *,unsigned *,	      /*			      */
  unsigned *);			      /*			      */

    /* Internal functions.					      */

void far mocatch(void); 	      /* Record mouse interrupts.     */
				      /*			      */
int cdecl moinst(void (far *)(void),  /* Install interrupt handler    */
		 unsigned);	      /*  unconditionally.	      */

#endif				      /* Ends "#ifndef DEF_BMOUSE"    */
