Logo ROOT   6.08/07
Reference Guide
TGTable.h
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 #ifndef ROOT_TGTable
12 #define ROOT_TGTable
13 
14 #ifndef ROOT_TGCanvas
15 #include "TGCanvas.h"
16 #endif
17 #ifndef ROOT_TGWidget
18 #include "TGWidget.h"
19 #endif
20 #ifndef ROOT_TGTableHeader
21 #include "TGTableHeader.h"
22 #endif
23 
24 class TGWindow;
25 class TGString;
26 class TGToolTip;
27 class TGPicture;
29 class TGTableCell;
30 class TGTableHeader;
31 class TGToolTip;
32 class TGTableFrame;
33 class TGTableHeaderFrame;
34 class TGTextButton;
35 class TGNumberEntryField;
36 class TGLabel;
37 class TGTextEntry;
38 class TTableRange;
39 
40 class TGTable : public TGCompositeFrame, public TGWidget {
41 
42 protected:
43  TObjArray *fRows; // Array of rows
44  TObjArray *fRowHeaders; // Array of row headers
45  TObjArray *fColumnHeaders; // Array of column headers
46  TGTableHeader *fTableHeader; // Top left element of the table
47  Bool_t fReadOnly; // Table readonly state
48  Pixel_t fSelectColor; // Select Color
49  Int_t fTMode; // Text justify mode
50  Bool_t fAllData; // Is the data bigger than the table
51  TTableRange *fCurrentRange; // Range of data currently loaded
52  TTableRange *fDataRange; // Full range of the data set
53  TTableRange *fGotoRange; // Range used by Goto frame
54  TGTableFrame *fTableFrame; // Container for the frames
55  TGCanvas *fCanvas; // Canvas that will contains the cells
56  UInt_t fCellWidth; // Default cell width
57  UInt_t fCellHeight; // Default cell width
58 
59  // Frames used for layout
60  TGTableHeaderFrame *fCHdrFrame; // Frame that contains the row headers
61  TGTableHeaderFrame *fRHdrFrame; // Frame that contains the row headers
62  TGHorizontalFrame *fRangeFrame; // Frame that contains the top part
63  TGHorizontalFrame *fTopFrame; // Frame that contains the top part
65  TGHorizontalFrame *fBottomFrame; // Frame that contains the bottom part
66  TGHorizontalFrame *fButtonFrame; // Contains the buttons
67 
68  // Buttons for interaction
69  TGTextButton *fNextButton; // Button to view next chunk
70  TGTextButton *fPrevButton; // Button to view previous chunk
71  TGTextButton *fUpdateButton; // Button to update current view
72  TGTextButton *fGotoButton; // Button to goto a new range
73 
74  // Labels and textentries for range information and input
75  TGLabel *fFirstCellLabel; // Label for the range frame
76  TGLabel *fRangeLabel; // Label for the range frame
77  TGTextEntry *fFirstCellEntry; // TextEntry for the range frame
78  TGTextEntry *fRangeEntry; // TextEntry for the range frame
79 
80  Pixel_t fOddRowBackground; // Background color for odd numbered rows
81  Pixel_t fEvenRowBackground; // Background color for even numbered rows
82  Pixel_t fHeaderBackground; // Background color for headers
83 
84  // Those are neither used nor even initialized:
85  // static const TGGC *fgDefaultSelectGC; // Default select GC
86  // static const TGGC *fgDefaultBckgndGC; // Default cell background GC
87  // static const Int_t fgDefaultTMode; // Default text justify mode
88 
89  // Data members to keep track of LayoutHints that can't be
90  // automatically cleaned
94  TList *fMainHintsList; // List for all hints used in the main table frame
95 
96  // Add rows and/or colums to the edge of the table.
97 
98  virtual void Init();
99 
100  // Remove rows and/or colums from the edge of the table.
101 protected:
102  TVirtualTableInterface *fInterface; // Interface to the data source
103 
104  virtual void DoRedraw();
105 
106  virtual void Expand(UInt_t nrows, UInt_t ncolumns);
107  virtual void ExpandColumns(UInt_t ncolumns);
108  virtual void ExpandRows(UInt_t nrows);
109 
110  virtual UInt_t GetRHdrHeight() const;
111  virtual UInt_t GetCHdrWidth() const;
112 
113  virtual void Shrink(UInt_t nrows, UInt_t ncolumns);
114  virtual void ShrinkColumns(UInt_t ncolumns);
115  virtual void ShrinkRows(UInt_t nrows);
116 
117  virtual void UpdateHeaders(EHeaderType type);
118  virtual void SetInterface(TVirtualTableInterface *interface,
119  UInt_t nrows = 50, UInt_t ncolumns = 20);
120  virtual void ResizeTable(UInt_t nrows, UInt_t ncolumns);
121 
122  virtual void UpdateRangeFrame();
123 
124 public:
125  TGTable(const TGWindow *p = 0, Int_t id = 0,
126  TVirtualTableInterface *interface = 0, UInt_t nrows = 50,
127  UInt_t ncolumns = 20);
128  virtual ~TGTable();
129 
130  virtual TObjArray *GetRow(UInt_t row);
131  virtual TObjArray *GetColumn(UInt_t columns);
132 
133 // // Selection
134 // virtual void Select(TGTableCell *celltl, TGTableCell *cellbr);
135 // virtual void Select(UInt_t xcell1, UInt_t ycell1, UInt_t xcell2, UInt_t ycell2);
136 // virtual void SelectAll();
137 // virtual void SelectRow(TGTableCell *cell);
138 // virtual void SelectRow(UInt_t row);
139 // virtual void SelectRows(UInt_t row, UInt_t nrows);
140 // virtual void SelectColumn(TGTableCell *cell);
141 // virtual void SelectColumn(UInt_t column);
142 // virtual void SelectColumns(UInt_t column, UInt_t ncolumns);
143 
144 // virtual void SetSelectGC(TGGC *gc);
145 // virtual void SetTextJustify(Int_t tmode);
146 
147  // Cells
148  virtual const TGTableCell* GetCell(UInt_t i, UInt_t j) const;
149  virtual TGTableCell* GetCell(UInt_t i, UInt_t j);
150 
151  virtual const TGTableCell* FindCell(TGString label) const;
152  virtual TGTableCell* FindCell(TGString label);
153 
154  virtual void Show();
155 
156  // Because insertion and removal of columns in the middle of a data
157  // set is not yet supported in this design iteration, these methods
158  // have been commented out.
159 
160 // // Insert a range of columns or rows, if the label is empty, a
161 // // default scheme will be used.
162 // virtual void InsertRowBefore(UInt_t row, UInt_t nrows);
163 // virtual void InsertRowBefore(TGString label, UInt_t nrows);
164 // virtual void InsertRowAfter(UInt_t row, UInt_t nrows);
165 // virtual void InsertRowAfter(TGString label, UInt_t nrows);
166 // virtual void InsertRowAt(UInt_t row, UInt_t nrows = 1);
167 // virtual void InsertRowAt(TGString label, UInt_t nrows);
168 
169 // virtual void InsertColumnBefore(UInt_t column, UInt_t ncolumns);
170 // virtual void InsertColumnBefore(TGString label, UInt_t ncolumns);
171 // virtual void InsertColumnAfter(UInt_t column, UInt_t ncolumns);
172 // virtual void InsertColumnAfter(TGString label, UInt_t ncolumns);
173 // virtual void InsertColumnAt(UInt_t column, UInt_t ncolumns = 1);
174 // virtual void InsertColumnAt(TGString label, UInt_t ncolumns);
175 
176 // // Remove rows or columns.
177 // virtual void RemoveRows(UInt_t row, UInt_t nrows = 1);
178 // virtual void RemoveColumns(UInt_t column, UInt_t ncolumns = 1);
179 
180  // Update view
181  virtual void UpdateView();
182 
183  // Getters
184  virtual UInt_t GetNTableRows() const;
185  virtual UInt_t GetNDataRows() const;
186  virtual UInt_t GetNTableColumns() const;
187  virtual UInt_t GetNDataColumns() const;
188  virtual UInt_t GetNTableCells() const;
189  virtual UInt_t GetNDataCells() const;
190  virtual const TTableRange *GetCurrentRange() const;
191 
193 
194  virtual TGCanvas *GetCanvas() { return fCanvas; }
195  virtual const TGTableHeaderFrame *GetRHdrFrame() { return fRHdrFrame; }
196  virtual const TGTableHeaderFrame *GetCHdrFrame() { return fCHdrFrame; }
197  virtual const TGTableHeader *GetRowHeader(const UInt_t row) const;
198  virtual TGTableHeader *GetRowHeader(const UInt_t row);
199  virtual const TGTableHeader *GetColumnHeader(const UInt_t column) const;
200  virtual TGTableHeader *GetColumnHeader(const UInt_t column);
201  virtual TGTableHeader *GetTableHeader();
202 
203 // virtual const TGGC* GetSelectGC() const;
204 // virtual const TGGC* GetCellBckgndGC(TGTableCell *cell) const;
205 // virtual const TGGC* GetCellBckgndGC(UInt_t row, UInt_t column) const;
206 
207  virtual Pixel_t GetRowBackground(UInt_t row) const;
208  virtual Pixel_t GetHeaderBackground() const ;
209 
210  virtual void SetOddRowBackground(Pixel_t pixel);
211  virtual void SetEvenRowBackground(Pixel_t pixel);
212  virtual void SetHeaderBackground(Pixel_t pixel);
213  virtual void SetDefaultColors();
214 
215  // Range manipulators
216  virtual void MoveTable(Int_t rows, Int_t columns);
217  virtual void GotoTableRange(Int_t xtl, Int_t ytl,
218  Int_t xbr, Int_t ybr);
219  // Operators
220  virtual TGTableCell* operator() (UInt_t row, UInt_t column);
221 
222  // Internal slots
223  virtual void ScrollCHeaders(Int_t xpos);
224  virtual void ScrollRHeaders(Int_t ypos);
225  virtual void NextChunk();
226  virtual void PreviousChunk();
227  virtual void UserRangeChange();
228  virtual void Goto();
229  virtual void Update();
230 
231  ClassDef(TGTable, 0) // A table used to visualize data from diffent sources.
232 };
233 
234 class TTableRange {
235 public:
236  UInt_t fXtl; // Top left X coordinate
237  UInt_t fYtl; // Top left Y coordinate
238  UInt_t fXbr; // Bottom right X coordinate
239  UInt_t fYbr; // Bottom right Y coordinate
240 
241  TTableRange();
242  virtual ~TTableRange() {}
243  virtual void Print();
244 
245  Bool_t operator==(TTableRange &other);
246  ClassDef(TTableRange, 0) // Range used in TGTable.
247 };
248 
249 #endif
250 
TGHorizontalFrame * fTopFrame
Definition: TGTable.h:63
Bool_t fReadOnly
Definition: TGTable.h:47
virtual TObjArray * GetColumn(UInt_t columns)
Return a pointer to a TObjArray that contains pointers to all the cells in column.
Definition: TGTable.cxx:818
virtual const TGTableCell * FindCell(TGString label) const
Const version of FindCell().
Definition: TGTable.cxx:914
An array of TObjects.
Definition: TObjArray.h:39
virtual UInt_t GetNDataColumns() const
Return the amount of columns in the data source.
Definition: TGTable.cxx:1129
virtual Pixel_t GetHeaderBackground() const
Get the background color of headers.
Definition: TGTable.cxx:1228
TGTableFrame * fTableFrame
Definition: TGTable.h:54
UInt_t fCellHeight
Definition: TGTable.h:57
virtual void Show()
Show the contents of the TGTable in stdout.
Definition: TGTable.cxx:945
virtual void Print(Option_t *option="") const
Print all frames in this composite frame.
Definition: TGFrame.cxx:1248
UInt_t fCellWidth
Definition: TGTable.h:56
virtual void SetHeaderBackground(Pixel_t pixel)
Set the background color for the headers.
Definition: TGTable.cxx:1291
TGTableHeaderFrame * fCHdrFrame
Definition: TGTable.h:60
virtual TGTableCell * operator()(UInt_t row, UInt_t column)
Operator for easy cell acces.
Definition: TGTable.cxx:1436
virtual void Update()
Update the range of the available data and refresh the current view.
Definition: TGTable.cxx:1544
virtual void Expand(UInt_t nrows, UInt_t ncolumns)
Expand a TGTable by nrows and ncolumns.
Definition: TGTable.cxx:440
virtual void DoRedraw()
Redraw the TGTable.
Definition: TGTable.cxx:431
virtual const TGTableHeaderFrame * GetCHdrFrame()
Definition: TGTable.h:196
TGTextButton * fNextButton
Definition: TGTable.h:69
virtual void NextChunk()
Move the table to the next chunk of the data set with the same size.
Definition: TGTable.cxx:1470
virtual UInt_t GetNTableCells() const
Return the amount of cells in the table.
Definition: TGTable.cxx:1137
virtual UInt_t GetNTableColumns() const
Return the amount of columns in the table.
Definition: TGTable.cxx:1121
virtual void UpdateHeaders(EHeaderType type)
Update the labels of the headers of the given type.
Definition: TGTable.cxx:660
virtual TObjArray * GetRow(UInt_t row)
Get row.
Definition: TGTable.cxx:806
virtual void GotoTableRange(Int_t xtl, Int_t ytl, Int_t xbr, Int_t ybr)
Move and resize the table to the specified range.
Definition: TGTable.cxx:1348
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Pixel_t fHeaderBackground
Definition: TGTable.h:82
virtual void PreviousChunk()
Move the table to the previous chunk of the data set with the same size.
Definition: TGTable.cxx:1479
TGHorizontalFrame * fBottomFrame
Definition: TGTable.h:65
virtual UInt_t GetNDataRows() const
Return the amount of rows in the data source.
Definition: TGTable.cxx:1113
TList * fCHdrHintsList
Definition: TGTable.h:93
TGTableHeaderFrame * fRHdrFrame
Definition: TGTable.h:61
TGTable(const TGWindow *p=0, Int_t id=0, TVirtualTableInterface *interface=0, UInt_t nrows=50, UInt_t ncolumns=20)
Create an array to hold a bunch of numbers.
Definition: TGTable.cxx:168
TTableRange * fGotoRange
Definition: TGTable.h:53
TGLabel * fFirstCellLabel
Definition: TGTable.h:75
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
TGHorizontalFrame * fButtonFrame
Definition: TGTable.h:66
virtual ~TGTable()
TGTable destructor.
Definition: TGTable.cxx:203
virtual void SetEvenRowBackground(Pixel_t pixel)
Set the background color for all even numbered rows.
Definition: TGTable.cxx:1264
TGTableHeader * fTableHeader
Definition: TGTable.h:46
virtual ~TTableRange()
Definition: TGTable.h:242
virtual void ScrollCHeaders(Int_t xpos)
Scroll the column headers horizontally.
Definition: TGTable.cxx:1444
virtual void Shrink(UInt_t nrows, UInt_t ncolumns)
Shrink the TGTable by nrows and ncolumns.
Definition: TGTable.cxx:550
TList * fCellHintsList
Definition: TGTable.h:91
Pixel_t fOddRowBackground
Definition: TGTable.h:80
virtual void SetOddRowBackground(Pixel_t pixel)
Set the background color for all odd numbered rows.
Definition: TGTable.cxx:1236
virtual TGTableHeader * GetTableHeader()
Return a pointer to the table header.
Definition: TGTable.cxx:1193
virtual void ScrollRHeaders(Int_t ypos)
Scroll the row headers vertically.
Definition: TGTable.cxx:1457
virtual void UpdateView()
Update and layout the visible part of the TGTable.
Definition: TGTable.cxx:1060
virtual void MoveTable(Int_t rows, Int_t columns)
Move and layout the table to the specified range.
Definition: TGTable.cxx:1333
TGTextButton * fUpdateButton
Definition: TGTable.h:71
A doubly linked list.
Definition: TList.h:47
UInt_t fXtl
Definition: TGTable.h:236
virtual const TGTableHeaderFrame * GetRHdrFrame()
Definition: TGTable.h:195
virtual void SetDefaultColors()
Set the background color for all rows and headers to their defaults.
Definition: TGTable.cxx:1323
virtual void ExpandRows(UInt_t nrows)
Expand the rows of a TGTable by nrows.
Definition: TGTable.cxx:488
virtual void SetInterface(TVirtualTableInterface *interface, UInt_t nrows=50, UInt_t ncolumns=20)
Set the interface that the TGTable uses to interface.
Definition: TGTable.cxx:683
TVirtualTableInterface * fInterface
Definition: TGTable.h:102
virtual void UserRangeChange()
Slot used when the text in one of the range frame text entries changes.
Definition: TGTable.cxx:1501
virtual void ExpandColumns(UInt_t ncolumns)
Expand the columns of a TGTable by ncolumns.
Definition: TGTable.cxx:449
unsigned int UInt_t
Definition: RtypesCore.h:42
TList * fMainHintsList
Definition: TGTable.h:94
TObjArray * fRows
Definition: TGTable.h:43
UInt_t fYtl
Definition: TGTable.h:237
TGCanvas * fCanvas
Definition: TGTable.h:55
TTableRange * fCurrentRange
Definition: TGTable.h:51
virtual UInt_t GetNTableRows() const
Return the amount of rows in the table.
Definition: TGTable.cxx:1105
TObjArray * fColumnHeaders
Definition: TGTable.h:45
UInt_t fXbr
Definition: TGTable.h:238
Pixel_t fEvenRowBackground
Definition: TGTable.h:81
virtual TVirtualTableInterface * GetInterface()
Definition: TGTable.h:192
virtual void ShrinkColumns(UInt_t ncolumns)
Shrink the columns of the TGTable by ncolumns.
Definition: TGTable.cxx:559
virtual UInt_t GetCHdrWidth() const
Get the current width of the column header frame.
Definition: TGTable.cxx:524
TObjArray * fRowHeaders
Definition: TGTable.h:44
virtual void ShrinkRows(UInt_t nrows)
Shrink the rows of the TGTable by nrows.
Definition: TGTable.cxx:612
int type
Definition: TGX11.cxx:120
Int_t fTMode
Definition: TGTable.h:49
TGTextButton * fPrevButton
Definition: TGTable.h:70
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition: TGTable.cxx:1161
virtual void UpdateRangeFrame()
Update the range shown in the range frame.
Definition: TGTable.cxx:785
TGTextEntry * fFirstCellEntry
Definition: TGTable.h:77
Pixel_t fSelectColor
Definition: TGTable.h:48
EHeaderType
Definition: TGTableHeader.h:18
TList * fRHdrHintsList
Definition: TGTable.h:92
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition: TGTable.cxx:1216
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:101
UInt_t fYbr
Definition: TGTable.h:239
virtual void Goto()
Slot used by the Goto button and whenever return is pressed in on of the text entries in the range fr...
Definition: TGTable.cxx:1489
virtual UInt_t GetNDataCells() const
Return the amount of cell in the data source.
Definition: TGTable.cxx:1145
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition: TGTable.cxx:1177
TGHorizontalFrame * fRangeFrame
Definition: TGTable.h:62
Bool_t fAllData
Definition: TGTable.h:50
TGTextButton * fGotoButton
Definition: TGTable.h:72
TTableRange * fDataRange
Definition: TGTable.h:52
virtual const TTableRange * GetCurrentRange() const
Return the current range of the TGTable.
Definition: TGTable.cxx:1153
virtual TGCanvas * GetCanvas()
Definition: TGTable.h:194
virtual void Init()
Initialise the TGTable.
Definition: TGTable.cxx:233
TGHorizontalFrame * fTopExtraFrame
Definition: TGTable.h:64
TGTextEntry * fRangeEntry
Definition: TGTable.h:78
virtual const TGTableCell * GetCell(UInt_t i, UInt_t j) const
Const version of GetCell().
Definition: TGTable.cxx:892
TGLabel * fRangeLabel
Definition: TGTable.h:76
virtual void ResizeTable(UInt_t nrows, UInt_t ncolumns)
Resize the table to newnrows and newncolumns and add all the frames to their parent frames...
Definition: TGTable.cxx:722
virtual UInt_t GetRHdrHeight() const
Get the current height of the row header frame.
Definition: TGTable.cxx:537