26 ClassImp(TGTableCell);
38 const TGGC *TGTableCell::fgDefaultGC = 0;
39 const TGFont *TGTableCell::fgDefaultFont = 0;
44 TGTableCell::TGTableCell(
const TGWindow *p, TGTable *table, TGString *label,
45 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
46 GContext_t norm, FontStruct_t font, UInt_t option,
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),
56 fLabel =
new TGString(
"0");
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,
70 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
71 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
72 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
76 fLabel =
new TGString(label);
78 fLabel =
new TGString(
"0");
129 TGTableCell::~TGTableCell()
131 if (fImage)
delete fImage;
132 if (fLabel)
delete fLabel;
133 if (fTip)
delete fTip;
139 void TGTableCell::Init(Bool_t resize)
141 Int_t max_ascent = 0, max_descent = 0;
143 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
144 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
145 fTHeight = max_ascent + max_descent;
151 TGTableHeader *chdr = 0;
152 TGTableHeader *rhdr = 0;
154 chdr = fTable->GetColumnHeader(fColumn);
155 rhdr = fTable->GetRowHeader(fRow);
157 SetBackgroundColor(rhdr->GetBackground());
158 if (chdr) Resize(chdr->GetWidth(), rhdr->GetHeight());
161 SetBackgroundColor(fTable->GetRowBackground(fRow));
166 Resize(fWidth, fHeight);
167 SetBackgroundColor(fgWhitePixel);
176 void TGTableCell::DoRedraw()
184 if (fTWidth > fWidth - 4) fTMode = kTextLeft;
186 if (fTMode & kTextLeft) {
188 }
else if (fTMode & kTextRight) {
189 x = fWidth - fTWidth - 4;
191 x = (fWidth - fTWidth) / 2;
194 if (fTMode & kTextTop) {
196 }
else if (fTMode & kTextBottom) {
197 y = fHeight - fTHeight - 3;
199 y = (fHeight - fTHeight - 4) / 2;
204 fLabel->Draw(fId, fNormGC, x, y);
210 void TGTableCell::MoveDraw(Int_t x, Int_t y)
221 void TGTableCell::Resize(UInt_t width, UInt_t height)
225 TGFrame::Resize(width, height);
232 void TGTableCell::Resize(TGDimension newsize)
234 Resize(newsize.fWidth, newsize.fHeight);
240 FontStruct_t TGTableCell::GetDefaultFontStruct()
243 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
244 return fgDefaultFont->GetFontStruct();
250 const TGGC &TGTableCell::GetDefaultGC()
253 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
260 void TGTableCell::DrawBorder()
263 gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
269 void TGTableCell::DrawBorder(Handle_t
id, Int_t x, Int_t y)
271 gVirtualX->DrawRectangle(
id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
277 void TGTableCell::Highlight()
299 void TGTableCell::DrawCopy(Handle_t
id, Int_t x, Int_t y)
304 Int_t lx = 0, ly = 0;
306 if (fTMode & kTextLeft) {
308 }
else if (fTMode & kTextRight) {
309 lx = fWidth - fTWidth - 4;
311 lx = (fWidth - fTWidth) / 2;
314 if (fTMode & kTextTop) {
316 }
else if (fTMode & kTextBottom) {
317 ly = fHeight - fTHeight - 3;
319 ly = (fHeight - fTHeight - 4) / 2;
330 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
331 gVirtualX->FillRectangle(
id, fNormGC, x, y, fWidth, fHeight);
332 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
333 DrawBorder(
id, x, y);
337 fLabel->Draw(
id, fNormGC, x + lx, y + ly);
343 void TGTableCell::SetLabel(
const char *label)
345 fLabel->SetString(label);
347 Int_t max_ascent = 0, max_descent = 0;
349 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
350 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
351 fTHeight = max_ascent + max_descent;
358 void TGTableCell::SetImage(TGPicture *image)
361 if (fImage)
delete fImage;
374 void TGTableCell::SetFont(FontStruct_t font)
376 if (font != fFontStruct) {
377 FontH_t v = gVirtualX->GetFontHandle(font);
381 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
382 TGGC *gc = pool->FindGC(fNormGC);
384 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
389 fNormGC = gc->GetGC();
390 gClient->NeedRedraw(
this);
398 void TGTableCell::SetFont(
const char *fontName)
400 TGFont *font = fClient->GetFont(fontName);
402 SetFont(font->GetFontStruct());
409 void TGTableCell::SetTextJustify(Int_t tmode)
417 void TGTableCell::Select()
425 void TGTableCell::SelectRow()
433 void TGTableCell::SelectColumn()