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
21
22
23/** \class TGTableCell
24 \ingroup guiwidgets
25
26TGTableCell is the class that represents a single cell in a TGTable.
27
28This class is for internal use in TGTable only.
29
30*/
31
32
35
36////////////////////////////////////////////////////////////////////////////////
37/// TGTableCell constructor.
38
40 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
42 Bool_t resize)
43 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
44 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
45 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
46 fTable(table)
47{
48 if (label) {
49 fLabel = label;
50 } else {
51 fLabel = new TGString("0");
52 }
53
54 fNormGC = norm;
55 Init(resize);
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// TGTableCell constructor
60
61TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, const char *label,
62 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
64 Bool_t resize)
65 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
66 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
67 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
68 fTable(table)
69{
70 if (label) {
71 fLabel = new TGString(label);
72 } else {
73 fLabel = new TGString("0");
74 }
75
76 fNormGC = norm;
77 Init(resize);
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// TGTableCell destructor.
82
84{
85 if (fImage) delete fImage;
86 if (fLabel) delete fLabel;
87 if (fTip) delete fTip;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Initialise the TGTableCell.
92
94{
96
98 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
100
101 // Modifications for individual cell drawing test, original block is marked
102
103 if (fTable) {
104 // Original from here
105 TGTableHeader *chdr = 0;
106 TGTableHeader *rhdr = 0;
107 if(resize) {
110 if (rhdr) {
111 SetBackgroundColor(rhdr->GetBackground());
112 if (chdr) Resize(chdr->GetWidth(), rhdr->GetHeight());
113 }
114 }
116 // Up to here
117 } else {
118 fWidth = 80;
119 fHeight = 25;
122 }
123 // End of modifications
124
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Redraw the TGTableCell.
129
131{
133
134 Int_t x = 0, y = 0;
135
136 // To be done: Add a tooltip with the complete label when it
137 // doesn't fit in the cell.
138 if (fTWidth > fWidth - 4) fTMode = kTextLeft;
139
140 if (fTMode & kTextLeft) {
141 x = 4;
142 } else if (fTMode & kTextRight) {
143 x = fWidth - fTWidth - 4;
144 } else {
145 x = (fWidth - fTWidth) / 2;
146 }
147
148 if (fTMode & kTextTop) {
149 y = 3;
150 } else if (fTMode & kTextBottom) {
151 y = fHeight - fTHeight - 3;
152 } else {
153 y = (fHeight - fTHeight - 4) / 2;
154 }
155
156 y += fTHeight;
157
158 fLabel->Draw(fId, fNormGC, x, y);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Move the TGTableCell and redraw it.
163
165{
166 // Note, this method is unused.
167
168 TGFrame::Move(x, y);
169 DoRedraw();
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Resize the TGTableCell.
174
182
183////////////////////////////////////////////////////////////////////////////////
184/// Resize the TGTableCell.
185
187{
188 Resize(newsize.fWidth, newsize.fHeight);
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Return default font structure.
193
195{
196 if (!fgDefaultFont)
197 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
198 return fgDefaultFont->GetFontStruct();
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Return default graphics context.
203
205{
206 if (!fgDefaultGC)
207 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
208 return *fgDefaultGC;
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Draw the cell border.
213
215{
216 // FIXME Borders are drawn very crudely. There is much room for improvement.
217 gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// DrawBorder called from DrawCopy.
222
224{
225 gVirtualX->DrawRectangle(id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Highlight the this TGTableCell.
230
232{
233 // Currently not implemented.
234}
235
236
237////////////////////////////////////////////////////////////////////////////////
238/// Draw list view item in other window.
239/// List view item is placed and layout in the container frame,
240/// but is drawn in viewport.
241
243{
244 // FIXME this method is only needed if the table container frame is a
245 // TGContainer. It is broken and not used in the current implementation.
246
247 Int_t lx = 0, ly = 0;
248
249 if (fTMode & kTextLeft) {
250 lx = 4;
251 } else if (fTMode & kTextRight) {
252 lx = fWidth - fTWidth - 4;
253 } else {
254 lx = (fWidth - fTWidth) / 2;
255 }
256
257 if (fTMode & kTextTop) {
258 ly = 3;
259 } else if (fTMode & kTextBottom) {
260 ly = fHeight - fTHeight - 3;
261 } else {
262 ly = (fHeight - fTHeight - 4) / 2;
263 }
264
265 ly += fTHeight;
266
267 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
268 gVirtualX->FillRectangle(id, fNormGC, x, y, fWidth, fHeight);
269 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
270 DrawBorder(id, x, y);
271
272 fLabel->Draw(id, fNormGC, x + lx, y + ly);
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Set the label of this cell to label.
277
278void TGTableCell::SetLabel(const char *label)
279{
280 fLabel->SetString(label);
281
283
285 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
287
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Set the image that this cell contains to image.
292
294{
295 // Note: currently not used.
296 if (fImage) delete fImage;
297 fImage = image;
298}
299
300
301////////////////////////////////////////////////////////////////////////////////
302/// Changes text font.
303/// If global is kTRUE font is changed globally, otherwise - locally.
304
306{
307 if (font != fFontStruct) {
308 FontH_t v = gVirtualX->GetFontHandle(font);
309 if (!v) return;
310
311 fFontStruct = font;
312 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
313 TGGC *gc = pool->FindGC(fNormGC);
314
315 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
317
318 gc->SetFont(v);
319
320 fNormGC = gc->GetGC();
321 gClient->NeedRedraw(this);
322 }
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Changes text font specified by name.
327/// If global is true color is changed globally, otherwise - locally.
328
330{
331 TGFont *font = fClient->GetFont(fontName);
332 if (font) {
333 SetFont(font->GetFontStruct());
334 }
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Set the text justify mode of the cell to mode.
339
344
345////////////////////////////////////////////////////////////////////////////////
346/// Select this TGTableCell.
347
349{
350 // Note: currently not implemented.
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Select the row that this TGTableCell belongs to.
355
357{
358 // Note: currently not implemented.
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Select the column that this TGTableCell belongs to.
363
365{
366 // Note: currently not implemented.
367}
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:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
@ 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:356
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
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:597
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:304
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:585
UInt_t fWidth
frame width
Definition TGFrame.h:87
virtual void Layout()
Definition TGFrame.h:201
static Pixel_t fgWhitePixel
Definition TGFrame.h:103
static Pixel_t fgBlackPixel
Definition TGFrame.h:104
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
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:54
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.
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.
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:1162
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition TGTable.cxx:1146
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition TGTable.cxx:1201
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