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// //
25// TGTableCell //
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
35
36////////////////////////////////////////////////////////////////////////////////
37/// TGTableCell constructor.
38
40 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
41 GContext_t norm, FontStruct_t font, UInt_t option,
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,
63 GContext_t norm, FontStruct_t font, UInt_t option,
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::TGTableCell(const TGWindow *p, TGTable *table, TGPicture *image,
82// TGString *label, UInt_t row, UInt_t column,
83// GContext_t norm, FontStruct_t font, UInt_t option,
84// Bool_t resize)
85// : TGFrame(p, 80, 25, option), fTip(0), fReadOnly(kFALSE), fEnabled(kTRUE),
86// fTMode(kTextRight | kTextCenterY), fImage(image), fFontStruct(font),
87// fHasOwnFont(kFALSE), fColumn(column), fRow(row), fTable(table)
88// {
89// if (label) {
90// fLabel = label;
91// } else {
92// fLabel = new TGString("0");
93// }
94// fNormGC = norm;
95
96// Init(resize);
97// }
98
99// //______________________________________________________________________________
100// TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, TGPicture *image,
101// const char *label, UInt_t row, UInt_t column,
102// GContext_t norm, FontStruct_t font, UInt_t option,
103// Bool_t resize)
104// : TGFrame(p, 80, 25, option), fTip(0), fReadOnly(kFALSE), fEnabled(kTRUE),
105// fTMode(kTextRight | kTextCenterY), fImage(image), fFontStruct(font),
106// fHasOwnFont(kFALSE), fColumn(column), fRow(row), fTable(table)
107// {
108
109// if (label) {
110// fLabel = new TGString(label);
111// } else {
112// fLabel = new TGString("0");
113// }
114
115// fNormGC = norm;
116
117// Init(resize);
118// }
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// TGTableCell destructor.
123
125{
126 if (fImage) delete fImage;
127 if (fLabel) delete fLabel;
128 if (fTip) delete fTip;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Initialise the TGTableCell.
133
135{
136 Int_t max_ascent = 0, max_descent = 0;
137
139 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
140 fTHeight = max_ascent + max_descent;
141
142 // Modifications for individual cell drawing test, original block is marked
143
144 if (fTable) {
145 // Original from here
146 TGTableHeader *chdr = 0;
147 TGTableHeader *rhdr = 0;
148 if(resize) {
150 rhdr = fTable->GetRowHeader(fRow);
151 if (rhdr) {
153 if (chdr) Resize(chdr->GetWidth(), rhdr->GetHeight());
154 }
155 }
157 // Upto here
158 } else {
159 fWidth = 80;
160 fHeight = 25;
163 }
164 // End of modifications
165
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Redraw the TGTableCell.
170
172{
174
175 Int_t x = 0, y = 0;
176
177 // To be done: Add a tooltip with the complete label when it
178 // doesn't fit in the cell.
179 if (fTWidth > fWidth - 4) fTMode = kTextLeft;
180
181 if (fTMode & kTextLeft) {
182 x = 4;
183 } else if (fTMode & kTextRight) {
184 x = fWidth - fTWidth - 4;
185 } else {
186 x = (fWidth - fTWidth) / 2;
187 }
188
189 if (fTMode & kTextTop) {
190 y = 3;
191 } else if (fTMode & kTextBottom) {
192 y = fHeight - fTHeight - 3;
193 } else {
194 y = (fHeight - fTHeight - 4) / 2;
195 }
196
197 y += fTHeight;
198
199 fLabel->Draw(fId, fNormGC, x, y);
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Move the TGTableCell and redraw it.
204
206{
207 // Note, this method is unused.
208
209 TGFrame::Move(x, y);
210 DoRedraw();
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Resize the TGTableCell.
215
217{
218 fWidth = width;
219 fHeight = height;
220 TGFrame::Resize(width, height);
221 Layout();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Resize the TGTableCell.
226
228{
229 Resize(newsize.fWidth, newsize.fHeight);
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Return default font structure.
234
236{
237 if (!fgDefaultFont)
238 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Return default graphics context.
244
246{
247 if (!fgDefaultGC)
248 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
249 return *fgDefaultGC;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Draw the cell border.
254
256{
257 // FIXME Borders are drawn very crudely. There is much room for improvement.
258 gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// DrawBorder called from DrawCopy.
263
265{
266 gVirtualX->DrawRectangle(id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Highlight the this TGTableCell.
271
273{
274 // Currently not implemented.
275}
276
277// //______________________________________________________________________________
278// void TGTableCell::SetRow(UInt_t row)
279// {
280// fRow = row;
281// }
282
283// //______________________________________________________________________________
284// void TGTableCell::SetColumn(UInt_t column)
285// {
286// fColumn = column;
287// }
288
289////////////////////////////////////////////////////////////////////////////////
290/// Draw list view item in other window.
291/// List view item is placed and layout in the container frame,
292/// but is drawn in viewport.
293
295{
296 // FIXME this method is only needed if the table container frame is a
297 // TGContainer. It is broken and not used in the current implementation.
298
299 Int_t lx = 0, ly = 0;
300
301 if (fTMode & kTextLeft) {
302 lx = 4;
303 } else if (fTMode & kTextRight) {
304 lx = fWidth - fTWidth - 4;
305 } else {
306 lx = (fWidth - fTWidth) / 2;
307 }
308
309 if (fTMode & kTextTop) {
310 ly = 3;
311 } else if (fTMode & kTextBottom) {
312 ly = fHeight - fTHeight - 3;
313 } else {
314 ly = (fHeight - fTHeight - 4) / 2;
315 }
316
317 ly += fTHeight;
318
319 // if (fActive) {
320 // gVirtualX->SetForeground(fNormGC, fgDefaultSelectedBackground);
321 // gVirtualX->FillRectangle(id, fNormGC, x + lx, y + ly, fTWidth, fTHeight + 1);
322 // gVirtualX->SetForeground(fNormGC, fClient->GetResourcePool()->GetSelectedFgndColor());
323 // } else {
324
325 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
326 gVirtualX->FillRectangle(id, fNormGC, x, y, fWidth, fHeight);
327 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
328 DrawBorder(id, x, y);
329
330 // }
331
332 fLabel->Draw(id, fNormGC, x + lx, y + ly);
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Set the label of this cell to label.
337
338void TGTableCell::SetLabel(const char *label)
339{
340 fLabel->SetString(label);
341
342 Int_t max_ascent = 0, max_descent = 0;
343
345 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
346 fTHeight = max_ascent + max_descent;
347
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Set the image that this cell contains to image.
352
354{
355 // Note: currently not used.
356 if (fImage) delete fImage;
357 fImage = image;
358}
359
360// //______________________________________________________________________________
361// void TGTableCell::SetBckgndGC(TGGC *gc)
362// {
363// }
364
365////////////////////////////////////////////////////////////////////////////////
366/// Changes text font.
367/// If global is kTRUE font is changed globally, otherwise - locally.
368
370{
371 if (font != fFontStruct) {
372 FontH_t v = gVirtualX->GetFontHandle(font);
373 if (!v) return;
374
375 fFontStruct = font;
377 TGGC *gc = pool->FindGC(fNormGC);
378
379 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy
381
382 gc->SetFont(v);
383
384 fNormGC = gc->GetGC();
385 gClient->NeedRedraw(this);
386 }
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Changes text font specified by name.
391/// If global is true color is changed globally, otherwise - locally.
392
393void TGTableCell::SetFont(const char *fontName)
394{
395 TGFont *font = fClient->GetFont(fontName);
396 if (font) {
397 SetFont(font->GetFontStruct());
398 }
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Set the text justify mode of the cell to mode.
403
405{
406 fTMode = tmode;
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Select this TGTableCell.
411
413{
414 // Note: currently not implemented.
415}
416
417////////////////////////////////////////////////////////////////////////////////
418/// Select the row that this TGTableCell belongs to.
419
421{
422 // Note: currently not implemented.
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Select the column that this TGTableCell belongs to.
427
429{
430 // Note: currently not implemented.
431}
ULong_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
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
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
#define gClient
Definition TGClient.h:166
@ kTextLeft
Definition TGWidget.h:33
@ kTextBottom
Definition TGWidget.h:37
@ kTextTop
Definition TGWidget.h:36
@ kTextRight
Definition TGWidget.h:34
@ kTextCenterY
Definition TGWidget.h:38
#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:347
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:133
UInt_t fHeight
Definition TGDimension.h:30
UInt_t fWidth
Definition TGDimension.h:29
FontStruct_t GetFontStruct() const
Definition TGFont.h:193
virtual void DoRedraw()
Redraw the frame.
Definition TGFrame.cxx:415
UInt_t fHeight
Definition TGFrame.h:112
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:297
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition TGFrame.cxx:578
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
UInt_t fWidth
Definition TGFrame.h:111
virtual void Layout()
Definition TGFrame.h:223
virtual Pixel_t GetBackground() const
Definition TGFrame.h:216
static Pixel_t fgWhitePixel
Definition TGFrame.h:127
static Pixel_t fgBlackPixel
Definition TGFrame.h:128
TGGC * GetGC(GCValues_t *values, Bool_t rw=kFALSE)
Get the best matching graphics context depending on values.
Definition TGGC.cxx:986
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition TGGC.cxx:950
Definition TGGC.h:31
GContext_t GetGC() const
Definition TGGC.h:50
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:410
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
virtual void Resize(UInt_t width, UInt_t height)
Resize the TGTableCell.
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.
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
virtual const TGTableHeader * GetColumnHeader(const UInt_t column) const
Const version of GetColumnHeader();.
Definition TGTable.cxx:1170
virtual const TGTableHeader * GetRowHeader(const UInt_t row) const
Const version of GetRowHeader();.
Definition TGTable.cxx:1154
virtual Pixel_t GetRowBackground(UInt_t row) const
Get the background collor for row.
Definition TGTable.cxx:1209
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Graphics context structure.
Definition GuiTypes.h:224