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 "TClass.h"
13#include "TGWindow.h"
14#include "TGResourcePool.h"
15#include "Riostream.h"
16#include "TSystem.h"
17#include "TImage.h"
18#include "TEnv.h"
19#include "TGToolTip.h"
20#include "TGWidget.h"
21#include "TGPicture.h"
22#include "TGTable.h"
23#include "TRandom3.h"
24#include "TVirtualX.h"
25
27
28//////////////////////////////////////////////////////////////////////////
29// //
30// TGTableHeader //
31// //
32// TGTableHeader is the class that implements a header for a row or //
33// column. Interactivity on a per column or row basis is implemented //
34// using this header. //
35// //
36// TGTableHeader is for internal use in TGTable only. //
37// //
38//////////////////////////////////////////////////////////////////////////
39
40////////////////////////////////////////////////////////////////////////////////
41/// TGTableHeader constuctor.
42
45 UInt_t height, GContext_t norm, FontStruct_t font,
46 UInt_t option)
47 : TGTableCell(p, table, label, 0, 0, width, height, norm, font, option,
48 kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
49 fHasOwnLabel(kFALSE)
50{
51 if (type == kColumnHeader) {
52 fWidth = (table) ? table->GetTableHeader()->GetWidth() : 80;
53 fHeight = 25;
54 fRow = 0;
55 fColumn = position;
56 } else if (type == kRowHeader) {
57 fWidth = 80;
58 fHeight = (table) ? table->GetTableHeader()->GetHeight() : 25;
59 fRow = position;
60 fColumn = 0;
61 } else {
62 fWidth = 80;
63 fHeight = 25;
64 }
65
66 if (!label) {
68 } else {
70 }
71
72 Init();
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// TGTableHeader constuctor.
77
79 const char *label, UInt_t position,
81 GContext_t norm, FontStruct_t font, UInt_t option)
82 : TGTableCell(p, table, label, 0, 0, width, height, norm, font,
83 option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
84 fHasOwnLabel(kFALSE)
85{
86 if (type == kColumnHeader) {
87 fWidth = table->GetTableHeader()->GetWidth();
88 fHeight = 25;
89 fRow = 0;
90 fColumn = position;
91 } else if (type == kRowHeader) {
92 fWidth = 80;
93 fHeight = table->GetTableHeader()->GetHeight();
94 fRow = position;
95 fColumn = 0;
96 } else {
97 fWidth = 80;
98 fHeight = 25;
99 }
100
101 if (!label) {
103 } else {
105 }
106
107 Init();
108}
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// TGTableHeader destructor.
113
115{
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Initialize the TGTableHeader
120
122{
123 if (fType == kTableHeader) {
125 } else {
127 }
128
130
131 Int_t max_ascent = 0, max_descent = 0;
132
134 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
135 fTHeight = max_ascent + max_descent;
136
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Resize the TGTableHeader.
141
143{
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Resize the TGTableHeader.
149
151{
152 Resize(GetDefaultWidth(), height);
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Set the label of the TGTableHeader to label.
157
158void TGTableHeader::SetLabel(const char *label)
159{
160 if(label) {
162 } else {
164 }
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Set the label of the TGTableHeader to the default label, "Row #"
169/// or "Col #".
170
172{
174 if (fLabel) delete fLabel;
175 fLabel = new TGString();
176 if (fType == kRowHeader) {
177 *fLabel += "Row ";
178 *fLabel += fRow;
179 } else if (fType == kColumnHeader) {
180 *fLabel += "Col ";
181 *fLabel += fColumn;
182 } else {
184 *fLabel += "x";
186 *fLabel += " Table";
187 }
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Set the position of the TGTableHeader to pos.
192
194{
195 // Verify functionality
196
197 if (fType == kRowHeader) {
198 fRow = pos;
199 fColumn = 0;
200 } else if (fType == kColumnHeader) {
201 fRow = 0;
202 fColumn = pos;
203 } else {
204 fRow = 0;
205 fColumn = 0;
206 }
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Resize the TGTableHeader.
211
213{
214 Resize(newsize.fWidth, newsize.fHeight);
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Resize the TGTableHeader.
219
221{
222 // Implementation of resizing of an entire row of columns probably goes here.
223 TGTableCell::Resize(width, height);
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Sort the contents of this row or column in given order.
228
230{
231 // Note: not implemented yet.
232
233 if (order == kSortAscending) {
234 } else {
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Update the positon of the TGTableHeader.
240
242{
243 // Verify functionality. If rows are inserted or removed, internal
244 // column numbers are no longer consistent.
245
246 UInt_t nhdr = 0;
247 if (fType == kColumnHeader) {
248 while(fTable->GetColumnHeader(nhdr) != this) {
249 nhdr++;
250 }
251 fColumn = nhdr;
252 } else if (fType == kRowHeader) {
253 while(fTable->GetRowHeader(nhdr) != this) {
254 nhdr++;
255 }
256 fRow = nhdr;
257 } else {
258 fRow = 0;
259 fColumn = 0;
260 }
261}
Handle_t GContext_t
Definition: GuiTypes.h:37
Handle_t FontStruct_t
Definition: GuiTypes.h:38
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
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:120
const Bool_t kSortAscending
Definition: TList.h:37
#define gVirtualX
Definition: TVirtualX.h:338
UInt_t fHeight
Definition: TGDimension.h:30
UInt_t fWidth
Definition: TGDimension.h:29
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:215
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:296
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:217
Int_t GetLength() const
Definition: TGString.h:39
const char * GetString() const
Definition: TGString.h:40
virtual void SetLabel(const char *label)
Set the label of this cell to label.
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:102
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
UInt_t fTWidth
Definition: TGTableCell.h:35
FontStruct_t fFontStruct
Definition: TGTableCell.h:37
TGTable * fTable
Definition: TGTableCell.h:42
UInt_t fTHeight
Definition: TGTableCell.h:36
TGString * fLabel
Definition: TGTableCell.h:29
UInt_t fRow
Definition: TGTableCell.h:41
UInt_t fColumn
Definition: TGTableCell.h:40
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:103
virtual void SetPosition(UInt_t pos)
Set the position of the TGTableHeader to pos.
EHeaderType fType
Definition: TGTableHeader.h:27
virtual void SetLabel(const char *label)
Set the label of the TGTableHeader to label.
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
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 constuctor.
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableHeader.
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition: TGTable.cxx:1177
virtual TGTableHeader * GetTableHeader()
Return a pointer to the table header.
Definition: TGTable.cxx:1193
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition: TGTable.cxx:1161
virtual UInt_t GetNTableRows() const
Return the amount of rows in the table.
Definition: TGTable.cxx:1105
virtual Pixel_t GetHeaderBackground() const
Get the background color of headers.
Definition: TGTable.cxx:1228
virtual UInt_t GetNTableColumns() const
Return the amount of columns in the table.
Definition: TGTable.cxx:1121