#include "TGTableCell.h"
#include "TClass.h"
#include "TGWindow.h"
#include "TGResourcePool.h"
#include "Riostream.h"
#include "TSystem.h"
#include "TImage.h"
#include "TEnv.h"
#include "TGToolTip.h"
#include "TGWidget.h"
#include "TGPicture.h"
#include "TGTable.h"
#include "TRandom3.h"
ClassImp(TGTableHeader)
TGTableHeader::TGTableHeader(const TGWindow *p, TGTable *table, TGString *label,
UInt_t position, EHeaderType type, UInt_t width,
UInt_t height, GContext_t norm, FontStruct_t font,
UInt_t option)
: TGTableCell(p, table, label, 0, 0, width, height, norm, font, option,
kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
fHasOwnLabel(kFALSE)
{
if (type == kColumnHeader) {
fWidth = table->GetTableHeader()->GetWidth();
fHeight = 25;
fRow = 0;
fColumn = position;
} else if (type == kRowHeader) {
fWidth = 80;
fHeight = table->GetTableHeader()->GetHeight();
fRow = position;
fColumn = 0;
} else {
fWidth = 80;
fHeight = 25;
}
if (!label) {
SetDefaultLabel();
} else {
fHasOwnLabel = kTRUE;
}
Init();
}
TGTableHeader::TGTableHeader(const TGWindow *p, TGTable *table,
const char *label, UInt_t position,
EHeaderType type, UInt_t width, UInt_t height,
GContext_t norm, FontStruct_t font, UInt_t option)
: TGTableCell(p, table, label, 0, 0, width, height, norm, font,
option, kFALSE), fType(type), fReadOnly(kFALSE), fEnabled(kTRUE),
fHasOwnLabel(kFALSE)
{
if (type == kColumnHeader) {
fWidth = table->GetTableHeader()->GetWidth();
fHeight = 25;
fRow = 0;
fColumn = position;
} else if (type == kRowHeader) {
fWidth = 80;
fHeight = table->GetTableHeader()->GetHeight();
fRow = position;
fColumn = 0;
} else {
fWidth = 80;
fHeight = 25;
}
if (!label) {
SetDefaultLabel();
} else {
fHasOwnLabel = kTRUE;
}
Init();
}
TGTableHeader::~TGTableHeader()
{
}
void TGTableHeader::Init()
{
if (fType == kTableHeader) {
SetBackgroundColor(fTable->GetBackground());
} else {
SetBackgroundColor(fTable->GetHeaderBackground());
}
Resize(fWidth, fHeight);
Int_t max_ascent = 0, max_descent = 0;
fTWidth = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
fTHeight = max_ascent + max_descent;
}
void TGTableHeader::SetWidth(UInt_t width)
{
Resize(width, GetDefaultHeight());
}
void TGTableHeader::SetHeight(UInt_t height)
{
Resize(GetDefaultWidth(), height);
}
void TGTableHeader::SetLabel(const char *label)
{
if(label) {
TGTableCell::SetLabel(label);
} else {
SetDefaultLabel();
}
}
void TGTableHeader::SetDefaultLabel()
{
fHasOwnLabel = kFALSE;
if (fLabel) delete fLabel;
fLabel = new TGString();
if (fType == kRowHeader) {
*fLabel += "Row ";
*fLabel += fRow;
} else if (fType == kColumnHeader) {
*fLabel += "Col ";
*fLabel += fColumn;
} else {
*fLabel += fTable->GetNTableRows();
*fLabel += "x";
*fLabel += fTable->GetNTableColumns();
*fLabel += " Table";
}
}
void TGTableHeader::SetPosition(UInt_t pos)
{
if (fType == kRowHeader) {
fRow = pos;
fColumn = 0;
} else if (fType == kColumnHeader) {
fRow = 0;
fColumn = pos;
} else {
fRow = 0;
fColumn = 0;
}
}
void TGTableHeader::Resize(TGDimension newsize)
{
Resize(newsize.fWidth, newsize.fHeight);
}
void TGTableHeader::Resize(UInt_t width, UInt_t height)
{
TGTableCell::Resize(width, height);
}
void TGTableHeader::Sort(Bool_t order)
{
if (order == kSortAscending) {
} else {
}
}
void TGTableHeader::UpdatePosition()
{
UInt_t nhdr = 0;
if (fType == kColumnHeader) {
while(fTable->GetColumnHeader(nhdr) != this) {
nhdr++;
}
fColumn = nhdr;
} else if (fType == kRowHeader) {
while(fTable->GetRowHeader(nhdr) != this) {
nhdr++;
}
fRow = nhdr;
} else {
fRow = 0;
fColumn = 0;
}
}