// This may look like C code, but it is really -*- C++ -*-

/***********************************************************
Copyright 1991 by the Massachusetts Institute of Technology

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of M.I.T. not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission.  M.I.T. makes no representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.


Author: Roman J. Budzianowski - Project Athena MIT

******************************************************************/

#ifndef _WindowStream_h
#define _WindowStream_h

#include <xt++/Intrinsic.h>
#include <xt++/Xaw/Text.h>
#include <iostream.h>


class  windowbuf : public streambuf {	/* a stream buffer interface for TextWidget */
 public:
   windowbuf() : widget(NULL) { }
   windowbuf(TextWidget* w) : widget(w) {}
   ~windowbuf() {}
 public: /* virtuals */
   int	overflow(int=EOF);
   int	underflow();
//   int	sync() ;
//   streambuf* setbuf(char*  p, int len) ;
   windowbuf* attach(TextWidget* w) { widget=w; initialize(); return this; }
   void print();
   void clear();
   void top();
 protected:
   TextWidget* widget;

   void initialize();
};

class wstreambase : virtual public ios { 
 public:
   wstreambase() { init(&buf); }
   wstreambase(TextWidget* w) : buf(w) { init(&buf); }
	
   ~wstreambase() {}

   windowbuf* attach(TextWidget* w) { return buf.attach(w); }
   void print() { buf.print(); }

 protected:
   void winit(TextWidget* w) { buf.attach(w); }
   void clear() { buf.clear(); }
   void top()   { buf.top(); }
 private:
   windowbuf		buf ;
};

class iwstream : public wstreambase, public istream {
 public:
   iwstream() {}
   iwstream(TextWidget* w) : wstreambase(w) {}
   ~iwstream() {}
};

class owstream : public wstreambase, public ostream {
 public:
   owstream& clear() { wstreambase::clear(); return *this; }
   owstream& top() { wstreambase::top(); return *this; }

   owstream&	operator<< (owstream& (*f)(owstream&))
     { return (*f)(*this) ; }

   owstream() {}
   owstream(TextWidget* w) : wstreambase(w) {}
   ~owstream() {}
};

/***
class oostream : public ostream {
 public:
//   oostream&	operator<< (oostream& (*f)(oostream&))
//     { return (*f)(*this) ; }

   oostream() {}
   ~oostream() {}
};

class ioostream : public istream, public oostream {
 public:
   ioostream(streambuf*){}
   virtual		~ioostream() ;
 protected:
   ioostream() ;
};
***/

class wstream : public wstreambase, public iostream {
 public:
//   wstream&	operator<< (wstream& (*f)(wstream&))
//     { return (*f)(*this) ; }
   wstream& clear() { wstreambase::clear(); return *this; }
   wstream& top() { wstreambase::top(); return *this; }

   wstream() {}
   wstream(TextWidget* w) : wstreambase(w) {}
   ~wstream() {}
};

owstream& clear(owstream&);
owstream& top(owstream&);

wstream& clear(wstream&);
wstream& top(wstream&);



#endif

