home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / c / actlib11 / tvtools / touterr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-14  |  2.4 KB  |  87 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include <iostream.h>
  4.  
  5. #define Uses_otstream
  6. #define Uses_TApplication
  7. #define Uses_TDeskTop
  8. #define Uses_TRect
  9. #define Uses_TTerminal
  10. #define Uses_TWindow
  11. #define Uses_TOutErr
  12. #include "tvtools.h"
  13.  
  14.  
  15. class TOutputWindow : public TWindow
  16. {
  17.   TTerminal *_term;
  18.  
  19. public:
  20.  
  21.   TOutputWindow( TRect bounds, const char *title,
  22.                  ostream_withassign& ostr, ushort bufsize
  23.                );
  24.  
  25.   void attach( ostream_withassign& ostr )
  26.              {
  27.                // Attach TTerminal stream buffer to I/O stream.
  28.                ostr = _term;
  29.              }
  30. };
  31.  
  32. TOutputWindow::TOutputWindow( TRect bounds, const char *title,
  33.                               ostream_withassign& ostr, ushort bufsize
  34.                             ) :
  35.                               TWindowInit( &TOutputWindow::initFrame ),
  36.                               TWindow( bounds, title, wnNoNumber )
  37. {
  38.   // Terminal view should cover entire window.
  39.   bounds = getExtent();
  40.   bounds.grow(-1, -1);
  41.  
  42.   // Create terminal view and add to window.
  43.   _term = new TTerminal( bounds,
  44.                          standardScrollBar(sbHorizontal | sbHandleKeyboard),
  45.                          standardScrollBar(sbVertical | sbHandleKeyboard), 
  46.                          bufsize
  47.                        );
  48.   insert( _term );
  49.  
  50.   // Create TV output stream and copy it;
  51.   // normally attach( ostr ) would be sufficient.
  52.   otstream ot( _term );
  53.   ostr = ot;
  54. }
  55.  
  56. TOutErr::TOutErr( TRect& outbounds, ushort outbufsize,
  57.                   TRect& errbounds, ushort errbufsize
  58.                 ) :
  59.                   TProgInit( &TOutErr::initStatusLine, &TOutErr::initMenuBar,
  60.                              &TOutErr::initDeskTop
  61.                            )
  62. {
  63.   // Save current I/O assignments.
  64.   _old_cout = cout;
  65.   _old_cerr = cerr;
  66.   _old_clog = clog;
  67.  
  68.   TOutputWindow *tow;
  69.  
  70.   // Create standard output window.
  71.   tow = new TOutputWindow( outbounds, "Standard Output", cout, outbufsize );
  72.   deskTop->insert(tow);
  73.  
  74.   // Create standard error window and attach to log stream.
  75.   tow = new TOutputWindow( errbounds, "Standard Error", cerr, errbufsize );
  76.   tow->attach( clog );
  77.   deskTop->insert( tow );
  78. }
  79.  
  80. TOutErr::~TOutErr()
  81. {
  82.   // Restore old I/O assignments.
  83.   cout = _old_cout;
  84.   cerr = _old_cerr;
  85.   clog = _old_clog;
  86. }
  87.