Logo ROOT   6.08/07
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();
87  Bool_t SetCurrentRow(Long_t row);
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);
111  Bool_t AddText(TGText *text);
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; }
117  Bool_t BreakLine(TGLongPosition pos);
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
Bool_t IsSaved() const
Definition: TGText.h:101
Long_t fCurrentRow
Definition: TGText.h:78
TGTextLine * fFirst
Definition: TGText.h:76
TGTextLine * fCurrent
Definition: TGText.h:77
TLine * line
return c
Definition: TGText.h:71
char * GetText() const
Definition: TGText.h:60
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
bool Bool_t
Definition: RtypesCore.h:59
Bool_t fIsSaved
Definition: TGText.h:75
friend class TGText
Definition: TGText.h:37
TGTextLine * fNext
Definition: TGText.h:43
char * fString
Definition: TGText.h:40
#define ClassDef(name, id)
Definition: Rtypes.h:254
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
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
Long_t ColCount() const
Definition: TGText.h:121
TGTextLine & operator=(const TGTextLine &)
assignment operator
Definition: TGText.cxx:98
const char * GetFileName() const
Definition: TGText.h:102
Long_t RowCount() const
Definition: TGText.h:120
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:79
TGTextLine * fPrev
Definition: TGText.h:42
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:81
unsigned long ULong_t
Definition: RtypesCore.h:51
TGTextLine * GetCurrentLine() const
Definition: TGText.h:116
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:80
void Clear()
Clear a line of text.
Definition: TGText.cxx:124
Long_t GetLongestLine() const
Definition: TGText.h:124
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:349