Logo ROOT   6.14/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 
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();
83  Bool_t SetCurrentRow(Long_t row);
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);
107  Bool_t AddText(TGText *text);
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; }
113  Bool_t BreakLine(TGLongPosition pos);
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
TLine * line
Definition: TGText.h:67
char * GetText() const
Definition: TGText.h:56
unsigned int Replace(std::string &s, const std::string what, const std::string withWhat)
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 fIsSaved
Definition: TGText.h:71
friend class TGText
Definition: TGText.h:33
TGTextLine * fNext
Definition: TGText.h:39
char * fString
Definition: TGText.h:36
#define ClassDef(name, id)
Definition: Rtypes.h:320
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:121
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
TGTextLine & operator=(const TGTextLine &)
assignment operator
Definition: TGText.cxx:98
const char * GetFileName() const
Definition: TGText.h:98
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
Long_t fRowCount
Definition: TGText.h:75
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
TGTextLine * GetCurrentLine() const
Definition: TGText.h:112
RooCmdArg Save(Bool_t flag=kTRUE)
void InsChar(ULong_t pos, char character)
Insert a character at the specified position.
Definition: TGText.cxx:281
Long_t fColCount
Definition: TGText.h:76
#define c(i)
Definition: RSha256.hxx:101
void Clear()
Clear a line of text.
Definition: TGText.cxx:124
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
const char * Data() const
Definition: TString.h:364