home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / EDITORES / TSCREDD2.ZIP / SCRDISK4.EXE / SCRMOUSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-25  |  7.4 KB  |  409 lines

  1. /* Turbo ScrEdit Mouse interface Procedures */
  2.  
  3. extern char
  4.  S_MouseFirstTime;
  5.  
  6. extern unsigned char
  7.  S_MouseInstalled,
  8.  S_MouseVisable,
  9.  S_MsLeftPressed,
  10.  S_MsRightPressed,
  11.  S_MsMiddlePressed,
  12.  S_MsLeftReleased,
  13.  S_MsRightReleased,
  14.  S_MsMiddleReleased;
  15.  
  16. extern int
  17.  S_MsRowHold,
  18.  S_MsColHold,
  19.  S_MsRow,
  20.  S_MsCol,
  21.  S_Buttons;
  22.  
  23. extern unsigned
  24.  S_MsAx,
  25.  S_MsBx,
  26.  S_MsCx,
  27.  S_MsDx;
  28.  
  29. typedef struct{
  30.    char far *Ptr[256];
  31.    }S_Vectors;
  32. extern S_Vectors far *S_VectorRec;
  33.  
  34. typedef struct {
  35.     unsigned Ax, Bx, Cx, Dx;
  36.     char     MouseEvent;
  37.     char     MouseActive;
  38.     } S_EventRecord;
  39. extern S_EventRecord far *S_Ms;
  40.  
  41. static union  REGS  inreg, outreg;
  42. static struct SREGS seg;
  43. static char   S_PreviousEvent[9];
  44. void far S_SetMouseFlags (void)
  45. {
  46. S_Vectors far *S_VectorRec;
  47. S_EventRecord far *S_Ms2;
  48. unsigned int a,b,c,d;
  49.  
  50. a = _AX;
  51. b = _BX;
  52. c = _CX;
  53. d = _DX;
  54.  
  55. S_VectorRec = MK_FP(0x0000,0x0000);
  56. S_Ms2 = (S_EventRecord far *) S_VectorRec->Ptr[113];
  57.  
  58. S_Ms2->Ax = a;
  59. S_Ms2->Bx = b;
  60. S_Ms2->Cx = c;
  61. S_Ms2->Dx = d;
  62. if  (S_Ms2->MouseActive)
  63.     S_Ms2->MouseEvent = 1;
  64. }
  65.  
  66.  
  67. void S_ResetMouse(void)
  68. {
  69. inreg.x.ax = 0;
  70. int86(0x33,&inreg,&outreg);
  71. }
  72.  
  73.  
  74.  
  75. void S_InitMouse(void)
  76. {
  77. S_Ms        = farmalloc(sizeof(S_EventRecord));
  78. S_VectorRec = MK_FP(0x0000,0x0000);
  79. S_VectorRec->Ptr[113] = (char far *)S_Ms;
  80.  
  81. S_Ms->Ax          = 0;
  82. S_Ms->Bx          = 0;
  83. S_Ms->Cx          = 0;
  84. S_Ms->Dx          = 0;
  85. S_Ms->MouseActive = 0;
  86. S_Ms->MouseEvent  = 0;
  87. S_MouseFirstTime  = 0;
  88. S_Buttons         = 0;
  89. S_MsRow           = 0;
  90. S_MsRowHold       = 0;
  91. S_MsCol           = 0;
  92. S_MsColHold       = 0;
  93. S_MouseVisable    = 0;
  94. S_MsLeftPressed   = 0;
  95. S_MsRightPressed  = 0;
  96. S_MsMiddlePressed = 0;
  97. S_MsLeftReleased  = 0;
  98. S_MsRightReleased = 0;
  99. S_MsMiddleReleased= 0;
  100. strcpy(S_PreviousEvent,"00000000");
  101. inreg.x.ax = 0;
  102. int86(0x33,&inreg,&outreg);
  103.  
  104. if  (outreg.x.ax != 0)
  105.     {
  106.     S_MouseInstalled = 1;
  107.     S_Buttons        = outreg.x.bx;
  108.     inreg.x.ax       = 10;
  109.     inreg.x.bx       = 0;
  110.     inreg.x.cx       = 0x0000;
  111.     inreg.x.dx       = 0x0718;
  112.     int86(0x33,&inreg,&outreg);
  113.     S_MsRow          = 1;
  114.     S_MsCol          = 1;
  115.     }
  116. else
  117.     S_MouseInstalled = 0;
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. void S_SetMouseCursor(unsigned char Mask1L,
  126.                       unsigned char Mask1H,
  127.                       unsigned char Mask2L,
  128.                       unsigned char Mask2H)
  129. {
  130. typedef union
  131.     {
  132.     int word;
  133.     struct{
  134.        unsigned char H;
  135.        unsigned char L;
  136.        } byte;
  137.     }BuildReg;
  138. static BuildReg X;
  139.  
  140.  
  141. if  (S_MouseFirstTime) S_InitMouse();
  142. if  (S_MouseInstalled)
  143.     {
  144.     inreg.x.ax       = 10;
  145.     inreg.x.bx       = 0;
  146.     X.byte.H         = Mask1H;
  147.     X.byte.L         = Mask1L;
  148.     inreg.x.cx       = X.word;
  149.     X.byte.H         = Mask2H;
  150.     X.byte.L         = Mask2L;
  151.     inreg.x.dx       = X.word;
  152.     int86(0x33,&inreg,&outreg);
  153.     }
  154. }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. void S_ResetMouseFlags(void)
  162. {
  163. if  (S_MouseFirstTime) S_InitMouse();
  164. S_MsLeftPressed    = 0;
  165. S_MsRightPressed   = 0;
  166. S_MsMiddlePressed  = 0;
  167. S_MsLeftReleased   = 0;
  168. S_MsRightReleased  = 0;
  169. S_MsMiddleReleased = 0;
  170. }
  171.  
  172.  
  173. void S_SetMouseEvent(char *Bit)
  174. {
  175. char Work[9];
  176. int  testlen;
  177. if  (S_MouseFirstTime) S_InitMouse();
  178. if  (S_MouseInstalled)
  179.     {
  180.     strcpy(Work,"00000000");
  181.     if ((testlen = strlen(Bit))>8) testlen = 8;
  182.     memmove(&Work[0],Bit,testlen);
  183.     memcpy (&S_PreviousEvent[0],&Work[0],8);
  184.     inreg.x.cx = 0;
  185.  
  186.     if  (Work[0] == '1')
  187.         inreg.x.cx+=1;
  188.     if  (Work[1] == '1')
  189.         inreg.x.cx+=2;
  190.     if  (Work[2] == '1')
  191.         inreg.x.cx+=4;
  192.     if  (Work[3] == '1')
  193.         inreg.x.cx+=8;
  194.     if  (Work[4] == '1')
  195.         inreg.x.cx+=16;
  196.     if  (Work[5] == '1')
  197.         inreg.x.cx+=32;
  198.     if  (Work[6] == '1')
  199.         inreg.x.cx+=64;
  200.  
  201.     inreg.x.ax = 12;
  202.     inreg.x.dx = FP_OFF(S_SetMouseFlags);
  203.     seg.es     = FP_SEG(S_SetMouseFlags);
  204.     int86x(0x33,&inreg,&outreg,&seg);
  205.     }
  206. }
  207.  
  208.  
  209.  
  210.  
  211.  
  212. void S_AnalizeMouse(void)
  213. {
  214. char s_work[20];
  215. if  (S_MouseFirstTime) S_InitMouse();
  216. if  (S_Ms->MouseActive)
  217.     {
  218.     itoa(S_Ms->Ax,s_work,2);
  219.     if (S_Ms->Ax & 2)
  220.        S_MsLeftPressed    = 1;
  221.     if (S_Ms->Ax & 4)
  222.        S_MsLeftReleased   = 1;
  223.     if (S_Ms->Ax & 8)
  224.        S_MsRightPressed   = 1;
  225.     if (S_Ms->Ax & 16)
  226.        S_MsRightReleased  = 1;
  227.     if (S_Ms->Ax & 32)
  228.        S_MsMiddlePressed  = 1;
  229.     if (S_Ms->Ax & 64)
  230.        S_MsMiddleReleased = 1;
  231.  
  232.     if (S_Ms->Bx & 1)
  233.        S_MsLeftPressed    = 1;
  234.     if (S_Ms->Bx & 2)
  235.        S_MsRightPressed   = 1;
  236.     if (S_Ms->Bx & 4 )
  237.        S_MsMiddlePressed  = 1;
  238.  
  239.     S_MsCol = (S_Ms->Cx / 8) + 1;
  240.     S_MsRow = (S_Ms->Dx / 8) + 1;
  241.  
  242.     S_Ms->Ax = 0;
  243.     S_Ms->Cx = 0;
  244.     S_Ms->Dx = 0;
  245.  
  246.     S_Ms->MouseEvent = 0;
  247.     }
  248. }
  249.  
  250.  
  251.  
  252.  
  253.  
  254. void S_MoveMouse(void)
  255. {
  256. if  (S_MouseFirstTime) S_InitMouse();
  257. if  (S_MouseInstalled)
  258.     {
  259.     inreg.x.ax     = 4;
  260.     inreg.x.cx     = ((S_MsCol-1) * 8)+1;
  261.     inreg.x.dx     = ((S_MsRow-1) * 8)+1;
  262.     int86(0x33,&inreg,&outreg);
  263.     }
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. void S_SetMouseRange(int TopCol,
  272.                      int TopRow,
  273.                      int BotCol,
  274.                      int BotRow)
  275. {
  276. unsigned char Swap;
  277.  
  278. if  (S_MouseFirstTime) S_InitMouse();
  279. if  (S_MouseInstalled)
  280.     {
  281.     if (TopCol < 1)  TopCol = 1;
  282.     if (TopCol > 80) TopCol = 80;
  283.     if (TopRow < 1)  TopRow = 1;
  284.     if (TopRow > 25) TopRow = 25;
  285.  
  286.     if (BotCol < 1)  BotCol = 1;
  287.     if (BotCol > 80) BotCol = 80;
  288.     if (BotRow < 1)  BotRow = 1;
  289.     if (BotRow > 25) BotRow = 25;
  290.  
  291.     if (TopRow > BotRow)
  292.        {
  293.        Swap   = BotRow;
  294.        BotRow = TopRow;
  295.        TopRow = Swap;
  296.        }
  297.  
  298.     if (TopCol > BotCol)
  299.        {
  300.        Swap   = TopCol;
  301.        TopCol = BotCol;
  302.        BotCol = Swap;
  303.        }
  304.  
  305.     inreg.x.ax     = 7;
  306.     inreg.x.cx     = ((TopCol-1) * 8)+1;
  307.     inreg.x.dx     = ((BotCol-1) * 8)+1;
  308.     int86(0x33,&inreg,&outreg);
  309.  
  310.     inreg.x.ax     = 8;
  311.     inreg.x.cx     = ((TopRow-1) * 8)+1;
  312.     inreg.x.dx     = ((BotRow-1) * 8)+1;
  313.     int86(0x33,&inreg,&outreg);
  314.    }
  315. }
  316.  
  317.  
  318.  
  319.  
  320. void S_ShowMouse(void)
  321. {
  322. if  (S_MouseFirstTime) S_InitMouse();
  323. if  ((S_Ms->MouseActive)&&(!S_MouseVisable))
  324.     {
  325.     S_MouseVisable = 1;
  326.     S_MoveMouse();
  327.     }
  328. }
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. void S_HideMouse(void)
  337. {
  338. if  (S_MouseFirstTime) S_InitMouse();
  339. if  ((S_Ms->MouseActive)&&(S_MouseVisable)) S_MouseVisable = 0;
  340. }
  341.  
  342.  
  343.  
  344.  
  345.  
  346. void S_RemoveMouse(void)
  347. {
  348. if  (S_MouseFirstTime) S_InitMouse();
  349. if  (S_MouseInstalled)
  350.     {
  351.     if  ((S_Ms->MouseActive)&&(S_MouseVisable))
  352.         {
  353.         inreg.x.ax = 2;
  354.         int86(0x33,&inreg,&outreg);
  355.         }
  356.     }
  357. }
  358.  
  359.  
  360.  
  361.  
  362.  
  363. void S_RestoreMouse(void)
  364. {
  365. if  (S_MouseFirstTime) S_InitMouse();
  366. if  (S_MouseInstalled)
  367.     {
  368.     if  ((S_Ms->MouseActive)&&(S_MouseVisable))
  369.         {
  370.         inreg.x.ax = 1;
  371.         int86(0x33,&inreg,&outreg);
  372.         }
  373.     }
  374. }
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381. void S_ActivateMouse(void)
  382. {
  383. if  (S_MouseFirstTime) S_InitMouse();
  384. if  (S_MouseInstalled)
  385.     {
  386.     S_Ms->MouseActive = 1;
  387.     S_SetMouseEvent(S_PreviousEvent);
  388.     }
  389. }
  390.  
  391.  
  392.  
  393.  
  394.  
  395. void S_DisableMouse(void)
  396. {
  397. char S_HoldEvent[9];
  398. if  (S_MouseFirstTime) S_InitMouse();
  399. if  (S_Ms->MouseActive)
  400.     {
  401.     if  (S_MouseVisable) S_RemoveMouse();
  402.     strcpy(S_HoldEvent,S_PreviousEvent);
  403.     S_SetMouseEvent("00000000");
  404.     strcpy(S_PreviousEvent,S_HoldEvent);
  405.     S_Ms->MouseActive = 0;
  406.     }
  407. }
  408.  
  409.