Logo ROOT   6.12/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 #include "TGFrame.h"
27 
28 class TGHScrollBar;
29 class TGVScrollBar;
30 class TGClient;
31 class TGViewPort;
32 class TGCanvas;
33 class TGFrameElement;
34 class TGContainerTimer;
35 class TGContainerKeyboardTimer;
36 class TGContainerScrollTimer;
37 class TGListView;
38 class TGPicture;
39 class TGRectangle;
40 
41 class TGContainer : public TGCompositeFrame {
42 
43 friend class TGViewPort;
44 friend class TGCanvas;
47 friend class TGListView;
48 
49 protected:
50  TGViewPort *fViewPort; // container viewport
51  TGCanvas *fCanvas; // pointer to canvas
52  const TGWindow *fMsgWindow; // window handling container messages
53  TGFrameElement *fLastActiveEl; // last active item
54  Int_t fXp, fYp; // previous pointer position
55  Int_t fX0, fY0; // corner of rubber band box
56  Int_t fXf, fYf; // other corner of rubber band box
57  Bool_t fDragging; // true if in dragging mode
58  Int_t fTotal; // total items
59  Int_t fSelected; // number of selected items
60  TTimer *fScrollTimer; // autoscroll timer
61  Bool_t fOnMouseOver; // kTRUE when mouse pointer is over entry
62  Bool_t fLastDir; // direction of last search
63  Bool_t fLastCase; // case sensetivity of last search
64  Bool_t fLastSubstring; // substring search option of last search
65  TString fLastName; // the name of object of last search
66  TTimer *fKeyTimer; // keyboard timer
67  TString fKeyInput; // keyboard input (buffer)
68  Bool_t fKeyTimerActive;// kTRUE - keyboard timer is active
69  Bool_t fScrolling; // kTRUE - when scrolling is ON
72  TGRectangle fExposedRegion; // exposed area
73 
74  static TGGC *fgLineGC;
75  static const TGGC &GetLineGC();
76 
77  virtual void DoRedraw();
78  virtual void ActivateItem(TGFrameElement* el);
79  virtual void DeActivateItem(TGFrameElement* el);
80  virtual void SearchPattern();
81  virtual void OnAutoScroll();
82  virtual void RepeatSearch();
83 
84 private:
85  TGContainer(const TGContainer&); // not implemented
86  TGContainer& operator=(const TGContainer&); // not implemented
87 
88 public:
89  TGContainer(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
90  UInt_t options = kSunkenFrame,
94 
95  virtual ~TGContainer();
96 
97  virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
98  virtual void ClearViewPort();
99  virtual void Associate(const TGWindow *w) { fMsgWindow = w; }
100  virtual void AdjustPosition();
101  virtual void SetPagePosition(const TGPosition& pos);
102  virtual void SetPagePosition(Int_t x, Int_t y);
103  virtual void SetPageDimension(const TGDimension& dim);
104  virtual void SetPageDimension(UInt_t w, UInt_t h);
105  virtual void RemoveAll();
106  virtual void RemoveItem(TGFrame *item);
107  virtual void Layout();
108 
109  TGCanvas *GetCanvas() const { return fCanvas; }
110  const TGWindow *GetMessageWindow() const { return fMsgWindow; }
111  virtual TGPosition GetPagePosition() const;
112  virtual TGDimension GetPageDimension() const;
113 
114  virtual Int_t NumSelected() const { return fSelected; }
115  virtual Int_t NumItems() const { return fTotal; }
116  virtual TGFrameElement *FindFrame(Int_t x,Int_t y,Bool_t exclude=kTRUE);
117  virtual TGFrame *FindFrameByName(const char *name);
118  virtual TGHScrollBar *GetHScrollbar() const;
119  virtual TGVScrollBar *GetVScrollbar() const;
120  virtual void SetHsbPosition(Int_t newPos);
121  virtual void SetVsbPosition(Int_t newPos);
122  virtual void LineUp(Bool_t select = kFALSE);
123  virtual void LineDown(Bool_t select = kFALSE);
124  virtual void LineLeft(Bool_t select = kFALSE);
125  virtual void LineRight(Bool_t select = kFALSE);
126  virtual void PageUp(Bool_t select = kFALSE);
127  virtual void PageDown(Bool_t select = kFALSE);
128  virtual void Home(Bool_t select = kFALSE);
129  virtual void End(Bool_t select = kFALSE);
130  virtual void Search(Bool_t close = kTRUE);
131  virtual void *FindItem(const TString& name,
132  Bool_t direction = kTRUE,
133  Bool_t caseSensitive = kTRUE,
134  Bool_t subString = kFALSE);
135 
136  virtual const TGFrame *GetNextSelected(void **current);
137  virtual TGFrame *GetLastActive() const { return fLastActiveEl ? fLastActiveEl->fFrame : 0; }
138  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
139 
140  virtual Bool_t HandleDNDFinished() { fBdown = kFALSE; return kTRUE; }
141  virtual Bool_t HandleExpose(Event_t *event);
142  virtual Bool_t HandleButton(Event_t *event);
143  virtual Bool_t HandleDoubleClick(Event_t *event);
144  virtual Bool_t HandleMotion(Event_t *event);
145  virtual Bool_t HandleKey(Event_t *event);
146 
147  const TGPicture *GetObjPicture(TGFrame *f);
148  virtual void SetDragPixmap(const TGPicture *pic);
149 
150  virtual void SelectAll(); //*SIGNAL*
151  virtual void UnSelectAll(); //*SIGNAL*
152  virtual void InvertSelection(); //*SIGNAL*
153  virtual void ReturnPressed(TGFrame*); //*SIGNAL*
154  virtual void SpacePressed(TGFrame*); //*SIGNAL*
155  virtual void KeyPressed(TGFrame*, UInt_t keysym, UInt_t mask); //*SIGNAL*
156  virtual void OnMouseOver(TGFrame*); //*SIGNAL*
157  virtual void CurrentChanged(Int_t x,Int_t y);//*SIGNAL*
158  virtual void CurrentChanged(TGFrame* f); //*SIGNAL*
159  virtual void Clicked(TGFrame *f, Int_t btn); //*SIGNAL*
160  virtual void DoubleClicked(TGFrame *f, Int_t btn); //*SIGNAL*
161  virtual void DoubleClicked(TGFrame *f, Int_t btn, Int_t x, Int_t y); //*SIGNAL*
162  virtual void Clicked(TGFrame *f, Int_t btn, Int_t x, Int_t y); //*SIGNAL*
163 
164  ClassDef(TGContainer,0) // Canvas container
165 };
166 
167 
168 class TGViewPort : public TGCompositeFrame {
169 
170 protected:
171  Int_t fX0, fY0; // position of container frame in viewport
172  TGFrame *fContainer; // container frame
173 
174 private:
175  TGViewPort(const TGViewPort&); // not implemented
176  TGViewPort& operator=(const TGViewPort&); // not implemented
177 
178 public:
179  TGViewPort(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
180  UInt_t options = kChildFrame,
182 
183  TGFrame *GetContainer() const { return fContainer; }
184  void SetContainer(TGFrame *f);
185 
186  virtual void DrawBorder() { };
187  virtual void Layout() { }
188  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
189 
190  virtual void SetHPos(Int_t xpos);
191  virtual void SetVPos(Int_t ypos);
192  void SetPos(Int_t xpos, Int_t ypos);
193 
194  Int_t GetHPos() const { return fX0; }
195  Int_t GetVPos() const { return fY0; }
196  virtual Bool_t HandleConfigureNotify(Event_t *event);
197 
198  ClassDef(TGViewPort,0) // Viewport through which to look at a container frame
199 };
200 
201 
202 class TGCanvas : public TGFrame {
203 
204 protected:
205  TGViewPort *fVport; // viewport through which we look at contents
206  TGHScrollBar *fHScrollbar; // horizontal scrollbar
207  TGVScrollBar *fVScrollbar; // vertical scrollbar
208  Int_t fScrolling; // flag which scrolling modes are allowed
209 
210 private:
211  TGCanvas(const TGCanvas&); // not implemented
212  TGCanvas& operator=(const TGCanvas&); // not implemented
213 
214 public:
215  enum { kCanvasNoScroll = 0,
216  kCanvasScrollHorizontal = BIT(0),
217  kCanvasScrollVertical = BIT(1),
218  kCanvasScrollBoth = (kCanvasScrollHorizontal | kCanvasScrollVertical)
219  };
220 
221  TGCanvas(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
222  UInt_t options = kSunkenFrame | kDoubleBorder,
224  virtual ~TGCanvas();
225 
226  TGFrame *GetContainer() const { return fVport->GetContainer(); }
227  TGViewPort *GetViewPort() const { return fVport; }
228  TGHScrollBar *GetHScrollbar() const { return fHScrollbar; }
229  TGVScrollBar *GetVScrollbar() const { return fVScrollbar; }
230 
231  virtual void AddFrame(TGFrame *f, TGLayoutHints *l = 0);
232  virtual void SetContainer(TGFrame *f) { fVport->SetContainer(f); }
233  virtual void MapSubwindows();
234  virtual void DrawBorder();
235  virtual void Layout();
236  virtual void ClearViewPort();
237  virtual Int_t GetHsbPosition() const;
238  virtual Int_t GetVsbPosition() const;
239  virtual void SetHsbPosition(Int_t newPos);
240  virtual void SetVsbPosition(Int_t newPos);
241  void SetScrolling(Int_t scrolling);
242  Int_t GetScrolling() const { return fScrolling; }
243 
244  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
245  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
246 
247  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
248 
249  ClassDef(TGCanvas,0) // A canvas with two scrollbars and a viewport
250 };
251 
252 
253 #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:56
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:114
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:242
Int_t fSelected
Definition: TGCanvas.h:59
virtual void DrawBorder()
Draw frame border.
Definition: TGCanvas.h:186
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:187
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:78
Bool_t fBdown
Definition: TGCanvas.h:71
TH1 * h
Definition: legend2.C:5
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGCanvas.h:188
virtual void SetContainer(TGFrame *f)
Definition: TGCanvas.h:232
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:99
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void AdjustPosition()
Move content to position of highlighted/activated frame.
Definition: TGCanvas.cxx:1790
TGCanvas * fCanvas
Definition: TGCanvas.h:51
TGFrame * GetContainer() const
Definition: TGCanvas.h:226
const TGWindow * fMsgWindow
Definition: TGCanvas.h:52
virtual void OnAutoScroll()
Autoscroll while close to & beyond The Wall.
Definition: TGCanvas.cxx:1492
Int_t GetVPos() const
Definition: TGCanvas.h:195
Int_t fY0
Definition: TGCanvas.h:55
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:320
ULong_t Pixel_t
Definition: GuiTypes.h:39
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:53
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:244
virtual TGVScrollBar * GetVScrollbar() const
returns pointer to vert. scroll bar
Definition: TGCanvas.cxx:1750
TGVScrollBar * fVScrollbar
Definition: TGCanvas.h:207
TTimer * fScrollTimer
Definition: TGCanvas.h:60
virtual void LineDown(Bool_t select=kFALSE)
Move one line down.
Definition: TGCanvas.cxx:1953
TTimer * fKeyTimer
Definition: TGCanvas.h:66
TGFrame * GetContainer() const
Definition: TGCanvas.h:183
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:227
virtual void RemoveItem(TGFrame *item)
Remove item from container.
Definition: TGCanvas.cxx:657
TString fLastName
Definition: TGCanvas.h:65
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:194
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:72
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:54
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:109
Int_t fYDND
Definition: TGCanvas.h:70
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:68
Int_t fX0
Definition: TGCanvas.h:55
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:228
Int_t fXf
Definition: TGCanvas.h:56
TGFrame * fFrame
Definition: TGLayout.h:119
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
virtual Int_t NumItems() const
Definition: TGCanvas.h:115
virtual TGFrame * FindFrameByName(const char *name)
Find frame by name.
Definition: TGCanvas.cxx:1413
virtual Bool_t HandleDNDFinished()
Definition: TGCanvas.h:140
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:395
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:45
virtual ~TGContainer()
Delete canvas container.
Definition: TGCanvas.cxx:401
TGViewPort * fVport
Definition: TGCanvas.h:205
const TGWindow * GetMessageWindow() const
Definition: TGCanvas.h:110
UInt_t fWidth
Definition: TGFrame.h:134
virtual void ClearViewPort()
Clear view port and redraw full content.
Definition: TGCanvas.cxx:888
const Bool_t kFALSE
Definition: RtypesCore.h:88
Int_t fScrolling
Definition: TGCanvas.h:208
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:54
static TGGC * fgLineGC
Definition: TGCanvas.h:74
Int_t fXDND
Definition: TGCanvas.h:70
Bool_t fLastCase
Definition: TGCanvas.h:63
TGContainer(const TGContainer &)
TGHScrollBar * fHScrollbar
Definition: TGCanvas.h:206
virtual void SetPagePosition(const TGPosition &pos)
Set page position.
Definition: TGCanvas.cxx:761
TString fKeyInput
Definition: TGCanvas.h:67
virtual void RepeatSearch()
Repeats search.
Definition: TGCanvas.cxx:1620
friend class TGViewPort
Definition: TGCanvas.h:43
virtual void SetVsbPosition(Int_t newPos)
Set position of vertical scrollbar.
Definition: TGCanvas.cxx:1758
friend class TGContainerScrollTimer
Definition: TGCanvas.h:46
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:135
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:50
TGFrame * fContainer
Definition: TGCanvas.h:172
Bool_t fLastDir
Definition: TGCanvas.h:62
auto * l
Definition: textangle.C:4
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:58
virtual void DoRedraw()
Redraw content of container in the viewport region.
Definition: TGCanvas.cxx:797
virtual TGFrame * GetLastActive() const
Definition: TGCanvas.h:137
friend class TGCanvas
Definition: TGCanvas.h:44
Bool_t fOnMouseOver
Definition: TGCanvas.h:61
Int_t fY0
Definition: TGCanvas.h:171
virtual void SearchPattern()
Search for entry which name begins with pattern.
Definition: TGCanvas.cxx:1594
Bool_t fLastSubstring
Definition: TGCanvas.h:64
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void DeActivateItem(TGFrameElement *el)
DeActivate item.
Definition: TGCanvas.cxx:721
Definition: TGGC.h:31
TGVScrollBar * GetVScrollbar() const
Definition: TGCanvas.h:229
char name[80]
Definition: TGX11.cxx:109
Bool_t fDragging
Definition: TGCanvas.h:57
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:69