Logo ROOT   6.14/05
Reference Guide
TGTable.cxx
Go to the documentation of this file.
1 // Author: Roel Aaij 21/07/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 "TGCanvas.h"
12 #include "TGFrame.h"
13 #include "TClass.h"
14 #include "TGWindow.h"
15 #include "TGResourcePool.h"
16 #include "Riostream.h"
17 #include "TSystem.h"
18 #include "TImage.h"
19 #include "TEnv.h"
20 #include "TGToolTip.h"
21 #include "TGWidget.h"
22 #include "TGPicture.h"
23 #include "TRandom3.h"
24 #include "TVirtualTableInterface.h"
25 #include "TGTable.h"
26 #include "TGTableCell.h"
27 #include "TGTableHeader.h"
28 #include "TObjArray.h"
29 #include "TGTableContainer.h"
30 #include "TGScrollBar.h"
31 #include "TGButton.h"
32 #include "TGNumberEntry.h"
33 #include "TGTextEntry.h"
34 #include "TGLabel.h"
35 #include "TColor.h"
36 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Create an array to hold a bunch of numbers
42 
43 /* Begin_Html
44 <center><h2>TGTable</h2></center>
45 <br><br>
46 TGTable implements a table widget to display data in rows and
47 columns. The data is supplied by a TVirtualTableInterface.
48 <br><br>
49 The table is a TGCanvas to make use of already available viewport
50 functionality and drawing optimizations.
51 <br><br>
52 The top left cell in a table has coordinates (0,0)
53 <br><br>
54 A TObjArray is used internally to ensure little overhead and fast
55 acces to cells.
56 <br><br>
57 If the data source has more rows than the default 50 rows of cells in
58 memory, buttons at the bottom of the table can be used to load the
59 next or previous chunk of data.
60 <br><br>
61 At the top of the table, a frame is visible that shows the coordinates
62 of the top left cell currently in memmory in row,column. The amount of
63 rows and columns is also shown in rows x columns. These values can be
64 edited to move to a different area of the data source or to resize the
65 table. Tab will switch between the enties, return will move to the
66 currently entered range and resize the table if needed. Clicking the
67 goto button has the same effect.
68 <br><br>
69 A TGTable is created by first creating an appropriate
70 TVirtualTableInterface from the data that needs visualization and
71 then creating the TGTable using this interface.
72 <br><br>
73 A simple macro to use a TGTable with a TGSimpleTableInterface:
74 End_Html
75 Begin_Macro(source, gui)
76 {
77  Int_t i = 0, j = 0;
78  UInt_t nrows = 6, ncolumns = 5;
79  Double_t** data = new Double_t*[nrows];
80  for (i = 0; i < nrows; i++) {
81  data[i] = new Double_t[ncolumns];
82  for (j = 0; j < ncolumns; j++) {
83  data[i][j] = 10 * i + j;
84  }
85  }
86 
87  // Create a main frame to contain the table
88  TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
89  mainframe->SetCleanup(kDeepCleanup) ;
90 
91  // Create an interface
92  TGSimpleTableInterface *iface = new TGSimpleTableInterface(data, 6, 5);
93 
94  // Create the table
95  TGTable *table = new TGTable(mainframe, 999, iface);
96 
97  // Add the table to the main frame
98  mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
99 
100  //Update data
101  data[5][1] = 3.01;
102  //update the table view
103  table->Update();
104 
105  // Layout and map the main frame
106  mainframe->SetWindowName("Tree Table Test") ;
107  mainframe->MapSubwindows() ;
108  mainframe->Layout();
109  mainframe->Resize() ;
110  mainframe->MapWindow() ;
111 
112  return mainframe;
113 }
114 End_Macro
115 Begin_Html
116 
117 It is also possible to visualise data from a tree. A simple macro
118 showing the use of a TTreeTableInterface follows.
119 End_Html
120 Begin_Macro(source, gui)
121 {
122  // Open a root file.
123  TFile *file = new TFile("$ROOTSYS/tutorials/hsimple.root");
124  // Load a tree from the file
125  TNtuple *ntuple = (TNtuple *)file->Get("ntuple");
126 
127  // Create an interface
128  TTreeTableInterface *iface = new TTreeTableInterface(ntuple);
129 
130  // Create a main frame to contain the table
131  TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
132  mainframe->SetCleanup(kDeepCleanup) ;
133 
134  // Create the table
135  TGTable *table = new TGTable(mainframe, 999, iface, 10, 6);
136 
137  // Add the table to the main frame
138  mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
139 
140  // Set a selection
141  iface->SetSelection("px > 0.");
142  // Add a column
143  iface->AddColumn("(px+py)/(px-py)", 0);
144  //update the table view
145  table->Update();
146 
147  // Layout and map the main frame
148  mainframe->SetWindowName("Tree Table Test") ;
149  mainframe->MapSubwindows() ;
150  mainframe->Layout();
151  mainframe->Resize() ;
152  mainframe->MapWindow() ;
153 
154  return mainframe;
155 }
156 End_Macro
157 */
158 
159 // const TGGC *TGTable::fgDefaultSelectGC = 0;
160 // const TGGC *TGTable::fgDefaultBckgndGC = 0;
161 // const Int_t TGTable::fgDefaultTMode = kTextLeft | kTextTop;
162 
163 // TList *TGTable::fgEditList = 0 ;
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// TGTable constuctor.
167 
168 TGTable::TGTable(const TGWindow *p, Int_t id, TVirtualTableInterface *interface,
169  UInt_t nrows, UInt_t ncolumns)
170  : TGCompositeFrame(p, 500, 500, kVerticalFrame), TGWidget(id), fRows(0),
171  fRowHeaders(0), fColumnHeaders(0), fReadOnly(kFALSE), fSelectColor(0),
172  fTMode(0), fAllData(kFALSE), fTableFrame(0), fCanvas(0), fCellWidth(80),
173  fCellHeight(25), fInterface(interface)
174 {
175  fCurrentRange = new TTableRange();
176  fDataRange = new TTableRange();
177  fGotoRange = new TTableRange();
178  TGLayoutHints *hints = 0;
179  fCellHintsList = new TList(hints);
180  fRHdrHintsList = new TList(hints);
181  fCHdrHintsList = new TList(hints);
182  fMainHintsList = new TList(hints);
183 
184  // To be done: GetBackground colors for .rootrc
186  fEvenRowBackground = TColor::RGB2Pixel(204, 255, 204);
187  fOddRowBackground = TColor::RGB2Pixel(255, 255, 255);
188  fHeaderBackground = TColor::RGB2Pixel(204, 204, 255);
189 
190  fCurrentRange->fXbr = ncolumns;
191  fCurrentRange->fYbr = nrows;
192 
193  Init();
194 
195  if(fInterface) SetInterface(fInterface, nrows, ncolumns);
196  SetWindowName();
197 // MapWindow();
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// TGTable destructor.
202 
204 {
205  // delete all cells in a good way
206  UInt_t i = 0, j = 0;
207  for (i = 0; i < GetNTableRows(); i++) {
208  for (j = 0; j < GetNTableColumns(); j++) {
209  delete GetCell(i,j);
210  }
211  delete fRows->At(i);
212  }
213  delete fRows;
214  delete fRowHeaders;
215  delete fColumnHeaders;
216 
217  delete fCurrentRange;
218  delete fDataRange;
219  delete fGotoRange;
220 
221  fCellHintsList->Delete();
222  delete fCellHintsList;
223  delete fRHdrHintsList;
224  delete fCHdrHintsList;
225 
226  fMainHintsList->Delete();
227  delete fMainHintsList;
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Initialise the TGTable.
232 
233 void TGTable::Init()
234 {
235  UInt_t nrows = GetNTableRows();
236  UInt_t ncolumns = GetNTableColumns();
237 
238  // Main layout frames
239  fTopFrame = new TGHorizontalFrame(this, fWidth, fCellHeight);
240  fTopExtraFrame = new TGHorizontalFrame(fTopFrame, fWidth - fCellWidth,
241  fCellHeight);
242  TGString *str = new TGString();
243  *str += GetNTableRows();
244  *str += "x";
245  *str += GetNTableColumns();
246  *str += " Table";
247  fTableHeader = new TGTableHeader(fTopFrame, this, str, 0,
248  kTableHeader);
249 
250  fBottomFrame = new TGHorizontalFrame(this, fWidth, fHeight - fCellHeight);
251  fRHdrFrame = new TGTableHeaderFrame(fBottomFrame, this, fCellWidth,
252  fHeight - fCellHeight, kRowHeader);
253  fCHdrFrame = new TGTableHeaderFrame(fTopExtraFrame, this, fWidth - fCellWidth,
254  fCellHeight, kColumnHeader);
255 
256  // Frame for the buttons at the bottom
257  fButtonFrame = new TGHorizontalFrame(this, 200, 50);
258  fNextButton = new TGTextButton(fButtonFrame, "Next", WidgetId() + 2000);
259  fPrevButton = new TGTextButton(fButtonFrame, "Previous", WidgetId() + 2001);
260  fUpdateButton = new TGTextButton(fButtonFrame, "Update", WidgetId() + 2002);
261 
262  fCanvas = new TGCanvas(fBottomFrame, ncolumns * fCellWidth,
263  nrows * fCellHeight, 0);
264  fTableFrame = new TGTableFrame(fCanvas->GetViewPort(), nrows, ncolumns);
265  fTableFrame->SetCanvas(fCanvas);
266  fCanvas->SetContainer(fTableFrame->GetFrame());
267 
268  // Frame to display range info and goto button.
269  fRangeFrame = new TGHorizontalFrame(this, 450, 50);
270  fFirstCellLabel = new TGLabel(fRangeFrame, "Top left cell in range:");
271  fRangeLabel = new TGLabel(fRangeFrame, "Range:");
272  fFirstCellEntry = new TGTextEntry(fRangeFrame, "0,0", WidgetId() + 2050);
273  fFirstCellEntry->SetWidth(100);
274  fFirstCellEntry->SetAlignment(kTextRight);
275  fFirstCellEntry->Connect("TextChanged(const char *)", "TGTable", this,
276  "UserRangeChange()");
277  fFirstCellEntry->Connect("ReturnPressed()", "TGTable", this, "Goto()");
278 
279  TString range;
280  range += GetNTableRows();
281  range += "x";
282  range += GetNTableColumns();
283  fRangeEntry = new TGTextEntry(range, fRangeFrame, WidgetId() + 2051);
284  fRangeEntry->SetWidth(100);
285  fRangeEntry->SetAlignment(kTextRight);
286  fRangeEntry->Connect("TextChanged(const char *)", "TGTable", this,
287  "UserRangeChange()");
288  fRangeEntry->Connect("ReturnPressed()", "TGTable", this, "Goto()");
289  fRangeEntry->Connect("TabPressed()", "TGTextEntry", fFirstCellEntry,
290  "SetFocus()");
291  fFirstCellEntry->Connect("TabPressed()", "TGTextEntry", fRangeEntry,
292  "SetFocus()");
293 
294  fGotoRange->fXbr = GetNTableRows();
295  fGotoRange->fYbr = GetNTableColumns();
296  fGotoButton = new TGTextButton(fRangeFrame, "Goto", WidgetId() + 2003);
297  fGotoButton->SetState(kButtonDisabled);
298 
299  // Set frame backgrounds
300  fCHdrFrame->SetBackgroundColor(fBackground);
301  fRHdrFrame->SetBackgroundColor(fBackground);
302  fRangeFrame->SetBackgroundColor(fBackground);
303  fTopFrame->SetBackgroundColor(fBackground);
304  fTopExtraFrame->SetBackgroundColor(fBackground);
305  fBottomFrame->SetBackgroundColor(fBackground);
306  fButtonFrame->SetBackgroundColor(fBackground);
307  fFirstCellLabel->SetBackgroundColor(fBackground);
308  fRangeLabel->SetBackgroundColor(fBackground);
309 
310  // Create the cells needed
311  UInt_t i = 0, j = 0;
312  TGString *label = 0;
313  fRowHeaders = new TObjArray(nrows);
314  for(i = 0; i < nrows; i++) {
315  TGTableHeader *hdr = new TGTableHeader(fRHdrFrame, this,
316  label, i, kRowHeader);
317  fRowHeaders->AddAt(hdr, i);
318  }
319  fColumnHeaders = new TObjArray(ncolumns);
320  for(i = 0; i < ncolumns; i++) {
321  TGTableHeader *hdr = new TGTableHeader(fCHdrFrame, this,
322  label, i, kColumnHeader);
323  fColumnHeaders->AddAt(hdr, i);
324  }
325 
326  TGTableCell *cell = 0;
327  TObjArray *row = 0;
328  fRows = new TObjArray(nrows);
329  for (i = 0; i < nrows; i++) {
330  row = new TObjArray(ncolumns);
331  fRows->AddAt(row, i);
332  for (j = 0; j < ncolumns; j++) {
333  cell = new TGTableCell(fCanvas->GetContainer(), this, label, i, j);
334  row->AddAt(cell, j);
335  }
336  }
337 
338  // Check if the table covers all the data
339  if ((GetNDataColumns() >= GetNTableColumns()) &&
340  (GetNDataRows() >= GetNTableRows())) {
341  fAllData = kTRUE;
342  } else {
343  fAllData = kFALSE;
344  }
345 
346  TGLayoutHints *lhints = 0;
347 
348  // Add cells and headers to layout frames
349  for (i = 0; i < nrows; i++) {
350  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
351  fRHdrHintsList->Add(lhints);
352  fRHdrFrame->AddFrame(GetRowHeader(i), lhints);
353  for (j = 0; j < ncolumns; j++) {
354  if (i == 0) {
355  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
356  fCHdrHintsList->Add(lhints);
357  fCHdrFrame->AddFrame(GetColumnHeader(j), lhints);
358  }
359  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
360  fCellHintsList->Add(lhints);
361  fCanvas->AddFrame(GetCell(i,j), lhints);
362  }
363  }
364 
365  // Add frames to the range frame
366  lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
367  fRangeFrame->AddFrame(fGotoButton, lhints);
368  lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
369  fRangeFrame->AddFrame(fRangeEntry, lhints);
370  lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
371  fRangeFrame->AddFrame(fRangeLabel, lhints);
372  lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
373  fRangeFrame->AddFrame(fFirstCellEntry, lhints);
374  lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
375  fRangeFrame->AddFrame(fFirstCellLabel, lhints);
376  lhints = new TGLayoutHints(kLHintsRight |kLHintsTop);
377  fRangeFrame->Resize();
378  // Range frame size = 448
379  AddFrame(fRangeFrame, lhints);
380 
381  // Add table to the main composite frame
382  lhints = new TGLayoutHints(kLHintsLeft |kLHintsTop);
383  fTopFrame->AddFrame(fTableHeader, lhints);
385  fTopExtraFrame->AddFrame(fCHdrFrame, lhints);
387  fTopFrame->AddFrame(fTopExtraFrame, lhints);
389  fBottomFrame->AddFrame(fRHdrFrame, lhints);
391  | kLHintsExpandY);
392  fBottomFrame->AddFrame(fCanvas, lhints);
393 
394  // Add buttons to button frame
395  lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
396  fButtonFrame->AddFrame(fNextButton, lhints);
397  lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 3, 4, 4);
398  fButtonFrame->AddFrame(fPrevButton, lhints);
399  lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
400  fButtonFrame->AddFrame(fUpdateButton, lhints);
401  fButtonFrame->Resize();
402  fButtonFrame->ChangeOptions(fButtonFrame->GetOptions() | kFixedWidth);
403 
405  AddFrame(fTopFrame, lhints);
408  AddFrame(fBottomFrame, lhints);
409  lhints = new TGLayoutHints(kLHintsExpandX | kLHintsTop);
410  AddFrame(fButtonFrame, lhints);
411 
412  // Setup scrolling for the headers
413  TGScrollBar *sbar= fCanvas->GetVScrollbar();
414  sbar->Connect("PositionChanged(Int_t)", "TGTable", this, "ScrollRHeaders(Int_t)");
415  sbar = fCanvas->GetHScrollbar();
416  sbar->Connect("PositionChanged(Int_t)", "TGTable", this, "ScrollCHeaders(Int_t)");
417 
418  // Connections for buttons
419  fUpdateButton->Connect("Clicked()", "TGTable", this, "Update()");
420  fNextButton->Connect("Clicked()", "TGTable", this, "NextChunk()");
421  fPrevButton->Connect("Clicked()", "TGTable", this, "PreviousChunk()");
422  fGotoButton->Connect("Clicked()", "TGTable", this, "Goto()");
423 
424 // MapSubwindows();
425 // Layout();
426 }
427 
428 ////////////////////////////////////////////////////////////////////////////////
429 /// Redraw the TGTable.
430 
431 void TGTable::DoRedraw()
432 {
433  MapSubwindows();
434  Layout();
435 }
436 
437 ////////////////////////////////////////////////////////////////////////////////
438 /// Expand a TGTable by nrows and ncolumns.
439 
440 void TGTable::Expand(UInt_t nrows, UInt_t ncolumns)
441 {
442  ExpandRows(nrows);
443  ExpandColumns(ncolumns);
444 }
445 
446 ////////////////////////////////////////////////////////////////////////////////
447 /// Expand the columns of a TGTable by ncolumns.
448 
449 void TGTable::ExpandColumns(UInt_t ncolumns)
450 {
451  UInt_t i = 0, j = 0;
452  TGString *label = 0;
453 
454  UInt_t ntrows = GetNTableRows();
455  UInt_t ntcolumns = GetNTableColumns();
456 
457  fColumnHeaders->Expand(ntcolumns + ncolumns);
458 
459  for (i = 0; i < ncolumns; i++) {
460  TGTableHeader *header = new TGTableHeader(fCHdrFrame, this, label,
461  ntcolumns + i,
462  kColumnHeader);
463  fColumnHeaders->AddAt(header, ntcolumns + i);
464  }
465 
466  for (i = 0; i < ntrows; i++) {
467  GetRow(i)->Expand(ntcolumns + ncolumns);
468  for (j = 0; j < ncolumns; j++) {
469  TGTableCell *cell = new TGTableCell(fCanvas->GetContainer(), this, label, i,
470  ntcolumns + j);
471  if (GetRow(i)) GetRow(i)->AddAt(cell, ntcolumns + j);
472  }
473  }
474 
475  fCurrentRange->fXbr += ncolumns;
476 
477  if ((GetNDataColumns() == GetNTableColumns()) &&
478  (GetNDataRows() == GetNTableRows())) {
479  fAllData = kTRUE;
480  } else {
481  fAllData = kFALSE;
482  }
483 }
484 
485 ////////////////////////////////////////////////////////////////////////////////
486 /// Expand the rows of a TGTable by nrows.
487 
488 void TGTable::ExpandRows(UInt_t nrows)
489 {
490  UInt_t i = 0, j = 0;
491 
492  UInt_t ntrows = GetNTableRows();
493  UInt_t ntcolumns = GetNTableColumns();
494 
495  fRows->Expand(ntrows + nrows);
496  fRowHeaders->Expand(ntrows + nrows);
497  for (i = 0; i < nrows; i++) {
498  TObjArray *row = new TObjArray(ntcolumns);
499  fRows->AddAt(row, ntrows + i);
500  TGString *label = 0;
501  TGTableHeader *header = new TGTableHeader(fRHdrFrame, this, label,
502  ntrows + i, kRowHeader);
503  fRowHeaders->AddAt(header, ntrows + i);
504  for (j = 0; j < ntcolumns ; j++) {
505  TGTableCell *cell = new TGTableCell(fCanvas->GetContainer(), this, label,
506  ntrows + i, j);
507  if (GetRow(ntrows + i)) GetRow(ntrows + i)->AddAt(cell, j);
508  }
509  }
510 
511  fCurrentRange->fYbr += nrows;
512 
513  if ((GetNDataColumns() == GetNTableColumns()) &&
514  (GetNDataRows() == GetNTableRows())) {
515  fAllData = kTRUE;
516  } else {
517  fAllData = kFALSE;
518  }
519 }
520 
521 ////////////////////////////////////////////////////////////////////////////////
522 /// Get the current width of the column header frame.
523 
525 {
526  Int_t ncolumns = GetNTableColumns();
527  UInt_t width = 0;
528  for (Int_t i = 0; i < ncolumns; i++) {
529  if (GetColumnHeader(i)) width += GetColumnHeader(i)->GetWidth();
530  }
531  return width;
532 }
533 
534 ////////////////////////////////////////////////////////////////////////////////
535 /// Get the current height of the row header frame.
536 
538 {
539  Int_t nrows = GetNTableRows();
540  UInt_t height = 0;
541  for (Int_t i = 0; i < nrows; i++) {
542  if (GetRowHeader(i)) height += GetRowHeader(i)->GetHeight();
543  }
544  return height;
545 }
546 
547 ////////////////////////////////////////////////////////////////////////////////
548 /// Shrink the TGTable by nrows and ncolumns.
549 
550 void TGTable::Shrink(UInt_t nrows, UInt_t ncolumns)
551 {
552  ShrinkRows(nrows);
553  ShrinkColumns(ncolumns);
554 }
555 
556 ////////////////////////////////////////////////////////////////////////////////
557 /// Shrink the columns of the TGTable by ncolumns.
558 
559 void TGTable::ShrinkColumns(UInt_t ncolumns)
560 {
561  UInt_t i = 0, j = 0, k = 0;
562 
563  if(GetNTableColumns() - ncolumns < 1) {
564  Info("TGTable::ShrinkColumns", "Cannot shrink smaller than 1"
565  " column, adjusting");
566  ncolumns = GetNTableColumns() - 1;
567  }
568 
569  UInt_t ntrows = GetNTableRows();
570  UInt_t ntcolumns = GetNTableColumns();
571 
572  TGTableCell *cell = 0;
573 
574  //Destroy windows
575 
576  for (i = 0; i < ntrows; i++) {
577  for (j = 0; j < ncolumns; j++) {
578  k = ntcolumns - ncolumns + j;
579  if (GetRow(i)) {
580  cell = (TGTableCell *)GetRow(i)->RemoveAt(k);
581  if (cell) {
582  cell->DestroyWindow();
583  delete cell;
584  }
585  }
586  }
587  GetRow(i)->Expand(ntcolumns - ncolumns);
588  }
589 
590  TGTableHeader *hdr = 0;
591  for (j = 0; j < ncolumns; j++) {
592  hdr = (TGTableHeader *)fColumnHeaders->RemoveAt(ntcolumns - ncolumns + j);
593  hdr->DestroyWindow();
594  delete hdr;
595  }
596  fColumnHeaders->Expand(ntcolumns - ncolumns);
597 
598  fCurrentRange->fXbr -= ncolumns;
599 
600 
601  if ((GetNDataColumns() == GetNTableColumns()) &&
602  (GetNDataRows() == GetNTableRows())) {
603  fAllData = kTRUE;
604  } else {
605  fAllData = kFALSE;
606  }
607 }
608 
609 ////////////////////////////////////////////////////////////////////////////////
610 /// Shrink the rows of the TGTable by nrows.
611 
612 void TGTable::ShrinkRows(UInt_t nrows)
613 {
614  UInt_t i = 0 , j = 0;
615 
616  if(GetNTableRows() - nrows < 1) {
617  Info("TGTable::ShrinkRows", "Cannot shrink smaller than 1 row, adjusting");
618  nrows = GetNTableRows() - 1;
619  }
620 
621  UInt_t ntrows = GetNTableRows();
622  UInt_t ntcolumns = GetNTableColumns();
623 
624  TObjArray *row = 0;
625  TGTableCell *cell = 0;
626  TGTableHeader *hdr = 0;
627 
628  for (i = 0; i < nrows; i++) {
629  for (j = 0; j < ntcolumns ; j++) {
630  if (GetRow(ntrows - nrows + i)) {
631  cell = (TGTableCell *)GetRow(ntrows - nrows + i)->RemoveAt(j);
632  if (cell) {
633  cell->DestroyWindow();
634  delete cell;
635  }
636  }
637  }
638  row = (TObjArray *)fRows->RemoveAt(ntrows - nrows + i);
639  delete row;
640  hdr = (TGTableHeader *)fRowHeaders->RemoveAt(ntrows - nrows + i);
641  hdr->DestroyWindow();
642  delete hdr;
643  }
644  fRows->Expand(ntrows - nrows);
645  fRowHeaders->Expand(ntrows - nrows);
646 
647  fCurrentRange->fYbr -= nrows;
648 
649  if ((GetNDataColumns() == GetNTableColumns()) &&
650  (GetNDataRows() == GetNTableRows())) {
651  fAllData = kTRUE;
652  } else {
653  fAllData = kFALSE;
654  }
655 }
656 
657 ////////////////////////////////////////////////////////////////////////////////
658 /// Update the labels of the headers of the given type
659 
661 {
662  UInt_t max = 0, i = 0, d = 0;
663  if(type == kColumnHeader) {
664  max = GetNTableColumns();
665  for (i = 0; i < max; i++) {
666  d = fCurrentRange->fXtl + i;
667  if (GetColumnHeader(i) && fInterface->GetColumnHeader(d))
668  GetColumnHeader(i)->SetLabel(fInterface->GetColumnHeader(d));
669  }
670  } else if (type == kRowHeader) {
671  max = GetNTableRows();
672  for (i = 0; i < max; i++) {
673  d = fCurrentRange->fYtl + i;
674  if (GetRowHeader(i) && fInterface->GetRowHeader(d))
675  GetRowHeader(i)->SetLabel(fInterface->GetRowHeader(d));
676  }
677  }
678 }
679 
680 ////////////////////////////////////////////////////////////////////////////////
681 /// Set the interface that the TGTable uses to interface.
682 
684  UInt_t nrows, UInt_t ncolumns)
685 {
686  fInterface = interface;
687 
688  // Set up ranges
689 
690  fDataRange->fXtl = 0;
691  fDataRange->fYtl = 0;
692  fDataRange->fXbr = fInterface->GetNColumns();
693  fDataRange->fYbr = fInterface->GetNRows();
694 
695  UInt_t x = 0, y = 0;
696  if (fDataRange->fXbr < ncolumns) {
697  x = fDataRange->fXbr;
698  } else {
699  x = ncolumns;
700  }
701 
702  if (fDataRange->fYbr < nrows) {
703  y = fDataRange->fYbr;
704  } else {
705  y = nrows;
706  }
707 
708  GotoTableRange(0, 0, x, y);
709 
710  if ((GetNDataColumns() == GetNTableColumns()) &&
711  (GetNDataRows() == GetNTableRows())) {
712  fAllData = kTRUE;
713  } else {
714  fAllData = kFALSE;
715  }
716 }
717 
718 ////////////////////////////////////////////////////////////////////////////////
719 /// Resize the table to newnrows and newncolumns and add all the frames to
720 /// their parent frames.
721 
722 void TGTable::ResizeTable(UInt_t newnrows, UInt_t newncolumns)
723 {
724  UInt_t oldnrows = GetNTableRows();
725  UInt_t oldncolumns = GetNTableColumns();
726 
727  Int_t i = 0, j = 0;
728 
729  TGCompositeFrame *container = (TGCompositeFrame *)fCanvas->GetContainer();
730 
731  if (newnrows != oldnrows){
732  if (newnrows > oldnrows) {
733  ExpandRows(newnrows - oldnrows);
734  } else {
735  ShrinkRows(oldnrows - newnrows);
736  }
737  }
738 
739  if (newncolumns != oldncolumns){
740  if (newncolumns > oldncolumns) {
741  ExpandColumns(newncolumns - oldncolumns);
742  } else {
743  ShrinkColumns(oldncolumns - newncolumns);
744  }
745  }
746 
747  // Update the layoutmanager and add the frames.
748  if ((newncolumns != oldncolumns) || (newnrows != oldnrows)) {
749  container->RemoveAll();
750  fCellHintsList->Delete();
751 
752  fRHdrFrame->RemoveAll();
753  fRHdrHintsList->Delete();
754 
755  fCHdrFrame->RemoveAll();
756  fCHdrHintsList->Delete();
757 
758  container->SetLayoutManager(new TGMatrixLayout(container,
759  newnrows, newncolumns));
760  // Add frames to layout frames
761  TGLayoutHints *lhints = 0;
762  for (i = 0; i < (Int_t)newnrows; i++) {
763  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
764  fRHdrHintsList->Add(lhints);
765  fRHdrFrame->AddFrame(GetRowHeader(i), lhints);
766  for (j = 0; j < (Int_t)newncolumns; j++) {
767  if (i == 0) {
768  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
769  fCHdrHintsList->Add(lhints);
770  fCHdrFrame->AddFrame(GetColumnHeader(j), lhints);
771  }
772  lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
773  fCellHintsList->Add(lhints);
774  fCanvas->AddFrame(GetCell(i,j), lhints);
775  }
776  }
777  }
778  fCanvas->MapSubwindows();
779  fCanvas->Layout();
780 }
781 
782 ////////////////////////////////////////////////////////////////////////////////
783 /// Update the range shown in the range frame.
784 
786 {
787  TString tl, range;
788 
789  tl += fCurrentRange->fYtl;
790  tl += ",";
791  tl += fCurrentRange->fXtl;
792  fFirstCellEntry->SetText(tl.Data());
793 
794  range += GetNTableRows();
795  range += "x";
796  range += GetNTableColumns();
797  fRangeEntry->SetText(range.Data());
798 
799  fGotoButton->SetState(kButtonDisabled);
800 }
801 
802 ////////////////////////////////////////////////////////////////////////////////
803 /// Get row. NOTE: Do not delete the TObjArray returned or the cells
804 /// it contains, they are owned by the TGTable.
805 
807 {
808  return (TObjArray *)fRows->At(row);
809 }
810 
811 ////////////////////////////////////////////////////////////////////////////////
812 /// Return a pointer to a TObjArray that contains pointers to all
813 /// the cells in column. NOTE: The user will have to delete the
814 /// TObjArray, but do NOT delete the cells it contains, they are
815 /// owned by the TGTable and will be deleted from the TGTable with
816 /// undefined consequenses.
817 
819 {
820  UInt_t nrows = GetNTableRows();
821 
822  TObjArray *col = new TObjArray(nrows);
823  for(UInt_t ui = 0; ui < nrows; ui++) {
824  col->AddAt(GetCell(ui, column), ui);
825  }
826  return col;
827 }
828 
829 // //______________________________________________________________________________
830 // void TGTable::Select(TGTableCell *celltl, TGTableCell *cellbr)
831 // {
832 // }
833 
834 // //______________________________________________________________________________
835 // void TGTable::Select(UInt_t xcelltl, UInt_t ycelltl, UInt_t xcell2, UInt_t ycell2)
836 // {
837 // }
838 
839 // //______________________________________________________________________________
840 // void TGTable::SelectAll()
841 // {
842 // }
843 
844 // //______________________________________________________________________________
845 // void TGTable::SelectRow(TGTableCell *cell)
846 // {
847 // }
848 
849 // //______________________________________________________________________________
850 // void TGTable::SelectRow(UInt_t row)
851 // {
852 // }
853 
854 // //______________________________________________________________________________
855 // void TGTable::SelectRows(UInt_t row, UInt_t nrows)
856 // {
857 // }
858 
859 // //______________________________________________________________________________
860 // void TGTable::SelectColumn(TGTableCell *cell)
861 // {
862 // }
863 
864 // //______________________________________________________________________________
865 // void TGTable::SelectColumn(UInt_t column)
866 // {
867 // }
868 
869 // //______________________________________________________________________________
870 // void TGTable::SelectColumns(UInt_t column, UInt_t ncolumns)
871 // {
872 // }
873 
874 // //______________________________________________________________________________
875 // void TGTable::SetBckgndGC(TGGC *gc)
876 // {
877 // }
878 
879 // //______________________________________________________________________________
880 // void TGTable::SetSelectGC(TGGC *gc)
881 // {
882 // }
883 
884 // //______________________________________________________________________________
885 // void TGTable::SetTextJustify(Int_t tmode)
886 // {
887 // }
888 
889 ////////////////////////////////////////////////////////////////////////////////
890 /// Const version of GetCell().
891 
892 const TGTableCell* TGTable::GetCell(UInt_t i, UInt_t j) const
893 {
894  return const_cast<TGTable *>(this)->GetCell(i, j);
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 /// Return a pointer to the TGTableCell at position i,j.
899 
901 {
902  TObjArray *row = (TObjArray *)fRows->At(i);
903  if(row) {
904  TGTableCell *cell = (TGTableCell *)row->At(j);
905  return cell;
906  } else {
907  return 0;
908  }
909 }
910 
911 ////////////////////////////////////////////////////////////////////////////////
912 /// Const version of FindCell().
913 
914 const TGTableCell* TGTable::FindCell(TGString label) const
915 {
916  return const_cast<TGTable *>(this)->FindCell(label);
917 }
918 
919 ////////////////////////////////////////////////////////////////////////////////
920 /// Find the TGTableCell with label.
921 
923 {
924  TObjArray *row = 0;
925  TGTableCell *cell = 0;
926  UInt_t i = 0, j = 0;
927  //continue here
928  UInt_t nrows = GetNTableRows();
929  UInt_t ncolumns = GetNTableColumns();
930  for (i = 0; i < nrows; i++) {
931  for (j = 0; j < ncolumns; j++) {
932  row = (TObjArray *)fRows->At(j);
933  cell = (TGTableCell *)row->At(i);
934  if (*(cell->GetLabel()) == label) {
935  return cell;
936  }
937  }
938  }
939  return 0;
940 }
941 
942 ////////////////////////////////////////////////////////////////////////////////
943 /// Show the contents of the TGTable in stdout.
944 
945 void TGTable::Show()
946 {
947  TGTableCell *cell = 0;
948  TGTableHeader *hdr = 0;
949  UInt_t i = 0, j = 0;
950  UInt_t nrows = GetNTableRows();
951  UInt_t ncolumns = GetNTableColumns();
952 
953  // save actual formatting flags
954  std::ios_base::fmtflags org_flags = std::cout.flags();
955 
956  for (j = 0; j < ncolumns + 1; j++) {
957  if (j == 0) {
958  hdr = fTableHeader;
959  if (hdr) std::cout << " " << std::setw(12) << std::right
960  << hdr->GetLabel()->GetString() << " ";
961  } else {
962  hdr = GetColumnHeader(j - 1);
963  if (hdr) std::cout << " " << std::setw(12) << std::right
964  << hdr->GetLabel()->GetString() << " ";
965  }
966  }
967  std::cout << std::endl;
968 
969  for (i = 0; i < nrows; i++) {
970  for (j = 0; j < ncolumns + 1; j++) {
971  if (j == 0) {
972  hdr = GetRowHeader(i);
973  if (hdr) std::cout << " " << std::setw(12) << std::right
974  << hdr->GetLabel()->GetString() << " ";
975  } else {
976  cell = GetCell(i, j - 1);
977  if (cell) std::cout << " " << std::setw(12) << std::right
978  << cell->GetLabel()->GetString() << " ";
979  }
980  }
981  std::cout << std::endl;
982  }
983  // restore original formatting flags
984  std::cout.flags(org_flags);
985 }
986 
987 // //______________________________________________________________________________
988 // void TGTable::InsertRowBefore(UInt_t row, UInt_t nrows)
989 // {
990 // }
991 
992 // //______________________________________________________________________________
993 // void TGTable::InsertRowBefore(TGString label, UInt_t nrows)
994 // {
995 // }
996 
997 // //______________________________________________________________________________
998 // void TGTable::InsertRowAfter(UInt_t row, UInt_t nrows)
999 // {
1000 // }
1001 
1002 // //______________________________________________________________________________
1003 // void TGTable::InsertRowAfter(TGString label, UInt_t nrows)
1004 // {
1005 // }
1006 
1007 // //______________________________________________________________________________
1008 // void TGTable::InsertRowAt(UInt_t row, UInt_t nrows)
1009 // {
1010 // }
1011 
1012 // //______________________________________________________________________________
1013 // void TGTable::InsertRowAt(TGString label, UInt_t nrows)
1014 // {
1015 // }
1016 
1017 // //______________________________________________________________________________
1018 // void TGTable::InsertColumnBefore(UInt_t column, UInt_t ncolumns)
1019 // {
1020 // }
1021 
1022 // //______________________________________________________________________________
1023 // void TGTable::InsertColumnBefore(TGString label, UInt_t ncolumns)
1024 // {
1025 // }
1026 
1027 // //______________________________________________________________________________
1028 // void TGTable::InsertColumnAfter(UInt_t column, UInt_t ncolumns)
1029 // {
1030 // }
1031 
1032 // //______________________________________________________________________________
1033 // void TGTable::InsertColumnAfter(TGString label, UInt_t ncolumns)
1034 // {
1035 // }
1036 
1037 // //______________________________________________________________________________
1038 // void TGTable::InsertColumnAt(UInt_t column, UInt_t ncolumns)
1039 // {
1040 // }
1041 
1042 // //______________________________________________________________________________
1043 // void TGTable::InsertColumnAt(TGString label, UInt_t ncolumns)
1044 // {
1045 // }
1046 
1047 // //______________________________________________________________________________
1048 // void TGTable::RemoveRows(UInt_t row, UInt_t nrows)
1049 // {
1050 // }
1051 
1052 // //______________________________________________________________________________
1053 // void TGTable::RemoveColumns(UInt_t column, UInt_t ncolumns)
1054 // {
1055 // }
1056 
1057 ////////////////////////////////////////////////////////////////////////////////
1058 /// Update and layout the visible part of the TGTable.
1059 
1060 void TGTable::UpdateView()
1061 {
1062  UInt_t nrows = GetNTableRows();
1063  UInt_t ncolumns = GetNTableColumns();
1064 
1065  TGString *str = new TGString();
1066  *str += nrows;
1067  *str += "x";
1068  *str += ncolumns;
1069  *str += " Table";
1070  fTableHeader->SetLabel(str->GetString());
1071  delete str;
1072 
1073  UpdateHeaders(kRowHeader);
1074  UpdateHeaders(kColumnHeader);
1075 
1076  UInt_t i = 0, j = 0;
1077  UInt_t k = 0, l = 0;
1078 
1079  TGTableCell * cell = 0;
1080  for (i = 0; i < nrows; i++) {
1081  for (j = 0; j < ncolumns; j++) {
1082  cell = GetCell(i,j);
1083  k = fCurrentRange->fYtl + i;
1084  l = fCurrentRange->fXtl + j;
1085 
1086  const char *label = fInterface->GetValueAsString(k,l);
1087  if(cell) cell->SetLabel(label);
1088  }
1089  }
1090 
1091  MapSubwindows();
1092  Layout();
1093  gClient->NeedRedraw(fTableHeader);
1094  TGViewPort *vp = fCanvas->GetViewPort();
1095  fTableFrame->DrawRegion(0, 0, vp->GetWidth(), vp->GetHeight());
1096  fCHdrFrame->DrawRegion(0, 0, fCHdrFrame->GetWidth(), fCHdrFrame->GetHeight());
1097  fRHdrFrame->DrawRegion(0, 0, fRHdrFrame->GetWidth(), fRHdrFrame->GetHeight());
1098 
1099  UpdateRangeFrame();
1100 }
1101 
1102 ////////////////////////////////////////////////////////////////////////////////
1103 /// Return the amount of rows in the table.
1104 
1106 {
1107  return fCurrentRange->fYbr - fCurrentRange->fYtl;
1108 }
1109 
1110 ////////////////////////////////////////////////////////////////////////////////
1111 /// Return the amount of rows in the data source.
1112 
1114 {
1115  return fDataRange->fYbr - fDataRange->fYtl;
1116 }
1117 
1118 ////////////////////////////////////////////////////////////////////////////////
1119 /// Return the amount of columns in the table.
1120 
1122 {
1123  return fCurrentRange->fXbr - fCurrentRange->fXtl;
1124 }
1125 
1126 ////////////////////////////////////////////////////////////////////////////////
1127 /// Return the amount of columns in the data source.
1128 
1130 {
1131  return fDataRange->fYbr - fDataRange->fYtl;
1132 }
1133 
1134 ////////////////////////////////////////////////////////////////////////////////
1135 /// Return the amount of cells in the table.
1136 
1138 {
1139  return GetNTableRows() * GetNTableColumns();
1140 }
1141 
1142 ////////////////////////////////////////////////////////////////////////////////
1143 /// Return the amount of cell in the data source.
1144 
1146 {
1147  return GetNDataRows() * GetNDataColumns();
1148 }
1149 
1150 ////////////////////////////////////////////////////////////////////////////////
1151 /// Return the current range of the TGTable.
1152 
1154 {
1155  return fCurrentRange;
1156 }
1157 
1158 ////////////////////////////////////////////////////////////////////////////////
1159 /// Const version of GetRowHeader();
1160 
1161 const TGTableHeader *TGTable::GetRowHeader(const UInt_t row) const
1162 {
1163  return const_cast<TGTable *>(this)->GetRowHeader(row);
1164 }
1165 
1166 ////////////////////////////////////////////////////////////////////////////////
1167 /// Return a pointer to the header of row.
1168 
1170 {
1171  return (TGTableHeader *)fRowHeaders->At(row);
1172 }
1173 
1174 ////////////////////////////////////////////////////////////////////////////////
1175 /// Const version of GetColumnHeader();
1176 
1177 const TGTableHeader *TGTable::GetColumnHeader(const UInt_t column) const
1178 {
1179  return const_cast<TGTable *>(this)->GetColumnHeader(column);
1180 }
1181 
1182 ////////////////////////////////////////////////////////////////////////////////
1183 /// Return a pointer to the header of column.
1184 
1186 {
1187  return (TGTableHeader *)fColumnHeaders->At(column);
1188 }
1189 
1190 ////////////////////////////////////////////////////////////////////////////////
1191 /// Return a pointer to the table header.
1192 
1194 {
1195  return fTableHeader;
1196 }
1197 
1198 // //______________________________________________________________________________
1199 // const TGGC* TGTable::GetSelectGC() const
1200 // {
1201 // }
1202 
1203 // //______________________________________________________________________________
1204 // const TGGC* TGTable::GetCellBckgndGC(TGTableCell *cell) const
1205 // {
1206 // }
1207 
1208 // //______________________________________________________________________________
1209 // const TGGC* TGTable::GetCellBckgndGC(UInt_t row, UInt_t column) const
1210 // {
1211 // }
1212 
1213 ////////////////////////////////////////////////////////////////////////////////
1214 /// Get the background collor for row.
1215 
1217 {
1218  if (row % 2 == 0) { // Even rows
1219  return fEvenRowBackground;
1220  } else { // Odd rows
1221  return fOddRowBackground;
1222  }
1223 }
1224 
1225 ////////////////////////////////////////////////////////////////////////////////
1226 /// Get the background color of headers.
1227 
1229 {
1230  return fHeaderBackground;
1231 }
1232 
1233 ////////////////////////////////////////////////////////////////////////////////
1234 /// Set the background color for all odd numbered rows.
1235 
1237 {
1238  if(pixel == fOddRowBackground) return;
1239 
1240  fOddRowBackground = pixel;
1241 
1242  UInt_t nrows = GetNTableRows();
1243  UInt_t ncolumns = GetNTableColumns();
1244  UInt_t i = 0, j = 0;
1245  TGTableCell *cell = 0;
1246 
1247  for (i = 0; i < nrows; i++) {
1248  for (j = 0; j < ncolumns; j++) {
1249  if (i % 2) {
1250  cell = GetCell(i,j);
1251  if (cell) cell->SetBackgroundColor(fOddRowBackground);
1252  }
1253  }
1254  }
1255 
1256  UInt_t width = fCanvas->GetViewPort()->GetWidth();
1257  UInt_t height = fCanvas->GetViewPort()->GetHeight();
1258  fTableFrame->DrawRegion(0, 0, width, height);
1259 }
1260 
1261 ////////////////////////////////////////////////////////////////////////////////
1262 /// Set the background color for all even numbered rows.
1263 
1265 {
1266  if(pixel == fEvenRowBackground) return;
1267 
1268  fEvenRowBackground = pixel;
1269 
1270  UInt_t nrows = GetNTableRows();
1271  UInt_t ncolumns = GetNTableColumns();
1272  UInt_t i = 0, j = 0;
1273  TGTableCell *cell = 0;
1274 
1275  for (i = 0; i < nrows; i++) {
1276  for (j = 0; j < ncolumns; j++) {
1277  if (!(i % 2)) {
1278  cell = GetCell(i,j);
1279  if (cell) cell->SetBackgroundColor(fEvenRowBackground);
1280  }
1281  }
1282  }
1283  UInt_t width = fCanvas->GetViewPort()->GetWidth();
1284  UInt_t height = fCanvas->GetViewPort()->GetHeight();
1285  fTableFrame->DrawRegion(0, 0, width, height);
1286 }
1287 
1288 ////////////////////////////////////////////////////////////////////////////////
1289 /// Set the background color for the headers.
1290 
1292 {
1293  if(pixel == fHeaderBackground) return;
1294 
1295  fHeaderBackground = pixel;
1296 
1297  UInt_t nrows = GetNTableRows();
1298  UInt_t ncolumns = GetNTableColumns();
1299  UInt_t i = 0, j = 0;
1300  TGTableHeader *hdr = 0;
1301 
1302  for (i = 0; i < nrows; i++) {
1303  hdr = GetRowHeader(i);
1304  if (hdr) hdr->SetBackgroundColor(fHeaderBackground);
1305  }
1306  UInt_t height = fCanvas->GetViewPort()->GetHeight();
1307  UInt_t width = fTableHeader->GetWidth();
1308  fRHdrFrame->DrawRegion(0, 0, width, height);
1309 
1310  for (j = 0; j < ncolumns; j++) {
1311  hdr = GetColumnHeader(j);
1312  if (hdr) hdr->SetBackgroundColor(fHeaderBackground);
1313 // gClient->NeedRedraw(hdr);
1314  }
1315  width = fCanvas->GetViewPort()->GetWidth();
1316  height = fTableHeader->GetHeight();
1317  fCHdrFrame->DrawRegion(0, 0, width, height);
1318 }
1319 
1320 ////////////////////////////////////////////////////////////////////////////////
1321 /// Set the background color for all rows and headers to their defaults.
1322 
1324 {
1325  SetEvenRowBackground(TColor::RGB2Pixel(204, 255, 204));
1326  SetOddRowBackground(TColor::RGB2Pixel(255, 255, 255));
1327  SetHeaderBackground(TColor::RGB2Pixel(204, 204, 255));
1328 }
1329 
1330 ////////////////////////////////////////////////////////////////////////////////
1331 /// Move and layout the table to the specified range.
1332 
1333 void TGTable::MoveTable(Int_t rows, Int_t columns)
1334 {
1335  if (fAllData) return;
1336 
1337  Int_t xtl = fCurrentRange->fXtl + columns;
1338  Int_t ytl = fCurrentRange->fYtl + rows;
1339  Int_t xbr = fCurrentRange->fXbr + columns;
1340  Int_t ybr = fCurrentRange->fYbr + rows;
1341 
1342  GotoTableRange(xtl, ytl, xbr, ybr);
1343 }
1344 
1345 ////////////////////////////////////////////////////////////////////////////////
1346 /// Move and resize the table to the specified range.
1347 
1348 void TGTable::GotoTableRange(Int_t xtl, Int_t ytl, Int_t xbr, Int_t ybr)
1349 {
1350  if (fAllData) return;
1351 
1352  if(xtl == xbr || ytl == ybr) {
1353  Error("TGTable::GotoTableRange","x or y range = 0");
1354  return;
1355  }
1356 
1357  Int_t nrows = TMath::Abs(ybr - ytl);
1358  Int_t ncolumns = TMath::Abs(xbr - xtl);
1359 
1360  if (xtl > xbr) {
1361  Info("TGTable::GotoTableRange","Swapping x-range boundries");
1362  Int_t temp = xtl;
1363  xtl = xbr;
1364  xbr = temp;
1365  }
1366  if (ytl > ybr) {
1367  Info("TGTable::GotoTableRange","Swapping y-range boundries");
1368  Int_t temp = ytl;
1369  ytl = ybr;
1370  ybr = temp;
1371  }
1372 
1373  if((xtl < 0) || (xbr < 0)) {
1374  Info("TGTable::GotoTableRange", "Column boundry out of bounds, adjusting");
1375  xtl = 0;
1376  xbr = ncolumns;
1377  if (xbr > (Int_t)fDataRange->fXbr) {
1378  xbr = fDataRange->fXbr;
1379  ncolumns = TMath::Abs(xbr - xtl);
1380  }
1381  }
1382 
1383  if((ytl < 0) || (ybr < 0)) {
1384  Info("TGTable::GotoTableRange", "Row boundry out of bounds, adjusting");
1385  ytl = 0;
1386  ybr = nrows;
1387  if (ybr > (Int_t)fDataRange->fYbr) {
1388  ybr = fDataRange->fYbr;
1389  nrows = TMath::Abs(ybr - ytl);
1390  }
1391  }
1392 
1393  if((xtl > (Int_t)fDataRange->fXbr) || (xbr > (Int_t)fDataRange->fXbr)) {
1394  Info("TGTable::GotoTableRange", "Left Column boundry out of bounds, "
1395  "adjusting");
1396  xbr = fDataRange->fXbr;
1397  xtl = xbr - ncolumns;
1398  if (xtl < 0) {
1399  xtl = 0;
1400  ncolumns = TMath::Abs(xbr - xtl);
1401  Info("TGTable::GotoTableRange", "Right column boundry out of"
1402  " bounds, set to 0");
1403  }
1404  }
1405  if ((ytl > (Int_t)fDataRange->fYbr) || (ybr > (Int_t)fDataRange->fYbr)) {
1406  Info("TGTable::GotoTableRange", "Bottom row boundry out of bounds, "
1407  "adjusting");
1408  ybr = fDataRange->fYbr;
1409  ytl = ybr - nrows;
1410  if (ytl < 0) {
1411  ytl = 0;
1412  nrows = ybr - ytl;
1413  Info("TGTable::GotoTableRange", "Top row boundry out of bounds, "
1414  "set to 0");
1415  }
1416  }
1417 
1418  nrows = TMath::Abs(ybr - ytl);
1419  ncolumns = TMath::Abs(xbr - xtl);
1420 
1421  // Resize rows and columns if needed
1422  ResizeTable(nrows, ncolumns);
1423 
1424  fCurrentRange->fXtl = xtl;
1425  fCurrentRange->fYtl = ytl;
1426  fCurrentRange->fXbr = xbr;
1427  fCurrentRange->fYbr = ybr;
1428 
1429  // Update the table view.
1430  UpdateView();
1431 }
1432 
1433 ////////////////////////////////////////////////////////////////////////////////
1434 /// Operator for easy cell acces.
1435 
1437 {
1438  return GetCell(row, column);
1439 }
1440 
1441 ////////////////////////////////////////////////////////////////////////////////
1442 /// Scroll the column headers horizontally.
1443 
1444 void TGTable::ScrollCHeaders(Int_t xpos)
1445 {
1446  if (!fCHdrFrame) return;
1447 
1448  fCHdrFrame->Move(- xpos, 0);
1449  fCHdrFrame->Resize();
1450  fCHdrFrame->DrawRegion(0, 0, fCHdrFrame->GetWidth(),
1451  fCHdrFrame->GetHeight());
1452 }
1453 
1454 ////////////////////////////////////////////////////////////////////////////////
1455 /// Scroll the row headers vertically
1456 
1457 void TGTable::ScrollRHeaders(Int_t ypos)
1458 {
1459  if (!fRHdrFrame) return;
1460 
1461  fRHdrFrame->Move(fRHdrFrame->GetX(), -ypos);
1462  fRHdrFrame->Resize();
1463  fRHdrFrame->DrawRegion(0, 0, fRHdrFrame->GetWidth(),
1464  fRHdrFrame->GetHeight());
1465 }
1466 
1467 ////////////////////////////////////////////////////////////////////////////////
1468 /// Move the table to the next chunk of the data set with the same size.
1469 
1470 void TGTable::NextChunk()
1471 {
1472  MoveTable(GetNTableRows(), 0);
1473  UpdateRangeFrame();
1474 }
1475 
1476 ////////////////////////////////////////////////////////////////////////////////
1477 /// Move the table to the previous chunk of the data set with the same size.
1478 
1480 {
1481  MoveTable(-1 * (Int_t)GetNTableRows(), 0);
1482  UpdateRangeFrame();
1483 }
1484 
1485 ////////////////////////////////////////////////////////////////////////////////
1486 /// Slot used by the Goto button and whenever return is pressed in
1487 /// on of the text entries in the range frame.
1488 
1489 void TGTable::Goto()
1490 {
1491  if (fGotoButton->GetState() == kButtonUp) {
1492  GotoTableRange(fGotoRange->fXtl, fGotoRange->fYtl,
1493  fGotoRange->fXbr, fGotoRange->fYbr);
1494  UpdateRangeFrame();
1495  }
1496 }
1497 
1498 ////////////////////////////////////////////////////////////////////////////////
1499 /// Slot used when the text in one of the range frame text entries changes.
1500 
1502 {
1503  TString topleft(fFirstCellEntry->GetText());
1504  if(!topleft.Contains(",")) return;
1505 
1506  Int_t pos = topleft.First(',');
1507  TString itl = topleft(0,pos);
1508  TString jtl = topleft(pos+1, topleft.Length());
1509 
1510  if (itl.Contains(' ') || itl.Contains('\t') ||
1511  jtl.Contains(' ') || jtl.Contains('\t')) return;
1512 
1513  if (!itl.IsAlnum() || !jtl.IsAlnum()) return;
1514 
1515  fGotoRange->fXtl = jtl.Atoi();
1516  fGotoRange->fYtl = itl.Atoi();
1517 
1518  TString range(fRangeEntry->GetText());
1519  if(!range.Contains("x")) return;
1520 
1521  pos = 0;
1522  pos = range.First('x');
1523  TString ir = range(0,pos);
1524  TString jr = range(pos+1, range.Length());
1525 
1526  if (ir.Contains(' ') || ir.Contains('\t') ||
1527  jr.Contains(' ') || jr.Contains('\t')) return;
1528  if (!ir.IsAlnum() || !jr.IsAlnum()) return;
1529 
1530  fGotoRange->fXbr = jtl.Atoi() + jr.Atoi();
1531  fGotoRange->fYbr = itl.Atoi() + ir.Atoi();
1532 
1533  if (*fGotoRange == *fCurrentRange) {
1534  fGotoButton->SetState(kButtonDisabled);
1535  } else {
1536  fGotoButton->SetState(kButtonUp);
1537  }
1538 
1539 }
1540 
1541 ////////////////////////////////////////////////////////////////////////////////
1542 /// Update the range of the available data and refresh the current view.
1543 
1544 void TGTable::Update()
1545 {
1546  fDataRange->fXbr = fInterface->GetNColumns();
1547  fDataRange->fYbr = fInterface->GetNRows();
1548 
1549  GotoTableRange(fCurrentRange->fXtl, fCurrentRange->fYtl,
1550  fCurrentRange->fXbr, fCurrentRange->fYbr);
1551 
1552  UpdateView();
1553 }
1554 
1555 ////////////////////////////////////////////////////////////////////////////////
1556 /// TTableRange constuctor.
1557 
1558 TTableRange::TTableRange() : fXtl(0), fYtl(0), fXbr(0), fYbr(0)
1559 {
1560 }
1561 
1562 ////////////////////////////////////////////////////////////////////////////////
1563 /// Print the values of a range.
1564 
1565 void TTableRange::Print()
1566 {
1567  std::cout << "Range = (" << fXtl << "," << fYtl << ")->("
1568  << fXbr << "," << fYbr << ")" << std::endl;
1569 }
1570 
1571 ////////////////////////////////////////////////////////////////////////////////
1572 /// Operator to determine if 2 ranges are equal
1573 
1575 {
1576  if ((fXtl == other.fXtl) && (fYtl == other.fYtl) &&
1577  (fXbr == other.fXbr) && (fYbr == other.fYbr)) {
1578  return kTRUE;
1579  } else {
1580  return kFALSE;
1581  }
1582 }
virtual UInt_t GetNDataCells() const
virtual void SetLabel(const char *label)
Set the label of this cell to label.
An array of TObjects.
Definition: TObjArray.h:37
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
virtual UInt_t GetNColumns()=0
virtual void Print()
virtual UInt_t GetNTableRows() const
virtual UInt_t GetNDataColumns() const
TGHorizontalFrame(const TGWindow *p=0, UInt_t w=1, UInt_t h=1, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition: TGFrame.h:447
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
UInt_t GetHeight() const
Definition: TGFrame.h:272
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
virtual void SetInterface(TVirtualTableInterface *interface, UInt_t nrows=50, UInt_t ncolumns=20)
virtual void UpdateView()
Basic string class.
Definition: TString.h:131
Pixel_t fBackground
Definition: TGFrame.h:142
#define gClient
Definition: TGClient.h:166
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
virtual Pixel_t GetRowBackground(UInt_t row) const
virtual void RemoveAll()
Remove all frames from composite frame.
Definition: TGFrame.cxx:1113
int Int_t
Definition: RtypesCore.h:41
virtual void DoRedraw()
Redraw the frame.
bool Bool_t
Definition: RtypesCore.h:59
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
UInt_t GetWidth() const
Definition: TGFrame.h:271
virtual const TTableRange * GetCurrentRange() const
virtual TGTableCell * operator()(UInt_t row, UInt_t column)
virtual TObjArray * GetColumn(UInt_t columns)
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
void SetCanvas(TGCanvas *canvas)
virtual void SetHeaderBackground(Pixel_t pixel)
TGTable(const TGWindow *p=0, Int_t id=0, TVirtualTableInterface *interface=0, UInt_t nrows=50, UInt_t ncolumns=20)
virtual void Update()
virtual void MoveTable(Int_t rows, Int_t columns)
Double_t x[n]
Definition: legend1.C:17
virtual UInt_t GetNDataRows() const
virtual UInt_t GetRHdrHeight() const
ULong_t Pixel_t
Definition: GuiTypes.h:39
Bool_t operator==(TTableRange &other)
virtual Pixel_t GetHeaderBackground() const
Bool_t IsAlnum() const
Returns true if all characters in string are alphanumeric.
Definition: TString.cxx:1721
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:121
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
virtual void ExpandRows(UInt_t nrows)
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:487
virtual const TGTableCell * FindCell(TGString label) const
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition: TColor.cxx:2035
virtual TObjArray * GetRow(UInt_t row)
A doubly linked list.
Definition: TList.h:44
UInt_t fXtl
Definition: TGTable.h:230
virtual void Expand(UInt_t nrows, UInt_t ncolumns)
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
virtual void Init()
virtual void SetDefaultColors()
virtual ~TGTable()
virtual void ExpandColumns(UInt_t ncolumns)
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Definition: TObjArray.cxx:678
virtual void NextChunk()
virtual UInt_t GetNTableColumns() const
virtual void Show()
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
Ssiz_t Length() const
Definition: TString.h:405
UInt_t fYtl
Definition: TGTable.h:231
virtual TGTableHeader * GetTableHeader()
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:253
UInt_t fWidth
Definition: TGFrame.h:134
virtual void ShrinkRows(UInt_t nrows)
const char * GetString() const
Definition: TGString.h:40
const Bool_t kFALSE
Definition: RtypesCore.h:88
UInt_t fXbr
Definition: TGTable.h:232
#define d(i)
Definition: RSha256.hxx:102
virtual void ResizeTable(UInt_t nrows, UInt_t ncolumns)
virtual void SetEvenRowBackground(Pixel_t pixel)
virtual void UserRangeChange()
virtual void ScrollCHeaders(Int_t xpos)
virtual void PreviousChunk()
virtual void SetOddRowBackground(Pixel_t pixel)
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
#define ClassImp(name)
Definition: Rtypes.h:359
virtual TGString * GetLabel() const
Definition: TGTableCell.h:100
virtual void Layout()
Layout the tab widget.
Definition: TGTab.cxx:221
int type
Definition: TGX11.cxx:120
virtual UInt_t GetCHdrWidth() const
Double_t y[n]
Definition: legend1.C:17
virtual void Shrink(UInt_t nrows, UInt_t ncolumns)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
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 void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
virtual void Goto()
virtual void UpdateRangeFrame()
EHeaderType
Definition: TGTableHeader.h:16
virtual void ShrinkColumns(UInt_t ncolumns)
auto * l
Definition: textangle.C:4
UInt_t fYbr
Definition: TGTable.h:233
virtual void UpdateHeaders(EHeaderType type)
virtual void ScrollRHeaders(Int_t ypos)
virtual UInt_t GetNTableCells() const
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1896
virtual void GotoTableRange(Int_t xtl, Int_t ytl, Int_t xbr, Int_t ybr)
virtual const TGTableCell * GetCell(UInt_t i, UInt_t j) const
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void DestroyWindow()
Definition: TGWindow.h:92
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
const char * Data() const
Definition: TString.h:364