Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGView.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 30/6/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_TGView
13 #define ROOT_TGView
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGView //
19 // //
20 // A TGView provides the infrastructure for text viewer and editor //
21 // widgets. It provides a canvas (TGViewFrame) and (optionally) a //
22 // vertical and horizontal scrollbar and methods for marking and //
23 // scrolling. //
24 // //
25 // The TGView (and derivatives) will generate the following //
26 // event messages: //
27 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
28 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
29 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
30 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
31 // kC_TEXTVIEW, kTXT_F3, widget id, true //
32 // //
33 //////////////////////////////////////////////////////////////////////////
34 
35 #include "TGFrame.h"
36 #include "TGWidget.h"
37 #include "TTimer.h"
38 
39 class TGViewFrame;
40 class TGHScrollBar;
41 class TGVScrollBar;
42 
43 class TGView : public TGCompositeFrame, public TGWidget {
44 
45 friend class TGViewFrame;
46 
47 public:
48  enum { kNoHSB = BIT(0), kNoVSB = BIT(1) };
49  enum { kHorizontal = 0, kVertical = 1 };
50 
51 protected:
52  TGLongPosition fVisible; // position of visible region
53  TGLongPosition fMousePos; // position of mouse
54  TGLongPosition fScrollVal; // scroll value
55  TGDimension fVirtualSize; // the current virtual window size
56  TGRectangle fExposedRegion;// exposed area
57 
58  Int_t fScrolling; // scrolling direction
59  Atom_t fClipboard; // clipboard property
60  UInt_t fXMargin; // x margin
61  UInt_t fYMargin; // y margin
62  TGViewFrame *fCanvas; // frame containing the text
63  TGHScrollBar *fHsb; // horizontal scrollbar
64  TGVScrollBar *fVsb; // vertical scrollbar
65 
66  TGGC fWhiteGC; // graphics context used for scrolling
67  // generates GraphicsExposure events
68 
69  virtual void DoRedraw();
70  virtual void UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
71  virtual Bool_t ItemLayout() { return kFALSE; }
72 
73 private:
74  TGView(const TGView&); // not implemented
75  TGView& operator=(const TGView&); // not implemented
76 
77 public:
78  TGView(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
79  UInt_t xMargin = 0, UInt_t yMargin = 0,
80  UInt_t options = kSunkenFrame | kDoubleBorder,
81  UInt_t sboptions = 0,
82  Pixel_t back = GetWhitePixel());
83 
84  virtual ~TGView();
85 
86  TGViewFrame *GetCanvas() const { return fCanvas; }
87 
88  virtual void Clear(Option_t * = "");
89  virtual void SetVisibleStart(Int_t newTop, Int_t direction);
90  virtual void ScrollCanvas(Int_t newTop, Int_t direction);
91  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
92  virtual void DrawBorder();
93  virtual void Layout();
94  virtual void SetLayoutManager(TGLayoutManager*) { }
95  virtual void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height);
96 
97  virtual void ScrollToPosition(TGLongPosition newPos);
98  void ScrollUp(Int_t pixels)
99  { ScrollToPosition(TGLongPosition(fVisible.fX, fVisible.fY + pixels)); }
100  void ScrollDown(Int_t pixels)
101  { ScrollToPosition(TGLongPosition(fVisible.fX, fVisible.fY - pixels)); }
102  void ScrollLeft(Int_t pixels)
103  { ScrollToPosition(TGLongPosition(fVisible.fX + pixels, fVisible.fY)); }
104  void ScrollRight(Int_t pixels)
105  { ScrollToPosition(TGLongPosition(fVisible.fX - pixels, fVisible.fY)); }
106 
107  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
108  TGDimension GetVirtualSize() const { return fVirtualSize; }
109  TGLongPosition GetScrollValue() const { return fScrollVal; }
110  TGLongPosition GetScrollPosition() const { return fVisible; }
111 
112  TGLongPosition ToVirtual(TGLongPosition coord) const { return coord + fVisible; }
113  TGLongPosition ToPhysical(TGLongPosition coord) const { return coord - fVisible; }
114 
115  virtual Bool_t HandleButton(Event_t *event);
116  virtual Bool_t HandleExpose(Event_t *event);
117 
118  virtual void ChangeBackground(Pixel_t);
119  virtual void SetBackgroundColor(Pixel_t);
120  virtual void SetBackgroundPixmap(Pixmap_t p);
121  virtual void UpdateBackgroundStart();
122 
123  const TGGC &GetViewWhiteGC() { return fWhiteGC; }
124 
125  ClassDef(TGView,0) // View widget base class
126 };
127 
128 
129 class TGViewFrame : public TGCompositeFrame {
130 private:
131  TGView *fView; // pointer back to the view
132 
133  TGViewFrame(const TGViewFrame&); // not implemented
134  TGViewFrame& operator=(const TGViewFrame&); // not implemented
135 
136 public:
137  TGViewFrame(TGView *v, UInt_t w, UInt_t h, UInt_t options = 0,
138  Pixel_t back = GetWhitePixel());
139 
140  Bool_t HandleSelectionRequest(Event_t *event)
141  { return fView->HandleSelectionRequest(event); }
142  Bool_t HandleSelectionClear(Event_t *event)
143  { return fView->HandleSelectionClear(event); }
144  Bool_t HandleSelection(Event_t *event)
145  { return fView->HandleSelection(event); }
146  Bool_t HandleButton(Event_t *event)
147  { return fView->HandleButton(event); }
148  Bool_t HandleExpose(Event_t *event)
149  { return fView->HandleExpose(event); }
150  Bool_t HandleCrossing(Event_t *event)
151  { return fView->HandleCrossing(event); }
152  Bool_t HandleMotion(Event_t *event)
153  { return fView->HandleMotion(event); }
154  Bool_t HandleKey(Event_t *event)
155  { return fView->HandleKey(event); }
156  Bool_t HandleDoubleClick(Event_t *event)
157  { return fView->HandleDoubleClick(event); }
158 
159  ClassDef(TGViewFrame,0) // Frame containing the actual text
160 };
161 
162 
163 
164 #endif