ROOT  6.06/09
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 #ifndef ROOT_TString
27 #include "TString.h"
28 #endif
29 
30 #ifndef ROOT_TGDimension
31 #include "TGDimension.h"
32 #endif
33 
34 
35 class TGTextLine {
36 
37 friend class TGText;
38 
39 protected:
40  char *fString; // line of text
41  ULong_t fLength; // length of line
42  TGTextLine *fPrev; // previous line
43  TGTextLine *fNext; // next line
44 
45  TGTextLine(const TGTextLine&);
47 
48 public:
49  TGTextLine();
51  TGTextLine(const char *string);
52  virtual ~TGTextLine();
53 
54  void Clear();
56 
57  void DelText(ULong_t pos, ULong_t length);
58  void InsText(ULong_t pos, const char *text);
59  char *GetText(ULong_t pos, ULong_t length);
60  char *GetText() const { return fString; }
61  char *GetWord(ULong_t pos);
62 
63  void DelChar(ULong_t pos);
64  void InsChar(ULong_t pos, char character);
65  char GetChar(ULong_t pos);
66 
67  ClassDef(TGTextLine,0) // Line in TGText
68 };
69 
70 
71 class TGText {
72 
73 protected:
74  TString fFilename; // name of opened file ("" if open buffer)
75  Bool_t fIsSaved; // false if text needs to be saved
76  TGTextLine *fFirst; // first line of text
77  TGTextLine *fCurrent; // current line
78  Long_t fCurrentRow; // current row number
79  Long_t fRowCount; // number of rows
80  Long_t fColCount; // number of columns in current line
81  Long_t fLongestLine; // length of longest line
82 
83  TGText(const TGText&);
84  TGText& operator=(const TGText&);
85 
86  void Init();
88  void LongestLine();
89 
90 public:
91  TGText();
92  TGText(TGText *text);
93  TGText(const char *string);
94  virtual ~TGText();
95 
96  void Clear();
97  Bool_t Load(const char *fn, Long_t startpos = 0, Long_t length = -1);
98  Bool_t LoadBuffer(const char *txtbuf);
99  Bool_t Save(const char *fn);
100  Bool_t Append(const char *fn);
101  Bool_t IsSaved() const { return fIsSaved; }
102  const char *GetFileName() const { return fFilename.Data(); }
103 
105  Bool_t InsChar(TGLongPosition pos, char c);
106  char GetChar(TGLongPosition pos);
107 
109  Bool_t InsText(TGLongPosition pos, const char *buf);
110  Bool_t InsText(TGLongPosition ins_pos, TGText *src, TGLongPosition start_src, TGLongPosition end_src);
112 
113  Bool_t DelLine(ULong_t pos);
114  char *GetLine(TGLongPosition pos, ULong_t length);
115  TString AsString();
116  TGTextLine *GetCurrentLine() const { return fCurrent; }
118  Bool_t InsLine(ULong_t row, const char *string);
119 
120  Long_t RowCount() const { return fRowCount; }
121  Long_t ColCount() const { return fColCount; }
122 
124  Long_t GetLongestLine() const { return fLongestLine; }
125 
126  void ReTab(Long_t row);
127 
128  Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString,
129  Bool_t direction, Bool_t caseSensitive);
130  Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText,
131  Bool_t direction, Bool_t caseSensitive);
132 
133  ClassDef(TGText,0) // Text used by TGTextEdit
134 };
135 
136 #endif
char * GetText() const
Definition: TGText.h:60
Long_t fCurrentRow
Definition: TGText.h:78
TGTextLine * fFirst
Definition: TGText.h:76
TGTextLine * fCurrent
Definition: TGText.h:77
TGText()
Create default (empty) text buffer.
Definition: TGText.cxx:362
Bool_t Append(const char *fn)
Append buffer to file fn.
Definition: TGText.cxx:650
TLine * line
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
Definition: TGText.cxx:887
Definition: TGText.h:71
void Clear()
Clear text buffer.
Definition: TGText.cxx:405
virtual ~TGTextLine()
Delete a line of text.
Definition: TGText.cxx:115
void DelText(ULong_t pos, ULong_t length)
Delete length chars from line starting at position pos.
Definition: TGText.cxx:135
Basic string class.
Definition: TString.h:137
Long_t GetLongestLine() const
Definition: TGText.h:124
bool Bool_t
Definition: RtypesCore.h:59
Long_t RowCount() const
Definition: TGText.h:120
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition: TGText.cxx:1007
Long_t ColCount() const
Definition: TGText.h:121
Bool_t fIsSaved
Definition: TGText.h:75
TGTextLine * fNext
Definition: TGText.h:43
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition: TGText.cxx:512
const char * Data() const
Definition: TString.h:349
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition: TGText.cxx:690
char * fString
Definition: TGText.h:40
#define ClassDef(name, id)
Definition: Rtypes.h:254
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:1196
ULong_t fLength
Definition: TGText.h:41
TString fFilename
Definition: TGText.h:74
void DelChar(ULong_t pos)
Delete a character from the line.
Definition: TGText.cxx:262
ULong_t GetLineLength()
Definition: TGText.h:55
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
Definition: TGText.cxx:996
TGTextLine & operator=(const TGTextLine &)
assignment operator
Definition: TGText.cxx:98
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
Definition: TGText.cxx:430
TGTextLine * GetCurrentLine() const
Definition: TGText.h:116
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
char * GetWord(ULong_t pos)
Get word at position. Returned string must be deleted.
Definition: TGText.cxx:203
void InsText(ULong_t pos, const char *text)
Insert text in line starting at position pos.
Definition: TGText.cxx:160
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:1142
Long_t fRowCount
Definition: TGText.h:79
TGText & operator=(const TGText &)
assignment operator
Definition: TGText.cxx:330
Bool_t IsSaved() const
Definition: TGText.h:101
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
Definition: TGText.cxx:722
void Init()
Common initialization method.
Definition: TGText.cxx:348
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Definition: TGText.cxx:735
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition: TGText.cxx:609
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition: TGText.cxx:1042
TGTextLine * fPrev
Definition: TGText.h:42
long Long_t
Definition: RtypesCore.h:50
TText * text
Long_t fLongestLine
Definition: TGText.h:81
unsigned long ULong_t
Definition: RtypesCore.h:51
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
Definition: TGText.cxx:706
TString AsString()
Returns content as ROOT string.
Definition: TGText.cxx:1237
const char * GetFileName() const
Definition: TGText.h:102
Bool_t AddText(TGText *text)
Add another text buffer to this buffer.
Definition: TGText.cxx:910
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
Definition: TGText.cxx:281
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Definition: TGText.cxx:963
Long_t fColCount
Definition: TGText.h:80
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition: TGText.cxx:1086
Bool_t InsLine(ULong_t row, const char *string)
Insert string before specified position.
Definition: TGText.cxx:927
void Clear()
Clear a line of text.
Definition: TGText.cxx:124
void LongestLine()
Set fLongestLine.
Definition: TGText.cxx:1219
char GetChar(ULong_t pos)
Get a character at the specified position from the line.
Definition: TGText.cxx:302
Bool_t SetCurrentRow(Long_t row)
Make specified row the current row.
Definition: TGText.cxx:1054
virtual ~TGText()
Destroy text buffer.
Definition: TGText.cxx:396