⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mousec.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      mousec.c                            14.03.95       */
/*!
/  --------------------------------------------------------------
/  Copyright (C) 1993: Michael Braun
/                      Kaetinger Muehlenweg 103 A
/                      D-28816 Stuhr
/  --------------------------------------------------------------
/
/    handling of mouse events
/
/
/    Copyright Note:
/    This program was developed on the base of a chapter in
/    the following book. It has been carried on and adapted
/    to the special requirements of mbedit by M. Braun.
/
/       Title    : PC intern 3.0
/       Author   : Michael Tischer
/       Publisher: Data Becker, Duesseldorf
/       ISBN     : 3-89011-591-8
/       1st edition 1992
/
*/

/*== Include-Dateien einbinden =======================================*/

#include "config.h"
#include "global.h"
#include "standard.h"
#include "mousec.h"
#include "mbedit.h"
#include "perform.h"
#include "history.h"
#include "disp_hnd.h"
#include "mon_outp.h"
#include "mbed_sub.h"
#include "kb_input.h"


#define UEBERFLUESSIG 0  /* ist jetzt selbst ueberfluessig ! 09.03.95 */
#define RING_BUFFER   0


#if (!WITH_MOUSE)

/* dummy routine */
void MouEventHandler( int EvFlags, int ButState, int x, int y )
{
   EvFlags;     /* wg. compiler warning */
   ButState;
   x;
   y;

   return;
}  /* MouEventHandler */

#else

extern void far AssHand( void );            /* Extern-Deklaration des */
                                            /* Assembler-Handlers     */
/*== Typedefs ========================================================*/

typedef unsigned char BYTE;               /* wir basteln uns ein Byte */
typedef unsigned long PTRVIEW;               /* Maske f乺 Maus-Cursor */
typedef struct {                      /* beschreibt einen Mausbereich */
                BYTE x1,             /* Koordinaten der oberen linken */
                     y1,             /* und unteren rechten Ecke des  */
                     x2,             /* spezifizierten Bereichs       */
                     y2;
               } BEREICH;
typedef void (far * MOUHAPTR)( void );   /* Pointer auf Event-Handler */

/*== Konstanten ======================================================*/


/*-- Event-Codes -----------------------------------------------------*/

#define EV_MOU_MOVE      1                             /* Maus bewegt */
#define EV_LEFT_PRESS    2            /* linker Mausknopf niedergedr. */
#define EV_LEFT_REL      4            /* linker Mausknopf losgelassen */
#define EV_RIGHT_PRESS   8           /* rechter Mausknopf niedergedr. */
#define EV_RIGHT_REL    16           /* rechter Mausknopf losgelassen */
#define EV_MOU_ALL      31                        /* alle Maus-Events */

#define KEIN_BEREICH 255           /* Maus-Cursor nicht in Bereich xy */

/*-- Makros ----------------------------------------------------------*/

#define MouGetCol()         (ev_col)        /* liefern Mausposition & */
#define MouGetRow()         (ev_row)        /* -bereich im Moment des */
#define MouGetBereich()     (ev_ber)        /* Event-Eintritts        */
#define MouAvail()          ( mavail )  /* liefert TRUE, wenn Maus v. */
#define MouGetAktCol()      ( moucol )       /* liefern jeweils aktu- */
#define MouGetAktRow()      ( mourow )       /* elle Mausposition und */
#define MouGetAktBer()      ( mouber )       /* aktuellen Mausbereich */
#define MouIsLeftPress()    ( mouevent & EV_LEFT_PRESS )
#define MouIsLeftRel()      ( mouevent & EV_LEFT_REL )
#define MouIsRightPress()   ( mouevent & EV_RIGHT_PRESS )
#define MouIsRightRel()     ( mouevent & EV_RIGHT_REL )
#define MouSetMoveAreaAll() MouSetMoveArea( 0, 0, (BYTE) (tcol-1), \
                                                  (BYTE) (tline-1), 0 );

#define ELVEK(x) ( sizeof(x) / sizeof(x[0]) ) /* Anzahl Elemente in X */

/*-- Makros zur Erstellung der Bit-Maske, die das Erscheinungsbild ---*/
/*-- des Maus-Cursors definiert.                                   ---*/
/*-- Der Aufruf von MouPtrMask lautet beispielsweise:              ---*/
/*--   MouPtrMask( PTRDIFCHAR( 'x' ), PTRINVCOL )                  ---*/
/*-- um den Maus-Cursor als ein kleines X darzustellen, das die    ---*/
/*-- invertierte Farbe des Zeichens tr刧t, das von ihm 乥erdeckt   ---*/
/*-- wird.                                                         ---*/

#define MouPtrMask( z, f )\
  ( (( (PTRVIEW) f) >> 8 << 24) + ((( PTRVIEW) z) >> 8 << 16) +\
    (((f) & 255) << 8) + ((z) & 255) )

#define PTRSAMECHAR   ( 0x00ff )        /* gleiches Zeichen           */
#define PTRDIFCHAR(z) ( (z) << 8 )      /* anderes Zeichen            */
#define PTRSAMECOL    ( 0x00ff )        /* gleiche Farbe              */
#define PTRINVCOL     ( 0x7777 )        /* Farbe invertiert           */
#define PTRSAMECOLB   ( 0x807f )        /* gleiche Farbe blinkend     */
#define PTRINVCOLB    ( 0xF777 )        /* invertierte Farbe blinkend */
#define PTRDIFCOL(f)  ( (f) << 8 )      /* andere Farbe               */
#define PTRDIFCOLB(f) (((f)|0x80) << 8) /* andere Farbe blinkend      */

#define MOUINT(rin, rout) int86(0x33, &rin, &rout)
#define MOUINTX(rin, rout, sr) int86x(0x33, &rin, &rout, &sr)

/*-- Makros zur Umrechnung zwischen Maus-Koordinaten in Bezug auf den */
/*-- virtuellen Maus-Bildschirm und dem Textbildschirm                */

#define SPALTEN_94  0  /* 1 = 94-Spalten-Modus, 0 = andere Modi (80) */

#if SPALTEN_94

static const int size_tab [] = {
                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8,  /*  0 -  9 */
                    8, 8, 8, 8, 8, 8, 8, 8, 8, 8,  /* 10 - 19 */
                    8, 8, 8, 8, 8, 8, 8, 8, 7, 8,  /* 20 - 29 */
                 /*                ^25      ^28               */
                    8, 8, 8, 8, 7, 8, 8, 8, 8, 8,  /* 30 - 39 */
                 /* ^30         ^34                           */
                    8, 8, 8, 4, 8, 8, 8, 8, 8, 8,  /* 40 - 49 */
                 /*          ^43                              */
                    4, 8, 8, 8, 8, 8, 8, 8, 8, 8,  /* 50 - 59 */
                 /* ^50                                       */
                    4, 8, 8, 8 };                  /* 60 - 63 */
                 /* ^60                                       */

#if 0
#define XTOCOL(x) ( ((x) / ((COLUMNS == 94) ? 7 : 8)) )
#define YTOROW(y) ( ((y) / size_tab[ROWS & 0x3f]) )
#define COLTOX(c) ( ((c) * ((COLUMNS == 94) ? 7 : 8)) + 4 )
#define ROWTOY(r) ( ((r) * size_tab[ROWS & 0x3f])     + 3 )
#else
#define XTOCOL(x) ( ((x) / 8) )
#define YTOROW(y) ( ((y) / size_tab[ROWS & 0x3f]) )
#define COLTOX(c) ( ((c) * 8) + 4 )
#define ROWTOY(r) ( ((r) * size_tab[ROWS & 0x3f])     + 3 )
#endif

#else

#define XTOCOL(x) ( ((x) >> 3) )          /* Rundung ! */   /* X durch 8 */
#define YTOROW(y) ( ((y) >> 3) )                            /* Y durch 8 */
#define COLTOX(c) ( ((c) << 3) + 4)                         /* C mal 8 */
#define ROWTOY(r) ( ((r) << 3) + 4)                         /* R mal 8 */

#endif

/*== globale Variablen ===============================================*/

static BYTE tline,                              /* Anzahl Text-Zeilen */
            tcol,                              /* Anzahl Text-Spalten */
            mavail = FALSE;          /* ist TRUE, wenn Maus verf乬bar */

/*-- Maske f乺 den Standard-Maus-Cursor ------------------------------*/

static PTRVIEW stdptr = MouPtrMask( PTRSAMECHAR, PTRINVCOL );
static int  mouevent = EV_LEFT_REL + EV_RIGHT_REL;     /* Event-Maske */
static BYTE moucol,                   /* Mausspalte (Text-Bildschirm) */
            mourow;                   /* Mauszeile  (Text-Bildschirm) */

static byte center_col = (INIT_COLUMNS / 2);
static byte center_row = (INIT_ROWS / 2);
static byte old_win_row, old_win_col;
static int  event_count, disp_window_active;


/***********************************************************************
*  Funktion         : M o u D e f i n e P t r                          *
**--------------------------------------------------------------------**
*  Aufgabe          : Definiert die Cursor- und die Screen-Maks, die   *
*                     das Erscheinungsbild des Maus-Cursors bestimmen  *
*  Eingabe-Parameter: MASK = die beiden Bit-Masken, vereint zu einem   *
*                            32-Bit-Wert vom Typ UNSIGNED LONG         *
*  Return-Wert      : keiner                                           *
*  Info             : - Die h攈erwertigen 16-Bit von MASK repr剆en-    *
*                       tieren die Screen-Mask, die niederwertigen 16  *
*                       Bit die Cursor-Mask                            *
***********************************************************************/

#pragma check_stack(off)                  /* kein Stack-Checking hier */

void MouDefinePtr( PTRVIEW mask )
{
 static PTRVIEW altercursor = (PTRVIEW) 0;   /* letzter Wert f乺 MASK */
 union REGS regs;                /* Prozessorregs f乺 Interruptaufruf */

 if ( altercursor != mask )  /* Ver刵derung gegen乥er letztem Aufruf? */
  {                                                             /* Ja */
   regs.x.ax = 0x000a;          /* Fktnr. f乺 "Set text pointer type" */
   regs.x.bx = 0;                       /* Software-Cursor einstellen */
   regs.x.cx = (word) mask;                  /* Lo-Word ist AND-Maske */
   regs.x.dx = (word)(mask >> 16);           /* Hi-Word ist XOR-Maske */
   MOUINT(regs, regs);                       /* Maus-Treiber aufrufen */
   altercursor = mask;                       /* neue Bit-Maske merken */
  }
}

/***********************************************************************
*  Funktion         : M o u E v e n t H a n d l e r                    *
**--------------------------------------------------------------------**
*  Aufgabe          : Wird vom Maustreiber 乥er die Assembler-Routine  *
*                     AssHand aufgerufen, sobald ein Ereignis in Ver-  *
*                     bindung mit der Maus eingetreten ist.            *
*  Eingabe-Parameter: EvFlags  = Event-Maske des Ereignis              *
*                     ButState = Status der Mauskn攑fe                 *
*                     X, Y     = die aktuelle Position des Maus-Cur-   *
*                                sors, bereits umgerechnet in das Ko-  *
*                                ordinatensystem des Textbildschirms   *
*  Return-Wert      : keiner                                           *
*  Info             : - Diese Funktion ist nur zum Aufruf durch den    *
*                       Maus-Treiber bestimmt und darf nicht von einer *
*                       anderen Funktion aufgerufen werden.            *
***********************************************************************/

#define TEST_MOUSE 0

#if (TEST_MOUSE)
static int x_sav, y_sav;
#endif


void _loadds MouEventHandler( int EvFlags, int ButState, int x, int y )
{
#define LBITS ( EV_LEFT_PRESS | EV_LEFT_REL )
#define RBITS ( EV_RIGHT_PRESS | EV_RIGHT_REL )

static BYTE oldcol, oldrow;

 ButState;    /* wg. compiler warning */

#if (TEST_MOUSE)
 x_sav = x;
 y_sav = y;
#endif

 mouevent &= ~1;                                  /* Bit 0 ausblenden */
 mouevent |= ( EvFlags & 1 );           /* Bit 0 aus EvFlags kopieren */

 if ( EvFlags & LBITS )      /* linker Mausknopf losg. oder niederg.? */
 {                                                             /* Ja */
   mouevent &= ~LBITS;                /* bisherigen Status ausblenden */
   mouevent |= ( EvFlags & LBITS );        /* neuen Status einblenden */
 }

 if ( EvFlags & RBITS )     /* rechter Mausknopf losg. oder niederg.? */
 {                             /* Ja, Bits ausblenden und einblenden */
   mouevent &= ~RBITS;                /* bisherigen Status ausblenden */
   mouevent |= ( EvFlags & RBITS );        /* neuen Status einblenden */
 }

 moucol = (BYTE) XTOCOL(x);         /* Spalte in Textspalten umrechnen */
 mourow = (BYTE) YTOROW(y);           /* Zeile in Textzeilen umrechnen */


 if ((mourow != oldrow) ||   /* ignore minor movements */
     (moucol != oldcol) ||   /* in the pixel position. */
     (EvFlags & LBITS)  ||   /* handle every button event. */
     (EvFlags & RBITS))
    event_count++;

 oldrow = mourow;
 oldcol = moucol;

 return;
}  /* MouEventHandler */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -