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

  1. //  Module:     Wdw_Copy  (Window Class)
  2. //  Version:    2.11
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    IBM-PC MS-DOS
  6. //
  7. //  Purpose:    Copy constructor / assignment operator
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "Str.hpp"
  12. #include "Window.hpp"
  13.  
  14. extern "C"
  15.     {
  16.     #include "string.h"
  17.     #include "stdio.h"
  18.     #include "stddef.h"
  19.     #include "dos.h"
  20.     }
  21.  
  22. // copy constructor
  23. Window::Window(const Window & w) : Header(w.Header)
  24.     {
  25.     // duplicate instance variables
  26.     HomeLine = w.HomeLine;
  27.     HomeCol  = w.HomeCol;
  28.     Length   = w.Length;
  29.     Width    = w.Width;
  30.     CrsLine  = w.CrsLine;
  31.     CrsCol   = w.CrsCol;
  32.  
  33.     InsideColor = w.InsideColor;
  34.     BorderColor = w.BorderColor;
  35.  
  36.     Border = w.Border;
  37.  
  38.     Wrapped   = w.Wrapped;
  39.     Concealed = w.Concealed;
  40.  
  41.     // allocate a buffer
  42.  
  43.     BufferSW = new WindowWord [Length * Width];
  44.  
  45.     if (BufferSW == NULL)
  46.         ErrorHandler();
  47.  
  48.     // copy existing buffer into new buffer
  49.     for (unsigned int l = 0; l < Length; ++l)
  50.         {
  51.         for (unsigned int c = 0; c < Width; ++c)
  52.             BufferSW[l * Width + c] = w.BufferSW[l * Width + c];
  53.         }
  54.  
  55.     // add window to list
  56.     WdwList.Store(this);
  57.  
  58.     // make this the top window
  59.     TopWindow = this;
  60.  
  61.     // plot what it owns
  62.     PlotOwnership();
  63.  
  64.     // display it
  65.     Paint();
  66.     }
  67.  
  68. // assignment operator
  69. void Window::operator = (const Window & w)
  70.     {
  71.     // free old buffer
  72.     delete BufferSW;
  73.  
  74.     // copy instance variables
  75.     HomeLine = w.HomeLine;
  76.     HomeCol  = w.HomeCol;
  77.     Length   = w.Length;
  78.     Width    = w.Width;
  79.     CrsLine  = w.CrsLine;
  80.     CrsCol   = w.CrsCol;
  81.  
  82.     InsideColor = w.InsideColor;
  83.     BorderColor = w.BorderColor;
  84.  
  85.     Border = w.Border;
  86.  
  87.     Wrapped   = w.Wrapped;
  88.     Concealed = w.Concealed;
  89.  
  90.     Header = w.Header;
  91.  
  92.     // allocate new buffer
  93.     BufferSW = new WindowWord [Length * Width];
  94.  
  95.     if (BufferSW == NULL)
  96.         ErrorHandler();
  97.  
  98.     // copy buffer from existing window
  99.     for (unsigned int l = 0; l < Length; ++l)
  100.         {
  101.         for (unsigned int c = 0; c < Width; ++c)
  102.             BufferSW[l * Width + c] = w.BufferSW[l * Width + c];
  103.         }
  104.  
  105.     // plot what this window owns
  106.     PlotOwnership();
  107.  
  108.     // paint all windows
  109.     Restack();
  110.     }
  111.