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