Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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&);
42  TGTextLine& operator=(const TGTextLine&);
43 
44 public:
45  TGTextLine();
46  TGTextLine(TGTextLine *line);
47  TGTextLine(const char *string);
48  virtual ~TGTextLine();
49 
50  void Clear();
51  ULong_t GetLineLength() { return fLength; }
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 
100  Bool_t DelChar(TGLongPosition pos);
101  Bool_t InsChar(TGLongPosition pos, char c);
102  char GetChar(TGLongPosition pos);
103 
104  Bool_t DelText(TGLongPosition start, TGLongPosition end);
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 
119  Long_t GetLineLength(Long_t row);
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