#include "TEveWindow.h"
#include "TEveWindowManager.h"
#include "TEveManager.h"
#include "TEveSelection.h"
#include "THashList.h"
#include "TGButton.h"
#include "TGMenu.h"
#include "TGPack.h"
#include "TGTab.h"
#include "TRootContextMenu.h"
#include <cassert>
ClassImp(TEveCompositeFrame);
TEveContextMenu* TEveCompositeFrame::fgCtxMenu = 0;
const TString TEveCompositeFrame::fgkEmptyFrameName("<relinquished>");
TList* TEveCompositeFrame::fgFrameList = new THashList;
TEveCompositeFrame::IconBarCreator_foo TEveCompositeFrame::fgIconBarCreator = 0;
UInt_t TEveCompositeFrame::fgTopFrameHeight = 14;
UInt_t TEveCompositeFrame::fgMiniBarHeight = 4;
Bool_t TEveCompositeFrame::fgAllowTopFrameCollapse = kTRUE;
void TEveCompositeFrame::SetupFrameMarkup(IconBarCreator_foo creator,
UInt_t top_frame_height,
UInt_t mini_bar_height,
Bool_t allow_top_collapse)
{
fgIconBarCreator = creator;
fgTopFrameHeight = top_frame_height;
fgMiniBarHeight = mini_bar_height;
fgAllowTopFrameCollapse = allow_top_collapse;
}
TEveCompositeFrame::TEveCompositeFrame(TGCompositeFrame* parent,
TEveWindow* eve_parent) :
TGCompositeFrame (parent, 0, 0, kVerticalFrame),
fTopFrame (0),
fToggleBar (0),
fTitleBar (0),
fIconBar (0),
fEveWindowLH (0),
fMiniBar (0),
fEveParent (eve_parent),
fEveWindow (0),
fShowInSync (kTRUE)
{
fTopFrame = new TGHorizontalFrame(this, 20, fgTopFrameHeight);
if (fgAllowTopFrameCollapse)
{
fToggleBar = new TGTextButton(fTopFrame, "Hide");
fToggleBar->ChangeOptions(kRaisedFrame);
fToggleBar->Resize(40, fgTopFrameHeight);
fToggleBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
fTopFrame->AddFrame(fToggleBar, new TGLayoutHints(kLHintsNormal));
}
fTitleBar = new TGTextButton(fTopFrame, "Title Bar");
fTitleBar->ChangeOptions(kRaisedFrame);
fTitleBar->Resize(40, fgTopFrameHeight);
fTitleBar->Connect("Clicked()", "TEveCompositeFrame", this, "TitleBarClicked()");
fTopFrame->AddFrame(fTitleBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
if (fgIconBarCreator)
{
fIconBar = (fgIconBarCreator)(this, fTopFrame, fgTopFrameHeight);
}
else
{
TGButton* b = new TGTextButton(fTopFrame, "Actions");
b->ChangeOptions(kRaisedFrame);
b->Resize(40, fgTopFrameHeight);
b->Connect("Pressed()", "TEveCompositeFrame", this, "ActionPressed()");
fIconBar = b;
}
fTopFrame->AddFrame(fIconBar, new TGLayoutHints(kLHintsNormal));
AddFrame(fTopFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
if (fgAllowTopFrameCollapse)
{
fMiniBar = new TGButton(this);
fMiniBar->ChangeOptions(kRaisedFrame | kFixedHeight);
fMiniBar->Resize(20, fgMiniBarHeight);
fMiniBar->SetBackgroundColor(TEveWindow::GetMiniBarBackgroundColor());
fMiniBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
AddFrame(fMiniBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
}
fTopFrame->SetCleanup(kLocalCleanup);
SetCleanup(kLocalCleanup);
MapSubwindows();
HideFrame(fMiniBar);
SetMapSubwindows(kFALSE);
fEveWindowLH = new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY);
if (fEveParent == 0)
fEveParent = gEve->GetWindowManager();
fgFrameList->Add(this);
}
TEveCompositeFrame::~TEveCompositeFrame()
{
fgFrameList->Remove(this);
if (fEveWindow != 0)
{
if (gDebug > 0)
Info("TEveCompositeFrame::~TEveCompositeFrame",
"EveWindow not null '%s', relinquishing it now.",
fEveWindow->GetElementName());
fEveWindow->ClearEveFrame();
RelinquishEveWindow();
}
delete fEveWindowLH;
}
void TEveCompositeFrame::WindowNameChanged(const TString& name)
{
fTitleBar->SetText(name);
}
void TEveCompositeFrame::AcquireEveWindow(TEveWindow* ew)
{
static const TEveException eh("TEveCompositeFrame::AcquireEveWindow ");
if (fEveWindow)
throw eh + "Window already set.";
if (ew == 0)
throw eh + "Called with 0 argument.";
fEveWindow = ew;
fEveWindow->IncDenyDestroy();
TGFrame* gui_frame = fEveWindow->GetGUIFrame();
gui_frame->ReparentWindow(this);
AddFrame(gui_frame, fEveWindowLH);
fEveWindow->PostDock();
gui_frame->MapWindow();
SetCurrent(fEveWindow->IsCurrent());
SetShowTitleBar(fEveWindow->GetShowTitleBar());
WindowNameChanged(fEveWindow->GetElementName());
}
TEveWindow* TEveCompositeFrame::RelinquishEveWindow(Bool_t reparent)
{
TEveWindow* ex_ew = fEveWindow;
if (fEveWindow)
{
TGFrame* gui_frame = fEveWindow->GetGUIFrame();
gui_frame->UnmapWindow();
fEveWindow->PreUndock();
RemoveFrame(gui_frame);
if (reparent)
gui_frame->ReparentWindow(fClient->GetDefaultRoot());
fEveWindow->DecDenyDestroy();
fEveWindow = 0;
SetCurrent(kFALSE);
WindowNameChanged(fgkEmptyFrameName);
}
return ex_ew;
}
TEveWindow* TEveCompositeFrame::GetEveParentAsWindow() const
{
return dynamic_cast<TEveWindow*>(fEveParent);
}
void TEveCompositeFrame::SetCurrent(Bool_t curr)
{
if (curr) {
fTitleBar->SetBackgroundColor(TEveWindow::GetCurrentBackgroundColor());
} else {
fTitleBar->SetBackgroundColor(GetDefaultFrameBackground());
}
fClient->NeedRedraw(fTitleBar);
}
void TEveCompositeFrame::SetShowTitleBar(Bool_t show)
{
if (show) {
HideFrame(fMiniBar);
ShowFrame(fTopFrame);
} else {
HideFrame(fTopFrame);
ShowFrame(fMiniBar);
}
fShowInSync = show == fEveWindow->GetShowTitleBar();
}
void TEveCompositeFrame::HideAllDecorations()
{
HideFrame(fTopFrame);
HideFrame(fMiniBar);
fShowInSync = kFALSE;
}
void TEveCompositeFrame::ShowNormalDecorations()
{
SetShowTitleBar(fEveWindow->GetShowTitleBar());
}
void TEveCompositeFrame::ActionPressed()
{
if (fgCtxMenu == 0) {
fgCtxMenu = new TEveContextMenu("", "");
}
fgCtxMenu->SetupAndPopup(fIconBar, fEveWindow);
}
void TEveCompositeFrame::FlipTitleBarState()
{
if (fShowInSync)
fEveWindow->FlipShowTitleBar();
else
SetShowTitleBar(fEveWindow->GetShowTitleBar());
}
void TEveCompositeFrame::TitleBarClicked()
{
fEveWindow->TitleBarClicked();
}
ClassImp(TEveCompositeFrameInMainFrame);
TEveCompositeFrameInMainFrame::TEveCompositeFrameInMainFrame(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGMainFrame* mf) :
TEveCompositeFrame(parent, eve_parent),
fMainFrame (mf),
fOriginalSlot (0),
fOriginalContainer (0)
{
fMainFrame->Connect("CloseWindow()", "TEveCompositeFrameInMainFrame", this, "MainFrameClosed()");
gEve->GetWindowManager()->Connect("WindowDeleted(TEveWindow*)", "TEveCompositeFrameInMainFrame", this, "SomeWindowClosed(TEveWindow*)");
}
TEveCompositeFrameInMainFrame::~TEveCompositeFrameInMainFrame()
{
if (gDebug > 0)
Info("~TEveCompositeFrameInMainFrame", "Destructor.");
if (gEve && gEve->GetWindowManager())
{
gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "SomeWindowClosed(TEveWindow*)");
}
else
{
Info("~TEveCompositeFrameInMainFrame", "gEve null - OK if it was terminated.");
}
}
void TEveCompositeFrameInMainFrame::WindowNameChanged(const TString& name)
{
fMainFrame->SetWindowName(name);
TEveCompositeFrame::WindowNameChanged(name);
}
void TEveCompositeFrameInMainFrame::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInMainFrame::Destroy()",
"Propagating call to main-frame.");
assert (fEveWindow == 0);
fMainFrame->CloseWindow();
}
void TEveCompositeFrameInMainFrame::SetOriginalSlotAndContainer(TEveWindow* slot,
TEveWindow* container)
{
static const TEveException kEH("TEveCompositeFrameInMainFrame::SetOriginalSlotAndContainer ");
if (container && ! container->CanMakeNewSlots())
throw kEH + "Given window can not make new slots.";
fOriginalSlot = slot;
fOriginalContainer = container;
}
void TEveCompositeFrameInMainFrame::SomeWindowClosed(TEveWindow* w)
{
if (w == fOriginalSlot)
fOriginalSlot = 0;
if (w == fOriginalContainer)
fOriginalContainer = 0;
}
void TEveCompositeFrameInMainFrame::MainFrameClosed()
{
if (fEveWindow != 0)
{
TEveWindow* swapCandidate = 0;
if (fOriginalSlot)
{
TEveCompositeFrameInPack* packFrame = dynamic_cast<TEveCompositeFrameInPack*>(fOriginalSlot->GetEveFrame());
if (packFrame) {
TGPack* pack = (TGPack*)(packFrame->GetParent());
pack->ShowFrame(packFrame);
}
swapCandidate = fOriginalSlot;
}
else if (fOriginalContainer)
{
swapCandidate = fOriginalContainer->NewSlot();
}
else if (gEve->GetWindowManager()->HasDefaultContainer())
{
swapCandidate = gEve->GetWindowManager()->GetDefaultContainer()->NewSlot();
}
if (swapCandidate)
{
TEveWindow::SwapWindows(fEveWindow, swapCandidate);
gEve->GetWindowManager()->WindowDocked(fEveWindow );
}
}
fMainFrame->DontCallClose();
if (fEveWindow != 0)
fEveWindow->DestroyWindowAndSlot();
if (gDebug > 0)
Info("TEveCompositeFrameInMainFrame::MainFrameClosed()",
"Expecting destructor call soon.");
}
ClassImp(TEveCompositeFrameInPack);
TEveCompositeFrameInPack::TEveCompositeFrameInPack(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGPack* pack) :
TEveCompositeFrame(parent, eve_parent),
fPack (pack)
{
}
TEveCompositeFrameInPack::~TEveCompositeFrameInPack()
{
}
void TEveCompositeFrameInPack::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInPack::Destroy()", "Removing from pack and deleting.");
assert(fEveWindow == 0);
fPack->RemoveFrame(this);
delete this;
}
ClassImp(TEveCompositeFrameInTab);
TEveCompositeFrameInTab::TEveCompositeFrameInTab(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGTab* tab) :
TEveCompositeFrame(parent, eve_parent),
fTab (tab),
fParentInTab (parent)
{
}
TEveCompositeFrameInTab::~TEveCompositeFrameInTab()
{
}
void TEveCompositeFrameInTab::WindowNameChanged(const TString& name)
{
Int_t t = FindTabIndex();
fTab->GetTabTab(t)->SetText(new TGString(name));
fTab->Layout();
TEveCompositeFrame::WindowNameChanged(name);
}
Int_t TEveCompositeFrameInTab::FindTabIndex()
{
static const TEveException eh("TEveCompositeFrameInTab::FindTabIndex ");
Int_t nt = fTab->GetNumberOfTabs();
for (Int_t t = 0; t < nt; ++t)
{
if (fTab->GetTabContainer(t) == fParentInTab)
{
return t;
}
}
throw eh + "parent frame not found in tab.";
}
void TEveCompositeFrameInTab::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInTab::Destroy()", "Removing from tab and deleting.");
assert (fEveWindow == 0);
Int_t t = FindTabIndex();
fTab->RemoveTab(t, kFALSE);
fParentInTab->DestroyWindow();
fParentInTab->SetCleanup(kNoCleanup);
delete fParentInTab;
delete this;
}
void TEveCompositeFrameInTab::SetCurrent(Bool_t curr)
{
TEveCompositeFrame::SetCurrent(curr);
Int_t t = FindTabIndex();
TGTabElement* te = fTab->GetTabTab(t);
if (curr) {
te->SetBackgroundColor(TEveWindow::GetCurrentBackgroundColor());
} else {
te->SetBackgroundColor(GetDefaultFrameBackground());
}
fClient->NeedRedraw(te);
}
ClassImp(TEveWindow);
UInt_t TEveWindow::fgMainFrameDefWidth = 640;
UInt_t TEveWindow::fgMainFrameDefHeight = 480;
Pixel_t TEveWindow::fgCurrentBackgroundColor = 0x80A0C0;
Pixel_t TEveWindow::fgMiniBarBackgroundColor = 0x80C0A0;
TEveWindow::TEveWindow(const char* n, const char* t) :
TEveElementList(n, t),
fEveFrame (0),
fShowTitleBar (kTRUE)
{
fChildClass = TEveWindow::Class();
}
TEveWindow::~TEveWindow()
{
if (gDebug > 0)
Info("~TEveWindow", "name='%s', deny-destroy=%d.",
GetElementName(), fDenyDestroy);
}
void TEveWindow::PreDeleteElement()
{
gEve->GetWindowManager()->DeleteWindow(this);
TEveElementList::PreDeleteElement();
}
void TEveWindow::PreUndock()
{
for (List_ci i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TEveWindow* w = dynamic_cast<TEveWindow*>(*i);
if (w)
w->PreUndock();
}
}
void TEveWindow::PostDock()
{
for (List_ci i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TEveWindow* w = dynamic_cast<TEveWindow*>(*i);
if (w)
w->PostDock();
}
}
void TEveWindow::NameTitleChanged()
{
fEveFrame->WindowNameChanged(GetElementName());
}
void TEveWindow::PopulateEmptyFrame(TEveCompositeFrame* ef)
{
ef->fEveParent->AddElement(this);
ef->AcquireEveWindow(this);
fEveFrame = ef;
}
void TEveWindow::SwapWindow(TEveWindow* w)
{
static const TEveException eh("TEveWindow::SwapWindow ");
if (w == 0)
throw eh + "Called with null argument.";
SwapWindows(this, w);
}
void TEveWindow::SwapWindowWithCurrent()
{
static const TEveException eh("TEveWindow::SwapWindowWithCurrent ");
TEveWindow* current = gEve->GetWindowManager()->GetCurrentWindow();
if (current == 0)
throw eh + "Current eve-window is not set.";
if (current == this)
throw eh + "This is the current window ... nothing changed.";
SwapWindows(this, current);
}
void TEveWindow::UndockWindow()
{
TEveWindow* return_cont = fEveFrame->GetEveParentAsWindow();
if (return_cont && ! return_cont->CanMakeNewSlots())
return_cont = 0;
TEveCompositeFrameInPack* packFrame = dynamic_cast<TEveCompositeFrameInPack*>(fEveFrame);
if (packFrame) {
TGPack* pack = (TGPack*)(packFrame->GetParent());
pack->HideFrame(fEveFrame);
}
TEveWindowSlot* ew_slot = TEveWindow::CreateWindowMainFrame(0);
TEveWindow::SwapWindows(ew_slot, this);
((TEveCompositeFrameInMainFrame*) fEveFrame)->
SetOriginalSlotAndContainer(ew_slot, return_cont);
gEve->GetWindowManager()->WindowUndocked(this );
}
void TEveWindow::UndockWindowDestroySlot()
{
TEveWindow* return_cont = fEveFrame->GetEveParentAsWindow();
if (return_cont && ! return_cont->CanMakeNewSlots())
return_cont = 0;
TEveWindowSlot* ew_slot = TEveWindow::CreateWindowMainFrame(0);
TEveWindow::SwapWindows(ew_slot, this);
((TEveCompositeFrameInMainFrame*) fEveFrame)->
SetOriginalSlotAndContainer(0, return_cont);
ew_slot->DestroyWindowAndSlot();
gEve->GetWindowManager()->WindowUndocked(this);
}
void TEveWindow::ReplaceWindow(TEveWindow* w)
{
fEveFrame->RelinquishEveWindow();
fEveFrame->fEveParent->AddElement(w);
fEveFrame->AcquireEveWindow(w);
w->fEveFrame = fEveFrame;
fEveFrame->fEveParent->RemoveElement(this);
w->fEveFrame->Layout();
}
void TEveWindow::DestroyWindow()
{
if (gDebug > 0)
Info("TEveWindow::DestroyWindow()", "name='%s', class='%s', deny-destroy=%d.",
GetElementName(), ClassName(), fDenyDestroy);
if (fEveFrame != 0 && fDenyDestroy == 1)
{
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
fEveFrame->UnmapWindow();
Bool_t dozrc = fDestroyOnZeroRefCnt;
fDestroyOnZeroRefCnt = kFALSE;
fEveFrame->RelinquishEveWindow();
ew_slot->PopulateEmptyFrame(fEveFrame);
fEveFrame->fEveParent->RemoveElement(this);
fDestroyOnZeroRefCnt = dozrc;
fEveFrame->Layout();
fEveFrame->MapWindow();
fEveFrame = 0;
}
TEveElementList::Destroy();
}
void TEveWindow::DestroyWindowAndSlot()
{
if (gDebug > 0)
Info("TEveWindow::DestroyWindowAndSlot()", "'name=%s', class= '%s', deny-destroy=%d.",
GetElementName(), ClassName(), fDenyDestroy);
if (fEveFrame != 0 && fDenyDestroy == 1)
{
fEveFrame->RelinquishEveWindow();
fEveFrame->Destroy();
fEveFrame = 0;
}
TEveElementList::Destroy();
}
void TEveWindow::ClearEveFrame()
{
fEveFrame = 0;
}
void TEveWindow::SetShowTitleBar(Bool_t x)
{
if (fShowTitleBar == x)
return;
fShowTitleBar = x;
fEveFrame->SetShowTitleBar(fShowTitleBar);
fEveFrame->Layout();
}
Bool_t TEveWindow::IsCurrent() const
{
return gEve->GetWindowManager()->IsCurrentWindow(this);
}
void TEveWindow::MakeCurrent()
{
if ( ! gEve->GetWindowManager()->IsCurrentWindow(this))
gEve->GetWindowManager()->SelectWindow(this);
}
void TEveWindow::SetCurrent(Bool_t curr)
{
fEveFrame->SetCurrent(curr);
}
Bool_t TEveWindow::IsAncestorOf(TEveWindow* win)
{
TEveWindow* parent = dynamic_cast<TEveWindow*>(win->fEveFrame->fEveParent);
if (parent)
{
if (parent == this)
return kTRUE;
else
return IsAncestorOf(parent);
}
else
{
return kFALSE;
}
}
void TEveWindow::TitleBarClicked()
{
gEve->GetWindowManager()->SelectWindow(this);
}
TEveWindowSlot* TEveWindow::CreateDefaultWindowSlot()
{
return new TEveWindowSlot("Free Window Slot", "A free window slot, can become a container or swallow a window.");
}
TEveWindowSlot* TEveWindow::CreateWindowMainFrame(TEveWindow* eve_parent)
{
TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(), fgMainFrameDefWidth, fgMainFrameDefHeight);
mf->SetCleanup(kLocalCleanup);
TEveCompositeFrameInMainFrame *slot = new TEveCompositeFrameInMainFrame
(mf, eve_parent, mf);
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
ew_slot->PopulateEmptyFrame(slot);
mf->AddFrame(slot, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
slot->MapWindow();
mf->Layout();
mf->MapWindow();
return ew_slot;
}
TEveWindowSlot* TEveWindow::CreateWindowInTab(TGTab* tab, TEveWindow* eve_parent)
{
TGCompositeFrame *parent = tab->AddTab("<unused>");
parent->SetCleanup(kLocalCleanup);
TEveCompositeFrameInTab *slot = new TEveCompositeFrameInTab(parent, eve_parent, tab);
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
ew_slot->PopulateEmptyFrame(slot);
parent->AddFrame(slot, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
tab->Layout();
slot->MapWindow();
return ew_slot;
}
void TEveWindow::SwapWindows(TEveWindow* w1, TEveWindow* w2)
{
static const TEveException eh("TEveWindow::SwapWindows ");
if (w1 == 0 || w2 == 0)
throw eh + "Called with null window.";
if (w1 == w2)
throw eh + "Windows are equal ... nothing to change.";
if (w1->IsAncestorOf(w2) || w2->IsAncestorOf(w1))
throw eh + "Windows are in direct ancestry.";
TEveCompositeFrame *f1 = w1->fEveFrame, *f2 = w2->fEveFrame;
TEveElement *p1 = f1->fEveParent, *p2 = f2->fEveParent;
if (p1 != p2)
{
p1->AddElement(w2);
p2->AddElement(w1);
}
f1->RelinquishEveWindow(kFALSE);
f2->RelinquishEveWindow(kFALSE);
f1->AcquireEveWindow(w2); w2->fEveFrame = f1;
f2->AcquireEveWindow(w1); w1->fEveFrame = f2;
if (p1 != p2)
{
p1->RemoveElement(w1);
p2->RemoveElement(w2);
}
f1->Layout(); f2->Layout();
}
UInt_t TEveWindow::GetMainFrameDefWidth()
{
return fgMainFrameDefWidth;
}
UInt_t TEveWindow::GetMainFrameDefHeight()
{
return fgMainFrameDefHeight;
}
void TEveWindow::SetMainFrameDefWidth (UInt_t x)
{
fgMainFrameDefWidth = x;
}
void TEveWindow::SetMainFrameDefHeight(UInt_t x)
{
fgMainFrameDefHeight = x;
}
Pixel_t TEveWindow::GetCurrentBackgroundColor()
{
return fgCurrentBackgroundColor;
}
Pixel_t TEveWindow::GetMiniBarBackgroundColor()
{
return fgMiniBarBackgroundColor;
}
void TEveWindow::SetCurrentBackgroundColor(Pixel_t p)
{
fgCurrentBackgroundColor = p;
}
void TEveWindow::SetMiniBarBackgroundColor(Pixel_t p)
{
fgMiniBarBackgroundColor = p;
}
ClassImp(TEveWindowSlot);
TEveWindowSlot::TEveWindowSlot(const char* n, const char* t) :
TEveWindow (n, t),
fEmptyButt (0),
fEmbedBuffer (0)
{
fEmptyButt = new TGTextButton(0, " <empty>\nclick to select");
fEmptyButt->ChangeOptions(kRaisedFrame);
fEmptyButt->SetTextJustify(kTextCenterX | kTextCenterY);
fEmptyButt->Connect("Clicked()", "TEveWindow", this, "TitleBarClicked()");
}
TEveWindowSlot::~TEveWindowSlot()
{
fEmptyButt->DeleteWindow();
}
TGFrame* TEveWindowSlot::GetGUIFrame()
{
return fEmptyButt;
}
void TEveWindowSlot::SetCurrent(Bool_t curr)
{
TEveWindow::SetCurrent(curr);
if (curr)
fEmptyButt->SetBackgroundColor(fgCurrentBackgroundColor);
else
fEmptyButt->SetBackgroundColor(fEmptyButt->GetDefaultFrameBackground());
gClient->NeedRedraw(fEmptyButt);
}
TEveWindowPack* TEveWindowSlot::MakePack()
{
TEveWindowPack* eve_pack = new TEveWindowPack
(0, "Pack", "Window container for horizontal and vertical stacking.");
ReplaceWindow(eve_pack);
return eve_pack;
}
TEveWindowTab* TEveWindowSlot::MakeTab()
{
TEveWindowTab* eve_tab = new TEveWindowTab
(0, "Tab", "Window container for horizontal and vertical stacking.");
ReplaceWindow(eve_tab);
return eve_tab;
}
TEveWindowFrame* TEveWindowSlot::MakeFrame(TGFrame* frame)
{
TEveWindowFrame* eve_frame = new TEveWindowFrame
(frame, "External frame", "");
ReplaceWindow(eve_frame);
return eve_frame;
}
TGCompositeFrame* TEveWindowSlot::StartEmbedding()
{
static const TEveException eh("TEveWindowSlot::StartEmbedding ");
if (fEmbedBuffer != 0)
throw eh + "Already embedding.";
fEmbedBuffer = new TGCompositeFrame(gClient->GetDefaultRoot());
fEmbedBuffer->SetEditable(kTRUE);
return fEmbedBuffer;
}
TEveWindowFrame* TEveWindowSlot::StopEmbedding(const char* name)
{
static const TEveException eh("TEveWindowSlot::StopEmbedding ");
if (fEmbedBuffer == 0) {
Warning(eh, "Embedding not in progress.");
return 0;
}
fEmbedBuffer->SetEditable(kFALSE);
Int_t size = fEmbedBuffer->GetList()->GetSize();
if (size == 0) {
Warning(eh, "Frame has not been registered.");
delete fEmbedBuffer;
fEmbedBuffer = 0;
return 0;
}
if (size > 1) {
Warning(eh, "Several frames have been registered (%d). Only the first one will be taken.", size);
}
TGFrame *f = ((TGFrameElement*)fEmbedBuffer->GetList()->First())->fFrame;
fEmbedBuffer->RemoveFrame(f);
f->UnmapWindow();
f->ReparentWindow(gClient->GetDefaultRoot());
delete fEmbedBuffer;
fEmbedBuffer = 0;
TGMainFrame *mf = dynamic_cast<TGMainFrame*>(f);
assert(mf != 0);
if (name) {
mf->SetWindowName(name);
}
TEveWindowFrame* eve_frame = new TEveWindowFrame
(f, mf->GetWindowName(), mf->ClassName());
ReplaceWindow(eve_frame);
return eve_frame;
}
ClassImp(TEveWindowFrame);
TEveWindowFrame::TEveWindowFrame(TGFrame* frame, const char* n, const char* t) :
TEveWindow (n, t),
fGUIFrame (frame)
{
if (fGUIFrame == 0)
{
fGUIFrame = new TGCompositeFrame();
fGUIFrame->SetCleanup(kLocalCleanup);
}
}
TEveWindowFrame::~TEveWindowFrame()
{
fGUIFrame->DeleteWindow();
}
TGCompositeFrame* TEveWindowFrame::GetGUICompositeFrame()
{
static const TEveException kEH("TEveWindowFrame::GetGUICompositeFrame ");
TGCompositeFrame *cf = dynamic_cast<TGCompositeFrame*>(fGUIFrame);
if (cf == 0)
throw kEH + "The registered frame is not a composite-frame.";
return cf;
}
ClassImp(TEveWindowPack);
TEveWindowPack::TEveWindowPack(TGPack* p, const char* n, const char* t) :
TEveWindow (n, t),
fPack (p ? p : new TGPack())
{
}
TEveWindowPack::~TEveWindowPack()
{
fPack->DeleteWindow();
}
TGFrame* TEveWindowPack::GetGUIFrame()
{
return fPack;
}
TEveWindowSlot* TEveWindowPack::NewSlot()
{
return NewSlotWithWeight(1.f);
}
TEveWindowSlot* TEveWindowPack::NewSlotWithWeight(Float_t w)
{
TEveCompositeFrame* slot = new TEveCompositeFrameInPack(fPack, this, fPack);
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
ew_slot->PopulateEmptyFrame(slot);
fPack->AddFrameWithWeight(slot, 0, w);
slot->MapWindow();
fPack->Layout();
return ew_slot;
}
void TEveWindowPack::FlipOrientation()
{
fPack->SetVertical( ! fPack->GetVertical());
}
void TEveWindowPack::SetVertical(Bool_t x)
{
fPack->SetVertical(x);
}
void TEveWindowPack::EqualizeFrames()
{
fPack->EqualizeFrames();
fPack->Layout();
}
ClassImp(TEveWindowTab);
TEveWindowTab::TEveWindowTab(TGTab* tab, const char* n, const char* t) :
TEveWindow(n, t),
fTab (tab ? tab : new TGTab())
{
}
TEveWindowTab::~TEveWindowTab()
{
fTab->DeleteWindow();
}
TGFrame* TEveWindowTab::GetGUIFrame()
{
return fTab;
}
TEveWindowSlot* TEveWindowTab::NewSlot()
{
return TEveWindow::CreateWindowInTab(fTab, this);
}
ClassImp(TEveContextMenu);
TEveContextMenu::TEveContextMenu(const char *name, const char *title) :
TContextMenu(name, title)
{
}
void TEveContextMenu::SetupAndPopup(TGWindow* button, TObject* obj)
{
Int_t x, y;
UInt_t w, h;
Window_t childdum;
gVirtualX->GetWindowSize(button->GetId(), x, y, w, h);
gVirtualX->TranslateCoordinates(button->GetId(),
gClient->GetDefaultRoot()->GetId(),
0, 0, x, y, childdum);
TRootContextMenu *rcm = dynamic_cast<TRootContextMenu*>(fContextMenuImp);
if (rcm != 0)
{
gVirtualX->SetWMTransientHint (rcm->GetId(), button->GetId());
}
Popup(x - 2, y + h - 2, obj);
}