Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 1/7/2000
5 * Copyright (C) 1995-2021, 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 *************************************************************************/
12#ifndef ROOT_TGTextView
13#define ROOT_TGTextView
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// //
28#include "TGView.h"
29#include "TGText.h"
30#include "TTimer.h"
32class TViewTimer;
34class TGTextView : public TGView {
37 TGText *fText; // text buffer
38 TGText *fClipText; // clipboard text buffer
39 FontStruct_t fFont; // text font
40 Int_t fMaxAscent; // maximum ascent in font
41 Int_t fMaxDescent; // maximum descent in font
42 Int_t fMaxWidth; // maximum width of character in font
43 TGGC fNormGC; // graphics context for drawing text
44 TGGC fSelGC; // graphics context for drawing marked text
45 TGGC fSelbackGC; // graphics context for drawing marked background
46 Bool_t fMarkedFromX; // true if text is marked from x
47 Bool_t fMarkedFromY; // true if text is marker from y
48 Bool_t fIsMarked; // true if text is marked/selected
49 Bool_t fIsMarking; // true if in marking mode
50 Bool_t fIsSaved; // true is content is saved
51 Bool_t fReadOnly; // text cannot be editted
52 TGLongPosition fMarkedStart; // start position of marked text
53 TGLongPosition fMarkedEnd; // end position of marked text
54 TViewTimer *fScrollTimer; // scrollbar timer
55 Atom_t *fDNDTypeList; // handles DND types
57 static const TGFont *fgDefaultFont;
62 void Init(Pixel_t bg);
63 virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
64 virtual void Mark(Long_t xPos, Long_t yPos);
65 virtual void UnMark();
66 virtual void Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
67 virtual void HLayout();
68 virtual void VLayout();
71 static const TGGC &GetDefaultGC();
72 static const TGGC &GetDefaultSelectedGC();
76 TGTextView(const TGTextView&) = delete;
77 TGTextView& operator=(const TGTextView&) = delete;
80 TGTextView(const TGWindow *parent = nullptr, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
81 UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
82 TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
83 Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
84 TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
85 Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
87 virtual ~TGTextView();
89 virtual Bool_t IsSaved() { fIsSaved = fText->IsSaved(); return fIsSaved;}
90 virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line);
91 virtual Long_t ToObjYCoord(Long_t yCoord);
92 virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line);
93 virtual Long_t ToScrYCoord(Long_t yCoord);
94 virtual void AdjustWidth();
95 virtual Bool_t LoadFile(const char *fname, long startpos = 0, long length = -1);
96 virtual Bool_t LoadBuffer(const char *txtbuf);
97 virtual void Clear(Option_t * = "");
98 virtual Bool_t Copy();
99 virtual Bool_t SelectAll();
100 virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
101 virtual void SetFont(FontStruct_t font);
106 virtual Long_t ReturnLineCount() { return fText->RowCount(); }
108 virtual void SetSBRange(Int_t direction);
109 virtual void SetHsbPosition(Long_t newPos);
110 virtual void SetVsbPosition(Long_t newPos);
111 virtual void ShowBottom();
112 virtual void ShowTop();
114 virtual void SavePrimitive(std::ostream &out, Option_t * = "");
115 virtual void SetText(TGText *text);
116 virtual void AddText(TGText *text);
117 virtual void AddLine(const char *string);
118 virtual void AddLineFast(const char *string);
119 virtual void Update();
120 virtual void Layout();
122 virtual void SetBackground(Pixel_t p);
123 virtual void SetSelectBack(Pixel_t p);
124 virtual void SetSelectFore(Pixel_t p);
125 virtual void SetForegroundColor(Pixel_t);
127 TGText *GetText() const { return fText; }
129 virtual void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; } //*TOGGLE* *GETTER=IsReadOnly
130 Bool_t IsReadOnly() const { return fReadOnly; }
131 Bool_t IsMarked() const { return fIsMarked; }
133 virtual Bool_t HandleDNDDrop(TDNDData *data);
134 virtual Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action,
135 Int_t xroot, Int_t yroot);
136 virtual Atom_t HandleDNDEnter(Atom_t * typelist);
137 virtual Bool_t HandleDNDLeave();
139 virtual Bool_t HandleButton(Event_t *event);
140 virtual Bool_t HandleDoubleClick(Event_t *event);
141 virtual Bool_t HandleSelectionClear(Event_t *event);
142 virtual Bool_t HandleSelectionRequest(Event_t *event);
143 virtual Bool_t HandleMotion(Event_t *event);
144 virtual Bool_t HandleTimer(TTimer *t);
145 virtual Bool_t HandleCrossing(Event_t *event);
147 virtual void DataChanged() { Emit("DataChanged()"); } //*SIGNAL*
148 virtual void DataDropped(const char *fname) { Emit("DataDropped(char *)", fname); } //*SIGNAL*
149 virtual void Marked(Bool_t mark) { Emit("Marked(Bool_t)", mark); } // *SIGNAL*
150 virtual void Clicked(const char *word) { Emit("Clicked(char *)", word); } //*SIGNAL*
151 virtual void DoubleClicked(const char *word) { Emit("DoubleClicked(char *)", word); } //*SIGNAL*
153 ClassDef(TGTextView,0) // Non-editable text viewer widget
157class TViewTimer : public TTimer {
161 TViewTimer(const TViewTimer&) = delete;
162 TViewTimer& operator=(const TViewTimer&) = delete;
165 TViewTimer(TGView *t, Long_t ms) : TTimer(ms, kTRUE), fView(t) { }
166 Bool_t Notify();
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition TError.cxx:170
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:694
Definition TGGC.h:31
virtual Long_t ReturnLineLength(Long_t line)
Definition TGTextView.h:104
virtual void AdjustWidth()
Adjust widget width to longest line.
virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
Search for string in text.
Int_t fMaxDescent
Definition TGTextView.h:41
virtual void Update()
update the whole window of text view
Definition TGTextView.h:43
Int_t fMaxAscent
Definition TGTextView.h:40
Bool_t fReadOnly
Definition TGTextView.h:51
TGText * fText
Definition TGTextView.h:37
virtual void UnMark()
Clear marked region.
virtual Bool_t IsSaved()
Definition TGTextView.h:89
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
virtual void SetHsbPosition(Long_t newPos)
Set position of horizontal scrollbar.
virtual Bool_t LoadFile(const char *fname, long startpos=0, long length=-1)
Load a file in the text view widget.
virtual void Mark(Long_t xPos, Long_t yPos)
Mark a text region from xPos to yPos.
virtual Long_t ReturnLongestLine()
Definition TGTextView.h:105
virtual void Copy(TObject &) const
Copy this to obj.
Definition TGTextView.h:66
static TGGC * fgDefaultSelectedGC
Definition TGTextView.h:59
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Int_t fMaxWidth
Definition TGTextView.h:42
TGText * fClipText
Definition TGTextView.h:38
virtual Bool_t HandleDoubleClick(Event_t *event)
handle double click
virtual Bool_t LoadBuffer(const char *txtbuf)
Load text from a text buffer. Return false in case of failure.
FontStruct_t fFont
Definition TGTextView.h:39
virtual void DataDropped(const char *fname)
Definition TGTextView.h:148
void Init(Pixel_t bg)
Initialize a text view widget.
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle request to send current clipboard contents to requestor window.
Bool_t fIsSaved
Definition TGTextView.h:50
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
Bool_t IsMarked() const
Definition TGTextView.h:131
virtual void SetReadOnly(Bool_t on=kTRUE)
Definition TGTextView.h:129
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text editor widget.
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t fIsMarking
Definition TGTextView.h:49
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a text edit widget as a C++ statement(s) on output stream out.
virtual void AddLine(const char *string)
Add a line of text to the view widget.
Bool_t fIsMarked
Definition TGTextView.h:48
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual Bool_t HandleSelectionClear(Event_t *event)
Handle selection clear event.
virtual void Clicked(const char *word)
Definition TGTextView.h:150
TGGC fSelbackGC
Definition TGTextView.h:45
virtual void HLayout()
Horizontal layout of widgets (canvas, scrollbar).
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.h:44
TViewTimer * fScrollTimer
Definition TGTextView.h:54
static const TGGC & GetDefaultSelectedBackgroundGC()
Return graphics context for highlighted frame background.
virtual Bool_t SelectAll()
Select all text in the viewer.
TGText * GetText() const
Definition TGTextView.h:127
virtual void Layout()
Layout the components of view.
virtual void SetForegroundColor(Pixel_t)
Set text color.
Atom_t * fDNDTypeList
Definition TGTextView.h:55
virtual void SetSelectBack(Pixel_t p)
set selected text background color
static TGGC * fgDefaultGC
Definition TGTextView.h:58
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
TGLongPosition fMarkedEnd
Definition TGTextView.h:53
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw lines in exposed region.
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
virtual void Clear(Option_t *="")
Clear text view widget.
virtual void VLayout()
Vertical layout of widgets (canvas, scrollbar).
virtual Bool_t HandleDNDLeave()
Handle Drag Leave event.
TGTextView & operator=(const TGTextView &)=delete
virtual void Marked(Bool_t mark)
Definition TGTextView.h:149
static const TGFont * fgDefaultFont
Definition TGTextView.h:57
virtual void DataChanged()
Definition TGTextView.h:147
Bool_t IsReadOnly() const
Definition TGTextView.h:130
Bool_t fMarkedFromY
Definition TGTextView.h:47
virtual Long_t ReturnLineCount()
Definition TGTextView.h:106
virtual Bool_t Copy()
Copy selected text to clipboard.
virtual void DoubleClicked(const char *word)
Definition TGTextView.h:151
TGTextView(const TGTextView &)=delete
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
virtual Atom_t HandleDNDEnter(Atom_t *typelist)
Handle Drag Enter event.
virtual Bool_t HandleTimer(TTimer *t)
Handle scroll timer.
virtual Long_t ReturnHeighestColHeight()
Definition TGTextView.h:102
virtual void AddLineFast(const char *string)
Add a line of text to the view widget.
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text editor.
virtual ~TGTextView()
Cleanup text view widget.
virtual void SetFont(FontStruct_t font)
Changes text entry font.
virtual void SetBackground(Pixel_t p)
set background color
virtual void ShowBottom()
Show bottom of the page.
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
virtual Bool_t HandleDNDDrop(TDNDData *data)
Handle Drop event.
TGLongPosition fMarkedStart
Definition TGTextView.h:52
virtual void SetText(TGText *text)
Adopt a new text buffer. The text will be deleted by this object.
Bool_t fMarkedFromX
Definition TGTextView.h:46
virtual void ShowTop()
Show top of the page.
virtual void AddText(TGText *text)
Add text to the view widget.
virtual void SetSelectFore(Pixel_t p)
set selected text color
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
static const TGGC * fgDefaultSelectedBackgroundGC
Definition TGTextView.h:60
Long_t RowCount() const
Definition TGText.h:116
Long_t GetLongestLine() const
Definition TGText.h:120
Bool_t IsSaved() const
Definition TGText.h:97
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition TGText.cxx:1043
TGLongPosition fScrollVal
Definition TGView.h:53
Mother of all ROOT objects.
Definition TObject.h:37
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
TViewTimer & operator=(const TViewTimer &)=delete
TGView * fView
Definition TGTextView.h:159
TViewTimer(TGView *t, Long_t ms)
Definition TGTextView.h:165
TViewTimer(const TViewTimer &)=delete
Bool_t Notify()
Notify when timer times out and reset the timer.
TText * text
TLine * line
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Event structure.
Definition GuiTypes.h:174
#define mark(osub)
Definition triangle.c:1206