ROOT logo
// @(#)root/gui:$Id$

/*************************************************************************
 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGTextViewStream                                                     //
//                                                                      //
// A TGTextViewStream is a text viewer widget. It is a specialization   //
// of TGTextView and std::ostream, and it uses a TGTextViewStreamBuf,   //
// who inherits from std::streambuf, allowing to stream text directly   //
// to the text view in a cout-like fashion                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGTextViewStream.h"
#include "TSystem.h"

ClassImp(TGTextViewStreamBuf)

#ifdef R__WIN32
#pragma warning( push )
#pragma warning( disable : 4355 )
#endif

//______________________________________________________________________________
TGTextViewStreamBuf::TGTextViewStreamBuf(TGTextView *textview) :
   fTextView(textview)
{
   // TGTextViewStreamBuf constructor.

   fInputbuffer.reserve(32);
   setg(&fInputbuffer[0], &fInputbuffer[0], &fInputbuffer[0]);
   setp(&fInputbuffer[0], &fInputbuffer[0]);
}

//______________________________________________________________________________
Int_t TGTextViewStreamBuf::overflow(Int_t c)
{
   // Method called to put a character into the controlled output sequence 
   // without changing the current position.

   typedef std::char_traits<char> Tr;
   if (c == Tr::eof())
      return Tr::not_eof(c);
   if (c=='\n') {
      fLinebuffer.push_back('\0');
      fTextView->AddLineFast(&fLinebuffer[0]);
      fLinebuffer.clear();
      fTextView->ShowBottom();
      fTextView->Update();
      gSystem->ProcessEvents();
   } else {
      fLinebuffer.push_back(c);
   }
   return c;
}

//______________________________________________________________________________
TGTextViewostream::TGTextViewostream(const TGWindow* parent, UInt_t w,
                                     UInt_t h,Int_t id, UInt_t sboptions,
                                     Pixel_t back) :
   TGTextView(parent, w, h, id, sboptions, back), std::ostream(&fStreambuffer),
   fStreambuffer(this)
{
   // TGTextViewostream constructor.

}

//______________________________________________________________________________
TGTextViewostream::TGTextViewostream(const TGWindow *parent, UInt_t w,
                                     UInt_t h, TGText *text, Int_t id,
                                     UInt_t sboptions, ULong_t back):
   TGTextView(parent, w, h, text, id, sboptions, back),
   std::ostream(&fStreambuffer), fStreambuffer(this)
{
   // TGTextViewostream constructor.

}

//______________________________________________________________________________
TGTextViewostream::TGTextViewostream(const TGWindow *parent, UInt_t w,
                                     UInt_t h,const char *string, Int_t id,
                                     UInt_t sboptions, ULong_t back):
   TGTextView(parent, w, h, string, id, sboptions, back),
   std::ostream(&fStreambuffer), fStreambuffer(this)
{
   // TGTextViewostream constructor.

}

#ifdef R__WIN32
#pragma warning( pop )
#endif
 TGTextViewStream.cxx:1
 TGTextViewStream.cxx:2
 TGTextViewStream.cxx:3
 TGTextViewStream.cxx:4
 TGTextViewStream.cxx:5
 TGTextViewStream.cxx:6
 TGTextViewStream.cxx:7
 TGTextViewStream.cxx:8
 TGTextViewStream.cxx:9
 TGTextViewStream.cxx:10
 TGTextViewStream.cxx:11
 TGTextViewStream.cxx:12
 TGTextViewStream.cxx:13
 TGTextViewStream.cxx:14
 TGTextViewStream.cxx:15
 TGTextViewStream.cxx:16
 TGTextViewStream.cxx:17
 TGTextViewStream.cxx:18
 TGTextViewStream.cxx:19
 TGTextViewStream.cxx:20
 TGTextViewStream.cxx:21
 TGTextViewStream.cxx:22
 TGTextViewStream.cxx:23
 TGTextViewStream.cxx:24
 TGTextViewStream.cxx:25
 TGTextViewStream.cxx:26
 TGTextViewStream.cxx:27
 TGTextViewStream.cxx:28
 TGTextViewStream.cxx:29
 TGTextViewStream.cxx:30
 TGTextViewStream.cxx:31
 TGTextViewStream.cxx:32
 TGTextViewStream.cxx:33
 TGTextViewStream.cxx:34
 TGTextViewStream.cxx:35
 TGTextViewStream.cxx:36
 TGTextViewStream.cxx:37
 TGTextViewStream.cxx:38
 TGTextViewStream.cxx:39
 TGTextViewStream.cxx:40
 TGTextViewStream.cxx:41
 TGTextViewStream.cxx:42
 TGTextViewStream.cxx:43
 TGTextViewStream.cxx:44
 TGTextViewStream.cxx:45
 TGTextViewStream.cxx:46
 TGTextViewStream.cxx:47
 TGTextViewStream.cxx:48
 TGTextViewStream.cxx:49
 TGTextViewStream.cxx:50
 TGTextViewStream.cxx:51
 TGTextViewStream.cxx:52
 TGTextViewStream.cxx:53
 TGTextViewStream.cxx:54
 TGTextViewStream.cxx:55
 TGTextViewStream.cxx:56
 TGTextViewStream.cxx:57
 TGTextViewStream.cxx:58
 TGTextViewStream.cxx:59
 TGTextViewStream.cxx:60
 TGTextViewStream.cxx:61
 TGTextViewStream.cxx:62
 TGTextViewStream.cxx:63
 TGTextViewStream.cxx:64
 TGTextViewStream.cxx:65
 TGTextViewStream.cxx:66
 TGTextViewStream.cxx:67
 TGTextViewStream.cxx:68
 TGTextViewStream.cxx:69
 TGTextViewStream.cxx:70
 TGTextViewStream.cxx:71
 TGTextViewStream.cxx:72
 TGTextViewStream.cxx:73
 TGTextViewStream.cxx:74
 TGTextViewStream.cxx:75
 TGTextViewStream.cxx:76
 TGTextViewStream.cxx:77
 TGTextViewStream.cxx:78
 TGTextViewStream.cxx:79
 TGTextViewStream.cxx:80
 TGTextViewStream.cxx:81
 TGTextViewStream.cxx:82
 TGTextViewStream.cxx:83
 TGTextViewStream.cxx:84
 TGTextViewStream.cxx:85
 TGTextViewStream.cxx:86
 TGTextViewStream.cxx:87
 TGTextViewStream.cxx:88
 TGTextViewStream.cxx:89
 TGTextViewStream.cxx:90
 TGTextViewStream.cxx:91
 TGTextViewStream.cxx:92
 TGTextViewStream.cxx:93
 TGTextViewStream.cxx:94
 TGTextViewStream.cxx:95
 TGTextViewStream.cxx:96
 TGTextViewStream.cxx:97
 TGTextViewStream.cxx:98
 TGTextViewStream.cxx:99
 TGTextViewStream.cxx:100