Logo ROOT  
Reference Guide
TGTextView.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 1/7/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGTextView
13 #define ROOT_TGTextView
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGTextView //
19 // //
20 // A TGTextView is a text viewer widget. It is a specialization of //
21 // TGView. It uses the TGText class (which contains all text //
22 // manipulation code, i.e. loading a file in memory, changing, //
23 // removing lines, etc.). Use a TGTextView to view non-editable text. //
24 // For supported messages see TGView. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TGView.h"
29 #include "TGText.h"
30 
31 class TViewTimer;
32 
33 class TGTextView : public TGView {
34 
35 protected:
36  TGText *fText; // text buffer
37  TGText *fClipText; // clipboard text buffer
38  FontStruct_t fFont; // text font
39  Int_t fMaxAscent; // maximum ascent in font
40  Int_t fMaxDescent; // maximum descent in font
41  Int_t fMaxWidth; // maximum width of character in font
42  TGGC fNormGC; // graphics context for drawing text
43  TGGC fSelGC; // graphics context for drawing marked text
44  TGGC fSelbackGC; // graphics context for drawing marked background
45  Bool_t fMarkedFromX; // true if text is marked from x
46  Bool_t fMarkedFromY; // true if text is marker from y
47  Bool_t fIsMarked; // true if text is marked/selected
48  Bool_t fIsMarking; // true if in marking mode
49  Bool_t fIsSaved; // true is content is saved
50  Bool_t fReadOnly; // text cannot be editted
51  TGLongPosition fMarkedStart; // start position of marked text
52  TGLongPosition fMarkedEnd; // end position of marked text
53  TViewTimer *fScrollTimer; // scrollbar timer
54  Atom_t *fDNDTypeList; // handles DND types
55 
56  static const TGFont *fgDefaultFont;
57  static TGGC *fgDefaultGC;
60 
61  void Init(Pixel_t bg);
62  virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
63  virtual void Mark(Long_t xPos, Long_t yPos);
64  virtual void UnMark();
65  virtual void Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
66  virtual void HLayout();
67  virtual void VLayout();
68 
70  static const TGGC &GetDefaultGC();
71  static const TGGC &GetDefaultSelectedGC();
72  static const TGGC &GetDefaultSelectedBackgroundGC();
73 
74 private:
75  TGTextView(const TGTextView&);
77 
78 public:
79  TGTextView(const TGWindow *parent = 0, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
80  UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
81  TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
82  Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
83  TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
84  Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
85 
86  virtual ~TGTextView();
87 
88  virtual Bool_t IsSaved() { fIsSaved = fText->IsSaved(); return fIsSaved;}
89  virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line);
90  virtual Long_t ToObjYCoord(Long_t yCoord);
91  virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line);
92  virtual Long_t ToScrYCoord(Long_t yCoord);
93  virtual void AdjustWidth();
94  virtual Bool_t LoadFile(const char *fname, long startpos = 0, long length = -1);
95  virtual Bool_t LoadBuffer(const char *txtbuf);
96  virtual void Clear(Option_t * = "");
97  virtual Bool_t Copy();
98  virtual Bool_t SelectAll();
99  virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
100  virtual void SetFont(FontStruct_t font);
102  virtual Long_t ReturnLongestLineWidth();
104  virtual Long_t ReturnLongestLine() { return fText->GetLongestLine(); }
105  virtual Long_t ReturnLineCount() { return fText->RowCount(); }
106 
107  virtual void SetSBRange(Int_t direction);
108  virtual void SetHsbPosition(Long_t newPos);
109  virtual void SetVsbPosition(Long_t newPos);
110  virtual void ShowBottom();
111  virtual void ShowTop();
112 
113  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
114  virtual void SetText(TGText *text);
115  virtual void AddText(TGText *text);
116  virtual void AddLine(const char *string);
117  virtual void AddLineFast(const char *string);
118  virtual void Update();
119  virtual void Layout();
120 
121  virtual void SetBackground(Pixel_t p);
122  virtual void SetSelectBack(Pixel_t p);
123  virtual void SetSelectFore(Pixel_t p);
124  virtual void SetForegroundColor(Pixel_t);
125 
126  TGText *GetText() const { return fText; }
127 
128  virtual void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; } //*TOGGLE* *GETTER=IsReadOnly
129  Bool_t IsReadOnly() const { return fReadOnly; }
130  Bool_t IsMarked() const { return fIsMarked; }
131 
132  virtual Bool_t HandleDNDDrop(TDNDData *data);
133  virtual Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action,
134  Int_t xroot, Int_t yroot);
135  virtual Atom_t HandleDNDEnter(Atom_t * typelist);
136  virtual Bool_t HandleDNDLeave();
137 
138  virtual Bool_t HandleButton(Event_t *event);
139  virtual Bool_t HandleDoubleClick(Event_t *event);
140  virtual Bool_t HandleSelectionClear(Event_t *event);
141  virtual Bool_t HandleSelectionRequest(Event_t *event);
142  virtual Bool_t HandleMotion(Event_t *event);
143  virtual Bool_t HandleTimer(TTimer *t);
144  virtual Bool_t HandleCrossing(Event_t *event);
145 
146  virtual void DataChanged() { Emit("DataChanged()"); } //*SIGNAL*
147  virtual void DataDropped(const char *fname) { Emit("DataDropped(char *)", fname); } //*SIGNAL*
148  virtual void Marked(Bool_t mark) { Emit("Marked(Bool_t)", mark); } // *SIGNAL*
149  virtual void Clicked(const char *word) { Emit("Clicked(char *)", word); } //*SIGNAL*
150  virtual void DoubleClicked(const char *word) { Emit("DoubleClicked(char *)", word); } //*SIGNAL*
151 
152  ClassDef(TGTextView,0) // Non-editable text viewer widget
153 };
154 
155 
156 class TViewTimer : public TTimer {
157 private:
159 
160  TViewTimer(const TViewTimer&); // not implemented
161  TViewTimer& operator=(const TViewTimer&); // not implemented
162 
163 public:
165  Bool_t Notify();
166 };
167 
168 
169 #endif
mark
#define mark(osub)
Definition: triangle.c:1206
TGTextView::AddLine
virtual void AddLine(const char *string)
Add a line of text to the view widget.
Definition: TGTextView.cxx:228
TGTextView::ReturnLineLength
virtual Long_t ReturnLineLength(Long_t line)
Definition: TGTextView.h:103
TGWindow
Definition: TGWindow.h:31
TGTextView::IsSaved
virtual Bool_t IsSaved()
Definition: TGTextView.h:88
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGTextView::fMaxDescent
Int_t fMaxDescent
Definition: TGTextView.h:40
TViewTimer
Definition: TGTextView.h:156
TGTextView::GetDefaultSelectedBackgroundGC
static const TGGC & GetDefaultSelectedBackgroundGC()
Return graphics context for highlighted frame background.
Definition: TGTextView.cxx:1549
TGTextView::DataChanged
virtual void DataChanged()
Definition: TGTextView.h:146
TGTextView::fNormGC
TGGC fNormGC
Definition: TGTextView.h:42
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGTextView::HandleSelectionRequest
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle request to send current clipboard contents to requestor window.
Definition: TGTextView.cxx:966
TGTextView::Marked
virtual void Marked(Bool_t mark)
Definition: TGTextView.h:148
TGTextView::ToScrXCoord
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
Definition: TGTextView.cxx:359
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
TGTextView::DoubleClicked
virtual void DoubleClicked(const char *word)
Definition: TGTextView.h:150
TGTextView::SetText
virtual void SetText(TGText *text)
Adopt a new text buffer. The text will be deleted by this object.
Definition: TGTextView.cxx:196
TGView::fScrollVal
TGLongPosition fScrollVal
Definition: TGView.h:54
TGLongPosition::fY
Long_t fY
Definition: TGDimension.h:66
TGTextView::HandleDNDPosition
virtual Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action, Int_t xroot, Int_t yroot)
Handle Drag position event.
Definition: TGTextView.cxx:1135
TGTextView::fgDefaultGC
static TGGC * fgDefaultGC
Definition: TGTextView.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TGView.h
TGTextView::fIsMarked
Bool_t fIsMarked
Definition: TGTextView.h:47
TGText
Definition: TGText.h:67
TGTextView::fIsSaved
Bool_t fIsSaved
Definition: TGTextView.h:49
TObject::MayNotUse
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:943
TGTextView::ReturnLineCount
virtual Long_t ReturnLineCount()
Definition: TGTextView.h:105
TGTextView::SetSelectFore
virtual void SetSelectFore(Pixel_t p)
set selected text color
Definition: TGTextView.cxx:187
TGTextView::ToScrYCoord
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
Definition: TGTextView.cxx:345
TGTextView::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a text edit widget as a C++ statement(s) on output stream out.
Definition: TGTextView.cxx:1560
TGTextView::fSelGC
TGGC fSelGC
Definition: TGTextView.h:43
TGTextView::SetSBRange
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
Definition: TGTextView.cxx:1413
TGTextView::SetReadOnly
virtual void SetReadOnly(Bool_t on=kTRUE)
Definition: TGTextView.h:128
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGTextView::fMarkedFromY
Bool_t fMarkedFromY
Definition: TGTextView.h:46
text
TText * text
Definition: entrylist_figure1.C:10
TGTextView::DrawRegion
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw lines in exposed region.
Definition: TGTextView.cxx:538
TGTextView::ReturnLongestLine
virtual Long_t ReturnLongestLine()
Definition: TGTextView.h:104
TGTextView::HLayout
virtual void HLayout()
Horizontal layout of widgets (canvas, scrollbar).
Definition: TGTextView.cxx:1337
bool
TGText::RowCount
Long_t RowCount() const
Definition: TGText.h:116
TGTextView::fMarkedFromX
Bool_t fMarkedFromX
Definition: TGTextView.h:45
TGTextView::HandleDNDEnter
virtual Atom_t HandleDNDEnter(Atom_t *typelist)
Handle Drag Enter event.
Definition: TGTextView.cxx:1144
TViewTimer::TViewTimer
TViewTimer(TGView *t, Long_t ms)
Definition: TGTextView.h:164
TGTextView::fFont
FontStruct_t fFont
Definition: TGTextView.h:38
TGTextView::fMaxAscent
Int_t fMaxAscent
Definition: TGTextView.h:39
TGTextView::Search
virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
Search for string in text.
Definition: TGTextView.cxx:289
TGTextView::HandleDoubleClick
virtual Bool_t HandleDoubleClick(Event_t *event)
handle double click
Definition: TGTextView.cxx:901
TTimer
Definition: TTimer.h:51
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGText::GetLongestLine
Long_t GetLongestLine() const
Definition: TGText.h:120
TGTextView::fMaxWidth
Int_t fMaxWidth
Definition: TGTextView.h:41
TViewTimer::fView
TGView * fView
Definition: TGTextView.h:158
TGTextView::SetHsbPosition
virtual void SetHsbPosition(Long_t newPos)
Set position of horizontal scrollbar.
Definition: TGTextView.cxx:1455
TGTextView::GetDefaultGC
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition: TGTextView.cxx:1525
TGTextView::Clear
virtual void Clear(Option_t *="")
Clear text view widget.
Definition: TGTextView.cxx:429
h
#define h(i)
Definition: RSha256.hxx:124
TGTextView::SetForegroundColor
virtual void SetForegroundColor(Pixel_t)
Set text color.
Definition: TGTextView.cxx:1516
TGTextView::fMarkedStart
TGLongPosition fMarkedStart
Definition: TGTextView.h:51
TGGC
Definition: TGGC.h:31
TGTextView::ToObjXCoord
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
Definition: TGTextView.cxx:391
TGTextView::IsReadOnly
Bool_t IsReadOnly() const
Definition: TGTextView.h:129
TGTextView::ShowTop
virtual void ShowTop()
Show top of the page.
Definition: TGTextView.cxx:1507
Atom_t
Handle_t Atom_t
Definition: GuiTypes.h:36
TGTextView::fgDefaultFont
static const TGFont * fgDefaultFont
Definition: TGTextView.h:56
TViewTimer::TViewTimer
TViewTimer(const TViewTimer &)
TGTextView::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text editor.
Definition: TGTextView.cxx:823
Long_t
long Long_t
Definition: RtypesCore.h:54
TGTextView::fText
TGText * fText
Definition: TGTextView.h:36
TGTextView::LoadBuffer
virtual Bool_t LoadBuffer(const char *txtbuf)
Load text from a text buffer. Return false in case of failure.
Definition: TGTextView.cxx:470
TGTextView::~TGTextView
virtual ~TGTextView()
Cleanup text view widget.
Definition: TGTextView.cxx:157
TGText::GetLineLength
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition: TGText.cxx:1043
TGTextView::SetSelectBack
virtual void SetSelectBack(Pixel_t p)
set selected text background color
Definition: TGTextView.cxx:178
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
y
Double_t y[n]
Definition: legend1.C:17
TGTextView::ToObjYCoord
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
Definition: TGTextView.cxx:383
TGTextView::AdjustWidth
virtual void AdjustWidth()
Adjust widget width to longest line.
Definition: TGTextView.cxx:1311
TDNDData
Definition: TGDNDManager.h:65
TGTextView::IsMarked
Bool_t IsMarked() const
Definition: TGTextView.h:130
line
TLine * line
Definition: entrylistblock_figure1.C:235
TGTextView::Copy
virtual void Copy(TObject &) const
Copy this to obj.
Definition: TGTextView.h:65
TGTextView::Copy
virtual Bool_t Copy()
Copy selected text to clipboard.
Definition: TGTextView.cxx:485
TGText.h
TGTextView::fMarkedEnd
TGLongPosition fMarkedEnd
Definition: TGTextView.h:52
unsigned int
TGLongPosition
Definition: TGDimension.h:63
TGTextView::fgDefaultSelectedGC
static TGGC * fgDefaultSelectedGC
Definition: TGTextView.h:58
TGTextView::Mark
virtual void Mark(Long_t xPos, Long_t yPos)
Mark a text region from xPos to yPos.
Definition: TGTextView.cxx:1169
TGTextView::ReturnHeighestColHeight
virtual Long_t ReturnHeighestColHeight()
Definition: TGTextView.h:101
TGTextView::HandleTimer
virtual Bool_t HandleTimer(TTimer *t)
Handle scroll timer.
Definition: TGTextView.cxx:718
TGTextView::GetText
TGText * GetText() const
Definition: TGTextView.h:126
TGTextView::UnMark
virtual void UnMark()
Clear marked region.
Definition: TGTextView.cxx:1292
TGTextView::fClipText
TGText * fClipText
Definition: TGTextView.h:37
TGTextView::HandleSelectionClear
virtual Bool_t HandleSelectionClear(Event_t *event)
Handle selection clear event.
Definition: TGTextView.cxx:955
TGTextView::HandleCrossing
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGTextView.cxx:673
TViewTimer::Notify
Bool_t Notify()
Notify when timer times out and reset the timer.
Definition: TGTextView.cxx:59
TGTextView::VLayout
virtual void VLayout()
Vertical layout of widgets (canvas, scrollbar).
Definition: TGTextView.cxx:1376
TGTextView::ReturnLongestLineWidth
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Definition: TGTextView.cxx:271
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGTextView
Definition: TGTextView.h:33
TGTextView::fDNDTypeList
Atom_t * fDNDTypeList
Definition: TGTextView.h:54
TGTextView::DataDropped
virtual void DataDropped(const char *fname)
Definition: TGTextView.h:147
TGTextView::AddLineFast
virtual void AddLineFast(const char *string)
Add a line of text to the view widget.
Definition: TGTextView.cxx:250
TGTextView::SetBackground
virtual void SetBackground(Pixel_t p)
set background color
Definition: TGTextView.cxx:168
Event_t
Definition: GuiTypes.h:173
TGTextView::fSelbackGC
TGGC fSelbackGC
Definition: TGTextView.h:44
TGTextView::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition: TGTextView.cxx:1479
TGTextView::fIsMarking
Bool_t fIsMarking
Definition: TGTextView.h:48
TGFrame::GetWhitePixel
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:694
TGTextView::fReadOnly
Bool_t fReadOnly
Definition: TGTextView.h:50
TGTextView::Init
void Init(Pixel_t bg)
Initialize a text view widget.
Definition: TGTextView.cxx:72
TGTextView::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text editor widget.
Definition: TGTextView.cxx:909
TGTextView::HandleDNDLeave
virtual Bool_t HandleDNDLeave()
Handle Drag Leave event.
Definition: TGTextView.cxx:1161
TGTextView::fScrollTimer
TViewTimer * fScrollTimer
Definition: TGTextView.h:53
TGTextView::ShowBottom
virtual void ShowBottom()
Show bottom of the page.
Definition: TGTextView.cxx:1490
TGeant4Unit::ms
static constexpr double ms
Definition: TGeant4SystemOfUnits.h:169
TGTextView::TGTextView
TGTextView(const TGTextView &)
TGTextView::Update
virtual void Update()
update the whole window of text view
Definition: TGTextView.cxx:261
TGTextView::Clicked
virtual void Clicked(const char *word)
Definition: TGTextView.h:149
TGTextView::fgDefaultSelectedBackgroundGC
static const TGGC * fgDefaultSelectedBackgroundGC
Definition: TGTextView.h:59
TGTextView::Layout
virtual void Layout()
Layout the components of view.
Definition: TGTextView.cxx:1328
TGFont
Definition: TGFont.h:149
TGTextView::SetFont
virtual void SetFont(FontStruct_t font)
Changes text entry font.
Definition: TGTextView.cxx:332
TGTextView::SetVsbPosition
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
Definition: TGTextView.cxx:1467
TGTextView::SelectAll
virtual Bool_t SelectAll()
Select all text in the viewer.
Definition: TGTextView.cxx:516
TGText::IsSaved
Bool_t IsSaved() const
Definition: TGText.h:97
TGTextView::GetDefaultSelectedGC
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
Definition: TGTextView.cxx:1537
TGView
Definition: TGView.h:43
TViewTimer::operator=
TViewTimer & operator=(const TViewTimer &)
TGTextView::HandleDNDDrop
virtual Bool_t HandleDNDDrop(TDNDData *data)
Handle Drop event.
Definition: TGTextView.cxx:1086
TGTextView::LoadFile
virtual Bool_t LoadFile(const char *fname, long startpos=0, long length=-1)
Load a file in the text view widget.
Definition: TGTextView.cxx:453
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TGTextView::AddText
virtual void AddText(TGText *text)
Add text to the view widget.
Definition: TGTextView.cxx:207
int
TGTextView::operator=
TGTextView & operator=(const TGTextView &)