Logo ROOT   6.12/07
Reference Guide
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 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TGTextViewStreamBuf constructor.
29 
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 
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');
50  fLinebuffer.clear();
52  fTextView->Update();
54  } else {
55  fLinebuffer.push_back(c);
56  }
57  return c;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// TGTextViewostream constructor.
62 
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 
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 
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 
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:424
virtual int overflow(int=traits::eof())
Method called to put a character into the controlled output sequence without changing the current pos...
std::vector< char > fLinebuffer
Definition: TGText.h:67
TH1 * h
Definition: legend2.C:5
virtual void AddLineFast(const char *string)
Add a line of text to the view widget.
Definition: TGTextView.cxx:249
TGTextViewStreamBuf fStreambuffer
std::vector< char > fInputbuffer
int Int_t
Definition: RtypesCore.h:41
STL namespace.
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual void ShowBottom()
Show bottom of the page.
virtual void Update()
update the whole window of text view
Definition: TGTextView.cxx:260
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
TGTextView * fTextView
unsigned int UInt_t
Definition: RtypesCore.h:42
#define ClassImp(name)
Definition: Rtypes.h:359
TText * text
unsigned long ULong_t
Definition: RtypesCore.h:51
TGTextViewostream(const TGWindow *parent=0, UInt_t w=1, UInt_t h=1, Int_t id=-1, UInt_t sboptions=0, Pixel_t back=TGTextView::GetWhitePixel())
TGTextViewostream constructor.
TGTextViewStreamBuf(TGTextView *textview)
TGTextViewStreamBuf constructor.