home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / source / krcto.cpp < prev    next >
Text File  |  1997-02-25  |  2KB  |  69 lines

  1. // Kroni's Classes: Output window for common text output
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krcto.cpp
  4.  
  5.  
  6. #include "krcto.hpp"
  7.  
  8. #include <istring.hpp>                           // IString
  9.  
  10.  
  11.  
  12. KrCommonTextOutput::KrCommonTextOutput (unsigned long id, IWindow* parent, IWindow* owner,
  13.                                         const IRectangle& initial, const Style& style )
  14.   : IMultiLineEdit (id, parent, owner, initial, style)
  15. {
  16.   ostrbuf = new _KrStreambuf (buffer, sizeof(buffer),this);
  17.   outputStream = new ostream (ostrbuf);
  18.   outputStream->setf(ios::unitbuf);
  19. };
  20.  
  21.  
  22. ostream & KrCommonTextOutput::stream ()
  23. {
  24.   return (*outputStream);
  25. };
  26.  
  27.  
  28.  
  29. _KrStreambuf::_KrStreambuf (char* c, int len, KrCommonTextOutput* top)
  30.   : streambuf (c,len)
  31. {
  32.   textOutputArea = top;
  33. };
  34.  
  35.  
  36. int _KrStreambuf::overflow (int c)
  37. {
  38.   if (out_waiting () > 0)
  39.      {
  40.        IString s (pbase(), out_waiting());
  41.        int i;
  42.        IString t;
  43.        while (i = s.indexOf ('\n') )
  44.           {
  45.           if (i>1)
  46.              t = s.subString (1,i-1);
  47.           else
  48.              t = "";
  49.           textOutputArea->add (t,t.length());
  50.           textOutputArea->addLineAsLast (IString(""));
  51.           textOutputArea->setCursorLinePosition(textOutputArea->numberOfLines());
  52.           if (i<s.length())
  53.              s = s.subString (i+1,s.length()-i);
  54.           else
  55.              s = "";
  56.           };
  57.        if (s.length())
  58.           textOutputArea->add (s,s.length());
  59.      };
  60.   setp (pbase(),epptr());
  61.   if (c!=EOF)
  62.      {
  63.        sputc (c);
  64.      };
  65.   return EOF+1;                                  // No error -> don't return EOF.
  66. };
  67.  
  68.  
  69.