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 "TGWidget.h"
13 #include "TGWindow.h"
14 #include "TGResourcePool.h"
15 #include "TGToolTip.h"
16 #include "TGPicture.h"
17 #include "TGTable.h"
18 #include "TVirtualTableInterface.h"
19 #include "TVirtualX.h"
20 
22 
23 
24 /** \class TGTableCell
25  \ingroup guiwidgets
26 
27 TGTableCell is the class that represents a single cell in a TGTable.
28 
29 This class is for internal use in TGTable only.
30 
31 */
32 
33 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// TGTableCell constructor.
39 
41  UInt_t row, UInt_t column, UInt_t width, UInt_t height,
42  GContext_t norm, FontStruct_t font, UInt_t option,
43  Bool_t resize)
44  : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
45  fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
46  fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
47  fTable(table)
48 {
49  if (label) {
50  fLabel = label;
51  } else {
52  fLabel = new TGString("0");
53  }
54 
55  fNormGC = norm;
56  Init(resize);
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// TGTableCell constructor
61 
62 TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, const char *label,
63  UInt_t row, UInt_t column, UInt_t width, UInt_t height,
64  GContext_t norm, FontStruct_t font, UInt_t option,
65  Bool_t resize)
66  : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
67  fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
68  fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
69  fTable(table)
70 {
71  if (label) {
72  fLabel = new TGString(label);
73  } else {
74  fLabel = new TGString("0");
75  }
76 
77  fNormGC = norm;
78  Init(resize);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// TGTableCell destructor.
83 
85 {
86  if (fImage) delete fImage;
87  if (fLabel) delete fLabel;
88  if (fTip) delete fTip;
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Initialise the TGTableCell.
93 
95 {
96  Int_t max_ascent = 0, max_descent = 0;
97 
99  gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
100  fTHeight = max_ascent + max_descent;
101 
102  // Modifications for individual cell drawing test, original block is marked
103 
104  if (fTable) {
105  // Original from here
106  TGTableHeader *chdr = 0;
107  TGTableHeader *rhdr = 0;
108  if(resize) {
109  chdr = fTable->GetColumnHeader(fColumn);
110  rhdr = fTable->GetRowHeader(fRow);
111  if (rhdr) {
113  if (chdr) Resize(chdr->GetWidth(), rhdr->GetHeight());
114  }
115  }
117  // Up to here
118  } else {
119  fWidth = 80;
120  fHeight = 25;
123  }
124  // End of modifications
125 
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Redraw the TGTableCell.
130 
132 {
134 
135  Int_t x = 0, y = 0;
136 
137  // To be done: Add a tooltip with the complete label when it
138  // doesn't fit in the cell.
139  if (fTWidth > fWidth - 4) fTMode = kTextLeft;
140 
141  if (fTMode & kTextLeft) {
142  x = 4;
143  } else if (fTMode & kTextRight) {
144  x = fWidth - fTWidth - 4;
145  } else {
146  x = (fWidth - fTWidth) / 2;
147  }
148 
149  if (fTMode & kTextTop) {
150  y = 3;
151  } else if (fTMode & kTextBottom) {
152  y = fHeight - fTHeight - 3;
153  } else {
154  y = (fHeight - fTHeight - 4) / 2;
155  }
156 
157  y += fTHeight;
158 
159  fLabel->Draw(fId, fNormGC, x, y);
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Move the TGTableCell and redraw it.
164 
166 {
167  // Note, this method is unused.
168 
169  TGFrame::Move(x, y);
170  DoRedraw();
171 }
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// Resize the TGTableCell.
175 
177 {
178  fWidth = width;
179  fHeight = height;
180  TGFrame::Resize(width, height);
181  Layout();
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Resize the TGTableCell.
186 
188 {
189  Resize(newsize.fWidth, newsize.fHeight);
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Return default font structure.
194 
196 {
197  if (!fgDefaultFont)
198  fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
199  return fgDefaultFont->GetFontStruct();
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Return default graphics context.
204 
206 {
207  if (!fgDefaultGC)
208  fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
209  return *fgDefaultGC;
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Draw the cell border.
214 
216 {
217  // FIXME Borders are drawn very crudely. There is much room for improvement.
218  gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// DrawBorder called from DrawCopy.
223 
225 {
226  gVirtualX->DrawRectangle(id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Highlight the this TGTableCell.
231 
233 {
234  // Currently not implemented.
235 }
236 
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Draw list view item in other window.
240 /// List view item is placed and layout in the container frame,
241 /// but is drawn in viewport.
242 
244 {
245  // FIXME this method is only needed if the table container frame is a
246  // TGContainer. It is broken and not used in the current implementation.
247 
248  Int_t lx = 0, ly = 0;
249 
250  if (fTMode & kTextLeft) {
251  lx = 4;
252  } else if (fTMode & kTextRight) {
253  lx = fWidth - fTWidth - 4;
254  } else {
255  lx = (fWidth - fTWidth) / 2;
256  }
257 
258  if (fTMode & kTextTop) {
259  ly = 3;
260  } else if (fTMode & kTextBottom) {
261  ly = fHeight - fTHeight - 3;
262  } else {
263  ly = (fHeight - fTHeight - 4) / 2;
264  }
265 
266  ly += fTHeight;
267 
268  gVirtualX->SetForeground(fNormGC, fgWhitePixel);
269  gVirtualX->FillRectangle(id, fNormGC, x, y, fWidth, fHeight);
270  gVirtualX->SetForeground(fNormGC, fgBlackPixel);
271  DrawBorder(id, x, y);
272 
273  fLabel->Draw(id, fNormGC, x + lx, y + ly);
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 /// Set the label of this cell to label.
278 
279 void TGTableCell::SetLabel(const char *label)
280 {
281  fLabel->SetString(label);
282 
283  Int_t max_ascent = 0, max_descent = 0;
284 
286  gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
287  fTHeight = max_ascent + max_descent;
288 
289 }
290 
291 ////////////////////////////////////////////////////////////////////////////////
292 /// Set the image that this cell contains to image.
293 
295 {
296  // Note: currently not used.
297  if (fImage) delete fImage;
298  fImage = image;
299 }
300 
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 /// Changes text font.
304 /// If global is kTRUE font is changed globally, otherwise - locally.
305 
307 {
308  if (font != fFontStruct) {
309  FontH_t v = gVirtualX->GetFontHandle(font);
310  if (!v) return;
311 
312  fFontStruct = font;
314  TGGC *gc = pool->FindGC(fNormGC);
315 
316  gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
317  fHasOwnFont = kTRUE;
318 
319  gc->SetFont(v);
320 
321  fNormGC = gc->GetGC();
322  gClient->NeedRedraw(this);
323  }
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Changes text font specified by name.
328 /// If global is true color is changed globally, otherwise - locally.
329 
330 void TGTableCell::SetFont(const char *fontName)
331 {
332  TGFont *font = fClient->GetFont(fontName);
333  if (font) {
334  SetFont(font->GetFontStruct());
335  }
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Set the text justify mode of the cell to mode.
340 
342 {
343  fTMode = tmode;
344 }
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// Select this TGTableCell.
348 
350 {
351  // Note: currently not implemented.
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 /// Select the row that this TGTableCell belongs to.
356 
358 {
359  // Note: currently not implemented.
360 }
361 
362 ////////////////////////////////////////////////////////////////////////////////
363 /// Select the column that this TGTableCell belongs to.
364 
366 {
367  // Note: currently not implemented.
368 }
TGTableCell::Init
void Init(Bool_t resize)
Initialise the TGTableCell.
Definition: TGTableCell.cxx:94
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
kTextTop
@ kTextTop
Definition: TGWidget.h:26
TGFrame::fgBlackPixel
static Pixel_t fgBlackPixel
Definition: TGFrame.h:104
TGTable::GetRowHeader
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition: TGTable.cxx:1148
TGTableCell::fgDefaultGC
static const TGGC * fgDefaultGC
Default graphics context.
Definition: TGTableCell.h:44
TGGC::GetGC
GContext_t GetGC() const
Definition: TGGC.h:41
TGPicture
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition: TGPicture.h:25
TGTableCell::GetWidth
virtual UInt_t GetWidth() const
Definition: TGTableCell.h:93
TGDimension
Definition: TGDimension.h:18
TGTable.h
TGFrame::SetBackgroundColor
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:312
TGTableCell::SetLabel
virtual void SetLabel(const char *label)
Set the label of this cell to label.
Definition: TGTableCell.cxx:279
TGGC::GetAttributes
const GCValues_t * GetAttributes() const
Definition: TGGC.h:69
TGResourcePool::GetGCPool
TGGCPool * GetGCPool() const
Definition: TGResourcePool.h:93
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TGTableCell::fTMode
Int_t fTMode
Text justify mode.
Definition: TGTableCell.h:33
TGTableCell::~TGTableCell
virtual ~TGTableCell()
TGTableCell destructor.
Definition: TGTableCell.cxx:84
FontH_t
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition: GuiTypes.h:35
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGPicture.h
TGFrame::fWidth
UInt_t fWidth
frame width
Definition: TGFrame.h:87
FontStruct_t
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
TGTableCell::fColumn
UInt_t fColumn
Column this cell belongs to.
Definition: TGTableCell.h:40
GCValues_t
Graphics context structure.
Definition: GuiTypes.h:224
TGTableCell::fNormGC
GContext_t fNormGC
graphics context used to draw the cell
Definition: TGTableCell.h:39
TGTableCell::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
Definition: TGTableCell.cxx:195
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
x
Double_t x[n]
Definition: legend1.C:17
TGFrame::fgWhitePixel
static Pixel_t fgWhitePixel
Definition: TGFrame.h:103
Handle_t
ULongptr_t Handle_t
Generic resource handle.
Definition: GuiTypes.h:26
TVirtualX.h
TGTableCell::fFontStruct
FontStruct_t fFontStruct
Font of the label.
Definition: TGTableCell.h:37
kTextCenterY
@ kTextCenterY
Definition: TGWidget.h:28
TGFrame::GetBackground
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:192
TGClient::GetResourcePool
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:124
TGTableCell::fTHeight
UInt_t fTHeight
Label height.
Definition: TGTableCell.h:36
TGTableCell::fgDefaultFont
static const TGFont * fgDefaultFont
Default font.
Definition: TGTableCell.h:45
TGTableCell::TGTableCell
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:40
TGFrame
Definition: TGFrame.h:80
v
@ v
Definition: rootcling_impl.cxx:3664
TGTableCell::SetFont
virtual void SetFont(FontStruct_t font)
Changes text font.
Definition: TGTableCell.cxx:306
TGWindow.h
TGTableCell::fTip
TGToolTip * fTip
Possible Tooltip.
Definition: TGTableCell.h:30
TVirtualTableInterface.h
TGGCPool::GetGC
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition: TGGC.cxx:987
bool
TGTableCell::fTWidth
UInt_t fTWidth
Label width.
Definition: TGTableCell.h:35
GContext_t
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
TGTableCell::DrawCopy
virtual void DrawCopy(Handle_t id, Int_t x, Int_t y)
Draw list view item in other window.
Definition: TGTableCell.cxx:243
TGTableCell::fTable
TGTable * fTable
TGTable that a cell belongs to.
Definition: TGTableCell.h:42
gClient
#define gClient
Definition: TGClient.h:157
kTextLeft
@ kTextLeft
Definition: TGWidget.h:23
TGString::GetLength
Int_t GetLength() const
Definition: TGString.h:29
TGDimension::fHeight
UInt_t fHeight
Definition: TGDimension.h:21
TGTableCell::Highlight
virtual void Highlight()
Highlight the this TGTableCell.
Definition: TGTableCell.cxx:232
TGGC
Encapsulate a graphics context used in the low level graphics.
Definition: TGGC.h:22
TGTableCell::fRow
UInt_t fRow
Row this cell belongs to.
Definition: TGTableCell.h:41
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
TGTableCell::GetDefaultGC
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGTableCell.cxx:205
TGObject::fId
Handle_t fId
X11/Win32 Window identifier.
Definition: TGObject.h:26
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TGFrame.h
TGDimension::fWidth
UInt_t fWidth
Definition: TGDimension.h:20
TGString::SetString
virtual void SetString(const char *s)
Definition: TGString.h:31
y
Double_t y[n]
Definition: legend1.C:17
kTextBottom
@ kTextBottom
Definition: TGWidget.h:27
TGWidget.h
TGTableCell::fHasOwnFont
Bool_t fHasOwnFont
Does the cell have it's own font.
Definition: TGTableCell.h:38
TGTableCell::SetImage
virtual void SetImage(TGPicture *image)
Set the image that this cell contains to image.
Definition: TGTableCell.cxx:294
unsigned int
TGTableCell::SetTextJustify
virtual void SetTextJustify(Int_t tmode)
Set the text justify mode of the cell to mode.
Definition: TGTableCell.cxx:341
TGTableCell::fLabel
TGString * fLabel
Text as shown in the cell.
Definition: TGTableCell.h:29
TGTableHeader
TGTableHeader is the class that implements a header for a row or column.
Definition: TGTableHeader.h:24
TGTableCell::SelectColumn
virtual void SelectColumn()
Select the column that this TGTableCell belongs to.
Definition: TGTableCell.cxx:365
TGTableCell::DoRedraw
virtual void DoRedraw()
Redraw the TGTableCell.
Definition: TGTableCell.cxx:131
TGTableCell::GetHeight
virtual UInt_t GetHeight() const
Definition: TGTableCell.h:94
TGTable::GetColumnHeader
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition: TGTable.cxx:1164
TGObject::fClient
TGClient * fClient
Connection to display server.
Definition: TGObject.h:27
TGGCPool
Definition: TGGC.h:103
TGTableCell::DrawBorder
virtual void DrawBorder()
Draw the cell border.
Definition: TGTableCell.cxx:215
TGFrame::Move
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:593
TGTableCell::fImage
TGPicture * fImage
Image or icon.
Definition: TGTableCell.h:34
TGToolTip.h
TGTableCell
TGTableCell is the class that represents a single cell in a TGTable.
Definition: TGTableCell.h:24
TGString::Draw
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition: TGString.cxx:56
TGClient::GetFont
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:350
TGString::GetString
const char * GetString() const
Definition: TGString.h:30
TGTableCell::SelectRow
virtual void SelectRow()
Select the row that this TGTableCell belongs to.
Definition: TGTableCell.cxx:357
TGResourcePool.h
TGGCPool::FindGC
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition: TGGC.cxx:951
TGFont::GetFontStruct
FontStruct_t GetFontStruct() const
Definition: TGFont.h:184
TGTableCell::MoveDraw
virtual void MoveDraw(Int_t x, Int_t y)
Move the TGTableCell and redraw it.
Definition: TGTableCell.cxx:165
kTextRight
@ kTextRight
Definition: TGWidget.h:24
TGTableCell::Resize
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
Definition: TGTableCell.cxx:176
TGFrame::fHeight
UInt_t fHeight
frame height
Definition: TGFrame.h:88
TGFont
Encapsulate fonts used in the GUI system.
Definition: TGFont.h:140
TGFrame::Layout
virtual void Layout()
Definition: TGFrame.h:199
TGTableCell::Select
virtual void Select()
Select this TGTableCell.
Definition: TGTableCell.cxx:349
TGTable::GetRowBackground
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition: TGTable.cxx:1203
TGString
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition: TGString.h:20
TGGC::SetFont
void SetFont(FontH_t v)
Set font.
Definition: TGGC.cxx:411
TGTable
Create an array to hold a bunch of numbers.
Definition: TGTable.h:34
int
TGFrame::DoRedraw
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:430