Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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"
19#include "TVirtualX.h"
20
22
23
24/** \class TGTableCell
25 \ingroup guiwidgets
26
27TGTableCell is the class that represents a single cell in a TGTable.
28
29This 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,
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
62TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, const char *label,
63 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
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) {
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;
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();
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
279void 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
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
330void 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}
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:35
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
ULongptr_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define gClient
Definition TGClient.h:156
@ kTextLeft
Definition TGWidget.h:23
@ kTextBottom
Definition TGWidget.h:27
@ kTextTop
Definition TGWidget.h:26
@ kTextRight
Definition TGWidget.h:24
@ kTextCenterY
Definition TGWidget.h:28
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
#define gVirtualX
Definition TVirtualX.h:337
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:124
UInt_t fHeight
Definition TGDimension.h:21
UInt_t fWidth
Definition TGDimension.h:20
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
UInt_t fHeight
frame height
Definition TGFrame.h:88
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:312
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:430
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:593
UInt_t fWidth
frame width
Definition TGFrame.h:87
virtual void Layout()
Definition TGFrame.h:199
virtual Pixel_t GetBackground() const
Definition TGFrame.h:192
static Pixel_t fgWhitePixel
Definition TGFrame.h:103
static Pixel_t fgBlackPixel
Definition TGFrame.h:104
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition TGGC.cxx:987
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition TGGC.cxx:951
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
TGGCPool * GetGCPool() const
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
Int_t GetLength() const
Definition TGString.h:29
virtual void SetString(const char *s)
Definition TGString.h:31
const char * GetString() const
Definition TGString.h:30
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:56
TGTableCell is the class that represents a single cell in a TGTable.
Definition TGTableCell.h:24
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
Default font.
Definition TGTableCell.h:45
virtual void SetLabel(const char *label)
Set the label of this cell to label.
TGToolTip * fTip
Possible Tooltip.
Definition TGTableCell.h:30
static const TGGC * fgDefaultGC
Default graphics context.
Definition TGTableCell.h:44
TGTableCell(const TGWindow *p=nullptr, TGTable *table=nullptr, TGString *label=nullptr, 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.
virtual UInt_t GetWidth() const
Definition TGTableCell.h:93
Int_t fTMode
Text justify mode.
Definition TGTableCell.h:33
UInt_t fTWidth
Label width.
Definition TGTableCell.h:35
void DoRedraw() override
Redraw the TGTableCell.
TGPicture * fImage
Image or icon.
Definition TGTableCell.h:34
FontStruct_t fFontStruct
Font of the label.
Definition TGTableCell.h:37
TGTable * fTable
TGTable that a cell belongs to.
Definition TGTableCell.h:42
UInt_t fTHeight
Label height.
Definition TGTableCell.h:36
virtual void SetFont(FontStruct_t font)
Changes text font.
virtual void SelectRow()
Select the row that this TGTableCell belongs to.
void DrawBorder() override
Draw the cell border.
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.
TGString * fLabel
Text as shown in the cell.
Definition TGTableCell.h:29
static FontStruct_t GetDefaultFontStruct()
Return default font structure.
UInt_t fRow
Row this cell belongs to.
Definition TGTableCell.h:41
void Resize(UInt_t width, UInt_t height) override
Resize the TGTableCell.
UInt_t fColumn
Column this cell belongs to.
Definition TGTableCell.h:40
Bool_t fHasOwnFont
Does the cell have it's own font.
Definition TGTableCell.h:38
void DrawCopy(Handle_t id, Int_t x, Int_t y) override
Draw list view item in other window.
void Init(Bool_t resize)
Initialise the TGTableCell.
virtual void Select()
Select this TGTableCell.
static const TGGC & GetDefaultGC()
Return default graphics context.
GContext_t fNormGC
graphics context used to draw the cell
Definition TGTableCell.h:39
~TGTableCell() override
TGTableCell destructor.
virtual UInt_t GetHeight() const
Definition TGTableCell.h:94
TGTableHeader is the class that implements a header for a row or column.
Create an array to hold a bunch of numbers.
Definition TGTable.h:34
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition TGTable.cxx:1164
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition TGTable.cxx:1148
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition TGTable.cxx:1203
ROOT GUI Window base class.
Definition TGWindow.h:23
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Graphics context structure.
Definition GuiTypes.h:224