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

  1. //  Module:     Wdw_Main  (Window Class main routines)
  2. //  Version:    2.11
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    IBM-PC MS-DOS
  6. //
  7. //  Purpose:    Static member initialization, utility functions and other.
  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. // internal prototype
  23. static void DefaultHandler();
  24.  
  25. // initialize static class members!
  26.  
  27. WorkList     Window::WdwList;
  28.  
  29. Window **    Window::ScrnOwner   = NULL;
  30. int          Window::Initialized = 0;
  31. Window *     Window::TopWindow   = NULL;
  32. unsigned int Window::MaxLength   = 0;
  33. unsigned int Window::MaxWidth    = 0;
  34.  
  35.  
  36. // actually display a character
  37. void Window::Display(int line, int col,
  38.                      unsigned char attr, char ch)
  39.     {
  40.     unsigned int rl = line + HomeLine;
  41.     unsigned int rc = col  + HomeCol;
  42.  
  43.     if ((rl >= MaxLength) || (rc >= MaxWidth))
  44.         return;
  45.  
  46.     if (this == ScrnOwner[rl * MaxWidth + rc])
  47.         Screen::PutChar(rl,rc,attr,ch);
  48.     }
  49.  
  50. // restack all windows
  51. void Window::Restack()
  52.     {
  53.     Screen::Clear();
  54.  
  55.     // clear screen ownership grid
  56.     for (unsigned int l = 0; l < MaxLength; ++l)
  57.         {
  58.         for (unsigned int c = 0; c < MaxWidth; ++c)
  59.             ScrnOwner[l * MaxWidth + c] = NULL;
  60.         }
  61.  
  62.  
  63.     // start with the "lowest" window in the list
  64.     WdwList.GoToTail();
  65.  
  66.     Window * curWdw = (Window *)WdwList.Examine();
  67.  
  68.     while (curWdw != NULL)
  69.         {
  70.         // plot what a Window owns
  71.         curWdw->PlotOwnership();
  72.  
  73.         // the paint it
  74.         curWdw->Paint();
  75.  
  76.         // get the next window
  77.         WdwList.GoPrev();
  78.  
  79.         curWdw = (Window *)WdwList.Examine();
  80.         }
  81.     }
  82.  
  83. // plot which screen locations belong to this window
  84. void Window::PlotOwnership()
  85.     {
  86.     unsigned int l, c;
  87.  
  88.     if (Concealed)
  89.         return;
  90.  
  91.     // mark locations own by display area of window
  92.     if ((Length == MaxLength) && (Width == MaxWidth))
  93.         {
  94.         for (l = 0; l < Length; ++l)
  95.             for (c = 0; c < Width; ++c)
  96.                 ScrnOwner[l * MaxWidth + c] = this;
  97.         }
  98.     else
  99.         {
  100.         for (l = HomeLine; l < HomeLine + Length; ++l)
  101.              for (c = HomeCol; c < HomeCol + Width; ++c)
  102.                  if ((l < MaxLength) && (c < MaxWidth))
  103.                      ScrnOwner[l * MaxWidth + c] = this;
  104.         }
  105.  
  106.     // mark border locations
  107.     if (Border != BT_NONE)
  108.         {
  109.         if (HomeCol > 0)
  110.             {
  111.             if (HomeLine > 0)
  112.                 ScrnOwner[(HomeLine - 1) * MaxWidth + (HomeCol - 1)] = this;
  113.  
  114.             if (Length < MaxLength)
  115.                 ScrnOwner[(Length + HomeLine) * MaxWidth + (HomeCol - 1)] = this;
  116.             }
  117.  
  118.         if (Width < MaxWidth)
  119.             {
  120.             if (HomeLine > 0)
  121.                 ScrnOwner[(HomeLine - 1) * MaxWidth + (Width + HomeCol)] = this;
  122.  
  123.             if (Length < MaxLength)
  124.                 ScrnOwner[(Length + HomeLine) * MaxWidth + (Width + HomeCol)] = this;
  125.             }
  126.  
  127.         if ((HomeLine + Length) < MaxLength)
  128.             {
  129.             for (c = HomeCol; c <= HomeCol + Width; ++c)
  130.                 ScrnOwner[(Length + HomeLine) * MaxWidth + c] = this;
  131.             }
  132.  
  133.         if (HomeLine > 0)
  134.             {
  135.             for (c = HomeCol; c <= HomeCol + Width; ++c)
  136.                 ScrnOwner[(HomeLine - 1) * MaxWidth + c] = this;
  137.             }
  138.  
  139.         if ((HomeCol + Width) < MaxWidth)
  140.             {
  141.             for (l = HomeLine; l <= HomeLine + Length; ++l)
  142.                 ScrnOwner[l * MaxWidth + Width + HomeCol] = this;
  143.             }
  144.  
  145.         if (HomeCol > 0)
  146.             {
  147.             for (l = HomeLine; l <= HomeLine + Length; ++l)
  148.                 ScrnOwner[l * MaxWidth + HomeCol - 1] = this;
  149.             }
  150.         }
  151.     }
  152.