home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / TVSRC.ZIP / TMOUSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.1 KB  |  159 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tmouse.cpp                                */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TMouse and THWMouse member functions      */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TEvent
  19. #include <tv.h>
  20.  
  21. #if !defined( __DOS_H )
  22. #include <Dos.h>
  23. #endif  // __DOS_H
  24.  
  25. uchar near THWMouse::buttonCount = 0;
  26. Boolean near THWMouse::handlerInstalled = False;
  27.  
  28. THWMouse::THWMouse()
  29. {
  30.     resume();
  31. }
  32.  
  33. void THWMouse::resume()
  34. {
  35.     if( getvect( 0x33 ) == 0 )
  36.         return;
  37.  
  38.     _AX = 0;
  39.     geninterrupt( 0x33 );
  40.  
  41.     if( _AX == 0 )
  42.         return;
  43.     buttonCount = _BL;
  44.  
  45.     _AX = 4;
  46.     _CX = 0;
  47.     _DX = 0;
  48.     geninterrupt( 0x33 );
  49. }
  50.  
  51. THWMouse::~THWMouse()
  52. {
  53.     suspend();
  54. }
  55.  
  56. void THWMouse::suspend()
  57. {
  58.     if( present() == False )
  59.         return;
  60.     hide();
  61.     if( handlerInstalled == True )
  62.         {
  63.         registerHandler( 0, 0 );
  64.         handlerInstalled = False;
  65.         }
  66.     buttonCount = 0;
  67. }
  68.  
  69. #pragma warn -asc
  70.  
  71. void THWMouse::show()
  72. {
  73.     asm push ax;
  74.     asm push es;
  75.        
  76.     if( present() )
  77.         {
  78.         _AX = 1;
  79.         geninterrupt( 0x33 );
  80.         }
  81.  
  82.     asm pop es;
  83.     asm pop ax;
  84. }
  85.  
  86. void THWMouse::hide()
  87. {
  88.     asm push ax;
  89.     asm push es;
  90.        
  91.     if( buttonCount != 0 )
  92.         {
  93.         _AX = 2;
  94.         geninterrupt( 0x33 );
  95.         }
  96.  
  97.     asm pop es;
  98.     asm pop ax;
  99. }
  100.  
  101. #pragma warn .asc
  102.  
  103. void THWMouse::setRange( ushort rx, ushort ry )
  104. {
  105.     if( buttonCount != 0 )
  106.         {
  107.         _DX = rx;
  108.         _DX <<= 3;
  109.         _CX = 0;
  110.         _AX = 7;
  111.         geninterrupt( 0x33 );
  112.  
  113.         _DX = ry;
  114.         _DX <<= 3;
  115.         _CX = 0;
  116.         _AX = 8;
  117.         geninterrupt( 0x33 );
  118.         }
  119. }
  120.  
  121. void THWMouse::getEvent( MouseEventType& me )
  122. {
  123.     _AX = 3;
  124.     geninterrupt( 0x33 );
  125.     _AL = _BL;
  126.     me.buttons = _AL;
  127.     me.where.x = _CX >> 3;
  128.     me.where.y = _DX >> 3;
  129.     me.doubleClick = False;
  130. }
  131.  
  132. void THWMouse::registerHandler( unsigned mask, void (far *func)() )
  133. {
  134.     if( !present() )
  135.         return;
  136.  
  137. #if defined( ProtectVersion )
  138.     _AX = 20;
  139. #else
  140.     _AX = 12;
  141. #endif
  142.     _CX = mask;
  143.     _DX = FP_OFF( func );
  144.     _ES = FP_SEG( func );
  145.     geninterrupt( 0x33 );
  146.     handlerInstalled = True;
  147. }
  148.  
  149. TMouse::TMouse()
  150. {
  151.     show();
  152. }
  153.  
  154. TMouse::~TMouse()
  155. {
  156.     hide();
  157. }
  158.  
  159.