Logo ROOT  
Reference Guide
TGText.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 26/04/98
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_TGText
13 #define ROOT_TGText
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGText //
19 // //
20 // A TGText is a multi line text buffer. It allows the text to be //
21 // loaded from file, saved to file and edited. It is used in the //
22 // TGTextEdit widget. Single line text is handled by TGTextBuffer. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include "TString.h"
27 
28 #include "TGDimension.h"
29 
30 
31 class TGTextLine {
32 
33 friend class TGText;
34 
35 protected:
36  char *fString; // line of text
37  ULong_t fLength; // length of line
38  TGTextLine *fPrev; // previous line
39  TGTextLine *fNext; // next line
40 
41  TGTextLine(const TGTextLine&);
43 
44 public:
47  TGTextLine(const char *string);
48  virtual ~TGTextLine();
49 
50  void Clear();
51  ULong_t GetLineLength() { return fLength; }
52 
53  void DelText(ULong_t pos, ULong_t length);
54  void InsText(ULong_t pos, const char *text);
55  char *GetText(ULong_t pos, ULong_t length);
56  char *GetText() const { return fString; }
57  char *GetWord(ULong_t pos);
58 
59  void DelChar(ULong_t pos);
60  void InsChar(ULong_t pos, char character);
61  char GetChar(ULong_t pos);
62 
63  ClassDef(TGTextLine,0) // Line in TGText
64 };
65 
66 
67 class TGText {
68 
69 protected:
70  TString fFilename; // name of opened file ("" if open buffer)
71  Bool_t fIsSaved; // false if text needs to be saved
72  TGTextLine *fFirst; // first line of text
73  TGTextLine *fCurrent; // current line
74  Long_t fCurrentRow; // current row number
75  Long_t fRowCount; // number of rows
76  Long_t fColCount; // number of columns in current line
77  Long_t fLongestLine; // length of longest line
78 
79  TGText(const TGText&);
80  TGText& operator=(const TGText&);
81 
82  void Init();
84  void LongestLine();
85 
86 public:
87  TGText();
88  TGText(TGText *text);
89  TGText(const char *string);
90  virtual ~TGText();
91 
92  void Clear();
93  Bool_t Load(const char *fn, Long_t startpos = 0, Long_t length = -1);
94  Bool_t LoadBuffer(const char *txtbuf);
95  Bool_t Save(const char *fn);
96  Bool_t Append(const char *fn);
97  Bool_t IsSaved() const { return fIsSaved; }
98  const char *GetFileName() const { return fFilename.Data(); }
99 
101  Bool_t InsChar(TGLongPosition pos, char c);
102  char GetChar(TGLongPosition pos);
103 
105  Bool_t InsText(TGLongPosition pos, const char *buf);
106  Bool_t InsText(TGLongPosition ins_pos, TGText *src, TGLongPosition start_src, TGLongPosition end_src);
108 
109  Bool_t DelLine(ULong_t pos);
110  char *GetLine(TGLongPosition pos, ULong_t length);
111  TString AsString();
112  TGTextLine *GetCurrentLine() const { return fCurrent; }
114  Bool_t InsLine(ULong_t row, const char *string);
115 
116  Long_t RowCount() const { return fRowCount; }
117  Long_t ColCount() const { return fColCount; }
118 
120  Long_t GetLongestLine() const { return fLongestLine; }
121 
122  void ReTab(Long_t row);
123 
124  Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString,
125  Bool_t direction, Bool_t caseSensitive);
126  Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText,
127  Bool_t direction, Bool_t caseSensitive);
128 
129  ClassDef(TGText,0) // Text used by TGTextEdit
130 };
131 
132 #endif
c
#define c(i)
Definition: RSha256.hxx:119
TGText::InsLine
Bool_t InsLine(ULong_t row, const char *string)
Insert string before specified position.
Definition: TGText.cxx:928
TGText::fFirst
TGTextLine * fFirst
Definition: TGText.h:72
TGText::TGText
TGText()
Create default (empty) text buffer.
Definition: TGText.cxx:363
TGText::operator=
TGText & operator=(const TGText &)
assignment operator
Definition: TGText.cxx:331
TGText::GetChar
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
Definition: TGText.cxx:723
TGText::Init
void Init()
Common initialization method.
Definition: TGText.cxx:349
TGText::BreakLine
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition: TGText.cxx:1008
TGText::DelText
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Definition: TGText.cxx:736
TString::Data
const char * Data() const
Definition: TString.h:369
TGText::Search
Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString, Bool_t direction, Bool_t caseSensitive)
Search for string searchString starting at the specified position going in forward (direction = true)...
Definition: TGText.cxx:1143
TGText::Append
Bool_t Append(const char *fn)
Append buffer to file fn.
Definition: TGText.cxx:651
TGTextLine::fLength
ULong_t fLength
Definition: TGText.h:43
TGText::InsText
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
Definition: TGText.cxx:888
TGText::AddText
Bool_t AddText(TGText *text)
Add another text buffer to this buffer.
Definition: TGText.cxx:911
TGText::Replace
Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace oldText by newText. Returns false if nothing replaced.
Definition: TGText.cxx:1197
TGTextLine::~TGTextLine
virtual ~TGTextLine()
Delete a line of text.
Definition: TGText.cxx:116
TGText::InsChar
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
Definition: TGText.cxx:707
TGDimension.h
TGText
Definition: TGText.h:67
TGTextLine::GetLineLength
ULong_t GetLineLength()
Definition: TGText.h:57
TGTextLine::Clear
void Clear()
Clear a line of text.
Definition: TGText.cxx:125
TGText::GetCurrentLine
TGTextLine * GetCurrentLine() const
Definition: TGText.h:112
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGTextLine::DelChar
void DelChar(ULong_t pos)
Delete a character from the line.
Definition: TGText.cxx:263
text
TText * text
Definition: entrylist_figure1.C:10
TString.h
bool
TGText::RowCount
Long_t RowCount() const
Definition: TGText.h:116
TGText::LongestLine
void LongestLine()
Set fLongestLine.
Definition: TGText.cxx:1220
TGText::SetCurrentRow
Bool_t SetCurrentRow(Long_t row)
Make specified row the current row.
Definition: TGText.cxx:1055
TGTextLine::InsText
void InsText(ULong_t pos, const char *text)
Insert text in line starting at position pos.
Definition: TGText.cxx:161
TGText::~TGText
virtual ~TGText()
Destroy text buffer.
Definition: TGText.cxx:397
TGText::GetLongestLine
Long_t GetLongestLine() const
Definition: TGText.h:120
TGText::fCurrent
TGTextLine * fCurrent
Definition: TGText.h:73
TGText::fRowCount
Long_t fRowCount
Definition: TGText.h:75
TGText::Load
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
Definition: TGText.cxx:431
TGText::fCurrentRow
Long_t fCurrentRow
Definition: TGText.h:74
Long_t
long Long_t
Definition: RtypesCore.h:54
TGTextLine::operator=
TGTextLine & operator=(const TGTextLine &)
assignment operator
Definition: TGText.cxx:99
TGText::GetFileName
const char * GetFileName() const
Definition: TGText.h:98
TGText::GetLineLength
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition: TGText.cxx:1043
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGText::Clear
void Clear()
Clear text buffer.
Definition: TGText.cxx:406
line
TLine * line
Definition: entrylistblock_figure1.C:235
TGTextLine::TGTextLine
TGTextLine()
Create empty line of text (default ctor).
Definition: TGText.cxx:46
TGText::fLongestLine
Long_t fLongestLine
Definition: TGText.h:77
TGLongPosition
Definition: TGDimension.h:63
TGTextLine::GetWord
char * GetWord(ULong_t pos)
Get word at position. Returned string must be deleted.
Definition: TGText.cxx:204
TGText::LoadBuffer
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition: TGText.cxx:513
TGTextLine::DelText
void DelText(ULong_t pos, ULong_t length)
Delete length chars from line starting at position pos.
Definition: TGText.cxx:136
TGText::fColCount
Long_t fColCount
Definition: TGText.h:76
TGTextLine::fPrev
TGTextLine * fPrev
Definition: TGText.h:44
TGText::fIsSaved
Bool_t fIsSaved
Definition: TGText.h:71
TGTextLine::InsChar
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
Definition: TGText.cxx:282
TGText::DelLine
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Definition: TGText.cxx:964
TGText::Save
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition: TGText.cxx:610
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGTextLine::fString
char * fString
Definition: TGText.h:42
TGTextLine::GetChar
char GetChar(ULong_t pos)
Get a character at the specified position from the line.
Definition: TGText.cxx:303
TGTextLine
Definition: TGText.h:31
TGText::DelChar
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition: TGText.cxx:691
TGText::GetLine
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
Definition: TGText.cxx:997
TGTextLine::fNext
TGTextLine * fNext
Definition: TGText.h:45
TGText::AsString
TString AsString()
Returns content as ROOT string.
Definition: TGText.cxx:1238
TGTextLine::GetText
char * GetText() const
Definition: TGText.h:62
TGText::fFilename
TString fFilename
Definition: TGText.h:70
TGText::ReTab
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition: TGText.cxx:1087
TGText::ColCount
Long_t ColCount() const
Definition: TGText.h:117
TGText::IsSaved
Bool_t IsSaved() const
Definition: TGText.h:97