Logo ROOT  
Reference Guide
TGTableCell.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 "TGFrame.h"
12#include "TClass.h"
13#include "TGWidget.h"
14#include "TGWindow.h"
15#include "TGResourcePool.h"
16#include "Riostream.h"
17#include "TSystem.h"
18#include "TImage.h"
19#include "TEnv.h"
20#include "TGToolTip.h"
21#include "TGPicture.h"
22#include "TGTable.h"
24#include "TColor.h"
25#include "TVirtualX.h"
26
28
29//////////////////////////////////////////////////////////////////////////
30// //
31// TGTableCell //
32// //
33// TGTableCell is the class that represents a single cell in a TGTable. //
34// //
35// This class is for internal use in TGTable only. //
36// //
37//////////////////////////////////////////////////////////////////////////
38
41
42////////////////////////////////////////////////////////////////////////////////
43/// TGTableCell constructor.
44
46 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
47 GContext_t norm, FontStruct_t font, UInt_t option,
48 Bool_t resize)
49 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
50 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
51 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
52 fTable(table)
53{
54 if (label) {
55 fLabel = label;
56 } else {
57 fLabel = new TGString("0");
58 }
59
60 fNormGC = norm;
61 Init(resize);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// TGTableCell constructor
66
67TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, const char *label,
68 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
69 GContext_t norm, FontStruct_t font, UInt_t option,
70 Bool_t resize)
71 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
72 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
73 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
74 fTable(table)
75{
76 if (label) {
77 fLabel = new TGString(label);
78 } else {
79 fLabel = new TGString("0");
80 }
81
82 fNormGC = norm;
83 Init(resize);
84}
85
86// //______________________________________________________________________________
87// TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, TGPicture *image,
88// TGString *label, UInt_t row, UInt_t column,
89// GContext_t norm, FontStruct_t font, UInt_t option,
90// Bool_t resize)
91// : TGFrame(p, 80, 25, option), fTip(0), fReadOnly(kFALSE), fEnabled(kTRUE),
92// fTMode(kTextRight | kTextCenterY), fImage(image), fFontStruct(font),
93// fHasOwnFont(kFALSE), fColumn(column), fRow(row), fTable(table)
94// {
95// if (label) {
96// fLabel = label;
97// } else {
98// fLabel = new TGString("0");
99// }
100// fNormGC = norm;
101
102// Init(resize);
103// }
104
105// //______________________________________________________________________________
106// TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, TGPicture *image,
107// const char *label, UInt_t row, UInt_t column,
108// GContext_t norm, FontStruct_t font, UInt_t option,
109// Bool_t resize)
110// : TGFrame(p, 80, 25, option), fTip(0), fReadOnly(kFALSE), fEnabled(kTRUE),
111// fTMode(kTextRight | kTextCenterY), fImage(image), fFontStruct(font),
112// fHasOwnFont(kFALSE), fColumn(column), fRow(row), fTable(table)
113// {
114
115// if (label) {
116// fLabel = new TGString(label);
117// } else {
118// fLabel = new TGString("0");
119// }
120
121// fNormGC = norm;
122
123// Init(resize);
124// }
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// TGTableCell destructor.
129
131{
132 if (fImage) delete fImage;
133 if (fLabel) delete fLabel;
134 if (fTip) delete fTip;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Initialise the TGTableCell.
139
141{
142 Int_t max_ascent = 0, max_descent = 0;
143
145 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
146 fTHeight = max_ascent + max_descent;
147
148 // Modifications for individual cell drawing test, original block is marked
149
150 if (fTable) {
151 // Original from here
152 TGTableHeader *chdr = 0;
153 TGTableHeader *rhdr = 0;
154 if(resize) {
156 rhdr = fTable->GetRowHeader(fRow);
157 if (rhdr) {
159 if (chdr) Resize(chdr->GetWidth(), rhdr->GetHeight());
160 }
161 }
163 // Upto here
164 } else {
165 fWidth = 80;
166 fHeight = 25;
169 }
170 // End of modifications
171
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Redraw the TGTableCell.
176
178{
180
181 Int_t x = 0, y = 0;
182
183 // To be done: Add a tooltip with the complete label when it
184 // doesn't fit in the cell.
185 if (fTWidth > fWidth - 4) fTMode = kTextLeft;
186
187 if (fTMode & kTextLeft) {
188 x = 4;
189 } else if (fTMode & kTextRight) {
190 x = fWidth - fTWidth - 4;
191 } else {
192 x = (fWidth - fTWidth) / 2;
193 }
194
195 if (fTMode & kTextTop) {
196 y = 3;
197 } else if (fTMode & kTextBottom) {
198 y = fHeight - fTHeight - 3;
199 } else {
200 y = (fHeight - fTHeight - 4) / 2;
201 }
202
203 y += fTHeight;
204
205 fLabel->Draw(fId, fNormGC, x, y);
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Move the TGTableCell and redraw it.
210
212{
213 // Note, this method is unused.
214
215 TGFrame::Move(x, y);
216 DoRedraw();
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Resize the TGTableCell.
221
223{
224 fWidth = width;
225 fHeight = height;
226 TGFrame::Resize(width, height);
227 Layout();
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Resize the TGTableCell.
232
234{
235 Resize(newsize.fWidth, newsize.fHeight);
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Return default font structure.
240
242{
243 if (!fgDefaultFont)
244 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Return default graphics context.
250
252{
253 if (!fgDefaultGC)
254 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
255 return *fgDefaultGC;
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Draw the cell border.
260
262{
263 // FIXME Borders are drawn very crudely. There is much room for improvement.
264 gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// DrawBorder called from DrawCopy.
269
271{
272 gVirtualX->DrawRectangle(id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Highlight the this TGTableCell.
277
279{
280 // Currently not implemented.
281}
282
283// //______________________________________________________________________________
284// void TGTableCell::SetRow(UInt_t row)
285// {
286// fRow = row;
287// }
288
289// //______________________________________________________________________________
290// void TGTableCell::SetColumn(UInt_t column)
291// {
292// fColumn = column;
293// }
294
295////////////////////////////////////////////////////////////////////////////////
296/// Draw list view item in other window.
297/// List view item is placed and layout in the container frame,
298/// but is drawn in viewport.
299
301{
302 // FIXME this method is only needed if the table container frame is a
303 // TGContainer. It is broken and not used in the current implementation.
304
305 Int_t lx = 0, ly = 0;
306
307 if (fTMode & kTextLeft) {
308 lx = 4;
309 } else if (fTMode & kTextRight) {
310 lx = fWidth - fTWidth - 4;
311 } else {
312 lx = (fWidth - fTWidth) / 2;
313 }
314
315 if (fTMode & kTextTop) {
316 ly = 3;
317 } else if (fTMode & kTextBottom) {
318 ly = fHeight - fTHeight - 3;
319 } else {
320 ly = (fHeight - fTHeight - 4) / 2;
321 }
322
323 ly += fTHeight;
324
325 // if (fActive) {
326 // gVirtualX->SetForeground(fNormGC, fgDefaultSelectedBackground);
327 // gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
328 // gVirtualX->SetForeground(fNormGC, fClient->GetResourcePool()->GetSelectedFgndColor());
329 // } else {
330
331 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
332 gVirtualX->FillRectangle(id, fNormGC, x, y, fWidth, fHeight);
333 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
334 DrawBorder(id, x, y);
335
336 // }
337
338 fLabel->Draw(id, fNormGC, x + lx, y + ly);
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Set the label of this cell to label.
343
344void TGTableCell::SetLabel(const char *label)
345{
346 fLabel->SetString(label);
347
348 Int_t max_ascent = 0, max_descent = 0;
349
351 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
352 fTHeight = max_ascent + max_descent;
353
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// Set the image that this cell contains to image.
358
360{
361 // Note: currently not used.
362 if (fImage) delete fImage;
363 fImage = image;
364}
365
366// //______________________________________________________________________________
367// void TGTableCell::SetBckgndGC(TGGC *gc)
368// {
369// }
370
371////////////////////////////////////////////////////////////////////////////////
372/// Changes text font.
373/// If global is kTRUE font is changed globally, otherwise - locally.
374
376{
377 if (font != fFontStruct) {
378 FontH_t v = gVirtualX->GetFontHandle(font);
379 if (!v) return;
380
381 fFontStruct = font;
383 TGGC *gc = pool->FindGC(fNormGC);
384
385 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
387
388 gc->SetFont(v);
389
390 fNormGC = gc->GetGC();
391 gClient->NeedRedraw(this);
392 }
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Changes text font specified by name.
397/// If global is true color is changed globally, otherwise - locally.
398
399void TGTableCell::SetFont(const char *fontName)
400{
401 TGFont *font = fClient->GetFont(fontName);
402 if (font) {
403 SetFont(font->GetFontStruct());
404 }
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Set the text justify mode of the cell to mode.
409
411{
412 fTMode = tmode;
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Select this TGTableCell.
417
419{
420 // Note: currently not implemented.
421}
422
423////////////////////////////////////////////////////////////////////////////////
424/// Select the row that this TGTableCell belongs to.
425
427{
428 // Note: currently not implemented.
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// Select the column that this TGTableCell belongs to.
433
435{
436 // Note: currently not implemented.
437}
ULong_t Handle_t
Definition: GuiTypes.h:25
Handle_t FontH_t
Definition: GuiTypes.h:34
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
#define gClient
Definition: TGClient.h:166
@ kTextLeft
Definition: TGWidget.h:34
@ kTextBottom
Definition: TGWidget.h:38
@ kTextTop
Definition: TGWidget.h:37
@ kTextRight
Definition: TGWidget.h:35
@ kTextCenterY
Definition: TGWidget.h:39
#define gVirtualX
Definition: TVirtualX.h:338
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:348
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:133
UInt_t fHeight
Definition: TGDimension.h:30
UInt_t fWidth
Definition: TGDimension.h:29
Definition: TGFont.h:149
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:414
UInt_t fHeight
Definition: TGFrame.h:113
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:296
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:577
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
UInt_t fWidth
Definition: TGFrame.h:112
virtual void Layout()
Definition: TGFrame.h:224
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:217
static Pixel_t fgWhitePixel
Definition: TGFrame.h:128
static Pixel_t fgBlackPixel
Definition: TGFrame.h:129
Definition: TGGC.h:112
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:985
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition: TGGC.cxx:949
Definition: TGGC.h:31
GContext_t GetGC() const
Definition: TGGC.h:50
void SetFont(FontH_t v)
Set font.
Definition: TGGC.cxx:409
const GCValues_t * GetAttributes() const
Definition: TGGC.h:78
TGClient * fClient
Definition: TGObject.h:37
Handle_t fId
Definition: TGObject.h:36
TGGCPool * GetGCPool() const
Int_t GetLength() const
Definition: TGString.h:39
virtual void SetString(const char *s)
Definition: TGString.h:41
const char * GetString() const
Definition: TGString.h:40
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition: TGString.cxx:51
virtual void SelectColumn()
Select the column that this TGTableCell belongs to.
virtual void SetTextJustify(Int_t tmode)
Set the text justify mode of the cell to mode.
static const TGFont * fgDefaultFont
Definition: TGTableCell.h:45
virtual void SetLabel(const char *label)
Set the label of this cell to label.
TGToolTip * fTip
Definition: TGTableCell.h:30
static const TGGC * fgDefaultGC
Definition: TGTableCell.h:44
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:102
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
Int_t fTMode
Definition: TGTableCell.h:33
UInt_t fTWidth
Definition: TGTableCell.h:35
virtual void DrawCopy(Handle_t id, Int_t x, Int_t y)
Draw list view item in other window.
TGPicture * fImage
Definition: TGTableCell.h:34
FontStruct_t fFontStruct
Definition: TGTableCell.h:37
TGTable * fTable
Definition: TGTableCell.h:42
UInt_t fTHeight
Definition: TGTableCell.h:36
virtual void SetFont(FontStruct_t font)
Changes text font.
virtual void SelectRow()
Select the row that this TGTableCell belongs to.
virtual void Highlight()
Highlight the this TGTableCell.
virtual void SetImage(TGPicture *image)
Set the image that this cell contains to image.
virtual void MoveDraw(Int_t x, Int_t y)
Move the TGTableCell and redraw it.
TGTableCell(const TGWindow *p=0, TGTable *table=0, TGString *label=0, 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.
Definition: TGTableCell.cxx:45
TGString * fLabel
Definition: TGTableCell.h:29
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
UInt_t fRow
Definition: TGTableCell.h:41
virtual void DoRedraw()
Redraw the TGTableCell.
UInt_t fColumn
Definition: TGTableCell.h:40
virtual ~TGTableCell()
TGTableCell destructor.
Bool_t fHasOwnFont
Definition: TGTableCell.h:38
void Init(Bool_t resize)
Initialise the TGTableCell.
virtual void DrawBorder()
Draw the cell border.
virtual void Select()
Select this TGTableCell.
static const TGGC & GetDefaultGC()
Return default graphics context.
GContext_t fNormGC
Definition: TGTableCell.h:39
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:103
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition: TGTable.cxx:1177
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition: TGTable.cxx:1161
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition: TGTable.cxx:1216
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17