CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWTabularWidget.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TableWidget
4 // Class : FWTabularWidget
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Mon Feb 2 16:45:21 EST 2009
11 // $Id: FWTabularWidget.cc,v 1.16 2011/03/07 13:13:51 amraktad Exp $
12 //
13 
14 // system include files
15 #include <cassert>
16 #include <limits.h>
17 #include <iostream>
18 #include "TGResourcePool.h"
19 
20 // user include files
24 
25 
26 //
27 // constants, enums and typedefs
28 //
29 
30 //
31 // static data member definitions
32 //
33 
34 const int FWTabularWidget::kTextBuffer = 2;
36 
37 //
38 // constructors and destructor
39 //
40 FWTabularWidget::FWTabularWidget(FWTableManagerBase* iTable, const TGWindow* p, GContext_t context):
41 TGFrame(p),
42 m_table(iTable),
43 m_widthOfTextInColumns(m_table->numberOfColumns(),static_cast<unsigned int>(0)),
44 m_vOffset(0),
45 m_hOffset(0),
46 m_normGC(context),
47 m_backgroundGC(ULONG_MAX),
48 m_growInWidth(true)
49 {
50 
51  m_textHeight = iTable->cellHeight();
53 
55  for(std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(), itEnd = m_widthOfTextInColumns.end();
56  it!=itEnd;
57  ++it){
58  m_tableWidth +=*it;
59  }
60  Resize();
61 
62  gVirtualX->GrabButton(fId,kAnyButton, kAnyModifier, kButtonPressMask|kButtonReleaseMask,kNone,kNone);
63  m_table->Connect("visualPropertiesChanged()","FWTabularWidget",this,"needToRedraw()");
64 }
65 
66 // FWTabularWidget::FWTabularWidget(const FWTabularWidget& rhs)
67 // {
68 // // do actual copying here;
69 // }
70 
72 {
73  m_table->Disconnect("visualPropertiesChanged()", this, "needToRedraw()");
74 }
75 
76 //
77 // assignment operators
78 //
79 // const FWTabularWidget& FWTabularWidget::operator=(const FWTabularWidget& rhs)
80 // {
81 // //An exception safe implementation is
82 // FWTabularWidget temp(rhs);
83 // swap(rhs);
84 //
85 // return *this;
86 // }
87 
88 //
89 // member functions
90 //
91 void
93 {
96 }
97 
98 void
100 {
101  fClient->NeedRedraw(this);
102 }
103 
104 
105 void
106 FWTabularWidget::setWidthOfTextInColumns(const std::vector<unsigned int>& iNew)
107 {
108  assert(iNew.size() == static_cast<unsigned int>(m_table->numberOfColumns()));
109 
111  if (m_growInWidth)
112  {
113  // with of columns grow to prevent resizing/flickering on next event
114  m_widthOfTextInColumnsMax.resize(iNew.size());
115  std::vector<unsigned int>::iterator k = m_widthOfTextInColumnsMax.begin();
116  for(std::vector<unsigned int>::iterator it = m_widthOfTextInColumns.begin(); it != m_widthOfTextInColumns.end(); ++it, ++k)
117  {
118  if ( *it < *k )
119  *it = *k;
120  else
121  *k = *it;
122  }
123  }
124 
125  m_tableWidth=0;
126  for(std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(), itEnd = m_widthOfTextInColumns.end();
127  it!=itEnd;
128  ++it){
130  }
132 }
133 
134 void
136 {
137  if(iV != m_vOffset) {
138  m_vOffset = iV;
139  fClient->NeedRedraw(this);
140  }
141 }
142 void
144 {
145  if(iH != m_hOffset){
146  m_hOffset = iH;
147  fClient->NeedRedraw(this);
148  }
149 }
150 
151 Bool_t
153 {
154  if (event->fType==kButtonPress) {
155  Int_t row,col,relX,relY;
156  translateToRowColumn(event->fX, event->fY, row, col,relX,relY);
157  //std::cout <<"Press: "<<relX<<" "<<relY<<" "<<row<<" "<<col<<" "<<m_table->numberOfRows()<<" "<<m_table->numberOfColumns()<<std::endl;
158  if (row >= 0 && row < m_table->numberOfRows() && col >= 0 && col < m_table->numberOfColumns()) {
159  FWTableCellRendererBase* renderer = m_table->cellRenderer(row,col);
160  if (renderer) {
161  renderer->buttonEvent(event,relX,relY);
162  }
163  buttonPressed(row,col,event,relX,relY);
164  }
165  return true;
166  }
167  if (event->fType==kButtonRelease) {
168  Int_t row,col,relX,relY;
169  translateToRowColumn(event->fX, event->fY, row, col,relX, relY);
170  //std::cout <<"Release: "<<relX<<" "<<relY<<" "<<row<<" "<<col<<" "<<m_table->numberOfRows()<<" "<<m_table->numberOfColumns()<<std::endl;
171  if (row >= 0 && row < m_table->numberOfRows() && col >= 0 && col < m_table->numberOfColumns()) {
172  FWTableCellRendererBase* renderer = m_table->cellRenderer(row,col);
173  if (renderer) {
174  renderer->buttonEvent(event,relX,relY);
175  }
176  buttonReleased(row,col,event,relX,relY);
177  }
178  return true;
179  }
180  return false;
181 }
182 
183 void
184 FWTabularWidget::translateToRowColumn(Int_t iX, Int_t iY, Int_t& oRow, Int_t& oCol, Int_t& oRelX, Int_t& oRelY) const
185 {
186  if( iX < 0 ) {
187  oCol = -1;
188  oRelX = 0;
189  } else {
190  if(iX+static_cast<Int_t>(m_hOffset) > static_cast<Int_t>(m_tableWidth) ) {
191  oCol = m_widthOfTextInColumns.size();
192  oRelX = 0;
193  } else {
194  iX +=m_hOffset;
195  oCol = 0;
196  for(std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(), itEnd = m_widthOfTextInColumns.end();
197  it!=itEnd;
198  ++it,++oCol){
199  oRelX=iX-kTextBuffer;
200  iX-=2*kTextBuffer+kSeperatorWidth+*it;
201  if(iX <= 0) {
202  break;
203  }
204  }
205  }
206  }
207  if( iY < 0) {
208  oRow = -1;
209  oRelY=0;
210  } else {
211  oRow = (int)(float(iY+m_vOffset)/(m_textHeight+2*kTextBuffer+kSeperatorWidth));
213  Int_t numRows = m_table->numberOfRows();
214  if(oRow > numRows) {
215  oRow = numRows;
216  oRelY=0;
217  }
218  }
219 }
220 
221 void
222 FWTabularWidget::buttonPressed(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY)
223 {
224  //std::cout <<"buttonPressed "<<row<<" "<<column<<std::endl;
225  Long_t args[5];
226  args[0]=(Long_t)row;
227  args[1]=(Long_t)column;
228  args[2]=(Long_t)event;
229  args[3]=(Long_t)relX;
230  args[4]=(Long_t)relY;
231  Emit("buttonPressed(Int_t,Int_t,Event_t*,Int_t,Int_t)",args);
232 }
233 void
234 FWTabularWidget::buttonReleased(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY)
235 {
236  //std::cout <<"buttonReleased "<<row<<" "<<column<<std::endl;
237  Long_t args[6];
238  args[0]=(Long_t)row;
239  args[1]=(Long_t)column;
240  args[2]=(Long_t)event;
241  args[3]=(Long_t)relX;
242  args[4]=(Long_t)relY;
243  Emit("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)",args);
244 }
245 
246 void
248 {
249  TGFrame::DoRedraw();
250 
251  //std::cout <<"DoRedraw "<<m_tableWidth<<std::endl;
252 
253  const int yOrigin = -m_vOffset;
254  const int xOrigin = -m_hOffset;
255  const int visibleWidth = m_tableWidth+xOrigin-kSeperatorWidth;
256  int y=yOrigin;
257  if(m_backgroundGC != ULONG_MAX) {
258  gVirtualX->FillRectangle(fId,m_backgroundGC,xOrigin,y,m_tableWidth,
259  GetHeight());
260  }
261  gVirtualX->DrawLine(fId, m_normGC, xOrigin, y, visibleWidth, y);
262  //Draw data
263  const int numRows=m_table->numberOfRows();
264 
265  //figure out which rows and columns are visible
266  Int_t startRow, startColumn,relX,relY;
267  translateToRowColumn(0,0,startRow,startColumn,relX,relY);
268  if(startRow<0) { startRow = 0;}
269  if(startColumn<0) { startColumn=0;}
270  Int_t endRow, endColumn;
271  translateToRowColumn(GetWidth(),GetHeight(),endRow,endColumn,relX,relY);
272  if(endRow >= numRows) {
273  endRow = numRows-1;
274  }
275  if(endColumn >= static_cast<Int_t>(m_widthOfTextInColumns.size())) {
276  endColumn = m_widthOfTextInColumns.size()-1;
277  }
278  //std::cout <<"start "<<startRow<<" "<<startColumn<<" end "<<endRow<<" "<<endColumn<<std::endl;
279 
280  //calculate offset for rows and columns
281  Int_t rowOffset = (kSeperatorWidth+2*kTextBuffer+m_textHeight)*startRow;
282  Int_t columnOffset=kSeperatorWidth+kTextBuffer+xOrigin;
283  for(std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin(), itEnd = m_widthOfTextInColumns.begin()+startColumn;
284  itTextWidth != itEnd; ++itTextWidth) {
285  columnOffset+=*itTextWidth+kTextBuffer+kSeperatorWidth+kTextBuffer;
286  }
287 
288 
289  y+=rowOffset;
290  for(int row = startRow; row <= endRow; ++row) {
291  std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin()+startColumn;
292  //int x=kSeperatorWidth+kTextBuffer+xOrigin;
293  int x = columnOffset;
295  for(int col = startColumn;
296  col <= endColumn;
297  ++col,++itTextWidth) {
298  m_table->cellRenderer(row,col)->draw(fId,x,y,*itTextWidth,m_textHeight);
299  //UInt_t textWidth = font->TextWidth(itData->c_str(),-1);
300  x+=*itTextWidth+kTextBuffer+kSeperatorWidth+kTextBuffer;
301  }
303  gVirtualX->DrawLine(fId, m_normGC, xOrigin, y, visibleWidth, y);
304  }
305 
306  //draw column separators
307  int x=xOrigin;
308  gVirtualX->DrawLine(fId,m_normGC,x,0,x,y);
309  x+=kSeperatorWidth;
310  for(std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin();
311  itTextWidth != m_widthOfTextInColumns.end();
312  ++itTextWidth) {
313  x+=2*kTextBuffer+*itTextWidth;
314  gVirtualX->DrawLine(fId,m_normGC,x,0,x,y);
315  x+=kSeperatorWidth;
316  }
317 }
318 
319 void
321 {
322  m_normGC = iContext;
323 }
324 void
326 {
327  m_backgroundGC = iContext;
328 }
329 
330 //
331 // const member functions
332 //
333 TGDimension
335 {
336  // returns default size
337 
338  UInt_t w = fWidth;
339  if(! (GetOptions() & kFixedWidth) ) {
340  w=m_tableWidth;
341  }
342  UInt_t h = fHeight;
343  if(! (GetOptions() & kFixedHeight) ) {
344  unsigned int numRows = m_table->numberOfRows();
345 
347  }
348  return TGDimension(w, h);
349 }
350 
351 //
352 // static member functions
353 //
354 const TGGC&
356 {
357  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
358  return *s_default;
359 }
360 
361 ClassImp(FWTabularWidget)
void buttonReleased(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
virtual int numberOfColumns() const =0
Number of columns in the table.
void translateToRowColumn(Int_t iX, Int_t iY, Int_t &oRow, Int_t &oCol, Int_t &oRelX, Int_t &oRelY) const
FWTabularWidget(FWTableManagerBase *iManager, const TGWindow *p=0, GContext_t context=getDefaultGC()())
unsigned int m_vOffset
void setLineContext(GContext_t iContext)
virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)=0
void buttonPressed(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
virtual std::vector< unsigned int > maxWidthForColumns() const
for each column in the table this returns the present maximum width for that column ...
virtual int numberOfRows() const =0
Number of rows in the table.
void setWidthOfTextInColumns(const std::vector< unsigned int > &)
virtual FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const =0
TGDimension GetDefaultSize() const
static const TGGC & getDefaultGC()
virtual Bool_t HandleButton(Event_t *event)
GContext_t m_backgroundGC
GContext_t m_normGC
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< unsigned int > m_widthOfTextInColumns
int k[5][pyjets_maxn]
void setHorizontalOffset(UInt_t)
unsigned int UInt_t
Definition: FUTypes.h:12
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
unsigned int m_hOffset
FWTableManagerBase * m_table
void setBackgroundAreaContext(GContext_t iContext)
dictionary args
std::vector< unsigned int > m_widthOfTextInColumnsMax
virtual void buttonEvent(Event_t *iClickEvent, int iRelClickX, int iRelClickY)
static const int kSeperatorWidth
static const int kTextBuffer
T w() const
virtual unsigned int cellHeight() const
require all cells to be the same height
Definition: DDAxes.h:10
void setVerticalOffset(UInt_t)
int col
Definition: cuy.py:1008
virtual ~FWTabularWidget()