Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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-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 *************************************************************************/
11
12#ifndef ROOT_TGTextView
13#define ROOT_TGTextView
14
15
16#include "TGView.h"
17#include "TGText.h"
18#include "TTimer.h"
19
20class TViewTimer;
21
22class TGTextView : public TGView {
23
24protected:
25 TGText *fText; ///< text buffer
26 TGText *fClipText; ///< clipboard text buffer
27 FontStruct_t fFont; ///< text font
28 Int_t fMaxAscent; ///< maximum ascent in font
29 Int_t fMaxDescent; ///< maximum descent in font
30 Int_t fMaxWidth; ///< maximum width of character in font
31 TGGC fNormGC; ///< graphics context for drawing text
32 TGGC fSelGC; ///< graphics context for drawing marked text
33 TGGC fSelbackGC; ///< graphics context for drawing marked background
34 Bool_t fMarkedFromX; ///< true if text is marked from x
35 Bool_t fMarkedFromY; ///< true if text is marker from y
36 Bool_t fIsMarked; ///< true if text is marked/selected
37 Bool_t fIsMarking; ///< true if in marking mode
38 Bool_t fIsSaved; ///< true is content is saved
39 Bool_t fReadOnly; ///< text cannot be edited
40 TGLongPosition fMarkedStart; ///< start position of marked text
41 TGLongPosition fMarkedEnd; ///< end position of marked text
42 TViewTimer *fScrollTimer; ///< scrollbar timer
43 Atom_t *fDNDTypeList; ///< handles DND types
44
45 static const TGFont *fgDefaultFont;
49
50 void Init(Pixel_t bg);
51 void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override;
52 virtual void Mark(Long_t xPos, Long_t yPos);
53 virtual void UnMark();
54 void Copy(TObject &) const override { MayNotUse("Copy(TObject &)"); }
55 virtual void HLayout();
56 virtual void VLayout();
57
59 static const TGGC &GetDefaultGC();
60 static const TGGC &GetDefaultSelectedGC();
62
63private:
64 TGTextView(const TGTextView&) = delete;
65 TGTextView& operator=(const TGTextView&) = delete;
66
67public:
68 TGTextView(const TGWindow *parent = nullptr, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
69 UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
70 TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
71 Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
72 TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
73 Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
74
75 virtual ~TGTextView();
76
77 virtual Bool_t IsSaved() { fIsSaved = fText->IsSaved(); return fIsSaved;}
78 virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line);
79 virtual Long_t ToObjYCoord(Long_t yCoord);
80 virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line);
81 virtual Long_t ToScrYCoord(Long_t yCoord);
82 virtual void AdjustWidth();
83 virtual Bool_t LoadFile(const char *fname, long startpos = 0, long length = -1);
84 virtual Bool_t LoadBuffer(const char *txtbuf);
85 void Clear(Option_t * = "") override;
86 virtual Bool_t Copy();
87 virtual Bool_t SelectAll();
88 virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
89 virtual void SetFont(FontStruct_t font);
94 virtual Long_t ReturnLineCount() { return fText->RowCount(); }
95
96 virtual void SetSBRange(Int_t direction);
97 virtual void SetHsbPosition(Long_t newPos);
98 virtual void SetVsbPosition(Long_t newPos);
99 virtual void ShowBottom();
100 virtual void ShowTop();
101
102 void SavePrimitive(std::ostream &out, Option_t * = "") override;
103 virtual void SetText(TGText *text);
104 virtual void AddText(TGText *text);
105 virtual void AddLine(const char *string);
106 virtual void AddLineFast(const char *string);
107 virtual void Update();
108 void Layout() override;
109
110 virtual void SetBackground(Pixel_t p);
111 virtual void SetSelectBack(Pixel_t p);
112 virtual void SetSelectFore(Pixel_t p);
113 void SetForegroundColor(Pixel_t) override;
114
115 TGText *GetText() const { return fText; }
116
117 virtual void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; } //*TOGGLE* *GETTER=IsReadOnly
118 Bool_t IsReadOnly() const { return fReadOnly; }
119 Bool_t IsMarked() const { return fIsMarked; }
120
123 Int_t xroot, Int_t yroot) override;
125 Bool_t HandleDNDLeave() override;
126
127 Bool_t HandleButton(Event_t *event) override;
131 Bool_t HandleMotion(Event_t *event) override;
132 Bool_t HandleTimer(TTimer *t) override;
134
135 virtual void DataChanged() { Emit("DataChanged()"); } //*SIGNAL*
136 virtual void DataDropped(const char *fname) { Emit("DataDropped(char *)", fname); } //*SIGNAL*
137 virtual void Marked(Bool_t mark) { Emit("Marked(Bool_t)", mark); } // *SIGNAL*
138 virtual void Clicked(const char *word) { Emit("Clicked(char *)", word); } //*SIGNAL*
139 virtual void DoubleClicked(const char *word) { Emit("DoubleClicked(char *)", word); } //*SIGNAL*
140
141 ClassDefOverride(TGTextView,0) // Non-editable text viewer widget
142};
143
144
145class TViewTimer : public TTimer {
146private:
148
149 TViewTimer(const TViewTimer&) = delete;
150 TViewTimer& operator=(const TViewTimer&) = delete;
151
152public:
153 TViewTimer(TGView *t, Long_t ms) : TTimer(ms, kTRUE), fView(t) { }
154 Bool_t Notify() override;
155};
156
157
158#endif
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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:180
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t Atom_t typelist
Option_t Option_t TPoint TPoint const char text
Drag and drop data container.
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:709
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
Long_t fY
y position
Definition TGDimension.h:57
A TGTextView is a text viewer widget.
Definition TGTextView.h:22
Bool_t HandleDNDLeave() override
Handle Drag Leave event.
virtual Long_t ReturnLineLength(Long_t line)
Definition TGTextView.h:92
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
maximum descent in font
Definition TGTextView.h:29
virtual void Update()
update the whole window of text view
TGGC fNormGC
graphics context for drawing text
Definition TGTextView.h:31
Int_t fMaxAscent
maximum ascent in font
Definition TGTextView.h:28
Bool_t fReadOnly
text cannot be edited
Definition TGTextView.h:39
TGText * fText
text buffer
Definition TGTextView.h:25
virtual void UnMark()
Clear marked region.
virtual Bool_t IsSaved()
Definition TGTextView.h:77
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.
void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override
Draw lines in exposed region.
virtual Long_t ReturnLongestLine()
Definition TGTextView.h:93
static TGGC * fgDefaultSelectedGC
Definition TGTextView.h:47
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
Int_t fMaxWidth
maximum width of character in font
Definition TGTextView.h:30
TGText * fClipText
clipboard text buffer
Definition TGTextView.h:26
virtual Bool_t LoadBuffer(const char *txtbuf)
Load text from a text buffer. Return false in case of failure.
void Layout() override
Layout the components of view.
FontStruct_t fFont
text font
Definition TGTextView.h:27
virtual void DataDropped(const char *fname)
Definition TGTextView.h:136
void Init(Pixel_t bg)
Initialize a text view widget.
Bool_t fIsSaved
true is content is saved
Definition TGTextView.h:38
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
Bool_t IsMarked() const
Definition TGTextView.h:119
virtual void SetReadOnly(Bool_t on=kTRUE)
Definition TGTextView.h:117
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t fIsMarking
true if in marking mode
Definition TGTextView.h:37
Bool_t HandleTimer(TTimer *t) override
Handle scroll timer.
Bool_t HandleSelectionClear(Event_t *event) override
Handle selection clear event.
Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action, Int_t xroot, Int_t yroot) override
Handle Drag position event.
virtual void AddLine(const char *string)
Add a line of text to the view widget.
Bool_t fIsMarked
true if text is marked/selected
Definition TGTextView.h:36
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in the text editor widget.
virtual void Clicked(const char *word)
Definition TGTextView.h:138
TGGC fSelbackGC
graphics context for drawing marked background
Definition TGTextView.h:33
virtual void HLayout()
Horizontal layout of widgets (canvas, scrollbar).
TGGC fSelGC
graphics context for drawing marked text
Definition TGTextView.h:32
Atom_t HandleDNDEnter(Atom_t *typelist) override
Handle Drag Enter event.
TViewTimer * fScrollTimer
scrollbar timer
Definition TGTextView.h:42
Bool_t HandleDoubleClick(Event_t *event) override
handle double click
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:115
void SetForegroundColor(Pixel_t) override
Set text color.
Atom_t * fDNDTypeList
handles DND types
Definition TGTextView.h:43
virtual void SetSelectBack(Pixel_t p)
set selected text background color
static TGGC * fgDefaultGC
Definition TGTextView.h:46
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
TGLongPosition fMarkedEnd
end position of marked text
Definition TGTextView.h:41
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
virtual void VLayout()
Vertical layout of widgets (canvas, scrollbar).
TGTextView & operator=(const TGTextView &)=delete
virtual void Marked(Bool_t mark)
Definition TGTextView.h:137
static const TGFont * fgDefaultFont
Definition TGTextView.h:45
void Copy(TObject &) const override
Copy this to obj.
Definition TGTextView.h:54
virtual void DataChanged()
Definition TGTextView.h:135
Bool_t IsReadOnly() const
Definition TGTextView.h:118
Bool_t fMarkedFromY
true if text is marker from y
Definition TGTextView.h:35
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a text edit widget as a C++ statement(s) on output stream out.
virtual Long_t ReturnLineCount()
Definition TGTextView.h:94
virtual Bool_t Copy()
Copy selected text to clipboard.
virtual void DoubleClicked(const char *word)
Definition TGTextView.h:139
TGTextView(const TGTextView &)=delete
Bool_t HandleSelectionRequest(Event_t *event) override
Handle request to send current clipboard contents to requestor window.
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in text editor.
virtual Long_t ReturnHeighestColHeight()
Definition TGTextView.h:90
virtual void AddLineFast(const char *string)
Add a line of text to the view widget.
virtual ~TGTextView()
Cleanup text view widget.
Bool_t HandleDNDDrop(TDNDData *data) override
Handle Drop event.
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.
TGLongPosition fMarkedStart
start position of marked text
Definition TGTextView.h:40
virtual void SetText(TGText *text)
Adopt a new text buffer. The text will be deleted by this object.
Bool_t fMarkedFromX
true if text is marked from x
Definition TGTextView.h:34
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.
void Clear(Option_t *="") override
Clear text view widget.
static const TGGC * fgDefaultSelectedBackgroundGC
Definition TGTextView.h:48
A TGText is a multi line text buffer.
Definition TGText.h:57
Long_t RowCount() const
Definition TGText.h:106
Long_t GetLongestLine() const
Definition TGText.h:110
Bool_t IsSaved() const
Definition TGText.h:87
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition TGText.cxx:1043
A TGView provides the infrastructure for text viewer and editor widgets.
Definition TGView.h:23
TGLongPosition fScrollVal
scroll value
Definition TGView.h:34
ROOT GUI Window base class.
Definition TGWindow.h:23
Mother of all ROOT objects.
Definition TObject.h:41
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:147
TViewTimer(TGView *t, Long_t ms)
Definition TGTextView.h:153
TViewTimer(const TViewTimer &)=delete
Bool_t Notify() override
Notify when timer times out and reset the timer.
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:1207