91 ClassImp(TGButtonGroup);
92 ClassImp(TGHButtonGroup);
93 ClassImp(TGVButtonGroup);
98 TGButtonGroup::TGButtonGroup(
const TGWindow *parent,
104 TGGroupFrame(parent, new TGString(title), options, norm, font, back)
107 if (options & kVerticalFrame) {
108 SetLayoutManager(
new TGVerticalLayout(
this));
110 SetLayoutManager(
new TGHorizontalLayout(
this));
113 fDrawBorder = !title.IsNull();
123 TGButtonGroup::TGButtonGroup(
const TGWindow *parent,
126 const TString &title,
130 TGGroupFrame(parent, new TGString(title), 0, norm, font, back)
133 fDrawBorder = !title.IsNull();
134 SetLayoutManager(
new TGMatrixLayout(
this,r,c,s,h));
140 void TGButtonGroup::Init()
143 fMapOfButtons =
new TMap();
154 TGButtonGroup::~TGButtonGroup()
156 TIter next(fMapOfButtons);
159 while ((item = (TGButton*)next())) {
163 SafeDelete(fMapOfButtons);
170 void TGButtonGroup::DoRedraw()
172 gVirtualX->ClearArea(fId, 0, 0, fWidth, fHeight);
183 void TGButtonGroup::DrawBorder()
185 if (!fDrawBorder)
return;
187 Int_t x, y, l, t, r, b, gl, gr, sep, max_ascent, max_descent;
189 UInt_t tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
190 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
193 t = (max_ascent + max_descent + 2) >> 1;
196 TGLayoutManager * lm = GetLayoutManager();
199 if ((lm->InheritsFrom(TGHorizontalLayout::Class())) ||
200 (lm->InheritsFrom(TGMatrixLayout::Class())))
206 UInt_t rr = 5 + (sep << 1) + tw;
210 gl = fWidth>rr ? Int_t(fWidth - rr) : 5 + sep;
213 gl = fWidth>tw ? Int_t((fWidth - tw)>>1) - sep : 5 + sep;
219 gr = gl + tw + (sep << 1);
221 switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
223 gVirtualX->DrawLine(fId, GetHilightGC()(), l, t, gl, t);
224 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, t+1, gl, t+1);
226 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t, r-1, t);
227 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t+1, r-2, t+1);
229 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, t, r-1, b-1);
230 gVirtualX->DrawLine(fId, GetShadowGC()(), r, t, r, b);
232 gVirtualX->DrawLine(fId, GetHilightGC()(), r-1, b-1, l, b-1);
233 gVirtualX->DrawLine(fId, GetShadowGC()(), r, b, l, b);
235 gVirtualX->DrawLine(fId, GetHilightGC()(), l, b-1, l, t);
236 gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, b-2, l+1, t+1);
240 gVirtualX->DrawLine(fId, GetShadowGC()(), l, t, gl, t);
241 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, t+1, gl, t+1);
243 gVirtualX->DrawLine(fId, GetShadowGC()(), gr, t, r-1, t);
244 gVirtualX->DrawLine(fId, GetHilightGC()(), gr, t+1, r-2, t+1);
246 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, t, r-1, b-1);
247 gVirtualX->DrawLine(fId, GetHilightGC()(), r, t, r, b);
249 gVirtualX->DrawLine(fId, GetShadowGC()(), r-1, b-1, l, b-1);
250 gVirtualX->DrawLine(fId, GetHilightGC()(), r, b, l, b);
252 gVirtualX->DrawLine(fId, GetShadowGC()(), l, b-1, l, t);
253 gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, b-2, l+1, t+1);
261 fText->Draw(fId, fNormGC, x, y + max_ascent);
263 fText->Draw(fId, GetHilightGC()(), x, y + 1 + max_ascent);
264 fText->Draw(fId, GetShadowGC()(), x, y + max_ascent);
271 void TGButtonGroup::SetBorderDrawn(Bool_t enable)
273 if (enable != IsBorderDrawn()) {
274 fDrawBorder = enable;
275 ChangedBy(
"SetBorderDrawn");
287 void TGButtonGroup::SetExclusive(Bool_t enable)
289 if (enable != IsExclusive()) {
291 ChangedBy(
"SetExclusive");
301 void TGButtonGroup::SetRadioButtonExclusive(Bool_t enable)
303 if (enable != IsRadioButtonExclusive()) {
305 ChangedBy(
"SetRadioButtonExclusive");
312 void TGButtonGroup::SetState(Bool_t state)
316 TIter next(fMapOfButtons);
319 while ((item = (TGButton*)next())) {
321 item->SetState(kButtonUp);
323 item->SetState(kButtonDisabled);
332 void TGButtonGroup::SetButton(Int_t
id, Bool_t down)
334 TGButton *b = Find(
id);
336 if (b && (b->IsDown() != down)) {
337 b->SetState(kButtonDown, kTRUE);
359 Int_t TGButtonGroup::Insert(TGButton *button, Int_t
id)
361 if (button->fGroup && button->fGroup !=
this)
362 button->fGroup->Remove(button);
364 if (button->fGroup ==
this) {
366 return GetId(button);
368 button->fGroup->Remove(button);
371 button->fGroup =
this;
372 button->Associate(
this);
374 static Int_t seq_no = -2;
377 if (
id < -1) bid = seq_no--;
378 else if (
id == -1) bid = GetCount()+1;
381 fMapOfButtons->Add(button, (TObject*)bid);
386 SetRadioButtonExclusive(button->IsA()->InheritsFrom(TGRadioButton::Class()));
388 Connect(button,
"Clicked()" ,
"TGButtonGroup",
this,
"ReleaseButtons()");
389 Connect(button,
"Pressed()" ,
"TGButtonGroup",
this,
"ButtonPressed()");
390 Connect(button,
"Released()",
"TGButtonGroup",
this,
"ButtonReleased()");
391 Connect(button,
"Clicked()" ,
"TGButtonGroup",
this,
"ButtonClicked()");
399 void TGButtonGroup::Remove(TGButton *button)
401 TGButton *item = (TGButton*) fMapOfButtons->Remove(button);
404 button->Disconnect(
this);
405 button->DestroyWindow();
415 TGButton *TGButtonGroup::Find(Int_t
id)
const
417 TIter next(fMapOfButtons);
420 while ((item = (TGButton*)next())) {
421 if ((Long_t)fMapOfButtons->GetValue(item) == id)
break;
431 Int_t TGButtonGroup::GetId(TGButton *button)
const
433 TPair *a = (TPair*) fMapOfButtons->FindObject(button);
435 return (Int_t)Long_t(a->Value());
444 void TGButtonGroup::ButtonPressed()
452 TGButton *btn =
dynamic_cast<TGButton*
>((TQObject*)gTQSender);
455 Error(
"ButtonPressed",
"gTQSender not a TGButton");
459 TGButton *btn = (TGButton*)gTQSender;
462 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
464 Int_t
id = (Int_t)Long_t(a->Value());
473 void TGButtonGroup::ButtonReleased()
475 TGButton *btn = (TGButton*)gTQSender;
477 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
479 Int_t
id = (Int_t)Long_t(a->Value());
488 void TGButtonGroup::ButtonClicked()
490 TGButton *btn = (TGButton*)gTQSender;
492 TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
494 Int_t
id = (Int_t)Long_t(a->Value());
503 void TGButtonGroup::ReleaseButtons()
505 if (!fExclGroup && !fRadioExcl)
return;
507 TGButton *btn = (TGButton*)gTQSender;
509 if (!fExclGroup && !btn)
512 TIter next(fMapOfButtons);
515 while ((item = (TGButton*)next())) {
518 if (btn != item && item->IsToggleButton() && item->IsOn() &&
519 (fExclGroup || (item->IsA()->InheritsFrom(TGRadioButton::Class())
520 && btn->IsA()->InheritsFrom(TGRadioButton::Class())))) {
529 void TGButtonGroup::Show()
534 fClient->NeedRedraw(
this);
540 void TGButtonGroup::Hide()
548 void TGButtonGroup::SetTitle(TGString *title)
551 Error(
"SetTitle",
"title cannot be 0, try \"\"");
555 if (strcmp(fText->GetString(), title->GetString())) {
556 SetBorderDrawn(title->GetLength() ? kTRUE : kFALSE);
557 TGGroupFrame::SetTitle(title);
558 ChangedBy(
"SetTitle");
565 void TGButtonGroup::SetTitle(
const char *title)
568 Error(
"SetTitle",
"title cannot be 0, try \"\"");
572 if (strcmp(fText->GetString(), title)) {
573 SetBorderDrawn(title && strlen(title));
574 TGGroupFrame::SetTitle(title);
575 ChangedBy(
"SetTitle");
583 void TGButtonGroup::SetLayoutHints(TGLayoutHints *l, TGButton *button)
588 while ((el = (TGFrameElement *)next())) {
589 if ((el->fFrame==(TGFrame*)button) || !button) {
590 el->fLayout = l ? l : fgDefaultHints;
599 void TGButtonGroup::SavePrimitive(std::ostream &out, Option_t *option )
604 option = GetName()+5;
605 TString parGC, parFont;
608 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
611 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
613 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
614 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
616 ufont->SavePrimitive(out, option);
617 parFont.Form(
"ufont->GetFontStruct()");
620 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
622 userGC->SavePrimitive(out, option);
623 parGC.Form(
"uGC->GetGC()");
627 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
629 out << std::endl <<
" // buttongroup frame" << std::endl;
631 out <<
" TGButtonGroup *";
632 out << GetName() <<
" = new TGButtonGroup(" << fParent->GetName()
633 <<
","<< quote << fText->GetString() << quote;
635 if (fBackground == GetDefaultFrameBackground()) {
636 if (fFontStruct == GetDefaultFontStruct()) {
637 if (fNormGC == GetDefaultGC()()) {
639 out <<
");" << std::endl;
641 out <<
"," << GetOptionString() <<
");" << std::endl;
644 out <<
"," << GetOptionString() <<
"," << parGC.Data() <<
");" << std::endl;
647 out <<
"," << GetOptionString() <<
"," << parGC.Data() <<
"," << parFont.Data() <<
");" << std::endl;
650 out <<
"," << GetOptionString() <<
"," << parGC.Data() <<
"," << parFont.Data() <<
",ucolor);" << std::endl;
652 if (option && strstr(option,
"keep_names"))
653 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
656 out <<
" " << GetName() <<
"->SetLayoutManager(";
659 GetLayoutManager()->SavePrimitive(out, option);
660 out <<
");"<< std::endl;
663 TIter next(GetList());
664 while ((f = (TGFrameElement *)next())) {
665 f->fFrame->SavePrimitive(out,option);
666 if (f->fFrame->InheritsFrom(
"TGButton"))
continue;
668 out <<
" " << GetName() <<
"->AddFrame(" << f->fFrame->GetName();
669 f->fLayout->SavePrimitive(out, option);
670 out <<
");"<< std::endl;
675 out <<
" " << GetName() <<
"->SetExclusive(kTRUE);" << std::endl;
677 if (IsRadioButtonExclusive())
678 out <<
" " << GetName() <<
"->SetRadioButtonExclusive(kTRUE);" << std::endl;
680 if (!IsBorderDrawn())
681 out <<
" " << GetName() <<
"->SetBorderDrawn(kFALSE);" << std::endl;
684 out <<
" " << GetName() <<
"->Resize(" << GetWidth()
685 <<
"," << GetHeight() <<
");" << std::endl;
688 out <<
" " << GetName() <<
"->SetState(kFALSE);" << std::endl;
690 out <<
" " << GetName() <<
"->Show();" << std::endl;
696 void TGHButtonGroup::SavePrimitive(std::ostream &out, Option_t *option )
701 option = GetName()+5;
702 TString parGC, parFont;
703 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
704 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
706 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
707 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
709 ufont->SavePrimitive(out, option);
710 parFont.Form(
"ufont->GetFontStruct()");
713 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
715 userGC->SavePrimitive(out, option);
716 parGC.Form(
"uGC->GetGC()");
720 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
722 out << std::endl <<
" // horizontal buttongroup frame" << std::endl;
724 out <<
" TGHButtonGroup *";
725 out << GetName() <<
" = new TGHButtonGroup(" << fParent->GetName()
726 <<
"," << quote << fText->GetString() << quote;
727 if (fBackground == GetDefaultFrameBackground()) {
729 if (fFontStruct == GetDefaultFontStruct()) {
731 if (fNormGC == GetDefaultGC()()) {
732 out <<
");" << std::endl;
734 out <<
"," << parGC.Data() <<
");" << std::endl;
737 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
");" << std::endl;
740 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
",ucolor);" << std::endl;
742 if (option && strstr(option,
"keep_names"))
743 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
746 TIter next(GetList());
747 while ((f = (TGFrameElement *)next())) {
748 f->fFrame->SavePrimitive(out,option);
749 if (f->fFrame->InheritsFrom(
"TGButton")){
750 out <<
" " << GetName() <<
"->SetLayoutHints(";
751 f->fLayout->SavePrimitive(out,
"nocoma");
752 out <<
"," << f->fFrame->GetName();
753 out <<
");"<< std::endl;
756 out <<
" " << GetName() <<
"->AddFrame(" << f->fFrame->GetName();
757 f->fLayout->SavePrimitive(out, option);
758 out <<
");"<< std::endl;
763 out <<
" " << GetName() <<
"->SetState(kFALSE);" << std::endl;
766 out <<
" " << GetName() <<
"->SetExclusive(kTRUE);" << std::endl;
768 if (IsRadioButtonExclusive())
769 out <<
" " << GetName() <<
"->SetRadioButtonExclusive(kTRUE);" << std::endl;
771 if (!IsBorderDrawn())
772 out <<
" " << GetName() <<
"->SetBorderDrawn(kFALSE);" << std::endl;
774 out <<
" " << GetName() <<
"->Resize(" << GetWidth() <<
","
775 << GetHeight() <<
");" << std::endl;
777 out <<
" " << GetName() <<
"->Show();" << std::endl;
783 void TGVButtonGroup::SavePrimitive(std::ostream &out, Option_t *option )
788 option = GetName()+5;
789 TString parGC, parFont;
790 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
791 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
793 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
794 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
796 ufont->SavePrimitive(out, option);
797 parFont.Form(
"ufont->GetFontStruct()");
800 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
802 userGC->SavePrimitive(out, option);
803 parGC.Form(
"uGC->GetGC()");
807 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
809 out << std::endl <<
" // vertical buttongroup frame" << std::endl;
811 out <<
" TGVButtonGroup *";
812 out << GetName() <<
" = new TGVButtonGroup(" << fParent->GetName()
813 <<
"," << quote << fText->GetString() << quote;
815 if (fBackground == GetDefaultFrameBackground()) {
816 if (fFontStruct == GetDefaultFontStruct()) {
817 if (fNormGC == GetDefaultGC()()) {
818 out <<
");" << std::endl;
820 out <<
"," << parGC.Data() <<
");" << std::endl;
823 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
");" << std::endl;
826 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
",ucolor);" << std::endl;
828 if (option && strstr(option,
"keep_names"))
829 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
832 TIter next(GetList());
833 while ((f = (TGFrameElement *)next())) {
834 f->fFrame->SavePrimitive(out,option);
835 if (f->fFrame->InheritsFrom(
"TGButton"))
continue;
837 out <<
" " << GetName() <<
"->AddFrame(" << f->fFrame->GetName();
838 f->fLayout->SavePrimitive(out, option);
839 out <<
");"<< std::endl;
844 out <<
" " << GetName() <<
"->SetState(kFALSE);" << std::endl;
847 out <<
" " << GetName() <<
"->SetExclusive(kTRUE);" << std::endl;
849 if (IsRadioButtonExclusive())
850 out <<
" " << GetName() <<
"->SetRadioButtonExclusive(kTRUE);" << std::endl;
852 if (!IsBorderDrawn())
853 out <<
" " << GetName() <<
"->SetBorderDrawn(kFALSE);" << std::endl;
855 out <<
" " << GetName() <<
"->Resize(" << GetWidth()
856 <<
"," << GetHeight() <<
");"<< std::endl;
858 out <<
" " << GetName() <<
"->Show();" << std::endl;