Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
18 ClassImp(TGTableFrame);
19 ClassImp(TGTableHeaderFrame);
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 
38 TGTableFrame::TGTableFrame(const TGWindow *p, UInt_t nrows, UInt_t ncolumns)
39  : TQObject(), fFrame(0), fCanvas(0)
40 {
41  fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
42  TGFrame::GetWhitePixel());
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,
49  kButtonPressMask | kButtonReleaseMask |
50  kPointerMotionMask, kNone, kNone);
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Handle mouse wheel to scroll.
55 
56 void TGTableFrame::HandleMouseWheel(Event_t *event)
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())
65  page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
66  fCanvas->GetViewPort()->GetHeight()) /
67  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 
86 void TGTableFrame::DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
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 
115 TGTableHeaderFrame::TGTableHeaderFrame(const TGWindow *p, TGTable *table,
116  UInt_t w, UInt_t h, EHeaderType type,
117  UInt_t options) :
118  TGCompositeFrame(p, w, h, options), fX0(0), fY0(0), fTable(table)
119 {
120  if (type == kRowHeader) {
121  ChangeOptions(GetOptions() | kVerticalFrame);
122  fY0 = fTable->GetTableHeader()->GetHeight();
123  } else if (type == kColumnHeader) {
124  ChangeOptions(GetOptions() | kHorizontalFrame);
125  fX0 = fTable->GetTableHeader()->GetWidth();
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 
136 void TGTableHeaderFrame::DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
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 }