Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TGCanvas.h"
15 #include "TGWidget.h"
16 #include "TGTableHeader.h"
17 
18 class TGWindow;
19 class TGString;
20 class TGToolTip;
21 class TGPicture;
22 class TVirtualTableInterface;
23 class TGTableCell;
24 class TGTableHeader;
25 class TGToolTip;
26 class TGTableFrame;
27 class TGTableHeaderFrame;
28 class TGTextButton;
29 class TGNumberEntryField;
30 class TGLabel;
31 class TGTextEntry;
32 class TTableRange;
33 
34 class TGTable : public TGCompositeFrame, public TGWidget {
35 
36 protected:
37  TObjArray *fRows; // Array of rows
38  TObjArray *fRowHeaders; // Array of row headers
39  TObjArray *fColumnHeaders; // Array of column headers
40  TGTableHeader *fTableHeader; // Top left element of the table
41  Bool_t fReadOnly; // Table readonly state
42  Pixel_t fSelectColor; // Select Color
43  Int_t fTMode; // Text justify mode
44  Bool_t fAllData; // Is the data bigger than the table
45  TTableRange *fCurrentRange; // Range of data currently loaded
46  TTableRange *fDataRange; // Full range of the data set
47  TTableRange *fGotoRange; // Range used by Goto frame
48  TGTableFrame *fTableFrame; // Container for the frames
49  TGCanvas *fCanvas; // Canvas that will contains the cells
50  UInt_t fCellWidth; // Default cell width
51  UInt_t fCellHeight; // Default cell width
52 
53  // Frames used for layout
54  TGTableHeaderFrame *fCHdrFrame; // Frame that contains the row headers
55  TGTableHeaderFrame *fRHdrFrame; // Frame that contains the row headers
56  TGHorizontalFrame *fRangeFrame; // Frame that contains the top part
57  TGHorizontalFrame *fTopFrame; // Frame that contains the top part
58  TGHorizontalFrame *fTopExtraFrame; // Dev idea
59  TGHorizontalFrame *fBottomFrame; // Frame that contains the bottom part
60  TGHorizontalFrame *fButtonFrame; // Contains the buttons
61 
62  // Buttons for interaction
63  TGTextButton *fNextButton; // Button to view next chunk
64  TGTextButton *fPrevButton; // Button to view previous chunk
65  TGTextButton *fUpdateButton; // Button to update current view
66  TGTextButton *fGotoButton; // Button to goto a new range
67 
68  // Labels and textentries for range information and input
69  TGLabel *fFirstCellLabel; // Label for the range frame
70  TGLabel *fRangeLabel; // Label for the range frame
71  TGTextEntry *fFirstCellEntry; // TextEntry for the range frame
72  TGTextEntry *fRangeEntry; // TextEntry for the range frame
73 
74  Pixel_t fOddRowBackground; // Background color for odd numbered rows
75  Pixel_t fEvenRowBackground; // Background color for even numbered rows
76  Pixel_t fHeaderBackground; // Background color for headers
77 
78  // Those are neither used nor even initialized:
79  // static const TGGC *fgDefaultSelectGC; // Default select GC
80  // static const TGGC *fgDefaultBckgndGC; // Default cell background GC
81  // static const Int_t fgDefaultTMode; // Default text justify mode
82 
83  // Data members to keep track of LayoutHints that can't be
84  // automatically cleaned
85  TList *fCellHintsList;
86  TList *fRHdrHintsList;
87  TList *fCHdrHintsList;
88  TList *fMainHintsList; // List for all hints used in the main table frame
89 
90  // Add rows and/or colums to the edge of the table.
91 
92  virtual void Init();
93 
94  // Remove rows and/or colums from the edge of the table.
95 protected:
96  TVirtualTableInterface *fInterface; // Interface to the data source
97 
98  virtual void DoRedraw();
99 
100  virtual void Expand(UInt_t nrows, UInt_t ncolumns);
101  virtual void ExpandColumns(UInt_t ncolumns);
102  virtual void ExpandRows(UInt_t nrows);
103 
104  virtual UInt_t GetRHdrHeight() const;
105  virtual UInt_t GetCHdrWidth() const;
106 
107  virtual void Shrink(UInt_t nrows, UInt_t ncolumns);
108  virtual void ShrinkColumns(UInt_t ncolumns);
109  virtual void ShrinkRows(UInt_t nrows);
110 
111  virtual void UpdateHeaders(EHeaderType type);
112  virtual void SetInterface(TVirtualTableInterface *interface,
113  UInt_t nrows = 50, UInt_t ncolumns = 20);
114  virtual void ResizeTable(UInt_t nrows, UInt_t ncolumns);
115 
116  virtual void UpdateRangeFrame();
117 
118 public:
119  TGTable(const TGWindow *p = 0, Int_t id = 0,
120  TVirtualTableInterface *interface = 0, UInt_t nrows = 50,
121  UInt_t ncolumns = 20);
122  virtual ~TGTable();
123 
124  virtual TObjArray *GetRow(UInt_t row);
125  virtual TObjArray *GetColumn(UInt_t columns);
126 
127 // // Selection
128 // virtual void Select(TGTableCell *celltl, TGTableCell *cellbr);
129 // virtual void Select(UInt_t xcell1, UInt_t ycell1, UInt_t xcell2, UInt_t ycell2);
130 // virtual void SelectAll();
131 // virtual void SelectRow(TGTableCell *cell);
132 // virtual void SelectRow(UInt_t row);
133 // virtual void SelectRows(UInt_t row, UInt_t nrows);
134 // virtual void SelectColumn(TGTableCell *cell);
135 // virtual void SelectColumn(UInt_t column);
136 // virtual void SelectColumns(UInt_t column, UInt_t ncolumns);
137 
138 // virtual void SetSelectGC(TGGC *gc);
139 // virtual void SetTextJustify(Int_t tmode);
140 
141  // Cells
142  virtual const TGTableCell* GetCell(UInt_t i, UInt_t j) const;
143  virtual TGTableCell* GetCell(UInt_t i, UInt_t j);
144 
145  virtual const TGTableCell* FindCell(TGString label) const;
146  virtual TGTableCell* FindCell(TGString label);
147 
148  virtual void Show();
149 
150  // Because insertion and removal of columns in the middle of a data
151  // set is not yet supported in this design iteration, these methods
152  // have been commented out.
153 
154 // // Insert a range of columns or rows, if the label is empty, a
155 // // default scheme will be used.
156 // virtual void InsertRowBefore(UInt_t row, UInt_t nrows);
157 // virtual void InsertRowBefore(TGString label, UInt_t nrows);
158 // virtual void InsertRowAfter(UInt_t row, UInt_t nrows);
159 // virtual void InsertRowAfter(TGString label, UInt_t nrows);
160 // virtual void InsertRowAt(UInt_t row, UInt_t nrows = 1);
161 // virtual void InsertRowAt(TGString label, UInt_t nrows);
162 
163 // virtual void InsertColumnBefore(UInt_t column, UInt_t ncolumns);
164 // virtual void InsertColumnBefore(TGString label, UInt_t ncolumns);
165 // virtual void InsertColumnAfter(UInt_t column, UInt_t ncolumns);
166 // virtual void InsertColumnAfter(TGString label, UInt_t ncolumns);
167 // virtual void InsertColumnAt(UInt_t column, UInt_t ncolumns = 1);
168 // virtual void InsertColumnAt(TGString label, UInt_t ncolumns);
169 
170 // // Remove rows or columns.
171 // virtual void RemoveRows(UInt_t row, UInt_t nrows = 1);
172 // virtual void RemoveColumns(UInt_t column, UInt_t ncolumns = 1);
173 
174  // Update view
175  virtual void UpdateView();
176 
177  // Getters
178  virtual UInt_t GetNTableRows() const;
179  virtual UInt_t GetNDataRows() const;
180  virtual UInt_t GetNTableColumns() const;
181  virtual UInt_t GetNDataColumns() const;
182  virtual UInt_t GetNTableCells() const;
183  virtual UInt_t GetNDataCells() const;
184  virtual const TTableRange *GetCurrentRange() const;
185 
186  virtual TVirtualTableInterface *GetInterface() { return fInterface; }
187 
188  virtual TGCanvas *GetCanvas() { return fCanvas; }
189  virtual const TGTableHeaderFrame *GetRHdrFrame() { return fRHdrFrame; }
190  virtual const TGTableHeaderFrame *GetCHdrFrame() { return fCHdrFrame; }
191  virtual const TGTableHeader *GetRowHeader(const UInt_t row) const;
192  virtual TGTableHeader *GetRowHeader(const UInt_t row);
193  virtual const TGTableHeader *GetColumnHeader(const UInt_t column) const;
194  virtual TGTableHeader *GetColumnHeader(const UInt_t column);
195  virtual TGTableHeader *GetTableHeader();
196 
197 // virtual const TGGC* GetSelectGC() const;
198 // virtual const TGGC* GetCellBckgndGC(TGTableCell *cell) const;
199 // virtual const TGGC* GetCellBckgndGC(UInt_t row, UInt_t column) const;
200 
201  virtual Pixel_t GetRowBackground(UInt_t row) const;
202  virtual Pixel_t GetHeaderBackground() const ;
203 
204  virtual void SetOddRowBackground(Pixel_t pixel);
205  virtual void SetEvenRowBackground(Pixel_t pixel);
206  virtual void SetHeaderBackground(Pixel_t pixel);
207  virtual void SetDefaultColors();
208 
209  // Range manipulators
210  virtual void MoveTable(Int_t rows, Int_t columns);
211  virtual void GotoTableRange(Int_t xtl, Int_t ytl,
212  Int_t xbr, Int_t ybr);
213  // Operators
214  virtual TGTableCell* operator() (UInt_t row, UInt_t column);
215 
216  // Internal slots
217  virtual void ScrollCHeaders(Int_t xpos);
218  virtual void ScrollRHeaders(Int_t ypos);
219  virtual void NextChunk();
220  virtual void PreviousChunk();
221  virtual void UserRangeChange();
222  virtual void Goto();
223  virtual void Update();
224 
225  ClassDef(TGTable, 0) // A table used to visualize data from diffent sources.
226 };
227 
228 class TTableRange {
229 public:
230  UInt_t fXtl; // Top left X coordinate
231  UInt_t fYtl; // Top left Y coordinate
232  UInt_t fXbr; // Bottom right X coordinate
233  UInt_t fYbr; // Bottom right Y coordinate
234 
235  TTableRange();
236  virtual ~TTableRange() {}
237  virtual void Print();
238 
239  Bool_t operator==(TTableRange &other);
240  ClassDef(TTableRange, 0) // Range used in TGTable.
241 };
242 
243 #endif
244