Logo ROOT  
Reference Guide
TGTableHeader.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 "TGTableCell.h"
12#include "TGWindow.h"
13#include "TGResourcePool.h"
14#include "TGWidget.h"
15#include "TGTable.h"
16#include "TRandom3.h"
17#include "TVirtualX.h"
18
20
21
22/** \class TGTableHeader
23 \ingroup guiwidgets
24
25TGTableHeader is the class that implements a header for a row or
26column. Interactivity on a per column or row basis is implemented
27using this header.
28
29TGTableHeader is for internal use in TGTable only.
30
31*/
32
33
34////////////////////////////////////////////////////////////////////////////////
35/// TGTableHeader constructor.
36
39 UInt_t height, GContext_t norm, FontStruct_t font,
40 UInt_t option)
41 : TGTableCell(p, table, label, 0, 0, width, height, norm, font, option,
42 kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
43 fHasOwnLabel(kFALSE)
44{
45 if (type == kColumnHeader) {
46 fWidth = (table) ? table->GetTableHeader()->GetWidth() : 80;
47 fHeight = 25;
48 fRow = 0;
49 fColumn = position;
50 } else if (type == kRowHeader) {
51 fWidth = 80;
52 fHeight = (table) ? table->GetTableHeader()->GetHeight() : 25;
53 fRow = position;
54 fColumn = 0;
55 } else {
56 fWidth = 80;
57 fHeight = 25;
58 }
59
60 if (!label) {
62 } else {
64 }
65
66 Init();
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// TGTableHeader constructor.
71
73 const char *label, UInt_t position,
75 GContext_t norm, FontStruct_t font, UInt_t option)
76 : TGTableCell(p, table, label, 0, 0, width, height, norm, font,
77 option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
78 fHasOwnLabel(kFALSE)
79{
80 if (type == kColumnHeader) {
81 fWidth = table->GetTableHeader()->GetWidth();
82 fHeight = 25;
83 fRow = 0;
84 fColumn = position;
85 } else if (type == kRowHeader) {
86 fWidth = 80;
87 fHeight = table->GetTableHeader()->GetHeight();
88 fRow = position;
89 fColumn = 0;
90 } else {
91 fWidth = 80;
92 fHeight = 25;
93 }
94
95 if (!label) {
97 } else {
99 }
100
101 Init();
102}
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// TGTableHeader destructor.
107
109{
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Initialize the TGTableHeader
114
116{
117 if (fType == kTableHeader) {
119 } else {
121 }
122
124
125 Int_t max_ascent = 0, max_descent = 0;
126
128 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
129 fTHeight = max_ascent + max_descent;
130
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Resize the TGTableHeader.
135
137{
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Resize the TGTableHeader.
143
145{
146 Resize(GetDefaultWidth(), height);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Set the label of the TGTableHeader to label.
151
152void TGTableHeader::SetLabel(const char *label)
153{
154 if(label) {
156 } else {
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Set the label of the TGTableHeader to the default label, "Row #"
163/// or "Col #".
164
166{
168 if (fLabel) delete fLabel;
169 fLabel = new TGString();
170 if (fType == kRowHeader) {
171 *fLabel += "Row ";
172 *fLabel += fRow;
173 } else if (fType == kColumnHeader) {
174 *fLabel += "Col ";
175 *fLabel += fColumn;
176 } else {
178 *fLabel += "x";
180 *fLabel += " Table";
181 }
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Set the position of the TGTableHeader to pos.
186
188{
189 // Verify functionality
190
191 if (fType == kRowHeader) {
192 fRow = pos;
193 fColumn = 0;
194 } else if (fType == kColumnHeader) {
195 fRow = 0;
196 fColumn = pos;
197 } else {
198 fRow = 0;
199 fColumn = 0;
200 }
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Resize the TGTableHeader.
205
207{
208 Resize(newsize.fWidth, newsize.fHeight);
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Resize the TGTableHeader.
213
215{
216 // Implementation of resizing of an entire row of columns probably goes here.
217 TGTableCell::Resize(width, height);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Sort the contents of this row or column in given order.
222
224{
225 // Note: not implemented yet.
226
227 if (order == kSortAscending) {
228 } else {
229 }
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Update the positon of the TGTableHeader.
234
236{
237 // Verify functionality. If rows are inserted or removed, internal
238 // column numbers are no longer consistent.
239
240 UInt_t nhdr = 0;
241 if (fType == kColumnHeader) {
242 while(fTable->GetColumnHeader(nhdr) != this) {
243 nhdr++;
244 }
245 fColumn = nhdr;
246 } else if (fType == kRowHeader) {
247 while(fTable->GetRowHeader(nhdr) != this) {
248 nhdr++;
249 }
250 fRow = nhdr;
251 } else {
252 fRow = 0;
253 fColumn = 0;
254 }
255}
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
EHeaderType
Definition: TGTableHeader.h:16
@ kColumnHeader
Definition: TGTableHeader.h:17
@ kRowHeader
Definition: TGTableHeader.h:18
@ kTableHeader
Definition: TGTableHeader.h:19
int type
Definition: TGX11.cxx:121
const Bool_t kSortAscending
Definition: TList.h:37
#define gVirtualX
Definition: TVirtualX.h:338
UInt_t fHeight
Definition: TGDimension.h:21
UInt_t fWidth
Definition: TGDimension.h:20
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:190
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:191
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:312
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:192
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition: TGString.h:20
Int_t GetLength() const
Definition: TGString.h:29
const char * GetString() const
Definition: TGString.h:30
TGTableCell is the class that represents a single cell in a TGTable.
Definition: TGTableCell.h:24
virtual void SetLabel(const char *label)
Set the label of this cell to label.
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:93
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
UInt_t fTWidth
Label width.
Definition: TGTableCell.h:35
FontStruct_t fFontStruct
Font of the label.
Definition: TGTableCell.h:37
TGTable * fTable
TGTable that a cell belongs to.
Definition: TGTableCell.h:42
UInt_t fTHeight
Label height.
Definition: TGTableCell.h:36
TGString * fLabel
Text as shown in the cell.
Definition: TGTableCell.h:29
UInt_t fRow
Row this cell belongs to.
Definition: TGTableCell.h:41
UInt_t fColumn
Column this cell belongs to.
Definition: TGTableCell.h:40
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:94
TGTableHeader is the class that implements a header for a row or column.
Definition: TGTableHeader.h:24
virtual void SetPosition(UInt_t pos)
Set the position of the TGTableHeader to pos.
UInt_t fWidth
Width for the column.
Definition: TGTableHeader.h:28
EHeaderType fType
Type of header.
Definition: TGTableHeader.h:27
virtual void SetLabel(const char *label)
Set the label of the TGTableHeader to label.
UInt_t fHeight
Height of the row.
Definition: TGTableHeader.h:29
virtual void Sort(Bool_t order=kSortAscending)
Sort the contents of this row or column in given order.
void Init()
Initialize the TGTableHeader.
Bool_t fHasOwnLabel
Flag on default or specific label usage.
Definition: TGTableHeader.h:32
virtual ~TGTableHeader()
TGTableHeader destructor.
virtual void UpdatePosition()
Update the positon of the TGTableHeader.
virtual void SetDefaultLabel()
Set the label of the TGTableHeader to the default label, "Row #" or "Col #".
virtual void SetWidth(UInt_t width)
Resize the TGTableHeader.
virtual void SetHeight(UInt_t height)
Resize the TGTableHeader.
TGTableHeader(const TGWindow *p=0, TGTable *table=0, TGString *label=0, UInt_t position=0, EHeaderType type=kColumnHeader, UInt_t width=80, UInt_t height=25, GContext_t norm=GetDefaultGC()(), FontStruct_t font=GetDefaultFontStruct(), UInt_t option=0)
TGTableHeader constructor.
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableHeader.
Create an array to hold a bunch of numbers.
Definition: TGTable.h:34
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition: TGTable.cxx:1164
virtual TGTableHeader * GetTableHeader()
Return a pointer to the table header.
Definition: TGTable.cxx:1180
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition: TGTable.cxx:1148
virtual UInt_t GetNTableRows() const
Return the amount of rows in the table.
Definition: TGTable.cxx:1092
virtual Pixel_t GetHeaderBackground() const
Get the background color of headers.
Definition: TGTable.cxx:1215
virtual UInt_t GetNTableColumns() const
Return the amount of columns in the table.
Definition: TGTable.cxx:1108
ROOT GUI Window base class.
Definition: TGWindow.h:23