CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWTableWidget.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TableWidget
4 // Class : FWTableWidget
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Mon Feb 2 16:45:42 EST 2009
11 //
12 
13 // system include files
14 #include <iostream>
15 #include "TGScrollBar.h"
16 #include "TGTableLayout.h"
17 #include "TGResourcePool.h"
18 
19 
20 // user include files
26 
27 //
28 // constants, enums and typedefs
29 //
30 static const UInt_t kRowOptions = kLHintsExpandX|kLHintsFillX|kLHintsShrinkX;
31 static const UInt_t kColOptions = kLHintsExpandY|kLHintsFillY|kLHintsShrinkY;
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
41 TGCompositeFrame(p),
42  m_bodyTable(iManager),
43  m_headerTable(iManager->hasLabelHeaders()?new FWAdapterHeaderTableManager(iManager): static_cast<FWTableManagerBase*>(0)),
44  m_rowHeaderTable(iManager->hasRowHeaders()?new FWAdapterRowHeaderTableManager(iManager): static_cast<FWTableManagerBase*>(0)),
45  m_header(0),
46  m_rowHeader(0),
47  m_showingVSlider(true),
48  m_showingHSlider(true),
49  m_sortedColumn(-1),
50  m_descendingSort(true),
51  m_forceLayout(false),
52  m_headerBackground(0),
53  m_headerForeground(0),
54  m_lineSeparator(0)
55 {
56  SetLayoutManager( new TGTableLayout(this,3,3) );
57 
58  if(0!=m_headerTable) {
60  AddFrame(m_header, new TGTableLayoutHints(1,2,0,1,kLHintsTop|kLHintsLeft|kRowOptions));
61  if (m_bodyTable->cellDataIsSortable()) m_header->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)","FWTableWidget",this,"buttonReleasedInHeader(Int_t,Int_t,Event_t*,Int_t,Int_t)");
62  }
63  m_body = new FWTabularWidget(iManager,this,GetWhiteGC()());
64  //m_body->SetBackgroundColor(kWidgetColor);
65  AddFrame(m_body, new TGTableLayoutHints(1,2,1,2,kLHintsTop|kLHintsLeft|kRowOptions|kColOptions));
66  m_body->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)","FWTableWidget",this,"buttonReleasedInBody(Int_t,Int_t,Event_t*,Int_t,Int_t)");
67 
68  //set sizes
69  std::vector<unsigned int> columnWidths = m_body->widthOfTextInColumns();
70  if(0!=m_header) {
71  std::vector<unsigned int> headerWidths = m_header->widthOfTextInColumns();
72  for(std::vector<unsigned int>::iterator it = columnWidths.begin(), itEnd=columnWidths.end(), itHeader=headerWidths.begin();
73  it != itEnd;
74  ++it,++itHeader) {
75  if(*itHeader > *it) {
76  *it = *itHeader;
77  }
78  }
79  }
80  if(0!=m_header) {
81  m_header->setWidthOfTextInColumns(columnWidths);
82  }
83  m_body->setWidthOfTextInColumns(columnWidths);
84  if(m_rowHeaderTable) {
85  m_rowHeader = new FWTabularWidget(m_rowHeaderTable,this, GetWhiteGC()());
86  //m_rowHeader->SetBackgroundColor(kWidgetColor);
87 
88  AddFrame(m_rowHeader, new TGTableLayoutHints(0,1,1,2,kLHintsTop|kLHintsLeft|kColOptions));
89  m_rowHeader->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)","FWTableWidget",this,"buttonReleasedInBody(Int_t,Int_t,Event_t*,Int_t,Int_t)");
90  m_rowHeader->Connect("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)","FWTableWidget",this,"buttonReleasedInRowHeader(Int_t,Int_t,Event_t*,Int_t,Int_t)");
92  }
93 
94  m_hSlider = new TGHScrollBar(this);
95  AddFrame(m_hSlider, new TGTableLayoutHints(1,2,2,3,kRowOptions));
96  m_hSlider->Connect("ProcessedEvent(Event_t*)", "FWTableWidget", this, "childrenEvent(Event_t *)");
97  m_vSlider = new TGVScrollBar(this);
98  m_vSlider->SetSmallIncrement(12);
99  AddFrame(m_vSlider, new TGTableLayoutHints(2,3,1,2,kColOptions));
100  m_vSlider->Connect("ProcessedEvent(Event_t*)", "FWTableWidget", this, "childrenEvent(Event_t *)");
101  MapSubwindows();
102  Layout();
103  //HideFrame(m_hSlider);
104  //HideFrame(m_vSlider);
105  m_hSlider->Associate(this);
106  m_vSlider->Associate(this);
107 
108  m_hSlider->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
109  m_vSlider->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
110  m_bodyTable->Connect("dataChanged()","FWTableWidget",this,"dataChanged()");
111 }
112 
113 // FWTableWidget::FWTableWidget(const FWTableWidget& rhs)
114 // {
115 // // do actual copying here;
116 // }
117 
119 {
120  if(0!=m_headerBackground) {
121  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_headerBackground->GetGC());
122  }
123  if(0!= m_headerForeground) {
124  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_headerForeground->GetGC());
125  }
126 
127  if(0!= m_lineSeparator) {
128  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_lineSeparator->GetGC());
129  }
130 
131 }
132 
133 //
134 // assignment operators
135 //
136 // const FWTableWidget& FWTableWidget::operator=(const FWTableWidget& rhs)
137 // {
138 // //An exception safe implementation is
139 // FWTableWidget temp(rhs);
140 // swap(rhs);
141 //
142 // return *this;
143 // }
144 
145 //
146 // member functions
147 //
148 void
149 FWTableWidget::sort(UInt_t iColumn, bool iDescendingSort)
150 {
151  if(0!=m_headerTable) {
152  m_headerTable->sort(iColumn,iDescendingSort);
153  }
154  m_bodyTable->sort(iColumn,iDescendingSort);
155  m_sortedColumn =iColumn;
156  m_descendingSort=iDescendingSort;
157 
158  //fClient->NeedRedraw(m_header);
159  //fClient->NeedRedraw(m_body);
160 }
161 
162 void
164 {
165  TGFrame::SetBackgroundColor(iColor);
166  if(m_rowHeaderTable) {
167  m_rowHeader->SetBackgroundColor(iColor);
168  fClient->NeedRedraw(m_rowHeader);
169  }
170  if(m_header) {
171  m_header->SetBackgroundColor(iColor);
172  fClient->NeedRedraw(m_header);
173  }
174  m_body->SetBackgroundColor(iColor);
175  fClient->NeedRedraw(m_body);
176  fClient->NeedRedraw(this);
177 }
178 
179 void
181 {
182  if(0==m_headerBackground) {
183  GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
184  m_headerBackground = gClient->GetResourcePool()->GetGCPool()->GetGC(&t,kTRUE);
185  }
186  m_headerBackground->SetForeground(iColor);
187  if(0!=m_header) {
189  }
190 }
191 void
193 {
194  if(0==m_headerForeground) {
195  GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
196  m_headerForeground = gClient->GetResourcePool()->GetGCPool()->GetGC(&t,kTRUE);
197  }
198  m_headerForeground->SetForeground(iColor);
199  if(0!=m_header) {
201  }
202 }
203 
204 void
206 {
207  if(0==m_lineSeparator) {
208  GCValues_t t = *(gClient->GetResourcePool()->GetFrameGC()->GetAttributes());
209  m_lineSeparator = gClient->GetResourcePool()->GetGCPool()->GetGC(&t,kTRUE);
210  }
211  m_lineSeparator->SetForeground(iColor);
213  if(m_rowHeader) {
215  }
216 }
217 
218 
219 void
220 FWTableWidget::Resize(UInt_t w, UInt_t h)
221 {
222  handleResize(w,h);
223  TGCompositeFrame::Resize(w,h);
224 }
225 
226 bool
228 {
229  //std::cout <<"Resize"<<std::endl;
230  bool redoLayout=false;
231 
232  TGDimension def = m_body->GetDefaultSize();
233  UInt_t fullWidth = def.fWidth;
234  if(m_rowHeader) {
235  fullWidth += m_rowHeader->GetDefaultSize().fWidth;
236  }
237 
238  UInt_t headerHeight = 0;
239  if(m_header) {
240  headerHeight = m_header->GetHeight();
241  }
242  UInt_t fullHeight = def.fHeight + headerHeight;
243 
244  UInt_t sBarWidth = (h < fullHeight) ? m_vSlider->GetWidth() : 0;
245  UInt_t sBarHeight = (w < fullWidth) ? m_hSlider->GetHeight() : 0;
246  if (sBarWidth == 0 && sBarHeight > 0 && h < fullHeight + sBarHeight)
247  sBarWidth = m_vSlider->GetWidth();
248  else if (sBarHeight == 0 && sBarWidth > 0 && h < fullWidth + sBarWidth)
249  sBarHeight = m_hSlider->GetHeight();
250  fullWidth += sBarWidth;
251  fullHeight += sBarHeight;
252 
253  if(w < fullWidth) {
254  if(!m_showingHSlider) {
255  ShowFrame(m_hSlider);
256  redoLayout=true;
257  m_showingHSlider=true;
258  }
259  m_hSlider->SetRange(fullWidth,w);
260  } else {
261  if(m_showingHSlider) {
262  HideFrame(m_hSlider);
263  m_hSlider->SetPosition(0);
264  m_showingHSlider = false;
265  redoLayout=true;
266  }
267  }
268 
269  if(h < fullHeight) {
270  if(!m_showingVSlider) {
271  ShowFrame(m_vSlider);
272  m_showingVSlider=true;
273  redoLayout=true;
274  }
275  m_vSlider->SetRange(fullHeight,h);
276  } else {
277  if(m_showingVSlider) {
278  HideFrame(m_vSlider);
279  m_vSlider->SetPosition(0);
280  m_showingVSlider = false;
281  redoLayout=true;
282  }
283  }
284  if(redoLayout) {
285  Layout();
286  }
287 
288  return redoLayout;
289 }
290 
291 void
292 FWTableWidget::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
293 {
294  //std::cout <<"MoveResize"<<std::endl;
295  if(w != GetWidth() || h != GetHeight()) {
296  handleResize(w,h);
297  }
298  TGCompositeFrame::MoveResize(x,y,w,h);
299 }
300 
301 Bool_t
302 FWTableWidget::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
303 {
304  // Handle message generated by the canvas scrollbars.
305 
306  switch (GET_MSG(msg)) {
307  case kC_HSCROLL:
308  switch (GET_SUBMSG(msg)) {
309  case kSB_SLIDERTRACK:
310  case kSB_SLIDERPOS:
311  m_body->setHorizontalOffset(parm1);
312  if(m_header) {
314  }
315  break;
316  }
317  break;
318 
319  case kC_VSCROLL:
320  switch (GET_SUBMSG(msg)) {
321  case kSB_SLIDERTRACK:
322  case kSB_SLIDERPOS:
323  m_body->setVerticalOffset(parm1);
324  if(m_rowHeader) {
326  }
327  break;
328  }
329  break;
330 
331  default:
332  break;
333  }
334  return kTRUE;
335 }
336 
337 void
338 FWTableWidget::buttonReleasedInHeader(Int_t row, Int_t column, Event_t* event,Int_t,Int_t)
339 {
340  Int_t btn = event->fCode;
341  Int_t keyMod = event->fState;
342  //Int_t keyMod = event->fState;
343  if (btn == kButton1 || btn == kButton3) {
344  if(m_sortedColumn==column) {
345  sort(column, !m_descendingSort);
346  } else {
347  sort(column,true);
348  }
349  }
350  columnClicked(column, btn, keyMod);
351 }
352 
353 void
354 FWTableWidget::buttonReleasedInBody(Int_t row, Int_t column, Event_t* event,Int_t iRelX,Int_t iRelY)
355 {
356  Int_t btn = event->fCode;
357  Int_t keyMod = event->fState;
358  if(btn == kButton5){
359  //should scroll down
360  if(m_vSlider) {
361  Int_t p = m_vSlider->GetPosition();
362  Int_t mx = m_vSlider->GetRange();
363  p+=m_vSlider->GetSmallIncrement();
364  if(p>mx){ p=mx;}
365  m_vSlider->SetPosition(p);
366  }
367  return;
368  }
369  if(btn == kButton4){
370  //should scroll up
371  if(m_vSlider) {
372  Int_t p = m_vSlider->GetPosition();
373  p -=m_vSlider->GetSmallIncrement();
374  if(0>p) {p=0;}
375  m_vSlider->SetPosition(p);
376  }
377  return;
378  }
379  if(btn != kButton1 && btn != kButton3) {return;}
380  if(row>=-1 and row < m_bodyTable->numberOfRows()) {
381  Int_t globalX,globalY;
382  Window_t childdum;
383  gVirtualX->TranslateCoordinates(m_body->GetId(),
384  gClient->GetDefaultRoot()->GetId(),
385  event->fX,event->fY,globalX,globalY,childdum);
386  cellClicked(m_bodyTable->unsortedRowNumber(row), column, btn, keyMod, globalX, globalY);
387  rowClicked(m_bodyTable->unsortedRowNumber(row), btn,keyMod,globalX,globalY);
388  }
389 }
390 
391 void
392 FWTableWidget::cellClicked(Int_t row, Int_t column, Int_t btn, Int_t keyMod, Int_t iGlobalX, Int_t iGlobalY)
393 {
394  keyMod = (keyMod&(kKeyShiftMask|kKeyControlMask));
395  //std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
396  Long_t args[6];
397  args[0]=(Long_t)row;
398  args[1]=(Long_t)column;
399  args[2]=(Long_t)btn;
400  args[3]=(Long_t)keyMod;
401  args[4]=(Long_t)iGlobalX;
402  args[5]=(Long_t)iGlobalY;
403  Emit("cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)",args);
404 }
405 
406 void
408 {
409  Clicked();
410 }
411 
412 void
414 {
415  Emit("Clicked()");
416 }
417 
418 void
419 FWTableWidget::rowClicked(Int_t row, Int_t btn, Int_t keyMod, Int_t iGlobalX, Int_t iGlobalY)
420 {
421  keyMod = (keyMod&(kKeyShiftMask|kKeyControlMask));
422  //std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
423  Long_t args[5];
424  args[0]=(Long_t)row;
425  args[1]=(Long_t)btn;
426  args[2]=(Long_t)keyMod;
427  args[3]=(Long_t)iGlobalX;
428  args[4]=(Long_t)iGlobalY;
429  Emit("rowClicked(Int_t,Int_t,Int_t,Int_t,Int_t)",args);
430 }
431 
432 void
433 FWTableWidget::columnClicked(Int_t column, Int_t btn, Int_t keyMod)
434 {
435  keyMod = (keyMod&(kKeyShiftMask|kKeyControlMask));
436  //std::cout <<"rowClicked "<<row<<" "<<btn<<" "<<keyMod<<std::endl;
437  Long_t args[3];
438  args[0]=(Long_t)column;
439  args[1]=(Long_t)btn;
440  args[2]=(Long_t)keyMod;
441  Emit("columnClicked(Int_t,Int_t,Int_t)",args);
442 }
443 
444 void
446 {
447  bool needs_layout = m_forceLayout; m_forceLayout = false;
448 
449  m_body->dataChanged();
450  if(m_rowHeader) {
453  }
454  //set sizes
455  std::vector<unsigned int> columnWidths = m_body->widthOfTextInColumns();
456  if(m_header) {
457  // reset header back to its internal max rather than the last width
458  m_header->dataChanged();
459  std::vector<unsigned int> headerWidths = m_header->widthOfTextInColumns();
460  for(std::vector<unsigned int>::iterator it = columnWidths.begin(), itEnd=columnWidths.end(), itHeader=headerWidths.begin();
461  it != itEnd;
462  ++it,++itHeader) {
463  if(*itHeader > *it) {
464  *it = *itHeader;
465  }
466  }
467  m_header->setWidthOfTextInColumns(columnWidths);
468  }
469  m_body->setWidthOfTextInColumns(columnWidths);
470 
471  //this updates sliders to match our new data
472  bool layoutDoneByhandleResize = handleResize(GetWidth(), GetHeight());
473  if (needs_layout && ! layoutDoneByhandleResize)
474  {
475  Layout();
476  }
477  gClient->NeedRedraw(m_body);
478  if (m_header) gClient->NeedRedraw(m_header);
479  if (m_rowHeader) gClient->NeedRedraw(m_rowHeader);
480 
481 }
482 
483 void
484 FWTableWidget::buttonPressedInRowHeader(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY)
485 {
486  Int_t btn = event->fCode;
487  if(btn != kButton1 && btn != kButton3) {return;}
488  m_bodyTable->buttonReleasedInRowHeader(row, event, relX, relY);
489 }
490 void
491 FWTableWidget::buttonReleasedInRowHeader(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY)
492 {
493  Int_t btn = event->fCode;
494  if(btn != kButton1 && btn != kButton3) {return;}
495  m_bodyTable->buttonReleasedInRowHeader(row, event, relX, relY);
496 }
497 
498 //
499 // const member functions
500 //
501 TGDimension
503 {
504  TGDimension returnValue;
505  if(m_header){
506  returnValue.fHeight += m_header->GetDefaultHeight();
507  }
508  if(m_rowHeader) {
509  returnValue.fWidth += m_rowHeader->GetDefaultWidth();
510  }
511  returnValue = returnValue + m_body->GetDefaultSize();
512  returnValue.fHeight += m_hSlider->GetDefaultHeight();
513  returnValue.fWidth += m_vSlider->GetDefaultWidth();
514 
515  return returnValue;
516 }
517 
518 void
520 {
524 }
525 
526 void
528 {
529  // override virtual TGFrame::DoRedraw() to prevent call of gVirtualX->ClearArea();
530 }
531 //
532 // static member functions
533 //
534 
535 ClassImp(FWTableWidget)
tuple t
Definition: tree.py:139
void SetBackgroundColor(Pixel_t)
virtual bool cellDataIsSortable() const
void buttonReleasedInRowHeader(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
FWTableManagerBase * m_bodyTable
const double w
Definition: UKUtility.cc:23
TGVScrollBar * m_vSlider
TGGC * m_headerBackground
void sort(int iCol, bool iSortOrder)
Call to have table sorted on values in column iCol with the sort order being descending if iSortOrder...
void SetHeaderBackgroundColor(Pixel_t)
void setLineContext(GContext_t iContext)
bool handleResize(UInt_t w, UInt_t h)
TGDimension GetDefaultSize() const
void SetLineSeparatorColor(Pixel_t)
T x() const
Cartesian x coordinate.
void buttonReleasedInBody(Int_t row, Int_t column, Event_t *event, Int_t, Int_t)
virtual ~FWTableWidget()
void sort(UInt_t iColumn, bool iDescendingSort)
void disableGrowInWidth()
void setWidthOfTextInColumns(const std::vector< unsigned int > &)
FWTabularWidget * m_body
virtual int unsortedRowNumber(int iSortedRowNumber) const =0
when passed the index to the sorted order of the rows it returns the original row number from the und...
TGGC * m_headerForeground
void cellClicked(Int_t iRow, Int_t iColumn, Int_t iButton, Int_t iKeyMod, Int_t iGlobalX, Int_t iGlobalY)
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
TGDimension GetDefaultSize() const
TGGC * m_lineSeparator
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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
virtual void buttonReleasedInRowHeader(Int_t row, Event_t *event, Int_t relX, Int_t relY)
virtual void DoRedraw()
void disableGrowInWidth()
void setHorizontalOffset(UInt_t)
const std::vector< unsigned int > & widthOfTextInColumns() const
static const UInt_t kRowOptions
#define column(...)
Definition: DbCore.h:74
FWTabularWidget * m_rowHeader
void columnClicked(Int_t iColumn, Int_t iButton, Int_t iKeyMod)
void setBackgroundAreaContext(GContext_t iContext)
void buttonPressedInRowHeader(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
void childrenEvent(Event_t *)
void rowClicked(Int_t iRow, Int_t iButton, Int_t iKeyMod, Int_t iGlobalX, Int_t iGlobalY)
void SetHeaderForegroundColor(Pixel_t)
static const UInt_t kColOptions
virtual void Resize(UInt_t w, UInt_t h)
volatile std::atomic< bool > shutdown_flag false
void buttonReleasedInHeader(Int_t row, Int_t column, Event_t *event, Int_t, Int_t)
FWTableManagerBase * m_headerTable
FWTabularWidget * m_header
FWTableManagerBase * m_rowHeaderTable
void setVerticalOffset(UInt_t)
JetCorrectorParameters::Definitions def
Definition: classes.h:6
TGHScrollBar * m_hSlider
FWTableWidget(FWTableManagerBase *iManager, const TGWindow *p=0)