home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CTECHAPP.ZIP / WINDOWS.ZIP / WDW_MISC.CPP < prev    next >
C/C++ Source or Header  |  1990-03-26  |  3KB  |  175 lines

  1. //  Module:     Wdw_Misc  (Window Class)
  2. //  Version:    2.11
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    IBM-PC MS-DOS
  6. //
  7. //  Purpose:    Miscellaneous methods
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "Screen.hpp"
  12. #include "Str.hpp"
  13. #include "Window.hpp"
  14.  
  15. extern "C"
  16.     {
  17.     #include "string.h"
  18.     #include "stddef.h"
  19.     #include "dos.h"
  20.     }
  21.  
  22. // change position
  23. void Window::Move(unsigned int line, unsigned int col)
  24.     {
  25.     if ((line > MaxLength) || (col > MaxWidth))
  26.         return;
  27.  
  28.     // set new window position
  29.     HomeLine = line;
  30.     HomeCol  = col;
  31.  
  32.     // redisplay all windows
  33.     Restack();
  34.     }
  35.  
  36. // make this the top window
  37. void Window::Hoist()
  38.     {
  39.     // delete window from list
  40.     WdwList.Delete(this);
  41.  
  42.     // add it to the list (making it the top window)!
  43.     WdwList.Store(this);
  44.  
  45.     TopWindow = this;
  46.  
  47.     // redisplay all windows
  48.     Restack();
  49.     }
  50.  
  51. // conceal this window
  52. void Window::Conceal()
  53.     {
  54.     Concealed = 0;
  55.  
  56.     Restack();
  57.     }
  58.  
  59. // reveal this window
  60. void Window::Reveal()
  61.     {
  62.     Concealed = 0;
  63.  
  64.     Restack();
  65.     }
  66.  
  67. // turn wrap on
  68. void Window::WrapOn()
  69.     {
  70.     Wrapped = 1;
  71.     }
  72.  
  73. // turn wrap off
  74. void Window::WrapOff()
  75.     {
  76.     Wrapped = 0;
  77.     }
  78.  
  79. // set the heading
  80. void Window::SetHead(String & heading)
  81.     {
  82.     if (Border == BT_NONE)
  83.         return;
  84.  
  85.     unsigned int c, hpos;
  86.     char bordchar;
  87.  
  88.     // pick border characater
  89.     if (Border == BT_SINGLE)
  90.         bordchar = 0xC4;
  91.     else
  92.         bordchar = 0xCD;
  93.  
  94.     Header = heading;
  95.  
  96.     // no header, fill in border
  97.     if (Header.Length() == 0)
  98.         {
  99.         for (c = 0; c < Width; ++c)
  100.             Display(-1,c,BorderColor,bordchar);
  101.  
  102.         return;
  103.         }
  104.  
  105.     hpos = 0;
  106.  
  107.     // display header and border fragment
  108.     for (c = 0; c < Width; ++c)
  109.         if (hpos < Header.Length())
  110.             {
  111.             Display(-1,c,BorderColor,Header[hpos]);
  112.             ++hpos;
  113.             }
  114.         else
  115.             Display(-1,c,BorderColor,bordchar);
  116.     }
  117.  
  118. // set the cursor position
  119. void Window::SetCursor(unsigned int line, unsigned int col)
  120.     {
  121.     // cursor can only be positioned within top window
  122.     if ((line > Length) || (col > Width) || (this != TopWindow))
  123.         return;
  124.  
  125.     unsigned char newl = line + HomeLine;
  126.     unsigned char newc = col  + HomeCol;
  127.  
  128.     if ((newl > MaxLength) || (newc > MaxWidth))
  129.         return;
  130.  
  131.     CrsLine = line;
  132.     CrsCol  = col;
  133.  
  134.     // physically set cursor position
  135.     Screen::CursorSetPos(newl, newc);
  136.     }
  137.  
  138. // get the cursor position
  139. void Window::GetCursor(unsigned int & line, unsigned int & col)
  140.     {
  141.     line = CrsLine;
  142.     col  = CrsCol;
  143.     }
  144.  
  145. // clear the entire window
  146. void Window::ClearAll()
  147.     {
  148.     unsigned int pos = 0;
  149.  
  150.     for (unsigned char l = 0; l < Length; ++l)
  151.         {
  152.         for (unsigned char c = 0; c < Width; ++c)
  153.             {
  154.             BufferSW[pos].Symbol    = ' ';
  155.             BufferSW[pos].Attribute = InsideColor;
  156.  
  157.             ++pos;
  158.             }
  159.         }
  160.     }
  161.  
  162. // clear one line of the window
  163. void Window::ClearLine(unsigned int line, unsigned int col)
  164.     {
  165.     unsigned int pos;
  166.  
  167.     for (unsigned char c = col; c < Width; ++c)
  168.         {
  169.         pos = line * Width + c;
  170.  
  171.         BufferSW[pos].Symbol    = ' ';
  172.         BufferSW[pos].Attribute = InsideColor;
  173.         }
  174.     }
  175.