#include "TGToolBar.h"
#include "TList.h"
#include "TGButton.h"
#include "TGPicture.h"
#include "TGToolTip.h"
#include "TSystem.h"
#include "TROOT.h"
#include "Riostream.h"
#include "TMap.h"
ClassImp(TGToolBar)
TGToolBar::TGToolBar(const TGWindow *p, UInt_t w, UInt_t h,
UInt_t options, ULong_t back) :
TGCompositeFrame(p, w, h, options, back)
{
fPictures = new TList;
fTrash = new TList;
fMapOfButtons = new TMap();
SetWindowName();
}
TGToolBar::~TGToolBar()
{
if (!MustCleanup()) {
if (fTrash) fTrash->Clear("nodelete");
}
delete fTrash;
fTrash = 0;
TIter next(fPictures);
const TGPicture *p;
while ((p = (const TGPicture *) next()))
fClient->FreePicture(p);
fPictures->Clear("nodelete");
delete fPictures;
delete fMapOfButtons;
}
TGButton *TGToolBar::AddButton(const TGWindow *w, ToolBarData_t *button, Int_t spacing)
{
const TGPicture *pic = fClient->GetPicture(button->fPixmap);
if (!pic) {
Error("AddButton", "pixmap not found: %s", button->fPixmap);
return 0;
}
fPictures->Add((TObject*)pic);
TGPictureButton *pbut;
TGLayoutHints *layout;
pbut = new TGPictureButton(this, pic, button->fId);
pbut->SetToolTipText(button->fTipText);
layout = new TGLayoutHints(kLHintsTop | kLHintsLeft, spacing, 0, 2, 2);
AddFrame(pbut, layout);
pbut->AllowStayDown(button->fStayDown);
pbut->Associate(w);
button->fButton = pbut;
fTrash->Add(pbut);
fTrash->Add(layout);
fMapOfButtons->Add(pbut, (TObject*)((Long_t)button->fId));
Connect(pbut, "Pressed()" , "TGToolBar", this, "ButtonPressed()");
Connect(pbut, "Released()", "TGToolBar", this, "ButtonReleased()");
Connect(pbut, "Clicked()" , "TGToolBar", this, "ButtonClicked()");
return pbut;
}
TGButton *TGToolBar::AddButton(const TGWindow *w, TGPictureButton *pbut, Int_t spacing)
{
const TGPicture *pic = pbut->GetPicture();
fPictures->Add((TObject*)pic);
TGLayoutHints *layout;
layout = new TGLayoutHints(kLHintsTop | kLHintsLeft, spacing, 0, 2, 2);
AddFrame(pbut, layout);
pbut->Associate(w);
fTrash->Add(pbut);
fTrash->Add(layout);
fMapOfButtons->Add(pbut, (TObject*)((Long_t)pbut->WidgetId()));
Connect(pbut, "Pressed()" , "TGToolBar", this, "ButtonPressed()");
Connect(pbut, "Released()", "TGToolBar", this, "ButtonReleased()");
Connect(pbut, "Clicked()" , "TGToolBar", this, "ButtonClicked()");
return pbut;
}
TGButton *TGToolBar::GetButton(Int_t id) const
{
TIter next(fMapOfButtons);
register TGButton *item = 0;
while ((item = (TGButton*)next())) {
if ((Long_t)fMapOfButtons->GetValue(item) == id) break;
}
return item;
}
void TGToolBar::SetId(TGButton *button, Long_t id)
{
TPair *a = (TPair*) fMapOfButtons->FindObject(button);
if (a) {
a->SetValue((TObject*)id);
}
}
Long_t TGToolBar::GetId(TGButton *button) const
{
TPair *a = (TPair*) fMapOfButtons->FindObject(button);
if (a)
return Long_t(a->Value());
else
return Long_t(-1);
}
void TGToolBar::ChangeIcon(ToolBarData_t *button, const char *new_icon)
{
const TGPicture *pic = fClient->GetPicture(new_icon);
if (!pic) {
Error("ChangeIcon", "pixmap not found: %s", new_icon);
return;
}
fPictures->Add((TObject*)pic);
((TGPictureButton *)button->fButton)->SetPicture(pic);
}
void TGToolBar::Cleanup()
{
delete fTrash;
fTrash = 0;
TGCompositeFrame::Cleanup();
}
void TGToolBar::ButtonPressed()
{
TGButton *btn = (TGButton*)gTQSender;
TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
if (a) {
Int_t id = (Int_t)Long_t(a->Value());
Pressed(id);
}
}
void TGToolBar::ButtonReleased()
{
TGButton *btn = (TGButton*)gTQSender;
TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
if (a) {
Int_t id = (Int_t)Long_t(a->Value());
Released(id);
}
}
void TGToolBar::ButtonClicked()
{
TGButton *btn = (TGButton*)gTQSender;
TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
if (a) {
Int_t id = (Int_t)Long_t(a->Value());
Clicked(id);
}
}
void TGToolBar::SavePrimitive(ostream &out, Option_t *option )
{
if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
out << endl;
out << " // tool bar" << endl;
out << " TGToolBar *";
out << GetName() << " = new TGToolBar(" << fParent->GetName()
<< "," << GetWidth() << "," << GetHeight();
if (fBackground == GetDefaultFrameBackground()) {
if (!GetOptions()) {
out <<");" << endl;
} else {
out << "," << GetOptionString() <<");" << endl;
}
} else {
out << "," << GetOptionString() << ",ucolor);" << endl;
}
char quote = '"';
int i = 0;
const char *picname;
TGFrameElement *f;
TIter next(GetList());
while ((f = (TGFrameElement *) next())) {
if (f->fFrame->InheritsFrom(TGPictureButton::Class())) {
if (!gROOT->ClassSaved(TGPictureButton::Class())) {
out << endl << " ToolBarData_t t;" << endl;
}
TGPictureButton *pb = (TGPictureButton *)f->fFrame;
picname = pb->GetPicture()->GetName();
out << " t.fPixmap = " << quote
<< gSystem->ExpandPathName(gSystem->UnixPathName(picname))
<< quote << ";" << endl;
out << " t.fTipText = " << quote
<< pb->GetToolTip()->GetText()->GetString() << quote << ";" << endl;
if (pb->GetState() == kButtonDown) {
out << " t.fStayDown = kTRUE;" << endl;
} else {
out << " t.fStayDown = kFALSE;" << endl;
}
out << " t.fId = " << i+1 << ";" << endl;
out << " t.fButton = 0;" << endl;
out << " " << GetName() << "->AddButton(" << GetParent()->GetName()
<< ",&t," << f->fLayout->GetPadLeft() << ");" << endl;
if (pb->GetState() == kButtonDown) {
out << " TGButton *" << pb->GetName() << " = t.fButton;" << endl;
out << " " << pb->GetName() << "->SetState(kButtonDown);" << endl;
}
if (pb->GetState() == kButtonDisabled) {
out << " TGButton *" << pb->GetName() << " = t.fButton;" << endl;
out << " " << pb->GetName() << "->SetState(kButtonDisabled);" << endl;
}
if (pb->GetState() == kButtonEngaged) {
out << " TGButton *" << pb->GetName() << " = t.fButton;" << endl;
out << " " << pb->GetName() << "->SetState(kButtonEngaged);" << endl;
}
i++;
} else {
f->fFrame->SavePrimitive(out, option);
out << " " << GetName()<<"->AddFrame(" << f->fFrame->GetName();
f->fLayout->SavePrimitive(out, option);
out << ");"<< endl;
}
}
}
Last change: Wed Jun 25 08:43:20 2008
Last generated: 2008-06-25 08:43
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.