#include "TGLabel.h"
#include "TGWidget.h"
#include "TGString.h"
#include "TGResourcePool.h"
#include "Riostream.h"
#include "TColor.h"
#include "TClass.h"
const TGFont *TGLabel::fgDefaultFont = 0;
const TGGC *TGLabel::fgDefaultGC = 0;
ClassImp(TGLabel)
TGLabel::TGLabel(const TGWindow *p, TGString *text, GContext_t norm,
FontStruct_t font, UInt_t options, ULong_t back) :
TGFrame(p, 1, 1, options, back)
{
fText = text;
fTMode = kTextCenterX | kTextCenterY;
fTextChanged = kTRUE;
fFontStruct = font;
fNormGC = norm;
fHasOwnFont = kFALSE;
fDisabled = kFALSE;
int max_ascent, max_descent;
fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
fTHeight = max_ascent + max_descent;
Resize(fTWidth, fTHeight + 1);
SetWindowName();
}
TGLabel::TGLabel(const TGWindow *p, const char *text, GContext_t norm,
FontStruct_t font, UInt_t options, ULong_t back) :
TGFrame(p, 1, 1, options, back)
{
fText = new TGString(!text && !p ? GetName() : text);
fTMode = kTextCenterX | kTextCenterY;
fTextChanged = kTRUE;
fFontStruct = font;
fNormGC = norm;
fHasOwnFont = kFALSE;
fDisabled = kFALSE;
int max_ascent, max_descent;
fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
fTHeight = max_ascent + max_descent;
Resize(fTWidth, fTHeight + 1);
SetWindowName();
}
TGLabel::TGLabel(const TGLabel& gl) :
TGFrame(gl),
fText(gl.fText),
fTWidth(gl.fTWidth),
fTHeight(gl.fTHeight),
fTMode(gl.fTMode),
fTextChanged(gl.fTextChanged),
fNormGC(gl.fNormGC),
fFontStruct(gl.fFontStruct),
fHasOwnFont(gl.fHasOwnFont),
fDisabled(gl.fDisabled)
{
}
TGLabel& TGLabel::operator=(const TGLabel& gl)
{
if(this!=&gl) {
TGFrame::operator=(gl);
fText=gl.fText;
fTWidth=gl.fTWidth;
fTHeight=gl.fTHeight;
fTMode=gl.fTMode;
fTextChanged=gl.fTextChanged;
fNormGC=gl.fNormGC;
fFontStruct=gl.fFontStruct;
fHasOwnFont=gl.fHasOwnFont;
fDisabled=gl.fDisabled;
}
return *this;
}
TGLabel::~TGLabel()
{
if (fText) delete fText;
if (fHasOwnFont) {
TGGCPool *pool = fClient->GetGCPool();
TGGC *gc = pool->FindGC(fNormGC);
pool->FreeGC(gc);
}
}
void TGLabel::SetText(TGString *new_text)
{
if (fText) delete fText;
fText = new_text;
fTextChanged = kTRUE;
int max_ascent, max_descent;
fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
fTHeight = max_ascent + max_descent;
fClient->NeedRedraw(this);
}
void TGLabel::DoRedraw()
{
int x, y;
TGFrame::DoRedraw();
if (fTextChanged) {
fTextChanged = kFALSE;
}
if (fTMode & kTextLeft)
x = 0;
else if (fTMode & kTextRight)
x = fWidth - fTWidth;
else
x = (fWidth - fTWidth) >> 1;
if (fTMode & kTextTop)
y = 0;
else if (fTMode & kTextBottom)
y = fHeight - fTHeight;
else
y = (fHeight - fTHeight) >> 1;
int max_ascent, max_descent;
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
if (!fDisabled) {
fText->Draw(fId, fNormGC, x, y + max_ascent);
} else {
FontH_t fontH;
if (GetDefaultFontStruct() != fFontStruct) {
fontH = gVirtualX->GetFontHandle(fFontStruct);
} else {
fontH = gVirtualX->GetFontHandle(GetDefaultFontStruct());
}
static TGGC *gc1 = 0;
static TGGC *gc2 = 0;
if (!gc1) {
gc1 = fClient->GetResourcePool()->GetGCPool()->FindGC(GetHilightGC()());
gc1 = new TGGC(*gc1);
}
gc1->SetFont(fontH);
fText->Draw(fId, gc1->GetGC(), x + 1, y + 1 + max_ascent);
if (!gc2) {
gc2 = fClient->GetResourcePool()->GetGCPool()->FindGC(GetShadowGC()());
gc2 = new TGGC(*gc2);
}
gc2->SetFont(fontH);
fText->Draw(fId, gc2->GetGC(), x, y + max_ascent);
}
}
void TGLabel::SetTextFont(FontStruct_t font, Bool_t global)
{
FontH_t v = gVirtualX->GetFontHandle(font);
if (!v) return;
fTextChanged = kTRUE;
fFontStruct = font;
TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
TGGC *gc = pool->FindGC(fNormGC);
if (!global) {
gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
fHasOwnFont = kTRUE;
}
gc->SetFont(v);
fNormGC = gc->GetGC();
int max_ascent, max_descent;
fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
fTHeight = max_ascent + max_descent;
fClient->NeedRedraw(this);
}
void TGLabel::SetTextFont(const char *fontName, Bool_t global)
{
TGFont *font = fClient->GetFont(fontName);
if (font) {
SetTextFont(font->GetFontStruct(), global);
}
}
void TGLabel::SetTextFont(TGFont *font, Bool_t global)
{
if (font) {
SetTextFont(font->GetFontStruct(), global);
}
}
void TGLabel::SetTextColor(Pixel_t color, Bool_t global)
{
TGGCPool *pool = fClient->GetResourcePool()->GetGCPool();
TGGC *gc = pool->FindGC(fNormGC);
if (!global) {
gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE);
fHasOwnFont = kTRUE;
}
gc->SetForeground(color);
fNormGC = gc->GetGC();
fClient->NeedRedraw(this);
}
void TGLabel::SetTextColor(TColor *color, Bool_t global)
{
if (color) {
SetTextColor(color->GetPixel(), global);
}
}
void TGLabel::SetTextJustify(Int_t mode)
{
fTextChanged = kTRUE;
fTMode = mode;
fClient->NeedRedraw(this);
}
Bool_t TGLabel::HasOwnFont() const
{
return fHasOwnFont;
}
void TGLabel::SavePrimitive(ostream &out, Option_t *option )
{
char quote = '"';
option = GetName()+5;
char parGC[50], parFont[50];
sprintf(parFont,"%s::GetDefaultFontStruct()",IsA()->GetName());
sprintf(parGC,"%s::GetDefaultGC()()",IsA()->GetName());
if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
TGFont *ufont = fClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
if (ufont) {
ufont->SavePrimitive(out, option);
sprintf(parFont,"ufont->GetFontStruct()");
}
TGGC *userGC = fClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
if (userGC) {
userGC->SavePrimitive(out, option);
sprintf(parGC,"uGC->GetGC()");
}
}
if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
TString label = GetText()->GetString();
label.ReplaceAll("\"","\\\"");
out << " TGLabel *";
out << GetName() << " = new TGLabel("<< fParent->GetName()
<< "," << quote << label << quote;
if (fBackground == GetDefaultFrameBackground()) {
if (!GetOptions()) {
if (fFontStruct == GetDefaultFontStruct()) {
if (fNormGC == GetDefaultGC()()) {
out <<");" << endl;
} else {
out << "," << parGC << ");" << endl;
}
} else {
out << "," << parGC << "," << parFont << ");" << endl;
}
} else {
out << "," << parGC << "," << parFont << "," << GetOptionString() <<");" << endl;
}
} else {
out << "," << parGC << "," << parFont << "," << GetOptionString() << ",ucolor);" << endl;
}
if (fDisabled)
out << " " << GetName() << "->Disable();" << endl;
out << " " << GetName() << "->SetTextJustify(" << GetTextJustify() << ");" << endl;
}
FontStruct_t TGLabel::GetDefaultFontStruct()
{
if (!fgDefaultFont)
fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
return fgDefaultFont->GetFontStruct();
}
const TGGC &TGLabel::GetDefaultGC()
{
if (!fgDefaultGC)
fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
return *fgDefaultGC;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.