47 TGToolBar::TGToolBar(
const TGWindow *p, UInt_t w, UInt_t h,
48 UInt_t options, ULong_t back) :
49 TGCompositeFrame(p, w, h, options, back)
54 fPictures =
new TList;
56 fMapOfButtons =
new TMap();
64 TGToolBar::~TGToolBar()
67 if (fTrash) fTrash->Clear(
"nodelete");
72 TIter next(fPictures);
74 while ((p = (
const TGPicture *) next()))
75 fClient->FreePicture(p);
79 fPictures->Clear(
"nodelete");
91 TGButton *TGToolBar::AddButton(
const TGWindow *w, ToolBarData_t *button, Int_t spacing)
93 const TGPicture *pic = fClient->GetPicture(button->fPixmap);
95 Error(
"AddButton",
"pixmap not found: %s", button->fPixmap);
98 fPictures->Add((TObject*)pic);
100 TGPictureButton *pbut;
101 TGLayoutHints *layout;
103 pbut =
new TGPictureButton(
this, pic, button->fId);
104 pbut->SetStyle(gClient->GetStyle());
105 pbut->SetToolTipText(button->fTipText);
107 layout =
new TGLayoutHints(kLHintsTop | kLHintsLeft, spacing, 0, 2, 2);
108 AddFrame(pbut, layout);
109 pbut->AllowStayDown(button->fStayDown);
111 button->fButton = pbut;
116 fMapOfButtons->Add(pbut, (TObject*)((Long_t)button->fId));
118 Connect(pbut,
"Pressed()" ,
"TGToolBar",
this,
"ButtonPressed()");
119 Connect(pbut,
"Released()",
"TGToolBar",
this,
"ButtonReleased()");
120 Connect(pbut,
"Clicked()" ,
"TGToolBar",
this,
"ButtonClicked()");
129 TGButton *TGToolBar::AddButton(
const TGWindow *w, TGPictureButton *pbut, Int_t spacing)
131 const TGPicture *pic = pbut->GetPicture();
132 fPictures->Add((TObject*)pic);
134 TGLayoutHints *layout;
135 layout =
new TGLayoutHints(kLHintsTop | kLHintsLeft, spacing, 0, 2, 2);
136 pbut->SetStyle(gClient->GetStyle());
137 AddFrame(pbut, layout);
143 fMapOfButtons->Add(pbut, (TObject*)((Long_t)pbut->WidgetId()));
145 Connect(pbut,
"Pressed()" ,
"TGToolBar",
this,
"ButtonPressed()");
146 Connect(pbut,
"Released()",
"TGToolBar",
this,
"ButtonReleased()");
147 Connect(pbut,
"Clicked()" ,
"TGToolBar",
this,
"ButtonClicked()");
156 TGButton *TGToolBar::GetButton(Int_t
id)
const
158 TIter next(fMapOfButtons);
161 while ((item = (TGButton*)next())) {
162 if ((Long_t)fMapOfButtons->GetValue(item) == id)
break;
171 void TGToolBar::SetId(TGButton *button, Long_t
id)
173 TPair *a = (TPair*) fMapOfButtons->FindObject(button);
175 a->SetValue((TObject*)
id);
183 Long_t TGToolBar::GetId(TGButton *button)
const
185 TPair *a = (TPair*) fMapOfButtons->FindObject(button);
187 return Long_t(a->Value());
195 void TGToolBar::ChangeIcon(ToolBarData_t *button,
const char *new_icon)
197 const TGPicture *pic = fClient->GetPicture(new_icon);
199 Error(
"ChangeIcon",
"pixmap not found: %s", new_icon);
202 fPictures->Add((TObject*)pic);
204 ((TGPictureButton *)button->fButton)->SetPicture(pic);
213 void TGToolBar::Cleanup()
219 TGCompositeFrame::Cleanup();
226 void TGToolBar::ButtonPressed()
228 TGButton *btn = (TGButton*)gTQSender;
230 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
232 Int_t
id = (Int_t)Long_t(a->Value());
241 void TGToolBar::ButtonReleased()
243 TGButton *btn = (TGButton*)gTQSender;
245 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
247 Int_t
id = (Int_t)Long_t(a->Value());
256 void TGToolBar::ButtonClicked()
258 TGButton *btn = (TGButton*)gTQSender;
260 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
262 Int_t
id = (Int_t)Long_t(a->Value());
270 void TGToolBar::SavePrimitive(std::ostream &out, Option_t *option )
272 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
275 out <<
" // tool bar" << std::endl;
277 out <<
" TGToolBar *";
278 out << GetName() <<
" = new TGToolBar(" << fParent->GetName()
279 <<
"," << GetWidth() <<
"," << GetHeight();
281 if (fBackground == GetDefaultFrameBackground()) {
283 out <<
");" << std::endl;
285 out <<
"," << GetOptionString() <<
");" << std::endl;
288 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
290 if (option && strstr(option,
"keep_names"))
291 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
299 TIter next(GetList());
301 while ((f = (TGFrameElement *) next())) {
302 if (f->fFrame->InheritsFrom(TGPictureButton::Class())) {
303 if (!gROOT->ClassSaved(TGPictureButton::Class())) {
305 out << std::endl <<
" ToolBarData_t t;" << std::endl;
308 TGPictureButton *pb = (TGPictureButton *)f->fFrame;
309 picname = pb->GetPicture()->GetName();
311 out <<
" t.fPixmap = " << quote
312 << gSystem->ExpandPathName(gSystem->UnixPathName(picname))
313 << quote <<
";" << std::endl;
314 out <<
" t.fTipText = " << quote
315 << pb->GetToolTip()->GetText()->GetString() << quote <<
";" << std::endl;
316 if (pb->GetState() == kButtonDown) {
317 out <<
" t.fStayDown = kTRUE;" << std::endl;
319 out <<
" t.fStayDown = kFALSE;" << std::endl;
321 out <<
" t.fId = " << i+1 <<
";" << std::endl;
322 out <<
" t.fButton = 0;" << std::endl;
323 out <<
" " << GetName() <<
"->AddButton(" << GetParent()->GetName()
324 <<
",&t," << f->fLayout->GetPadLeft() <<
");" << std::endl;
325 if (pb->GetState() == kButtonDown) {
326 out <<
" TGButton *" << pb->GetName() <<
" = t.fButton;" << std::endl;
327 out <<
" " << pb->GetName() <<
"->SetState(kButtonDown);" << std::endl;
329 if (pb->GetState() == kButtonDisabled) {
330 out <<
" TGButton *" << pb->GetName() <<
" = t.fButton;" << std::endl;
331 out <<
" " << pb->GetName() <<
"->SetState(kButtonDisabled);" << std::endl;
333 if (pb->GetState() == kButtonEngaged) {
334 out <<
" TGButton *" << pb->GetName() <<
" = t.fButton;" << std::endl;
335 out <<
" " << pb->GetName() <<
"->SetState(kButtonEngaged);" << std::endl;
339 f->fFrame->SavePrimitive(out, option);
340 out <<
" " << GetName()<<
"->AddFrame(" << f->fFrame->GetName();
341 f->fLayout->SavePrimitive(out, option);
342 out <<
");"<< std::endl;