Logo ROOT   6.08/07
Reference Guide
TGCanvas.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 11/01/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_TGCanvas
13 #define ROOT_TGCanvas
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGCanvas and TGViewPort and TGContainer //
19 // //
20 // A TGCanvas is a frame containing two scrollbars (horizontal and //
21 // vertical) and a viewport. The viewport acts as the window through //
22 // which we look at the contents of the container frame. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TGFrame
27 #include "TGFrame.h"
28 #endif
29 
30 class TGHScrollBar;
31 class TGVScrollBar;
32 class TGClient;
33 class TGViewPort;
34 class TGCanvas;
35 class TGFrameElement;
36 class TGContainerTimer;
37 class TGContainerKeyboardTimer;
38 class TGContainerScrollTimer;
39 class TGListView;
40 class TGPicture;
41 class TGRectangle;
42 
43 class TGContainer : public TGCompositeFrame {
44 
45 friend class TGViewPort;
46 friend class TGCanvas;
49 friend class TGListView;
50 
51 protected:
52  TGViewPort *fViewPort; // container viewport
53  TGCanvas *fCanvas; // pointer to canvas
54  const TGWindow *fMsgWindow; // window handling container messages
55  TGFrameElement *fLastActiveEl; // last active item
56  Int_t fXp, fYp; // previous pointer position
57  Int_t fX0, fY0; // corner of rubber band box
58  Int_t fXf, fYf; // other corner of rubber band box
59  Bool_t fDragging; // true if in dragging mode
60  Int_t fTotal; // total items
61  Int_t fSelected; // number of selected items
62  TTimer *fScrollTimer; // autoscroll timer
63  Bool_t fOnMouseOver; // kTRUE when mouse pointer is over entry
64  Bool_t fLastDir; // direction of last search
65  Bool_t fLastCase; // case sensetivity of last search
66  Bool_t fLastSubstring; // substring search option of last search
67  TString fLastName; // the name of object of last search
68  TTimer *fKeyTimer; // keyboard timer
69  TString fKeyInput; // keyboard input (buffer)
70  Bool_t fKeyTimerActive;// kTRUE - keyboard timer is active
71  Bool_t fScrolling; // kTRUE - when scrolling is ON
74  TGRectangle fExposedRegion; // exposed area
75 
76  static TGGC *fgLineGC;
77  static const TGGC &GetLineGC();
78 
79  virtual void DoRedraw();
80  virtual void ActivateItem(TGFrameElement* el);
81  virtual void DeActivateItem(TGFrameElement* el);
82  virtual void SearchPattern();
83  virtual void OnAutoScroll();
84  virtual void RepeatSearch();
85 
86 private:
87  TGContainer(const TGContainer&); // not implemented
88  TGContainer& operator=(const TGContainer&); // not implemented
89 
90 public:
91  TGContainer(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
92  UInt_t options = kSunkenFrame,
96 
97  virtual ~TGContainer();
98 
99  virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
100  virtual void ClearViewPort();
101  virtual void Associate(const TGWindow *w) { fMsgWindow = w; }
102  virtual void AdjustPosition();
103  virtual void SetPagePosition(const TGPosition& pos);
104  virtual void SetPagePosition(Int_t x, Int_t y);
105  virtual void SetPageDimension(const TGDimension& dim);
106  virtual void SetPageDimension(UInt_t w, UInt_t h);
107  virtual void RemoveAll();
108  virtual void RemoveItem(TGFrame *item);
109  virtual void Layout();
110 
111  TGCanvas *GetCanvas() const { return fCanvas; }
112  const TGWindow *GetMessageWindow() const { return fMsgWindow; }
113  virtual TGPosition GetPagePosition() const;
114  virtual TGDimension GetPageDimension() const;
115 
116  virtual Int_t NumSelected() const { return fSelected; }
117  virtual Int_t NumItems() const { return fTotal; }
118  virtual TGFrameElement *FindFrame(Int_t x,Int_t y,Bool_t exclude=kTRUE);
119  virtual TGFrame *FindFrameByName(const char *name);
120  virtual TGHScrollBar *GetHScrollbar() const;
121  virtual TGVScrollBar *GetVScrollbar() const;
122  virtual void SetHsbPosition(Int_t newPos);
123  virtual void SetVsbPosition(Int_t newPos);
124  virtual void LineUp(Bool_t select = kFALSE);
125  virtual void LineDown(Bool_t select = kFALSE);
126  virtual void LineLeft(Bool_t select = kFALSE);
127  virtual void LineRight(Bool_t select = kFALSE);
128  virtual void PageUp(Bool_t select = kFALSE);
129  virtual void PageDown(Bool_t select = kFALSE);
130  virtual void Home(Bool_t select = kFALSE);
131  virtual void End(Bool_t select = kFALSE);
132  virtual void Search(Bool_t close = kTRUE);
133  virtual void *FindItem(const TString& name,
134  Bool_t direction = kTRUE,
135  Bool_t caseSensitive = kTRUE,
136  Bool_t subString = kFALSE);
137 
138  virtual const TGFrame *GetNextSelected(void **current);
139  virtual TGFrame *GetLastActive() const { return fLastActiveEl ? fLastActiveEl->fFrame : 0; }
140  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
141 
142  virtual Bool_t HandleDNDFinished() { fBdown = kFALSE; return kTRUE; }
143  virtual Bool_t HandleExpose(Event_t *event);
144  virtual Bool_t HandleButton(Event_t *event);
145  virtual Bool_t HandleDoubleClick(Event_t *event);
146  virtual Bool_t HandleMotion(Event_t *event);
147  virtual Bool_t HandleKey(Event_t *event);
148 
149  const TGPicture *GetObjPicture(TGFrame *f);
150  virtual void SetDragPixmap(const TGPicture *pic);
151 
152  virtual void SelectAll(); //*SIGNAL*
153  virtual void UnSelectAll(); //*SIGNAL*
154  virtual void InvertSelection(); //*SIGNAL*
155  virtual void ReturnPressed(TGFrame*); //*SIGNAL*
156  virtual void SpacePressed(TGFrame*); //*SIGNAL*
157  virtual void KeyPressed(TGFrame*, UInt_t keysym, UInt_t mask); //*SIGNAL*
158  virtual void OnMouseOver(TGFrame*); //*SIGNAL*
159  virtual void CurrentChanged(Int_t x,Int_t y);//*SIGNAL*
160  virtual void CurrentChanged(TGFrame* f); //*SIGNAL*
161  virtual void Clicked(TGFrame *f, Int_t btn); //*SIGNAL*
162  virtual void DoubleClicked(TGFrame *f, Int_t btn); //*SIGNAL*
163  virtual void DoubleClicked(TGFrame *f, Int_t btn, Int_t x, Int_t y); //*SIGNAL*
164  virtual void Clicked(TGFrame *f, Int_t btn, Int_t x, Int_t y); //*SIGNAL*
165 
166  ClassDef(TGContainer,0) // Canvas container
167 };
168 
169 
170 class TGViewPort : public TGCompositeFrame {
171 
172 protected:
173  Int_t fX0, fY0; // position of container frame in viewport
174  TGFrame *fContainer; // container frame
175 
176 private:
177  TGViewPort(const TGViewPort&); // not implemented
178  TGViewPort& operator=(const TGViewPort&); // not implemented
179 
180 public:
181  TGViewPort(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
182  UInt_t options = kChildFrame,
184 
185  TGFrame *GetContainer() const { return fContainer; }
186  void SetContainer(TGFrame *f);
187 
188  virtual void DrawBorder() { };
189  virtual void Layout() { }
190  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
191 
192  virtual void SetHPos(Int_t xpos);
193  virtual void SetVPos(Int_t ypos);
194  void SetPos(Int_t xpos, Int_t ypos);
195 
196  Int_t GetHPos() const { return fX0; }
197  Int_t GetVPos() const { return fY0; }
198  virtual Bool_t HandleConfigureNotify(Event_t *event);
199 
200  ClassDef(TGViewPort,0) // Viewport through which to look at a container frame
201 };
202 
203 
204 class TGCanvas : public TGFrame {
205 
206 protected:
207  TGViewPort *fVport; // viewport through which we look at contents
208  TGHScrollBar *fHScrollbar; // horizontal scrollbar
209  TGVScrollBar *fVScrollbar; // vertical scrollbar
210  Int_t fScrolling; // flag which scrolling modes are allowed
211 
212 private:
213  TGCanvas(const TGCanvas&); // not implemented
214  TGCanvas& operator=(const TGCanvas&); // not implemented
215 
216 public:
217  enum { kCanvasNoScroll = 0,
218  kCanvasScrollHorizontal = BIT(0),
219  kCanvasScrollVertical = BIT(1),
220  kCanvasScrollBoth = (kCanvasScrollHorizontal | kCanvasScrollVertical)
221  };
222 
223  TGCanvas(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
224  UInt_t options = kSunkenFrame | kDoubleBorder,
226  virtual ~TGCanvas();
227 
228  TGFrame *GetContainer() const { return fVport->GetContainer(); }
229  TGViewPort *GetViewPort() const { return fVport; }
230  TGHScrollBar *GetHScrollbar() const { return fHScrollbar; }
231  TGVScrollBar *GetVScrollbar() const { return fVScrollbar; }
232 
233  virtual void AddFrame(TGFrame *f, TGLayoutHints *l = 0);
234  virtual void SetContainer(TGFrame *f) { fVport->SetContainer(f); }
235  virtual void MapSubwindows();
236  virtual void DrawBorder();
237  virtual void Layout();
238  virtual void ClearViewPort();
239  virtual Int_t GetHsbPosition() const;
240  virtual Int_t GetVsbPosition() const;
241  virtual void SetHsbPosition(Int_t newPos);
242  virtual void SetVsbPosition(Int_t newPos);
243  void SetScrolling(Int_t scrolling);
244  Int_t GetScrolling() const { return fScrolling; }
245 
246  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
247  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
248 
249  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
250 
251  ClassDef(TGCanvas,0) // A canvas with two scrollbars and a viewport
252 };
253 
254 
255 #endif
TGContainer & operator=(const TGContainer &)
virtual void ReturnPressed(TGFrame *)
Signal emitted when Return/Enter key pressed.
Definition: TGCanvas.cxx:479
Int_t fYf
Definition: TGCanvas.h:58
virtual void PageDown(Bool_t select=kFALSE)
Move position one page down.
Definition: TGCanvas.cxx:2024
virtual void LineLeft(Bool_t select=kFALSE)
Move current position one column left.
Definition: TGCanvas.cxx:1848
virtual Int_t NumSelected() const
Definition: TGCanvas.h:116
virtual void CurrentChanged(Int_t x, Int_t y)
Emit signal when current position changed.
Definition: TGCanvas.cxx:429
virtual const TGFrame * GetNextSelected(void **current)
Return the next selected item.
Definition: TGCanvas.cxx:678
Int_t GetScrolling() const
Definition: TGCanvas.h:244
Int_t fSelected
Definition: TGCanvas.h:61
virtual void DrawBorder()
Draw frame border.
Definition: TGCanvas.h:188
virtual void RemoveAll()
Remove all items from the container.
Definition: TGCanvas.cxx:638
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGCanvas.h:189
const char Option_t
Definition: RtypesCore.h:62
virtual void SetPageDimension(const TGDimension &dim)
Set page dimension.
Definition: TGCanvas.cxx:779
virtual void End(Bool_t select=kFALSE)
Move to the bottom-right corner of container.
Definition: TGCanvas.cxx:2085
#define BIT(n)
Definition: Rtypes.h:120
Bool_t fBdown
Definition: TGCanvas.h:73
TH1 * h
Definition: legend2.C:5
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGCanvas.h:190
virtual void SetContainer(TGFrame *f)
Definition: TGCanvas.h:234
static const TGGC & GetLineGC()
Get graphics context for line drawing.
Definition: TGCanvas.cxx:2102
virtual void DrawBorder()
Draw frame border.
Definition: TGFrame.cxx:403
virtual void Associate(const TGWindow *w)
Definition: TGCanvas.h:101
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void AdjustPosition()
Move content to position of highlighted/activated frame.
Definition: TGCanvas.cxx:1790
TGCanvas * fCanvas
Definition: TGCanvas.h:53
TGFrame * GetContainer() const
Definition: TGCanvas.h:228
const TGWindow * fMsgWindow
Definition: TGCanvas.h:54
virtual void OnAutoScroll()
Autoscroll while close to & beyond The Wall.
Definition: TGCanvas.cxx:1492
Int_t GetVPos() const
Definition: TGCanvas.h:197
Int_t fY0
Definition: TGCanvas.h:57
virtual TGPosition GetPagePosition() const
Returns page position.
Definition: TGCanvas.cxx:734
virtual void Home(Bool_t select=kFALSE)
Move to upper-left corner of container.
Definition: TGCanvas.cxx:2068
virtual TGDimension GetPageDimension() const
Returns page dimension.
Definition: TGCanvas.cxx:748
virtual TGFrameElement * FindFrame(Int_t x, Int_t y, Bool_t exclude=kTRUE)
Find frame located int container at position x,y.
Definition: TGCanvas.cxx:1654
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual void SetHsbPosition(Int_t newPos)
set new hor. position
Definition: TGCanvas.cxx:1774
TGFrameElement * fLastActiveEl
Definition: TGCanvas.h:55
virtual void SelectAll()
Select all items in the container.
Definition: TGCanvas.cxx:562
virtual void PageUp(Bool_t select=kFALSE)
Move position one page up.
Definition: TGCanvas.cxx:1980
const TGPicture * GetObjPicture(TGFrame *f)
Retrieve icons associated with class "name".
Definition: TGCanvas.cxx:1036
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGCanvas.h:246
virtual TGVScrollBar * GetVScrollbar() const
returns pointer to vert. scroll bar
Definition: TGCanvas.cxx:1750
TGVScrollBar * fVScrollbar
Definition: TGCanvas.h:209
TTimer * fScrollTimer
Definition: TGCanvas.h:62
virtual void LineDown(Bool_t select=kFALSE)
Move one line down.
Definition: TGCanvas.cxx:1953
TTimer * fKeyTimer
Definition: TGCanvas.h:68
TGFrame * GetContainer() const
Definition: TGCanvas.h:185
virtual void * FindItem(const TString &name, Bool_t direction=kTRUE, Bool_t caseSensitive=kTRUE, Bool_t subString=kFALSE)
Definition: TGCanvas.cxx:1687
TGViewPort * GetViewPort() const
Definition: TGCanvas.h:229
virtual void RemoveItem(TGFrame *item)
Remove item from container.
Definition: TGCanvas.cxx:657
TString fLastName
Definition: TGCanvas.h:67
virtual void Layout()
Layout container entries.
Definition: TGCanvas.cxx:417
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a canvas container as a C++ statement(s) on output stream out.
Definition: TGCanvas.cxx:2501
Int_t GetHPos() const
Definition: TGCanvas.h:196
virtual void OnMouseOver(TGFrame *)
Signal emitted when pointer is over entry.
Definition: TGCanvas.cxx:496
virtual Bool_t HandleExpose(Event_t *event)
Handle expose events. Do not use double buffer.
Definition: TGCanvas.cxx:900
TGRectangle fExposedRegion
Definition: TGCanvas.h:74
virtual void DoubleClicked(TGFrame *f, Int_t btn)
Emit DoubleClicked() signal.
Definition: TGCanvas.cxx:533
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click mouse event.
Definition: TGCanvas.cxx:1095
Int_t fYp
Definition: TGCanvas.h:56
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
Definition: TGCanvas.cxx:1275
void SetContainer(TGFrame *f)
Add container frame to the viewport.
Definition: TGCanvas.cxx:148
virtual void InvertSelection()
Invert the selection, all selected items become unselected and vice versa.
Definition: TGCanvas.cxx:611
TGCanvas * GetCanvas() const
Definition: TGCanvas.h:111
Int_t fYDND
Definition: TGCanvas.h:72
virtual void SetDragPixmap(const TGPicture *pic)
Set drag window pixmaps and hotpoint.
Definition: TGCanvas.cxx:1077
virtual void SpacePressed(TGFrame *)
Signal emitted when space key pressed.
Definition: TGCanvas.cxx:488
Bool_t fKeyTimerActive
Definition: TGCanvas.h:70
Int_t fX0
Definition: TGCanvas.h:57
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void LineRight(Bool_t select=kFALSE)
Move current position one column right.
Definition: TGCanvas.cxx:1887
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a region of container in viewport.
Definition: TGCanvas.cxx:816
TGHScrollBar * GetHScrollbar() const
Definition: TGCanvas.h:230
Int_t fXf
Definition: TGCanvas.h:58
TGFrame * fFrame
Definition: TGLayout.h:125
TLine * l
Definition: textangle.C:4
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual Int_t NumItems() const
Definition: TGCanvas.h:117
virtual TGFrame * FindFrameByName(const char *name)
Find frame by name.
Definition: TGCanvas.cxx:1413
virtual Bool_t HandleDNDFinished()
Definition: TGCanvas.h:142
virtual TGHScrollBar * GetHScrollbar() const
returns pointer to hor. scroll bar
Definition: TGCanvas.cxx:1742
virtual Bool_t ProcessMessage(Long_t, Long_t, Long_t)
Definition: TGFrame.h:411
virtual void Search(Bool_t close=kTRUE)
Invokes search dialog. Looks for item with the entered name.
Definition: TGCanvas.cxx:1464
friend class TGContainerKeyboardTimer
Definition: TGCanvas.h:47
virtual ~TGContainer()
Delete canvas container.
Definition: TGCanvas.cxx:401
TGViewPort * fVport
Definition: TGCanvas.h:207
const TGWindow * GetMessageWindow() const
Definition: TGCanvas.h:112
UInt_t fWidth
Definition: TGFrame.h:150
virtual void ClearViewPort()
Clear view port and redraw full content.
Definition: TGCanvas.cxx:888
Int_t fScrolling
Definition: TGCanvas.h:210
virtual Bool_t HandleConfigureNotify(Event_t *event)
This event is generated when the frame is resized.
Definition: TGFrame.cxx:425
long Long_t
Definition: RtypesCore.h:50
Int_t fXp
Definition: TGCanvas.h:56
static TGGC * fgLineGC
Definition: TGCanvas.h:76
Int_t fXDND
Definition: TGCanvas.h:72
Bool_t fLastCase
Definition: TGCanvas.h:65
TGContainer(const TGContainer &)
TGHScrollBar * fHScrollbar
Definition: TGCanvas.h:208
virtual void SetPagePosition(const TGPosition &pos)
Set page position.
Definition: TGCanvas.cxx:761
TString fKeyInput
Definition: TGCanvas.h:69
double f(double x)
virtual void RepeatSearch()
Repeats search.
Definition: TGCanvas.cxx:1620
friend class TGViewPort
Definition: TGCanvas.h:45
virtual void SetVsbPosition(Int_t newPos)
Set position of vertical scrollbar.
Definition: TGCanvas.cxx:1758
friend class TGContainerScrollTimer
Definition: TGCanvas.h:48
Double_t y[n]
Definition: legend1.C:17
virtual void UnSelectAll()
Unselect all items in the container.
Definition: TGCanvas.cxx:585
UInt_t fHeight
Definition: TGFrame.h:151
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events.
Definition: TGCanvas.cxx:1138
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
TGViewPort * fViewPort
Definition: TGCanvas.h:52
TGFrame * fContainer
Definition: TGCanvas.h:174
Bool_t fLastDir
Definition: TGCanvas.h:64
virtual void LineUp(Bool_t select=kFALSE)
Make current position first line in window by scrolling up.
Definition: TGCanvas.cxx:1924
virtual void ActivateItem(TGFrameElement *el)
Activate item.
Definition: TGCanvas.cxx:698
virtual void KeyPressed(TGFrame *, UInt_t keysym, UInt_t mask)
Signal emitted when keyboard key pressed.
Definition: TGCanvas.cxx:465
Int_t fTotal
Definition: TGCanvas.h:60
virtual void DoRedraw()
Redraw content of container in the viewport region.
Definition: TGCanvas.cxx:797
virtual TGFrame * GetLastActive() const
Definition: TGCanvas.h:139
friend class TGCanvas
Definition: TGCanvas.h:46
Bool_t fOnMouseOver
Definition: TGCanvas.h:63
Int_t fY0
Definition: TGCanvas.h:173
virtual void SearchPattern()
Search for entry which name begins with pattern.
Definition: TGCanvas.cxx:1594
Bool_t fLastSubstring
Definition: TGCanvas.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void DeActivateItem(TGFrameElement *el)
DeActivate item.
Definition: TGCanvas.cxx:721
Definition: TGGC.h:35
TGVScrollBar * GetVScrollbar() const
Definition: TGCanvas.h:231
char name[80]
Definition: TGX11.cxx:109
Bool_t fDragging
Definition: TGCanvas.h:59
virtual void Clicked(TGFrame *f, Int_t btn)
Emit Clicked() signal.
Definition: TGCanvas.cxx:505
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in container.
Definition: TGCanvas.cxx:926
Bool_t fScrolling
Definition: TGCanvas.h:71