Logo ROOT   6.14/05
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 
26 
27 //////////////////////////////////////////////////////////////////////////
28 // //
29 // TGTableHeader //
30 // //
31 // TGTableHeader is the class that implements a header for a row or //
32 // column. Interactivity on a per column or row basis is implemented //
33 // using this header. //
34 // //
35 // TGTableHeader is for internal use in TGTable only. //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// TGTableHeader constuctor.
41 
43  UInt_t position, EHeaderType type, UInt_t width,
44  UInt_t height, GContext_t norm, FontStruct_t font,
45  UInt_t option)
46  : TGTableCell(p, table, label, 0, 0, width, height, norm, font, option,
47  kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
48  fHasOwnLabel(kFALSE)
49 {
50  if (type == kColumnHeader) {
51  fWidth = (table) ? table->GetTableHeader()->GetWidth() : 80;
52  fHeight = 25;
53  fRow = 0;
54  fColumn = position;
55  } else if (type == kRowHeader) {
56  fWidth = 80;
57  fHeight = (table) ? table->GetTableHeader()->GetHeight() : 25;
58  fRow = position;
59  fColumn = 0;
60  } else {
61  fWidth = 80;
62  fHeight = 25;
63  }
64 
65  if (!label) {
67  } else {
69  }
70 
71  Init();
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// TGTableHeader constuctor.
76 
78  const char *label, UInt_t position,
80  GContext_t norm, FontStruct_t font, UInt_t option)
81  : TGTableCell(p, table, label, 0, 0, width, height, norm, font,
82  option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
84 {
85  if (type == kColumnHeader) {
86  fWidth = table->GetTableHeader()->GetWidth();
87  fHeight = 25;
88  fRow = 0;
89  fColumn = position;
90  } else if (type == kRowHeader) {
91  fWidth = 80;
92  fHeight = table->GetTableHeader()->GetHeight();
93  fRow = position;
94  fColumn = 0;
95  } else {
96  fWidth = 80;
97  fHeight = 25;
98  }
99 
100  if (!label) {
101  SetDefaultLabel();
102  } else {
104  }
105 
106  Init();
107 }
108 
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// TGTableHeader destructor.
112 
114 {
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Initialize the TGTableHeader
119 
121 {
122  if (fType == kTableHeader) {
124  } else {
126  }
127 
129 
130  Int_t max_ascent = 0, max_descent = 0;
131 
133  gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
134  fTHeight = max_ascent + max_descent;
135 
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Resize the TGTableHeader.
140 
142 {
143  Resize(width, GetDefaultHeight());
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Resize the TGTableHeader.
148 
150 {
151  Resize(GetDefaultWidth(), height);
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Set the label of the TGTableHeader to label.
156 
157 void TGTableHeader::SetLabel(const char *label)
158 {
159  if(label) {
160  TGTableCell::SetLabel(label);
161  } else {
162  SetDefaultLabel();
163  }
164 }
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Set the label of the TGTableHeader to the default label, "Row #"
168 /// or "Col #".
169 
171 {
173  if (fLabel) delete fLabel;
174  fLabel = new TGString();
175  if (fType == kRowHeader) {
176  *fLabel += "Row ";
177  *fLabel += fRow;
178  } else if (fType == kColumnHeader) {
179  *fLabel += "Col ";
180  *fLabel += fColumn;
181  } else {
182  *fLabel += fTable->GetNTableRows();
183  *fLabel += "x";
185  *fLabel += " Table";
186  }
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Set the position of the TGTableHeader to pos.
191 
193 {
194  // Verify functionality
195 
196  if (fType == kRowHeader) {
197  fRow = pos;
198  fColumn = 0;
199  } else if (fType == kColumnHeader) {
200  fRow = 0;
201  fColumn = pos;
202  } else {
203  fRow = 0;
204  fColumn = 0;
205  }
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Resize the TGTableHeader.
210 
212 {
213  Resize(newsize.fWidth, newsize.fHeight);
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Resize the TGTableHeader.
218 
220 {
221  // Implementation of resizing of an entire row of columns probably goes here.
222  TGTableCell::Resize(width, height);
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Sort the contents of this row or column in given order.
227 
229 {
230  // Note: not implemented yet.
231 
232  if (order == kSortAscending) {
233  } else {
234  }
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// Update the positon of the TGTableHeader.
239 
241 {
242  // Verify functionality. If rows are inserted or removed, internal
243  // column numbers are no longer consistent.
244 
245  UInt_t nhdr = 0;
246  if (fType == kColumnHeader) {
247  while(fTable->GetColumnHeader(nhdr) != this) {
248  nhdr++;
249  }
250  fColumn = nhdr;
251  } else if (fType == kRowHeader) {
252  while(fTable->GetRowHeader(nhdr) != this) {
253  nhdr++;
254  }
255  fRow = nhdr;
256  } else {
257  fRow = 0;
258  fColumn = 0;
259  }
260 }
Handle_t FontStruct_t
Definition: GuiTypes.h:38
virtual void SetLabel(const char *label)
Set the label of this cell to label.
virtual UInt_t GetNTableRows() const
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
UInt_t fColumn
Definition: TGTableCell.h:40
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.
Handle_t GContext_t
Definition: GuiTypes.h:37
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:102
FontStruct_t fFontStruct
Definition: TGTableCell.h:37
virtual void Sort(Bool_t order=kSortAscending)
Sort the contents of this row or column in given order.
UInt_t fTHeight
Definition: TGTableCell.h:36
Bool_t fHasOwnLabel
Definition: TGTableHeader.h:32
UInt_t fTWidth
Definition: TGTableCell.h:35
virtual ~TGTableHeader()
TGTableHeader destructor.
virtual Pixel_t GetHeaderBackground() const
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
UInt_t fHeight
Definition: TGDimension.h:30
UInt_t fRow
Definition: TGTableCell.h:41
UInt_t fWidth
Definition: TGDimension.h:29
EHeaderType fType
Definition: TGTableHeader.h:27
void Init()
Initialize the TGTableHeader.
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
virtual UInt_t GetNTableColumns() const
TGTable * fTable
Definition: TGTableCell.h:42
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetWidth(UInt_t width)
Resize the TGTableHeader.
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:237
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:239
virtual TGTableHeader * GetTableHeader()
TGString * fLabel
Definition: TGTableCell.h:29
virtual void SetHeight(UInt_t height)
Resize the TGTableHeader.
virtual void SetPosition(UInt_t pos)
Set the position of the TGTableHeader to pos.
#define gVirtualX
Definition: TVirtualX.h:350
const char * GetString() const
Definition: TGString.h:40
const Bool_t kFALSE
Definition: RtypesCore.h:88
PyObject * fType
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:103
#define ClassImp(name)
Definition: Rtypes.h:359
int type
Definition: TGX11.cxx:120
const Bool_t kSortAscending
Definition: TList.h:37
virtual void SetLabel(const char *label)
Set the label of the TGTableHeader to label.
EHeaderType
Definition: TGTableHeader.h:16
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
virtual void SetDefaultLabel()
Set the label of the TGTableHeader to the default label, "Row #" or "Col #".
Bool_t fReadOnly
Definition: TGTableHeader.h:30
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t GetLength() const
Definition: TGString.h:39
virtual void UpdatePosition()
Update the positon of the TGTableHeader.