00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "TGFrame.h"
00012 #include "TClass.h"
00013 #include "TGWidget.h"
00014 #include "TGWindow.h"
00015 #include "TGResourcePool.h"
00016 #include "Riostream.h"
00017 #include "TSystem.h"
00018 #include "TImage.h"
00019 #include "TEnv.h"
00020 #include "TGToolTip.h"
00021 #include "TGPicture.h"
00022 #include "TGTable.h"
00023 #include "TVirtualTableInterface.h"
00024 #include "TColor.h"
00025
00026 ClassImp(TGTableCell)
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 const TGGC *TGTableCell::fgDefaultGC = 0;
00039 const TGFont *TGTableCell::fgDefaultFont = 0;
00040
00041
00042 TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, TGString *label,
00043 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
00044 GContext_t norm, FontStruct_t font, UInt_t option,
00045 Bool_t resize)
00046 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
00047 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
00048 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
00049 fTable(table)
00050 {
00051
00052
00053 if (label) {
00054 fLabel = label;
00055 } else {
00056 fLabel = new TGString("0");
00057 }
00058
00059 fNormGC = norm;
00060 Init(resize);
00061 }
00062
00063
00064 TGTableCell::TGTableCell(const TGWindow *p, TGTable *table, const char *label,
00065 UInt_t row, UInt_t column, UInt_t width, UInt_t height,
00066 GContext_t norm, FontStruct_t font, UInt_t option,
00067 Bool_t resize)
00068 : TGFrame(p, width, height, option), fTip(0), fReadOnly(kFALSE),
00069 fEnabled(kTRUE), fTMode(kTextRight | kTextCenterY), fImage(0),
00070 fFontStruct(font), fHasOwnFont(kFALSE), fColumn(column), fRow(row),
00071 fTable(table)
00072 {
00073
00074
00075 if (label) {
00076 fLabel = new TGString(label);
00077 } else {
00078 fLabel = new TGString("0");
00079 }
00080
00081 fNormGC = norm;
00082 Init(resize);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 TGTableCell::~TGTableCell()
00128 {
00129
00130
00131 if (fImage) delete fImage;
00132 if (fLabel) delete fLabel;
00133 if (fTip) delete fTip;
00134 }
00135
00136
00137 void TGTableCell::Init(Bool_t resize)
00138 {
00139
00140
00141 Int_t max_ascent = 0, max_descent = 0;
00142
00143 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
00144 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00145 fTHeight = max_ascent + max_descent;
00146
00147
00148
00149 if (fTable) {
00150
00151 TGTableHeader *chdr = 0;
00152 TGTableHeader *rhdr = 0;
00153 if(resize) {
00154 chdr = fTable->GetColumnHeader(fColumn);
00155 rhdr = fTable->GetRowHeader(fRow);
00156 SetBackgroundColor(rhdr->GetBackground());
00157 Resize(chdr->GetWidth(), rhdr->GetHeight());
00158 }
00159 SetBackgroundColor(fTable->GetRowBackground(fRow));
00160
00161 } else {
00162 fWidth = 80;
00163 fHeight = 25;
00164 Resize(fWidth, fHeight);
00165 SetBackgroundColor(fgWhitePixel);
00166 }
00167
00168
00169 }
00170
00171
00172 void TGTableCell::DoRedraw()
00173 {
00174
00175
00176 TGFrame::DoRedraw();
00177
00178 Int_t x = 0, y = 0;
00179
00180
00181
00182 if (fTWidth > fWidth - 4) fTMode = kTextLeft;
00183
00184 if (fTMode & kTextLeft) {
00185 x = 4;
00186 } else if (fTMode & kTextRight) {
00187 x = fWidth - fTWidth - 4;
00188 } else {
00189 x = (fWidth - fTWidth) / 2;
00190 }
00191
00192 if (fTMode & kTextTop) {
00193 y = 3;
00194 } else if (fTMode & kTextBottom) {
00195 y = fHeight - fTHeight - 3;
00196 } else {
00197 y = (fHeight - fTHeight - 4) / 2;
00198 }
00199
00200 y += fTHeight;
00201
00202 fLabel->Draw(fId, fNormGC, x, y);
00203 }
00204
00205
00206 void TGTableCell::MoveDraw(Int_t x, Int_t y)
00207 {
00208
00209
00210
00211
00212 TGFrame::Move(x, y);
00213 DoRedraw();
00214 }
00215
00216
00217 void TGTableCell::Resize(UInt_t width, UInt_t height)
00218 {
00219
00220
00221 fWidth = width;
00222 fHeight = height;
00223 TGFrame::Resize(width, height);
00224 Layout();
00225 }
00226
00227
00228 void TGTableCell::Resize(TGDimension newsize)
00229 {
00230
00231
00232 Resize(newsize.fWidth, newsize.fHeight);
00233 }
00234
00235
00236 FontStruct_t TGTableCell::GetDefaultFontStruct()
00237 {
00238
00239
00240 if (!fgDefaultFont)
00241 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
00242 return fgDefaultFont->GetFontStruct();
00243 }
00244
00245
00246 const TGGC &TGTableCell::GetDefaultGC()
00247 {
00248
00249
00250 if (!fgDefaultGC)
00251 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
00252 return *fgDefaultGC;
00253 }
00254
00255
00256 void TGTableCell::DrawBorder()
00257 {
00258
00259
00260
00261 gVirtualX->DrawRectangle(fId, fNormGC, 0, 0, fWidth - 1, fHeight - 1);
00262 }
00263
00264
00265 void TGTableCell::DrawBorder(Handle_t id, Int_t x, Int_t y)
00266 {
00267
00268
00269 gVirtualX->DrawRectangle(id, fNormGC, x, y, x + fWidth - 1, y +fHeight - 1);
00270 }
00271
00272
00273 void TGTableCell::Highlight()
00274 {
00275
00276
00277
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 void TGTableCell::DrawCopy(Handle_t id, Int_t x, Int_t y)
00294 {
00295
00296
00297
00298
00299
00300
00301
00302 Int_t lx = 0, ly = 0;
00303
00304 if (fTMode & kTextLeft) {
00305 lx = 4;
00306 } else if (fTMode & kTextRight) {
00307 lx = fWidth - fTWidth - 4;
00308 } else {
00309 lx = (fWidth - fTWidth) / 2;
00310 }
00311
00312 if (fTMode & kTextTop) {
00313 ly = 3;
00314 } else if (fTMode & kTextBottom) {
00315 ly = fHeight - fTHeight - 3;
00316 } else {
00317 ly = (fHeight - fTHeight - 4) / 2;
00318 }
00319
00320 ly += fTHeight;
00321
00322
00323
00324
00325
00326
00327
00328 gVirtualX->SetForeground(fNormGC, fgWhitePixel);
00329 gVirtualX->FillRectangle(id, fNormGC, x, y, fWidth, fHeight);
00330 gVirtualX->SetForeground(fNormGC, fgBlackPixel);
00331 DrawBorder(id, x, y);
00332
00333
00334
00335 fLabel->Draw(id, fNormGC, x + lx, y + ly);
00336 }
00337
00338
00339 void TGTableCell::SetLabel(const char *label)
00340 {
00341
00342
00343 fLabel->SetString(label);
00344
00345 Int_t max_ascent = 0, max_descent = 0;
00346
00347 fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
00348 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00349 fTHeight = max_ascent + max_descent;
00350
00351 }
00352
00353
00354 void TGTableCell::SetImage(TGPicture *image)
00355 {
00356
00357
00358
00359 if (fImage) delete fImage;
00360 fImage = image;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369 void TGTableCell::SetFont(FontStruct_t font)
00370 {
00371
00372
00373
00374 if (font != fFontStruct) {
00375 FontH_t v = gVirtualX->GetFontHandle(font);
00376 if (!v) return;
00377
00378 fFontStruct = font;
00379 TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
00380 TGGC *gc = pool->FindGC(fNormGC);
00381
00382 gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
00383 fHasOwnFont = kTRUE;
00384
00385 gc->SetFont(v);
00386
00387 fNormGC = gc->GetGC();
00388 gClient->NeedRedraw(this);
00389 }
00390 }
00391
00392
00393 void TGTableCell::SetFont(const char *fontName)
00394 {
00395
00396
00397
00398 TGFont *font = fClient->GetFont(fontName);
00399 if (font) {
00400 SetFont(font->GetFontStruct());
00401 }
00402 }
00403
00404
00405 void TGTableCell::SetTextJustify(Int_t tmode)
00406 {
00407
00408
00409 fTMode = tmode;
00410 }
00411
00412
00413 void TGTableCell::Select()
00414 {
00415
00416
00417
00418 }
00419
00420
00421 void TGTableCell::SelectRow()
00422 {
00423
00424
00425
00426 }
00427
00428
00429 void TGTableCell::SelectColumn()
00430 {
00431
00432
00433
00434 }