Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
19
20
21/** \class TGTableHeader
22 \ingroup guiwidgets
23
24TGTableHeader is the class that implements a header for a row or
25column. Interactivity on a per column or row basis is implemented
26using this header.
27
28TGTableHeader is for internal use in TGTable only.
29
30*/
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// TGTableHeader constructor.
35
37 UInt_t position, EHeaderType type, UInt_t width,
38 UInt_t height, GContext_t norm, FontStruct_t font,
39 UInt_t option)
40 : TGTableCell(p, table, label, 0, 0, width, height, norm, font, option,
43{
44 if (type == kColumnHeader) {
45 fWidth = (table) ? table->GetTableHeader()->GetWidth() : 80;
46 fHeight = 25;
47 fRow = 0;
48 fColumn = position;
49 } else if (type == kRowHeader) {
50 fWidth = 80;
51 fHeight = (table) ? table->GetTableHeader()->GetHeight() : 25;
52 fRow = position;
53 fColumn = 0;
54 } else {
55 fWidth = 80;
56 fHeight = 25;
57 }
58
59 if (!label) {
61 } else {
63 }
64
65 Init();
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// TGTableHeader constructor.
70
72 const char *label, UInt_t position,
73 EHeaderType type, UInt_t width, UInt_t height,
74 GContext_t norm, FontStruct_t font, UInt_t option)
75 : TGTableCell(p, table, label, 0, 0, width, height, norm, font,
76 option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
78{
79 if (type == kColumnHeader) {
80 fWidth = table->GetTableHeader()->GetWidth();
81 fHeight = 25;
82 fRow = 0;
83 fColumn = position;
84 } else if (type == kRowHeader) {
85 fWidth = 80;
86 fHeight = table->GetTableHeader()->GetHeight();
87 fRow = position;
88 fColumn = 0;
89 } else {
90 fWidth = 80;
91 fHeight = 25;
92 }
93
94 if (!label) {
96 } else {
98 }
99
100 Init();
101}
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// TGTableHeader destructor.
106
110
111////////////////////////////////////////////////////////////////////////////////
112/// Initialize the TGTableHeader
113
115{
116 if (fType == kTableHeader) {
117 SetBackgroundColor(fTable->GetBackground());
118 } else {
119 SetBackgroundColor(fTable->GetHeaderBackground());
120 }
121
123
124 Int_t max_ascent = 0, max_descent = 0;
125
126 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
127 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
128 fTHeight = max_ascent + max_descent;
129
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Resize the TGTableHeader.
134
136{
137 Resize(width, GetDefaultHeight());
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Resize the TGTableHeader.
142
144{
145 Resize(GetDefaultWidth(), height);
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Set the label of the TGTableHeader to label.
150
151void TGTableHeader::SetLabel(const char *label)
152{
153 if(label) {
155 } else {
157 }
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Set the label of the TGTableHeader to the default label, "Row #"
162/// or "Col #".
163
165{
167 if (fLabel) delete fLabel;
168 fLabel = new TGString();
169 if (fType == kRowHeader) {
170 *fLabel += "Row ";
171 *fLabel += fRow;
172 } else if (fType == kColumnHeader) {
173 *fLabel += "Col ";
174 *fLabel += fColumn;
175 } else {
176 *fLabel += fTable->GetNTableRows();
177 *fLabel += "x";
178 *fLabel += fTable->GetNTableColumns();
179 *fLabel += " Table";
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Set the position of the TGTableHeader to pos.
185
187{
188 // Verify functionality
189
190 if (fType == kRowHeader) {
191 fRow = pos;
192 fColumn = 0;
193 } else if (fType == kColumnHeader) {
194 fRow = 0;
195 fColumn = pos;
196 } else {
197 fRow = 0;
198 fColumn = 0;
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Resize the TGTableHeader.
204
206{
207 Resize(newsize.fWidth, newsize.fHeight);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Resize the TGTableHeader.
212
214{
215 // Implementation of resizing of an entire row of columns probably goes here.
216 TGTableCell::Resize(width, height);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Sort the contents of this row or column in given order.
221
223{
224 // Note: not implemented yet.
225
226 if (order == kSortAscending) {
227 } else {
228 }
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Update the positon of the TGTableHeader.
233
235{
236 // Verify functionality. If rows are inserted or removed, internal
237 // column numbers are no longer consistent.
238
239 UInt_t nhdr = 0;
240 if (fType == kColumnHeader) {
241 while(fTable->GetColumnHeader(nhdr) != this) {
242 nhdr++;
243 }
244 fColumn = nhdr;
245 } else if (fType == kRowHeader) {
246 while(fTable->GetRowHeader(nhdr) != this) {
247 nhdr++;
248 }
249 fRow = nhdr;
250 } else {
251 fRow = 0;
252 fColumn = 0;
253 }
254}
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:39
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:40
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
EHeaderType
@ kColumnHeader
@ kRowHeader
@ kTableHeader
const Bool_t kSortAscending
Definition TList.h:31
#define gVirtualX
Definition TVirtualX.h:375
UInt_t fHeight
Definition TGDimension.h:21
UInt_t fWidth
Definition TGDimension.h:20
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:192
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:304
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
virtual void SetLabel(const char *label)
Set the label of this cell to label.
TGTableCell(const TGWindow *p=nullptr, TGTable *table=nullptr, TGString *label=nullptr, UInt_t row=0, UInt_t column=0, UInt_t width=80, UInt_t height=25, GContext_t norm=GetDefaultGC()(), FontStruct_t font=GetDefaultFontStruct(), UInt_t option=0, Bool_t resize=kTRUE)
TGTableCell constructor.
virtual UInt_t GetWidth() const
Definition TGTableCell.h:93
friend class TGTable
Definition TGTableCell.h:26
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
void Resize(UInt_t width, UInt_t height) override
Resize the TGTableCell.
UInt_t fColumn
Column this cell belongs to.
Definition TGTableCell.h:40
virtual UInt_t GetHeight() const
Definition TGTableCell.h:94
void Resize(UInt_t width, UInt_t height) override
Resize the TGTableHeader.
void SetWidth(UInt_t width) override
Resize the TGTableHeader.
virtual void SetPosition(UInt_t pos)
Set the position of the TGTableHeader to pos.
UInt_t fWidth
Width for the column.
EHeaderType fType
Type of header.
UInt_t fHeight
Height of the row.
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.
TGTableHeader(const TGWindow *p=nullptr, TGTable *table=nullptr, TGString *label=nullptr, 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 UpdatePosition()
Update the positon of the TGTableHeader.
virtual void SetDefaultLabel()
Set the label of the TGTableHeader to the default label, "Row #" or "Col #".
void SetLabel(const char *label) override
Set the label of the TGTableHeader to label.
Bool_t fEnabled
Cell enabled state.
void SetHeight(UInt_t height) override
Resize the TGTableHeader.
~TGTableHeader() override
TGTableHeader destructor.
Bool_t fReadOnly
Cell readonly state.
virtual TGTableHeader * GetTableHeader()
Return a pointer to the table header.
Definition TGTable.cxx:1178
TGWindow(Window_t id)
Definition TGWindow.h:34