home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / CURSOR.CPP < prev    next >
C/C++ Source or Header  |  1993-11-13  |  2KB  |  114 lines

  1. // ------------ cursor.cpp
  2. //
  3. // modified for OS/2 operation - jw13nov93
  4.  
  5. #include <dos.h>
  6. #include "cursor.h"
  7. #include "desktop.h"
  8.  
  9. Cursor::Cursor()
  10.     {
  11.     VioGetCurType(&ci, 0);
  12.     cs = 0;
  13.     Save();
  14.     }
  15.  
  16. Cursor::~Cursor()
  17.     {
  18.     Restore();
  19.     }
  20.  
  21.  
  22. // ------ get cursor shape and position
  23. void Cursor::GetCursor(){};
  24.  
  25.  
  26. // -------- get the current cursor position
  27. void Cursor::GetPosition(int &x, int &y)
  28.     {
  29.     USHORT    sx, sy;
  30.  
  31.     VioGetCurPos(&sy, &sx, 0);
  32.     x = sx;
  33.     y = sy;
  34.     }
  35.  
  36. // ------ position the cursor
  37.  
  38. void Cursor::SetPosition(int x, int y)
  39.     {
  40.     VioSetCurPos((USHORT)y, (USHORT)x, 0);
  41.     }
  42.  
  43.  
  44. // ------ save the current cursor configuration
  45. void Cursor::Save()
  46.     {
  47.     USHORT x, y;
  48.  
  49.     if (cs < MAXSAVES)    
  50.         {
  51.         VioGetCurPos(&y, &x, 0);
  52.         cursorpos[cs]    = (x<<8) | y;
  53.  
  54.         VioGetCurType(&ci, 0);
  55.         cursorshape[cs] = (ci.yStart << 8) | ci.cEnd;
  56.         cs++;
  57.         }
  58.     }
  59.  
  60. // ---- restore the saved cursor configuration
  61. void Cursor::Restore()
  62.     {
  63.     USHORT row = (USHORT)(cursorpos[cs] & 0xff);
  64.     USHORT col = (USHORT)((cursorpos[cs] >> 8) & 0xff);
  65.  
  66.     if (cs)    
  67.         {
  68.         --cs;
  69.         VioSetCurPos(row, col, 0);
  70.         SetType(cursorshape[cs]);
  71.         }
  72.     }
  73.  
  74. /* ---- set the cursor type ---- */
  75. void Cursor::SetType(unsigned t)
  76.     {
  77.     ci.yStart = (USHORT)((t >> 8) & 0xff);
  78.     ci.cEnd   = (USHORT)(t & 0xff);
  79.     VioSetCurType(&ci, 0);
  80.     }
  81.  
  82.  
  83. /* ----- swap the cursor stack ------- */
  84. void Cursor::SwapStack()
  85.     {
  86.     if (cs > 1)    
  87.         {
  88.         swap(cursorpos[cs-2], cursorpos[cs-1]);
  89.         swap(cursorshape[cs-2], cursorshape[cs-1]);
  90.         }
  91.     }
  92.  
  93.  
  94. /* ------ hide the cursor ------ */
  95. void Cursor::Hide()
  96.     {
  97.     USHORT t;
  98.  
  99.     t = ci.attr;
  100.     ci.attr = 0xffff;
  101.     VioSetCurType(&ci, 0);
  102.     ci.attr = t;
  103.     }
  104.  
  105.  
  106. /* ------ show the cursor ------ */
  107. void Cursor::Show()
  108.     {
  109.     VioSetCurType(&ci, 0);
  110.     }
  111.  
  112.  
  113.  
  114.