#include "TGMdi.h"
#include "TGMdiMenu.h"
#include "TList.h"
#include "Riostream.h"
ClassImp(TGMdiMenuBar)
TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
TGCompositeFrame(p, w, h, kHorizontalFrame)
{
fLHint = new TGLayoutHints(kLHintsNormal);
fLeftHint = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1);
fBarHint = new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 1, 1, 1, 1);
fRightHint = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 1, 2, 1, 1);
fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
AddFrame(fLeft, fLeftHint);
AddFrame(fBar, fBarHint);
AddFrame(fRight, fRightHint);
}
TGMdiMenuBar::~TGMdiMenuBar()
{
if (!MustCleanup()) {
delete fLHint;
delete fLeftHint;
delete fRightHint;
delete fBarHint;
}
}
void TGMdiMenuBar::AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
{
fBar->AddPopup(s, menu, l);
}
void TGMdiMenuBar::AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
TGFrameElement *el;
TIter nextl(fLeft->GetList());
while ((el = (TGFrameElement *) nextl())) {
fLeft->HideFrame(el->fFrame);
}
TIter nextr(fRight->GetList());
while ((el = (TGFrameElement *) nextr())) {
fRight->HideFrame(el->fFrame);
}
icon->ReparentWindow(fLeft);
buttons->ReparentWindow(fRight);
fLeft->AddFrame(icon, fLHint);
fRight->AddFrame(buttons, fLHint);
}
void TGMdiMenuBar::RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
fLeft->RemoveFrame(icon);
fRight->RemoveFrame(buttons);
TGFrameElement *el;
el = (TGFrameElement *)fLeft->GetList()->Last();
if (el)
fLeft->ShowFrame(el->fFrame);
el = (TGFrameElement *)fRight->GetList()->Last();
if (el)
fRight->ShowFrame(el->fFrame);
}
void TGMdiMenuBar::ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
TGFrameElement *el;
TIter nextl(fLeft->GetList());
while ((el = (TGFrameElement *) nextl())) {
fLeft->HideFrame(el->fFrame);
}
TIter nextr(fRight->GetList());
while ((el = (TGFrameElement *) nextr())) {
fRight->HideFrame(el->fFrame);
}
fLeft->ShowFrame(icon);
fRight->ShowFrame(buttons);
}
void TGMdiMenuBar::HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
fLeft->HideFrame(icon);
fRight->HideFrame(buttons);
TGFrameElement *el;
el = (TGFrameElement *)fLeft->GetList()->Last();
if (el)
fLeft->ShowFrame(el->fFrame);
el = (TGFrameElement *)fRight->GetList()->Last();
if (el)
fRight->ShowFrame(el->fFrame);
}
void TGMdiMenuBar::SavePrimitive(ostream &out, Option_t *option )
{
out << endl;
out << " // MDI menu bar" << endl;
out << " TGMdiMenuBar *";
out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
<< "," << GetWidth() << "," << GetHeight() << ");" << endl;
if (!fList) return;
out << " TGMenuBar *" << fBar->GetName() << " = " << GetName()
<< "->GetMenuBar();" << endl;
TGFrameElement *el;
TIter next(fBar->GetList());
while ((el = (TGFrameElement *)next())) {
el->fFrame->SavePrimitive(out, option);
el->fLayout->SavePrimitive(out, option);
out << ");" << endl;
}
}