Logo ROOT   6.14/05
Reference Guide
TGTableContainer.cxx
Go to the documentation of this file.
1 // Author: Roel Aaij 14/08/2007
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #include "TGTableContainer.h"
12 #include "TGTableCell.h"
13 #include "TGLayout.h"
14 #include "TGWindow.h"
15 #include "TGScrollBar.h"
16 #include "TGTable.h"
17 
20 
21 //////////////////////////////////////////////////////////////////////////
22 // //
23 // TGTableFrame and TGTableHeaderFrame //
24 // //
25 // TGTableFrame contains a composite frame that uses a TGMatrixLayout //
26 // to Layout the frames it contains. //
27 // //
28 // TGTableHeaderFrame implements a frame used to display TGTableHeaders //
29 // in a TGTable. //
30 // //
31 // Both classes are for internal use in TGTable only. //
32 // //
33 //////////////////////////////////////////////////////////////////////////
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Create the container used to view TGTableCells. p.
37 
39  : TQObject(), fFrame(0), fCanvas(0)
40 {
41  fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
43  fFrame->Connect("ProcessedEvent(Event_t*)", "TGTableFrame", this,
44  "HandleMouseWheel(Event_t*)");
45  fCanvas = 0;
46  fFrame->SetLayoutManager(new TGMatrixLayout(fFrame, nrows, ncolumns));
47 
48  gVirtualX->GrabButton(fFrame->GetId(), kAnyButton, kAnyModifier,
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Handle mouse wheel to scroll.
55 
57 {
58  if (event->fType != kButtonPress && event->fType != kButtonRelease)
59  return;
60 
61  Int_t page = 0;
62  if (event->fCode == kButton4 || event->fCode == kButton5) {
63  if (!fCanvas) return;
64  if (fCanvas->GetContainer()->GetHeight())
68  }
69 
70  if (event->fCode == kButton4) {
71  //scroll up
72  Int_t newpos = fCanvas->GetVsbPosition() - page;
73  if (newpos < 0) newpos = 0;
74  fCanvas->SetVsbPosition(newpos);
75  }
76  if (event->fCode == kButton5) {
77  // scroll down
78  Int_t newpos = fCanvas->GetVsbPosition() + page;
79  fCanvas->SetVsbPosition(newpos);
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Draw a region of container in viewport.
85 
87 {
88  TGFrameElement *el;
89  // Handle_t id = fId;
90 
91  Int_t xx = fCanvas->GetX() + fCanvas->GetHsbPosition() + x; // translate coordinates to current page position
92  Int_t yy = fCanvas->GetY() + fCanvas->GetVsbPosition() + y;
93 
94  TIter next(fFrame->GetList());
95 
96  while ((el = (TGFrameElement *) next())) {
97  if ((Int_t(el->fFrame->GetY()) >= yy - (Int_t)el->fFrame->GetHeight()) &&
98  (Int_t(el->fFrame->GetX()) >= xx - (Int_t)el->fFrame->GetWidth()) &&
99  (Int_t(el->fFrame->GetY()) <= yy + Int_t(h + el->fFrame->GetHeight())) &&
100  (Int_t(el->fFrame->GetX()) <= xx + Int_t(w + el->fFrame->GetWidth()))) {
101 
102  // draw either in container window or in double-buffer
103  // if (!fMapSubwindows) {
104  // el->fFrame->DrawCopy(id, el->fFrame->GetX() - pos.fX, el->fFrame->GetY() - pos.fY);
105  // } else {
106  gClient->NeedRedraw(el->fFrame);
107  // }
108  }
109  }
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// TGTableHeaderFrame constuctor.
114 
117  UInt_t options) :
118  TGCompositeFrame(p, w, h, options), fX0(0), fY0(0), fTable(table)
119 {
120  if (type == kRowHeader) {
123  } else if (type == kColumnHeader) {
126  } else {
127  Error("TGTableHeaderFrame::TGTableHeaderFrame",
128  "specify correct header type");
129  }
130 
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Draw a region of container in viewport.
135 
137 {
138  TGFrameElement *el;
139  // Handle_t id = fId;
140 
141  Int_t xx = fX0 + x; // translate coordinates to current page position
142  Int_t yy = fY0 + y;
143 
144  TIter next(fList);
145 
146  while ((el = (TGFrameElement *) next())) {
147  if ((Int_t(el->fFrame->GetY()) >= yy - (Int_t)el->fFrame->GetHeight()) &&
148  (Int_t(el->fFrame->GetX()) >= xx - (Int_t)el->fFrame->GetWidth()) &&
149  (Int_t(el->fFrame->GetY()) <= yy + Int_t(h + el->fFrame->GetHeight())) &&
150  (Int_t(el->fFrame->GetX()) <= xx + Int_t(w + el->fFrame->GetWidth()))) {
151 
152  fClient->NeedRedraw(el->fFrame);
153  }
154  }
155 }
virtual UInt_t GetOptions() const
Definition: TGFrame.h:244
float Float_t
Definition: RtypesCore.h:53
virtual void SetVsbPosition(Int_t newPos)
Set position of vertical scrollbar.
Definition: TGCanvas.cxx:2405
Int_t GetY() const
Definition: TGFrame.h:279
UInt_t GetHeight() const
Definition: TGFrame.h:272
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
void HandleMouseWheel(Event_t *event)
Handle mouse wheel to scroll.
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:49
#define gClient
Definition: TGClient.h:166
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
int Int_t
Definition: RtypesCore.h:41
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:102
TGFrame * GetContainer() const
Definition: TGCanvas.h:226
UInt_t GetWidth() const
Definition: TGFrame.h:271
virtual Int_t GetHsbPosition() const
Get position of horizontal scrollbar.
Definition: TGCanvas.cxx:2371
Handle_t GetId() const
Definition: TGObject.h:47
const Mask_t kPointerMotionMask
Definition: GuiTypes.h:162
Double_t x[n]
Definition: legend1.C:17
TGCompositeFrame(const TGCompositeFrame &)
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a region of container in viewport.
virtual TList * GetList() const
Definition: TGFrame.h:369
TGViewPort * GetViewPort() const
Definition: TGCanvas.h:227
const Mask_t kButtonPressMask
Definition: GuiTypes.h:160
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
Int_t GetX() const
Definition: TGFrame.h:278
TList * fList
Definition: TGFrame.h:351
EGEventType fType
Definition: GuiTypes.h:174
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
const Handle_t kNone
Definition: GuiTypes.h:87
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1025
virtual TGTableHeader * GetTableHeader()
#define gVirtualX
Definition: TVirtualX.h:350
#define h(i)
Definition: RSha256.hxx:106
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:103
#define ClassImp(name)
Definition: Rtypes.h:359
TGCompositeFrame * fFrame
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:161
UInt_t fCode
Definition: GuiTypes.h:179
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
TGCanvas * fCanvas
EHeaderType
Definition: TGTableHeader.h:16
TGClient * fClient
Definition: TGObject.h:37
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
TGTableHeaderFrame(const TGWindow *p, TGTable *table=0, UInt_t w=1, UInt_t h=1, EHeaderType type=kColumnHeader, UInt_t option=0)
TGTableHeaderFrame constuctor.
TGTableFrame(const TGWindow *p, UInt_t nrows, UInt_t ncolumns)
Create the container used to view TGTableCells. p.
const Mask_t kAnyModifier
Definition: GuiTypes.h:209
virtual Int_t GetVsbPosition() const
Get position of vertical scrollbar.
Definition: TGCanvas.cxx:2381
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw a region of container in viewport.