Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGTextViewStream.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 //////////////////////////////////////////////////////////////////////////
12 // //
13 // TGTextViewStream //
14 // //
15 // A TGTextViewStream is a text viewer widget. It is a specialization //
16 // of TGTextView and std::ostream, and it uses a TGTextViewStreamBuf, //
17 // who inherits from std::streambuf, allowing to stream text directly //
18 // to the text view in a cout-like fashion //
19 // //
20 //////////////////////////////////////////////////////////////////////////
21 
22 #include "TGTextViewStream.h"
23 #include "TSystem.h"
24 
25 ClassImp(TGTextViewStreamBuf);
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TGTextViewStreamBuf constructor.
29 
30 TGTextViewStreamBuf::TGTextViewStreamBuf(TGTextView *textview) :
31  fTextView(textview)
32 {
33  fInputbuffer.reserve(32);
34  setg(&fInputbuffer[0], &fInputbuffer[0], &fInputbuffer[0]);
35  setp(&fInputbuffer[0], &fInputbuffer[0]);
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Method called to put a character into the controlled output sequence
40 /// without changing the current position.
41 
42 Int_t TGTextViewStreamBuf::overflow(Int_t c)
43 {
44  typedef std::char_traits<char> Tr;
45  if (c == Tr::eof())
46  return Tr::not_eof(c);
47  if (c=='\n') {
48  fLinebuffer.push_back('\0');
49  fTextView->AddLineFast(&fLinebuffer[0]);
50  fLinebuffer.clear();
51  fTextView->ShowBottom();
52  fTextView->Update();
53  gSystem->ProcessEvents();
54  } else {
55  fLinebuffer.push_back(c);
56  }
57  return c;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// TGTextViewostream constructor.
62 
63 TGTextViewostream::TGTextViewostream(const TGWindow* parent, UInt_t w,
64  UInt_t h,Int_t id, UInt_t sboptions,
65  Pixel_t back) :
66  TGTextView(parent, w, h, id, sboptions, back), std::ostream(&fStreambuffer),
67  fStreambuffer(this)
68 {
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// TGTextViewostream constructor.
73 
74 TGTextViewostream::TGTextViewostream(const TGWindow *parent, UInt_t w,
75  UInt_t h, TGText *text, Int_t id,
76  UInt_t sboptions, ULong_t back):
77  TGTextView(parent, w, h, text, id, sboptions, back),
78  std::ostream(&fStreambuffer), fStreambuffer(this)
79 {
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// TGTextViewostream constructor.
84 
85 TGTextViewostream::TGTextViewostream(const TGWindow *parent, UInt_t w,
86  UInt_t h,const char *string, Int_t id,
87  UInt_t sboptions, ULong_t back):
88  TGTextView(parent, w, h, string, id, sboptions, back),
89  std::ostream(&fStreambuffer), fStreambuffer(this)
90 {
91 }
92