Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGTextView.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 1/7/2000
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_TGTextView
13 #define ROOT_TGTextView
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGTextView //
19 // //
20 // A TGTextView is a text viewer widget. It is a specialization of //
21 // TGView. It uses the TGText class (which contains all text //
22 // manipulation code, i.e. loading a file in memory, changing, //
23 // removing lines, etc.). Use a TGTextView to view non-editable text. //
24 // For supported messages see TGView. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TGView.h"
29 #include "TGText.h"
30 
31 class TViewTimer;
32 
33 class TGTextView : public TGView {
34 
35 protected:
36  TGText *fText; // text buffer
37  TGText *fClipText; // clipboard text buffer
38  FontStruct_t fFont; // text font
39  Int_t fMaxAscent; // maximum ascent in font
40  Int_t fMaxDescent; // maximum descent in font
41  Int_t fMaxWidth; // maximum width of character in font
42  TGGC fNormGC; // graphics context for drawing text
43  TGGC fSelGC; // graphics context for drawing marked text
44  TGGC fSelbackGC; // graphics context for drawing marked background
45  Bool_t fMarkedFromX; // true if text is marked from x
46  Bool_t fMarkedFromY; // true if text is marker from y
47  Bool_t fIsMarked; // true if text is marked/selected
48  Bool_t fIsMarking; // true if in marking mode
49  Bool_t fIsSaved; // true is content is saved
50  Bool_t fReadOnly; // text cannot be editted
51  TGLongPosition fMarkedStart; // start position of marked text
52  TGLongPosition fMarkedEnd; // end position of marked text
53  TViewTimer *fScrollTimer; // scrollbar timer
54  Atom_t *fDNDTypeList; // handles DND types
55 
56  static const TGFont *fgDefaultFont;
57  static TGGC *fgDefaultGC;
58  static TGGC *fgDefaultSelectedGC;
59  static const TGGC *fgDefaultSelectedBackgroundGC;
60 
61  void Init(Pixel_t bg);
62  virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
63  virtual void Mark(Long_t xPos, Long_t yPos);
64  virtual void UnMark();
65  virtual void Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
66  virtual void HLayout();
67  virtual void VLayout();
68 
69  static FontStruct_t GetDefaultFontStruct();
70  static const TGGC &GetDefaultGC();
71  static const TGGC &GetDefaultSelectedGC();
72  static const TGGC &GetDefaultSelectedBackgroundGC();
73 
74 private:
75  TGTextView(const TGTextView&);
76  TGTextView& operator=(const TGTextView&);
77 
78 public:
79  TGTextView(const TGWindow *parent = 0, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
80  UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
81  TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
82  Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
83  TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
84  Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
85 
86  virtual ~TGTextView();
87 
88  virtual Bool_t IsSaved() { fIsSaved = fText->IsSaved(); return fIsSaved;}
89  virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line);
90  virtual Long_t ToObjYCoord(Long_t yCoord);
91  virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line);
92  virtual Long_t ToScrYCoord(Long_t yCoord);
93  virtual void AdjustWidth();
94  virtual Bool_t LoadFile(const char *fname, long startpos = 0, long length = -1);
95  virtual Bool_t LoadBuffer(const char *txtbuf);
96  virtual void Clear(Option_t * = "");
97  virtual Bool_t Copy();
98  virtual Bool_t SelectAll();
99  virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
100  virtual void SetFont(FontStruct_t font);
101  virtual Long_t ReturnHeighestColHeight() { return fText->RowCount()*fScrollVal.fY; }
102  virtual Long_t ReturnLongestLineWidth();
103  virtual Long_t ReturnLineLength(Long_t line) { return fText->GetLineLength(line); }
104  virtual Long_t ReturnLongestLine() { return fText->GetLongestLine(); }
105  virtual Long_t ReturnLineCount() { return fText->RowCount(); }
106 
107  virtual void SetSBRange(Int_t direction);
108  virtual void SetHsbPosition(Long_t newPos);
109  virtual void SetVsbPosition(Long_t newPos);
110  virtual void ShowBottom();
111  virtual void ShowTop();
112 
113  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
114  virtual void SetText(TGText *text);
115  virtual void AddText(TGText *text);
116  virtual void AddLine(const char *string);
117  virtual void AddLineFast(const char *string);
118  virtual void Update();
119  virtual void Layout();
120 
121  virtual void SetBackground(Pixel_t p);
122  virtual void SetSelectBack(Pixel_t p);
123  virtual void SetSelectFore(Pixel_t p);
124  virtual void SetForegroundColor(Pixel_t);
125 
126  TGText *GetText() const { return fText; }
127 
128  virtual void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; } //*TOGGLE* *GETTER=IsReadOnly
129  Bool_t IsReadOnly() const { return fReadOnly; }
130  Bool_t IsMarked() const { return fIsMarked; }
131 
132  virtual Bool_t HandleDNDDrop(TDNDData *data);
133  virtual Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action,
134  Int_t xroot, Int_t yroot);
135  virtual Atom_t HandleDNDEnter(Atom_t * typelist);
136  virtual Bool_t HandleDNDLeave();
137 
138  virtual Bool_t HandleButton(Event_t *event);
139  virtual Bool_t HandleDoubleClick(Event_t *event);
140  virtual Bool_t HandleSelectionClear(Event_t *event);
141  virtual Bool_t HandleSelectionRequest(Event_t *event);
142  virtual Bool_t HandleMotion(Event_t *event);
143  virtual Bool_t HandleTimer(TTimer *t);
144  virtual Bool_t HandleCrossing(Event_t *event);
145 
146  virtual void DataChanged() { Emit("DataChanged()"); } //*SIGNAL*
147  virtual void DataDropped(const char *fname) { Emit("DataDropped(char *)", fname); } //*SIGNAL*
148  virtual void Marked(Bool_t mark) { Emit("Marked(Bool_t)", mark); } // *SIGNAL*
149  virtual void Clicked(const char *word) { Emit("Clicked(char *)", word); } //*SIGNAL*
150  virtual void DoubleClicked(const char *word) { Emit("DoubleClicked(char *)", word); } //*SIGNAL*
151 
152  ClassDef(TGTextView,0) // Non-editable text viewer widget
153 };
154 
155 
156 class TViewTimer : public TTimer {
157 private:
158  TGView *fView;
159 
160  TViewTimer(const TViewTimer&); // not implemented
161  TViewTimer& operator=(const TViewTimer&); // not implemented
162 
163 public:
164  TViewTimer(TGView *t, Long_t ms) : TTimer(ms, kTRUE), fView(t) { }
165  Bool_t Notify();
166 };
167 
168 
169 #endif