Logo ROOT   6.18/05
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
32
33friend class TGText;
34
35protected:
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
44public:
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
67class TGText {
68
69protected:
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
86public:
87 TGText();
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
110 char *GetLine(TGLongPosition pos, ULong_t length);
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
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
#define c(i)
Definition: RSha256.hxx:101
unsigned long ULong_t
Definition: RtypesCore.h:51
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:326
virtual ~TGTextLine()
Delete a line of text.
Definition: TGText.cxx:115
TGTextLine * fPrev
Definition: TGText.h:38
char * fString
Definition: TGText.h:36
void DelChar(ULong_t pos)
Delete a character from the line.
Definition: TGText.cxx:262
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
Definition: TGText.cxx:281
char GetChar(ULong_t pos)
Get a character at the specified position from the line.
Definition: TGText.cxx:302
ULong_t GetLineLength()
Definition: TGText.h:51
char * GetText() const
Definition: TGText.h:56
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
TGTextLine * fNext
Definition: TGText.h:39
void Clear()
Clear a line of text.
Definition: TGText.cxx:124
TGTextLine()
Create empty line of text (default ctor).
Definition: TGText.cxx:45
void DelText(ULong_t pos, ULong_t length)
Delete length chars from line starting at position pos.
Definition: TGText.cxx:135
ULong_t fLength
Definition: TGText.h:37
TGTextLine & operator=(const TGTextLine &)
assignment operator
Definition: TGText.cxx:98
Definition: TGText.h:67
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
Definition: TGText.cxx:706
Long_t ColCount() const
Definition: TGText.h:117
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition: TGText.cxx:1086
virtual ~TGText()
Destroy text buffer.
Definition: TGText.cxx:396
Long_t fColCount
Definition: TGText.h:76
Bool_t AddText(TGText *text)
Add another text buffer to this buffer.
Definition: TGText.cxx:910
Long_t RowCount() const
Definition: TGText.h:116
Long_t GetLongestLine() const
Definition: TGText.h:120
TGTextLine * fFirst
Definition: TGText.h:72
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Definition: TGText.cxx:735
TString fFilename
Definition: TGText.h:70
TGText()
Create default (empty) text buffer.
Definition: TGText.cxx:362
Long_t fLongestLine
Definition: TGText.h:77
Long_t fRowCount
Definition: TGText.h:75
Bool_t fIsSaved
Definition: TGText.h:71
void LongestLine()
Set fLongestLine.
Definition: TGText.cxx:1219
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
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Definition: TGText.cxx:963
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition: TGText.cxx:609
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
Bool_t InsLine(ULong_t row, const char *string)
Insert string before specified position.
Definition: TGText.cxx:927
Bool_t SetCurrentRow(Long_t row)
Make specified row the current row.
Definition: TGText.cxx:1054
Long_t fCurrentRow
Definition: TGText.h:74
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition: TGText.cxx:690
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition: TGText.cxx:1007
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
Definition: TGText.cxx:887
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
Definition: TGText.cxx:996
TGTextLine * fCurrent
Definition: TGText.h:73
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
Definition: TGText.cxx:722
Bool_t IsSaved() const
Definition: TGText.h:97
Bool_t Load(const char *fn, Long_t startpos=0, Long_t length=-1)
Load text from file fn.
Definition: TGText.cxx:430
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition: TGText.cxx:512
void Clear()
Clear text buffer.
Definition: TGText.cxx:405
Bool_t Append(const char *fn)
Append buffer to file fn.
Definition: TGText.cxx:650
TGTextLine * GetCurrentLine() const
Definition: TGText.h:112
const char * GetFileName() const
Definition: TGText.h:98
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition: TGText.cxx:1042
void Init()
Common initialization method.
Definition: TGText.cxx:348
TString AsString()
Returns content as ROOT string.
Definition: TGText.cxx:1237
TGText & operator=(const TGText &)
assignment operator
Definition: TGText.cxx:330
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
TText * text
TLine * line