TGText.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGText.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Fons Rademakers   26/04/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGText
00013 #define ROOT_TGText
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGText                                                               //
00019 //                                                                      //
00020 // A TGText is a multi line text buffer. It allows the text to be       //
00021 // loaded from file, saved to file and edited. It is used in the        //
00022 // TGTextEdit widget. Single line text is handled by TGTextBuffer.      //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 #ifndef ROOT_TString
00027 #include "TString.h"
00028 #endif
00029 
00030 #ifndef ROOT_TGDimension
00031 #include "TGDimension.h"
00032 #endif
00033 
00034 
00035 class TGTextLine {
00036 
00037 friend class TGText;
00038 
00039 protected:
00040    char         *fString;   // line of text
00041    ULong_t       fLength;   // lenght of line
00042    TGTextLine   *fPrev;     // previous line
00043    TGTextLine   *fNext;     // next line
00044 
00045    TGTextLine(const TGTextLine&);
00046    TGTextLine& operator=(const TGTextLine&);
00047 
00048 public:
00049    TGTextLine();
00050    TGTextLine(TGTextLine *line);
00051    TGTextLine(const char *string);
00052    virtual ~TGTextLine();
00053 
00054    void Clear();
00055    ULong_t GetLineLength() { return fLength; }
00056 
00057    void DelText(ULong_t pos, ULong_t length);
00058    void InsText(ULong_t pos, const char *text);
00059    char *GetText(ULong_t pos, ULong_t length);
00060    char *GetText() const { return fString; }
00061    char *GetWord(ULong_t pos);
00062 
00063    void DelChar(ULong_t pos);
00064    void InsChar(ULong_t pos, char character);
00065    char GetChar(ULong_t pos);
00066 
00067    ClassDef(TGTextLine,0)  // Line in TGText
00068 };
00069 
00070 
00071 class TGText {
00072 
00073 protected:
00074    TString      fFilename;       // name of opened file ("" if open buffer)
00075    Bool_t       fIsSaved;        // false if text needs to be saved
00076    TGTextLine  *fFirst;          // first line of text
00077    TGTextLine  *fCurrent;        // current line
00078    Long_t       fCurrentRow;     // current row number
00079    Long_t       fRowCount;       // number of rows
00080    Long_t       fColCount;       // number of columns in current line
00081    Long_t       fLongestLine;    // length of longest line
00082 
00083    TGText(const TGText&);
00084    TGText& operator=(const TGText&);
00085 
00086    void     Init();
00087    Bool_t   SetCurrentRow(Long_t row);
00088    void     LongestLine();
00089 
00090 public:
00091    TGText();
00092    TGText(TGText *text);
00093    TGText(const char *string);
00094    virtual ~TGText();
00095 
00096    void    Clear();
00097    Bool_t  Load(const char *fn, Long_t startpos = 0, Long_t length = -1);
00098    Bool_t  LoadBuffer(const char *txtbuf);
00099    Bool_t  Save(const char *fn);
00100    Bool_t  Append(const char *fn);
00101    Bool_t  IsSaved() const { return fIsSaved; }
00102    const char *GetFileName() const { return fFilename.Data(); }
00103 
00104    Bool_t  DelChar(TGLongPosition pos);
00105    Bool_t  InsChar(TGLongPosition pos, char c);
00106    char    GetChar(TGLongPosition pos);
00107 
00108    Bool_t  DelText(TGLongPosition start, TGLongPosition end);
00109    Bool_t  InsText(TGLongPosition pos, const char *buf);
00110    Bool_t  InsText(TGLongPosition ins_pos, TGText *src, TGLongPosition start_src, TGLongPosition end_src);
00111    Bool_t  AddText(TGText *text);
00112 
00113    Bool_t  DelLine(ULong_t pos);
00114    char   *GetLine(TGLongPosition pos, ULong_t length);
00115    TString AsString();
00116    TGTextLine *GetCurrentLine() const { return fCurrent; }
00117    Bool_t  BreakLine(TGLongPosition pos);
00118    Bool_t  InsLine(ULong_t row, const char *string);
00119 
00120    Long_t  RowCount() const { return fRowCount; }
00121    Long_t  ColCount() const { return fColCount; }
00122 
00123    Long_t  GetLineLength(Long_t row);
00124    Long_t  GetLongestLine() const { return fLongestLine; }
00125 
00126    void    ReTab(Long_t row);
00127 
00128    Bool_t  Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString,
00129                   Bool_t direction, Bool_t caseSensitive);
00130    Bool_t  Replace(TGLongPosition start, const char *oldText, const char *newText,
00131                    Bool_t direction, Bool_t caseSensitive);
00132 
00133    ClassDef(TGText,0)  // Text used by TGTextEdit
00134 };
00135 
00136 #endif

Generated on Tue Jul 5 14:20:09 2011 for ROOT_528-00b_version by  doxygen 1.5.1