46 const TGFont *TGTab::fgDefaultFont = 0;
47 const TGGC *TGTab::fgDefaultGC = 0;
49 ClassImp(TGTabElement);
50 ClassImp(TGTabLayout);
57 TGTabElement::TGTabElement(
const TGWindow *p, TGString *text, UInt_t w, UInt_t h,
58 GContext_t norm, FontStruct_t font,
59 UInt_t options, ULong_t back) :
60 TGFrame(p, w, h, options, back)
71 fEditDisabled = kEditDisableGrab | kEditDisableBtnEnable;
73 fClosePic = fClient->GetPicture(
"closetab.png");
74 fClosePicD = fClient->GetPicture(
"closetab_d.png");
75 int max_ascent, max_descent;
77 fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
78 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
79 fTHeight = max_ascent + max_descent;
80 Resize(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
82 gVirtualX->GrabButton(fId, kButton1, kAnyModifier, kButtonPressMask, kNone, kNone);
88 TGTabElement::~TGTabElement()
90 if (fClosePic) gClient->FreePicture(fClosePic);
91 if (fClosePicD) gClient->FreePicture(fClosePicD);
92 if (fText)
delete fText;
98 void TGTabElement::DrawBorder()
100 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, 0, 2);
101 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, 2, 2, 0);
102 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 0, fWidth-3, 0);
103 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-2, 1, fWidth-2, fHeight-1);
104 if (gClient->GetStyle() < 2) {
105 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-2, 1, fWidth-1, 2);
106 gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, 2, fWidth-1, fHeight-2);
108 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, fHeight-1);
111 int max_ascent, max_descent;
112 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
114 fText->Draw(fId, fNormGC, 6, max_ascent+3);
116 fText->Draw(fId, GetHilightGC()(), 7, max_ascent + 1);
117 fText->Draw(fId, GetShadowGC()(), 6, max_ascent);
120 if (fShowClose && fClosePic && fClosePicD) {
121 if (fEnabled && fActive)
122 fClosePic->Draw(fId, fNormGC, fTWidth+12, fHeight/2-7);
124 fClosePicD->Draw(fId, fNormGC, fTWidth+12, fHeight/2-7);
132 Bool_t TGTabElement::HandleButton(Event_t *event)
134 if (event->fType == kButtonPress) {
135 TGTab* main = (TGTab*)fParent;
137 if (fShowClose && event->fWindow == GetId() &&
138 (UInt_t)event->fX > fTWidth+12 && (UInt_t)
event->fX < fTWidth+26 &&
139 (UInt_t)event->fY > fHeight/2-7 && (UInt_t)
event->fY < fHeight/2+7) {
140 if (main->GetTabTab(main->GetCurrent()) ==
this) {
141 main->CloseTab(main->GetCurrent());
147 TIter next(main->GetList());
152 Int_t c = main->GetCurrent();
153 while ((el = (TGFrameElement *) next())) {
154 if (el->fFrame->GetId() == (Window_t)event->fWindow)
169 TGDimension TGTabElement::GetDefaultSize()
const
171 if (fShowClose && fClosePic && fClosePicD)
172 return TGDimension(TMath::Max(fTWidth+30, (UInt_t)45), fTHeight+6);
174 return TGDimension(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
180 void TGTabElement::SetText(TGString *text)
182 if (fText)
delete fText;
185 int max_ascent, max_descent;
186 fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
187 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
188 fTHeight = max_ascent + max_descent;
190 fClient->NeedRedraw(
this);
197 void TGTabElement::ShowClose(Bool_t show)
199 TGTab* main = (TGTab*)fParent;
201 if (fShowClose && fClosePic && fClosePicD)
202 Resize(TMath::Max(fTWidth+30, (UInt_t)45), fTHeight+6);
204 Resize(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
206 main->GetLayoutManager()->Layout();
212 TGTabLayout::TGTabLayout(TGTab *main)
215 fList = fMain->GetList();
221 void TGTabLayout::Layout()
225 UInt_t tabh = fMain->GetTabHeight(), bw = fMain->GetBorderWidth();
226 UInt_t w = fMain->GetWidth();
227 UInt_t h = fMain->GetHeight();
231 fMain->GetContainer()->MoveResize(0, tabh, w, h - tabh);
234 TGFrameElement *el, *elnxt;
238 while ((el = (TGFrameElement *) next())) {
239 elnxt = (TGFrameElement *) next();
240 tw = el->fFrame->GetDefaultWidth();
241 if (i == fMain->GetCurrent()) {
242 el->fFrame->MoveResize(xtab-2, 0, tw+3, tabh+1);
243 if (elnxt) elnxt->fFrame->RaiseWindow();
244 el->fFrame->RaiseWindow();
246 el->fFrame->MoveResize(xtab, 2, tw, tabh-1);
247 el->fFrame->LowerWindow();
249 UInt_t nw = (w - (bw << 1));
250 if (nw > 32768) nw = 1;
251 UInt_t nh = (h - tabh - (bw << 1));
252 if (nh > 32768) nh = 1;
254 elnxt->fFrame->MoveResize(bw, tabh + bw, nw, nh);
255 elnxt->fFrame->Layout();
265 TGDimension TGTabLayout::GetDefaultSize()
const
267 TGDimension dsize, dsize_te;
268 TGDimension size(0,0), size_te(0,0);
270 TGFrameElement *el, *elnxt;
273 while ((el = (TGFrameElement *)next())) {
274 dsize_te = el->fFrame->GetDefaultSize();
275 size_te.fWidth += dsize_te.fWidth;
276 elnxt = (TGFrameElement *) next();
278 dsize = elnxt->fFrame->GetDefaultSize();
279 if (size.fWidth < dsize.fWidth) size.fWidth = dsize.fWidth;
280 if (size.fHeight < dsize.fHeight) size.fHeight = dsize.fHeight;
285 if (size.fWidth < size_te.fWidth) size.fWidth = size_te.fWidth;
287 size.fWidth += fMain->GetBorderWidth() << 1;
288 size.fHeight += fMain->GetTabHeight() + (fMain->GetBorderWidth() << 1);
297 TGTab::TGTab(
const TGWindow *p, UInt_t w, UInt_t h,
298 GContext_t norm, FontStruct_t font,
299 UInt_t options, ULong_t back) :
300 TGCompositeFrame(p, w, h, options, back)
306 fRemoved =
new TList;
311 int max_ascent, max_descent;
312 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
313 fTabh = max_ascent + max_descent + 6;
315 SetLayoutManager(
new TGTabLayout(
this));
318 fContainer =
new TGCompositeFrame(
this, fWidth, fHeight - fTabh,
319 kVerticalFrame | kRaisedFrame | kDoubleBorder);
320 AddFrame(fContainer, 0);
322 fEditDisabled = kEditDisable | kEditDisableLayout;
323 fContainer->SetEditDisabled(kEditDisable | kEditDisableGrab);
341 TGCompositeFrame *TGTab::AddTab(TGString *text)
343 TGTabElement *te =
new TGTabElement(
this, text, 50, 20, fNormGC, fFontStruct);
346 TGCompositeFrame* cf =
new TGCompositeFrame(
this, fWidth, fHeight-21);
348 cf->SetEditDisabled(kEditDisableResize);
360 TGCompositeFrame *TGTab::AddTab(
const char *text)
362 return AddTab(
new TGString(text));
368 void TGTab::AddTab(
const char *text, TGCompositeFrame *cf)
370 AddTab(
new TGString(text), cf);
376 void TGTab::AddTab(TGString *text, TGCompositeFrame *cf)
378 TGTabElement *te =
new TGTabElement(
this, text, 50, 20, fNormGC, fFontStruct);
382 cf->SetEditDisabled(kEditDisableResize);
392 void TGTab::RemoveTab(Int_t tabIndex, Bool_t storeRemoved)
398 TGFrameElement *elTab, *elCont;
407 while ((elTab = (TGFrameElement *) next())) {
408 elCont = (TGFrameElement *) next();
410 if (count == tabIndex) {
411 elCont->fFrame->UnmapWindow();
412 TGFrame *frame = elTab->fFrame;
413 RemoveFrame(elTab->fFrame);
414 frame->DestroyWindow();
417 fRemoved->Add(elCont->fFrame);
418 RemoveFrame(elCont->fFrame);
419 if (tabIndex == fCurrent) {
429 GetLayoutManager()->Layout();
435 void TGTab::SetEnabled(Int_t tabIndex, Bool_t on)
437 TGTabElement *te = GetTabTab(tabIndex);
440 fClient->NeedRedraw(te);
447 Bool_t TGTab::IsEnabled(Int_t tabIndex)
const
449 TGTabElement *te = GetTabTab(tabIndex);
451 return te ? te->IsEnabled() : kFALSE;
458 void TGTab::ChangeTab(Int_t tabIndex, Bool_t emit)
460 TGTabElement *te = GetTabTab(tabIndex);
461 if (!te || !te->IsEnabled())
return;
463 if (tabIndex != fCurrent) {
464 if (GetTabTab(fCurrent)) {
465 GetTabTab(fCurrent)->SetActive(kFALSE);
466 fClient->NeedRedraw(GetTabTab(fCurrent));
468 TGFrameElement *el, *elnxt;
477 while ((el = (TGFrameElement *) next())) {
478 elnxt = (TGFrameElement *) next();
479 tw = el->fFrame->GetDefaultWidth();
480 if (count == fCurrent) {
481 el->fFrame->MoveResize(xtab-2, 0, tw+3, fTabh+1);
482 if (elnxt) elnxt->fFrame->RaiseWindow();
483 el->fFrame->RaiseWindow();
485 el->fFrame->MoveResize(xtab, 2, tw, fTabh-1);
486 el->fFrame->LowerWindow();
492 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_TAB), fCurrent, 0);
493 fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_TAB), fCurrent, 0);
496 GetTabTab(fCurrent)->SetActive(kTRUE);
497 fClient->NeedRedraw(GetTabTab(fCurrent));
507 Bool_t TGTab::SetTab(Int_t tabIndex, Bool_t emit)
519 count = count / 2 - 1;
520 if (tabIndex > count)
524 ChangeTab(tabIndex, emit);
535 Bool_t TGTab::SetTab(
const char *name, Bool_t emit)
539 TGTabElement *tab = 0;
544 while ((el = (TGFrameElement *) next())) {
546 tab = (TGTabElement *)el->fFrame;
548 if (*(tab->GetText()) == name) {
550 ChangeTab(count, emit);
563 TGCompositeFrame *TGTab::GetTabContainer(Int_t tabIndex)
const
565 if (tabIndex < 0)
return 0;
574 el = (TGFrameElement *) next();
575 if (el && count == tabIndex)
576 return (TGCompositeFrame *) el->fFrame;
587 TGCompositeFrame *TGTab::GetTabContainer(
const char *name)
const
590 TGTabElement *tab = 0;
591 TGCompositeFrame *comp = 0;
596 while ((el = (TGFrameElement *) next())) {
597 tab = (TGTabElement *) el->fFrame;
598 el = (TGFrameElement *) next();
599 comp = (TGCompositeFrame *) el->fFrame;
600 if (*tab->GetText() == name){
612 TGTabElement *TGTab::GetTabTab(Int_t tabIndex)
const
614 if (tabIndex < 0)
return 0;
622 while ((el = (TGFrameElement *) next())) {
624 if (count == tabIndex)
625 return (TGTabElement *) el->fFrame;
636 TGTabElement *TGTab::GetTabTab(
const char *name)
const
639 TGTabElement *tab = 0;
644 while ((el = (TGFrameElement *) next())) {
645 tab = (TGTabElement *)el->fFrame;
646 if (name == *(tab->GetText())) {
658 Int_t TGTab::GetNumberOfTabs()
const
676 FontStruct_t TGTab::GetDefaultFontStruct()
679 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
680 return fgDefaultFont->GetFontStruct();
686 const TGGC &TGTab::GetDefaultGC()
689 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
696 void TGTab::NewTab(
const char *text)
702 name = TString::Format(
"tab%d", GetNumberOfTabs()+1);
705 GetLayoutManager()->Layout();
711 void TGTab::SetText(
const char *text)
713 if (GetCurrentTab()) GetCurrentTab()->SetText(
new TGString(text));
714 GetLayoutManager()->Layout();
720 TGLayoutManager *TGTab::GetLayoutManager()
const
722 TGTab *tab = (TGTab*)
this;
724 if (tab->fLayoutManager->IsA() != TGTabLayout::Class()) {
725 tab->SetLayoutManager(
new TGTabLayout(tab));
728 return tab->fLayoutManager;
734 void TGTab::SavePrimitive(std::ostream &out, Option_t *option )
739 option = GetName()+5;
740 TString parGC, parFont;
741 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
742 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
744 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
745 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
747 ufont->SavePrimitive(out, option);
748 parFont.Form(
"ufont->GetFontStruct()");
751 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
753 userGC->SavePrimitive(out, option);
754 parGC.Form(
"uGC->GetGC()");
758 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
760 out << std::endl <<
" // tab widget" << std::endl;
763 out << GetName() <<
" = new TGTab(" << fParent->GetName()
764 <<
"," << GetWidth() <<
"," << GetHeight();
766 if (fBackground == GetDefaultFrameBackground()) {
767 if (GetOptions() == kChildFrame) {
768 if (fFontStruct == GetDefaultFontStruct()) {
769 if (fNormGC == GetDefaultGC()()) {
770 out <<
");" << std::endl;
772 out <<
"," << parGC.Data() <<
");" << std::endl;
775 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
");" << std::endl;
778 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
"," << GetOptionString() <<
");" << std::endl;
781 out <<
"," << parGC.Data() <<
"," << parFont.Data() <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
783 if (option && strstr(option,
"keep_names"))
784 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
786 TGCompositeFrame *cf;
787 TGLayoutManager * lm;
788 for (Int_t i=0; i<GetNumberOfTabs(); i++) {
789 cf = GetTabContainer(i);
790 if (!cf || !GetTabTab(i))
continue;
791 out << std::endl <<
" // container of " << quote
792 << GetTabTab(i)->GetString() << quote << std::endl;
793 out <<
" TGCompositeFrame *" << cf->GetName() <<
";" << std::endl;
794 out <<
" " << cf->GetName() <<
" = " << GetName()
795 <<
"->AddTab(" << quote << GetTabTab(i)->GetString()
796 << quote <<
");" << std::endl;
797 lm = cf->GetLayoutManager();
799 if ((cf->GetOptions() & kHorizontalFrame) &&
800 (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
802 }
else if ((GetOptions() & kVerticalFrame) &&
803 (lm->InheritsFrom(TGVerticalLayout::Class()))) {
806 out <<
" " << cf->GetName() <<
"->SetLayoutManager(";
807 lm->SavePrimitive(out, option);
808 out <<
");" << std::endl;
811 out <<
" " << GetName() <<
"->SetEnabled(" << i <<
", kFALSE);" << std::endl;
814 cf->SavePrimitiveSubframes(out, option);
816 if (GetTabTab(i)->IsCloseShown()) {
817 out <<
" TGTabElement *tab" << i <<
" = "
818 << GetName() <<
"->GetTabTab(" << i <<
");" << std::endl;
819 out <<
" tab" << i <<
"->ShowClose(kTRUE);" << std::endl;
821 if (GetTabTab(i)->GetBackground() != GetTabTab(i)->GetDefaultFrameBackground()) {
822 GetTabTab(i)->SaveUserColor(out, option);
823 out <<
" TGTabElement *tab" << i <<
" = "
824 << GetName() <<
"->GetTabTab(" << i <<
");" << std::endl;
825 out <<
" tab" << i <<
"->ChangeBackground(ucolor);" << std::endl;
829 out << std::endl <<
" " << GetName() <<
"->SetTab(" << GetCurrent() <<
");" << std::endl;
830 out << std::endl <<
" " << GetName() <<
"->Resize(" << GetName()
831 <<
"->GetDefaultSize());" << std::endl;
835 void TGTabLayout::SavePrimitive(std::ostream &out, Option_t * )
839 out <<
"new TGTabLayout(" << fMain->GetName() <<
")";