Logo ROOT   master
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:
45  TGTextLine();
47  TGTextLine(const char *string);
48  virtual ~TGTextLine();
49 
50  void Clear();
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
Bool_t IsSaved() const
Definition: TGText.h:97
Long_t fCurrentRow
Definition: TGText.h:74
TGTextLine * fFirst
Definition: TGText.h:72
TGTextLine * fCurrent
Definition: TGText.h:73
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:67
void Clear()
Clear text buffer.
Definition: TGText.cxx:405
char * GetText() const
Definition: TGText.h:56
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:131
bool Bool_t
Definition: RtypesCore.h:59
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition: TGText.cxx:1007
Bool_t fIsSaved
Definition: TGText.h:71
TGTextLine * fNext
Definition: TGText.h:39
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition: TGText.cxx:512
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition: TGText.cxx:690
char * fString
Definition: TGText.h:36
#define ClassDef(name, id)
Definition: Rtypes.h:326
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:37
TString fFilename
Definition: TGText.h:70
void DelChar(ULong_t pos)
Delete a character from the line.
Definition: TGText.cxx:262
ULong_t GetLineLength()
Definition: TGText.h:51
Long_t ColCount() const
Definition: TGText.h:117
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
const char * GetFileName() const
Definition: TGText.h:98
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
Definition: TGText.cxx:430
Long_t RowCount() const
Definition: TGText.h:116
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:75
TGText & operator=(const TGText &)
assignment operator
Definition: TGText.cxx:330
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:38
long Long_t
Definition: RtypesCore.h:50
TGTextLine()
Create empty line of text (default ctor).
Definition: TGText.cxx:45
TText * text
Long_t fLongestLine
Definition: TGText.h:77
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
TGTextLine * GetCurrentLine() const
Definition: TGText.h:112
TString AsString()
Returns content as ROOT string.
Definition: TGText.cxx:1237
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:76
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition: TGText.cxx:1086
#define c(i)
Definition: RSha256.hxx:101
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
Long_t GetLongestLine() const
Definition: TGText.h:120
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
const char * Data() const
Definition: TString.h:364