#include "TGWindow.h"
#include "Riostream.h"
#include "TApplication.h"
ClassImp(TGWindow)
ClassImp(TGUnknownWindowHandler)
Int_t TGWindow::fgCounter = 0;
TGWindow::TGWindow(const TGWindow *p, Int_t x, Int_t y, UInt_t w, UInt_t h,
UInt_t border, Int_t depth, UInt_t clss, void *visual,
SetWindowAttributes_t *attr, UInt_t wtype)
{
UInt_t type = wtype;
fId = 0;
fParent = 0;
if (!p && gClient) {
p = gClient->GetRoot();
}
if (p) {
fClient = p->fClient;
if (fClient->IsEditable()) type = wtype & ~1;
fParent = p;
if (fParent && fParent->IsMapSubwindows()) {
fId = gVirtualX->CreateWindow(fParent->fId, x, y,
TMath::Max(w, (UInt_t) 1),
TMath::Max(h, (UInt_t) 1), border,
depth, clss, visual, attr, type);
fClient->RegisterWindow(this);
}
fNeedRedraw = kFALSE;
fgCounter++;
fName = "frame";
fName += fgCounter;
}
fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
(fParent->fEditDisabled == kEditDisable) : 0;
SetWindowName();
}
TGWindow::TGWindow(TGClient *c, Window_t id, const TGWindow *parent)
{
fClient = c;
fId = id;
fParent = parent;
fClient->RegisterWindow(this);
fNeedRedraw = kFALSE;
fEditDisabled = (fId != gVirtualX->GetDefaultRootWindow()) && fParent ?
fParent->fEditDisabled : kFALSE;
fgCounter++;
fName = "frame";
fName += fgCounter;
}
TGWindow::~TGWindow()
{
if (fClient) {
if (fParent == fClient->GetDefaultRoot())
DestroyWindow();
fClient->UnregisterWindow(this);
}
}
void TGWindow::SetWindowName(const char *name)
{
if (!name && gDebug > 0) {
TString wname = ClassName();
wname += "::" + fName;
gVirtualX->SetWindowName(fId, (char *)wname.Data());
} else {
gVirtualX->SetWindowName(fId, (char *)name);
}
}
const TGWindow *TGWindow::GetMainFrame() const
{
return ((fParent == 0) || (fParent == fClient->GetDefaultRoot())) ? this : fParent->GetMainFrame();
}
void TGWindow::ReparentWindow(const TGWindow *p, Int_t x, Int_t y)
{
if (p == fParent) return;
if (p) {
gVirtualX->ReparentWindow(fId, p->GetId(), x, y);
gVirtualX->Update(1);
}
fParent = p;
}
void TGWindow::Move(Int_t x, Int_t y)
{
gVirtualX->MoveWindow(fId, x, y);
}
void TGWindow::Resize(UInt_t w, UInt_t h)
{
gVirtualX->ResizeWindow(fId, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
}
void TGWindow::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
{
gVirtualX->MoveResizeWindow(fId, x, y, TMath::Max(w, (UInt_t)1), TMath::Max(h, (UInt_t)1));
}
Bool_t TGWindow::IsMapped()
{
WindowAttributes_t attr;
gVirtualX->GetWindowAttributes(fId, attr);
return (attr.fMapState != kIsUnmapped);
}
void TGWindow::Print(Option_t *option) const
{
TString opt = option;
if (opt.Contains("tree")) {
const TGWindow *parent = fParent;
cout << ClassName() << ":\t" << fId << endl;
while (parent && (parent != fClient->GetDefaultRoot())) {
cout << "\t" << parent->ClassName() << ":\t" << parent->GetId() << endl;
parent = parent->GetParent();
}
} else {
cout << ClassName() << ":\t" << fId << endl;
}
}
Int_t TGWindow::GetCounter()
{
return fgCounter;
}
const char *TGWindow::GetName()const
{
TGWindow *w = (TGWindow*)this;
if (fName.BeginsWith("frame")) {
TString cname = ClassName();
if (cname.BeginsWith("TGed"))
cname.Replace(0, 1, 'f');
else if (cname.BeginsWith("TG"))
cname.Replace(0,2,'f');
else
cname.Replace(0, 1, 'f');
w->fName.Remove(0,5);
w->fName = cname + w->fName;
}
if (w->fName.Contains(" "))
w->fName.ReplaceAll(" ", "");
if (w->fName.Contains(":"))
w->fName.ReplaceAll(":", "");
return fName.Data();
}