TGTab.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGTab.cxx 35582 2010-09-22 13:38:27Z bellenot $
00002 // Author: Fons Rademakers   13/01/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 /**************************************************************************
00012 
00013     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 
00023 //////////////////////////////////////////////////////////////////////////
00024 //                                                                      //
00025 // TGTab, TGTabElement, TGTabLayout                                     //
00026 //                                                                      //
00027 // A tab widget contains a set of composite frames each with a little   //
00028 // tab with a name (like a set of folders with tabs).                   //
00029 //                                                                      //
00030 // The TGTab is user callable. The TGTabElement and TGTabLayout are     //
00031 // service classes of the tab widget.                                   //
00032 //                                                                      //
00033 // Clicking on a tab will bring the associated composite frame to the   //
00034 // front and generate the following event:                              //
00035 // kC_COMMAND, kCM_TAB, tab id, 0.                                      //
00036 //                                                                      //
00037 //////////////////////////////////////////////////////////////////////////
00038 
00039 #include "TGTab.h"
00040 #include "TGResourcePool.h"
00041 #include "TList.h"
00042 #include "Riostream.h"
00043 #include "TClass.h"
00044 #include "TGPicture.h"
00045 
00046 const TGFont *TGTab::fgDefaultFont = 0;
00047 const TGGC   *TGTab::fgDefaultGC = 0;
00048 
00049 ClassImp(TGTabElement)
00050 ClassImp(TGTabLayout)
00051 ClassImp(TGTab)
00052 
00053 
00054 //______________________________________________________________________________
00055 TGTabElement::TGTabElement(const TGWindow *p, TGString *text, UInt_t w, UInt_t h,
00056                            GContext_t norm, FontStruct_t font,
00057                            UInt_t options, ULong_t back) :
00058    TGFrame(p, w, h, options, back)
00059 {
00060    // Create a tab element. Text is adopted by tab element.
00061 
00062    fClosePic     = 0;
00063    fClosePicD    = 0;
00064    fShowClose    = kFALSE;
00065    fActive       = kFALSE;
00066    fText         = text;
00067    fBorderWidth  = 0;
00068    fNormGC       = norm;
00069    fFontStruct   = font;
00070    fEditDisabled = kEditDisableGrab | kEditDisableBtnEnable;
00071 
00072    fClosePic      = fClient->GetPicture("closetab.png");
00073    fClosePicD     = fClient->GetPicture("closetab_d.png");
00074    int max_ascent, max_descent;
00075    if (fText)
00076       fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
00077    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00078    fTHeight = max_ascent + max_descent;
00079    Resize(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
00080    fEnabled = kTRUE;
00081    gVirtualX->GrabButton(fId, kButton1, kAnyModifier, kButtonPressMask, kNone, kNone);
00082 }
00083 
00084 //______________________________________________________________________________
00085 TGTabElement::~TGTabElement()
00086 {
00087    // Delete tab element.
00088 
00089    if (fClosePic) gClient->FreePicture(fClosePic);
00090    if (fClosePicD) gClient->FreePicture(fClosePicD);
00091    if (fText) delete fText;
00092 }
00093 
00094 //______________________________________________________________________________
00095 void TGTabElement::DrawBorder()
00096 {
00097    // Draw little tab element.
00098 
00099    gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, 0, 2);
00100    gVirtualX->DrawLine(fId, GetHilightGC()(), 0, 2, 2, 0);
00101    gVirtualX->DrawLine(fId, GetHilightGC()(), 2, 0, fWidth-3, 0);
00102    gVirtualX->DrawLine(fId, GetShadowGC()(),  fWidth-2, 1, fWidth-2, fHeight-1);
00103    gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-2, 1, fWidth-1, 2);
00104    gVirtualX->DrawLine(fId, GetBlackGC()(), fWidth-1, 2, fWidth-1, fHeight-2);
00105    gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, fHeight-1);
00106 
00107    if (fText) {
00108       int max_ascent, max_descent;
00109       gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00110       if (fEnabled) {
00111          fText->Draw(fId, fNormGC, 6, max_ascent+3);
00112       } else {
00113          fText->Draw(fId, GetHilightGC()(), 7, max_ascent + 1);
00114          fText->Draw(fId, GetShadowGC()(), 6, max_ascent);
00115       }
00116    }
00117    if (fShowClose && fClosePic && fClosePicD) {
00118       if (fEnabled && fActive)
00119          fClosePic->Draw(fId, fNormGC, fTWidth+12, fHeight/2-7);
00120       else 
00121          fClosePicD->Draw(fId, fNormGC, fTWidth+12, fHeight/2-7);
00122    }
00123 }
00124 
00125 //______________________________________________________________________________
00126 Bool_t TGTabElement::HandleButton(Event_t *event)
00127 {
00128    // Handle button event in the tab widget. Basically we only handle
00129    // button events in the small tabs.
00130 
00131    if (event->fType == kButtonPress) {
00132       TGTab* main = (TGTab*)fParent;
00133       if (main) {
00134          if (fShowClose && event->fWindow == GetId() &&
00135              (UInt_t)event->fX > fTWidth+12 && (UInt_t)event->fX < fTWidth+26 &&
00136              (UInt_t)event->fY > fHeight/2-7 && (UInt_t)event->fY < fHeight/2+7) {
00137             if (main->GetTabTab(main->GetCurrent()) == this) {
00138                main->CloseTab(main->GetCurrent()); // emit signal
00139                //main->RemoveTab(main->GetCurrent());
00140                return kTRUE;
00141             }
00142          }
00143          TGFrameElement *el;
00144          TIter next(main->GetList());
00145 
00146          next();   // skip first container
00147 
00148          Int_t i = 0;
00149          Int_t c = main->GetCurrent();
00150          while ((el = (TGFrameElement *) next())) {
00151             if (el->fFrame->GetId() == (Window_t)event->fWindow)
00152                c = i;
00153             next(); i++;
00154          }
00155 
00156          // change tab and generate event
00157          main->SetTab(c);
00158       }
00159    }
00160    return kTRUE;
00161 }
00162 
00163 //______________________________________________________________________________
00164 TGDimension TGTabElement::GetDefaultSize() const
00165 {
00166    // Return default size of tab element.
00167 
00168    if (fShowClose && fClosePic && fClosePicD)
00169       return TGDimension(TMath::Max(fTWidth+30, (UInt_t)45), fTHeight+6);
00170    else
00171       return TGDimension(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
00172 }
00173 
00174 //______________________________________________________________________________
00175 void TGTabElement::SetText(TGString *text)
00176 {
00177    // Set new tab text.
00178 
00179    if (fText) delete fText;
00180    fText = text;
00181 
00182    int max_ascent, max_descent;
00183    fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
00184    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00185    fTHeight = max_ascent + max_descent;
00186 
00187    fClient->NeedRedraw(this);
00188 }
00189 
00190 //______________________________________________________________________________
00191 void TGTabElement::ShowClose(Bool_t show)
00192 {
00193    // Show/hide close icon on the tab element, then apply layout
00194    // to compute correct elements size.
00195 
00196    TGTab* main = (TGTab*)fParent;
00197    fShowClose = show;
00198    if (fShowClose && fClosePic && fClosePicD)
00199       Resize(TMath::Max(fTWidth+30, (UInt_t)45), fTHeight+6);
00200    else
00201       Resize(TMath::Max(fTWidth+12, (UInt_t)45), fTHeight+6);
00202    if (main)
00203       main->GetLayoutManager()->Layout();
00204 }
00205 
00206 //______________________________________________________________________________
00207 TGTabLayout::TGTabLayout(TGTab *main)
00208 {
00209    // Create a tab layout manager.
00210 
00211    fMain = main;
00212    fList = fMain->GetList();
00213 }
00214 
00215 //______________________________________________________________________________
00216 void TGTabLayout::Layout()
00217 {
00218    // Layout the tab widget.
00219 
00220    Int_t  i, xtab;
00221    UInt_t tw;
00222    UInt_t tabh = fMain->GetTabHeight(), bw = fMain->GetBorderWidth();
00223    UInt_t w = fMain->GetWidth();
00224    UInt_t h = fMain->GetHeight();
00225 
00226    xtab = 2;
00227 
00228    fMain->GetContainer()->MoveResize(0, tabh, w, h - tabh);
00229 
00230    // first frame is the container, so take next...
00231    TGFrameElement *el, *elnxt;
00232    TIter next(fList);
00233    i = 0;
00234    next();   // skip first
00235    while ((el = (TGFrameElement *) next())) {
00236       elnxt = (TGFrameElement *) next();
00237       tw = el->fFrame->GetDefaultWidth();
00238       if (i == fMain->GetCurrent()) {
00239          el->fFrame->MoveResize(xtab-2, 0, tw+3, tabh+1);
00240          elnxt->fFrame->RaiseWindow();
00241          el->fFrame->RaiseWindow();
00242       } else {
00243          el->fFrame->MoveResize(xtab, 2, tw, tabh-1);
00244          el->fFrame->LowerWindow();
00245       }
00246       UInt_t nw = (w - (bw << 1));
00247       if (nw > 32768) nw = 1;
00248       UInt_t nh = (h - tabh - (bw << 1));
00249       if (nh > 32768) nh = 1;
00250       elnxt->fFrame->MoveResize(bw, tabh + bw, nw, nh);
00251       elnxt->fFrame->Layout();
00252       xtab += (Int_t)tw;
00253       i++;
00254    }
00255 }
00256 
00257 //______________________________________________________________________________
00258 TGDimension TGTabLayout::GetDefaultSize() const
00259 {
00260    // Get default size of tab widget.
00261 
00262    TGDimension dsize, dsize_te;
00263    TGDimension size(0,0), size_te(0,0);
00264 
00265    TGFrameElement *el, *elnxt;
00266    TIter next(fList);
00267    next();   // skip first container
00268    while ((el = (TGFrameElement *)next())) {
00269       dsize_te = el->fFrame->GetDefaultSize();
00270       size_te.fWidth += dsize_te.fWidth;
00271       elnxt = (TGFrameElement *) next();
00272       dsize = elnxt->fFrame->GetDefaultSize();
00273       if (size.fWidth < dsize.fWidth) size.fWidth = dsize.fWidth;
00274       if (size.fHeight < dsize.fHeight) size.fHeight = dsize.fHeight;
00275    }
00276 
00277    // check if tab elements make a larger width than the containers
00278    if (size.fWidth < size_te.fWidth) size.fWidth = size_te.fWidth;
00279 
00280    size.fWidth += fMain->GetBorderWidth() << 1;
00281    size.fHeight += fMain->GetTabHeight() + (fMain->GetBorderWidth() << 1);
00282 
00283    return size;
00284 }
00285 
00286 
00287 //______________________________________________________________________________
00288 TGTab::TGTab(const TGWindow *p, UInt_t w, UInt_t h,
00289              GContext_t norm, FontStruct_t font,
00290              UInt_t options, ULong_t back) :
00291    TGCompositeFrame(p, w, h, options, back)
00292 {
00293    // Create tab widget.
00294 
00295    fMsgWindow  = p;
00296 
00297    fBorderWidth = 2;
00298    fCurrent     = 0;
00299    fRemoved     = new TList;
00300 
00301    fNormGC     = norm;
00302    fFontStruct = font;
00303 
00304    int max_ascent, max_descent;
00305    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00306    fTabh = max_ascent + max_descent + 6;
00307 
00308    SetLayoutManager(new TGTabLayout(this));
00309 
00310    // we need this in order to avoid border blinking when switching tabs...
00311    fContainer = new TGCompositeFrame(this, fWidth, fHeight - fTabh,
00312                        kVerticalFrame | kRaisedFrame | kDoubleBorder);
00313    AddFrame(fContainer, 0);
00314 
00315    fEditDisabled = kEditDisable | kEditDisableLayout;
00316    fContainer->SetEditDisabled(kEditDisable | kEditDisableGrab);
00317 }
00318 
00319 //______________________________________________________________________________
00320 TGTab::~TGTab()
00321 {
00322    // Delete tab widget. This deletes the tab windows and the containers.
00323    // The tab string is deleted by the TGTabElement dtor.
00324 
00325    Cleanup();
00326    fRemoved->Delete();
00327    delete fRemoved;
00328 }
00329 
00330 //______________________________________________________________________________
00331 TGCompositeFrame *TGTab::AddTab(TGString *text)
00332 {
00333    // Add a tab to the tab widget. Returns the new container, which
00334    // is owned by the tab widget. The text is adopted by the tab widget.
00335 
00336    TGTabElement *te = new TGTabElement(this, text, 50, 20, fNormGC, fFontStruct);
00337    AddFrame(te, 0);
00338    
00339    TGCompositeFrame* cf = new TGCompositeFrame(this, fWidth, fHeight-21);
00340    AddFrame(cf, 0);
00341    cf->SetEditDisabled(kEditDisableResize);
00342 
00343    te->MapWindow();
00344    cf->MapWindow();
00345 
00346    return cf;
00347 }
00348 
00349 //______________________________________________________________________________
00350 TGCompositeFrame *TGTab::AddTab(const char *text)
00351 {
00352    // Add a tab to the tab widget. Returns the new container. The container
00353    // is owned by the tab widget.
00354 
00355    return AddTab(new TGString(text));
00356 }
00357 
00358 //______________________________________________________________________________
00359 void TGTab::AddTab(const char *text, TGCompositeFrame *cf)
00360 {
00361    // Add a tab to the tab widget and fill it with given TGCompositeFrame.
00362 
00363    AddTab(new TGString(text), cf);
00364 }
00365 
00366 //______________________________________________________________________________
00367 void TGTab::AddTab(TGString *text, TGCompositeFrame *cf)
00368 {
00369    // Add a tab to the tab widget and fill it with given TGCompositeFrame.
00370 
00371    TGTabElement *te = new TGTabElement(this, text, 50, 20, fNormGC, fFontStruct);
00372    AddFrame(te, 0);
00373 
00374    AddFrame(cf, 0);
00375    cf->SetEditDisabled(kEditDisableResize);
00376 
00377    te->MapWindow();
00378    cf->MapWindow();
00379 }
00380 
00381 //______________________________________________________________________________
00382 void TGTab::RemoveTab(Int_t tabIndex, Bool_t storeRemoved)
00383 {
00384    // Remove container and tab of tab with index tabIndex.
00385    // Does NOT remove the container contents!
00386 
00387    if (tabIndex < 0) {
00388       tabIndex = fCurrent;
00389    }
00390 
00391    TGFrameElement *elTab, *elCont;
00392    Int_t  count = 0;
00393 
00394    // Notify (signal) for removed tab "tabIndex"
00395    Removed(tabIndex);
00396 
00397    TIter next(fList) ;
00398    next() ; // skip first container
00399 
00400    while ((elTab = (TGFrameElement *) next())) {
00401       elCont = (TGFrameElement *) next();
00402 
00403       if (count == tabIndex) {
00404          elCont->fFrame->UnmapWindow();   // will be destroyed later
00405          TGFrame *frame = elTab->fFrame;
00406          RemoveFrame(elTab->fFrame);
00407          frame->DestroyWindow();
00408          delete frame;
00409          if (storeRemoved)
00410             fRemoved->Add(elCont->fFrame);   // delete only in dtor
00411          RemoveFrame(elCont->fFrame);
00412          if (tabIndex == fCurrent) {
00413             // select another tab only if the current is the one we delete
00414             SetTab(0);
00415          } else
00416             fCurrent--;
00417          break;
00418       }
00419       count++;
00420    }
00421 
00422    GetLayoutManager()->Layout();
00423 }
00424 
00425 //______________________________________________________________________________
00426 void TGTab::SetEnabled(Int_t tabIndex, Bool_t on)
00427 {
00428    // Enable or disable tab.
00429 
00430    TGTabElement *te = GetTabTab(tabIndex);
00431    if (te) {
00432       te->SetEnabled(on);
00433       fClient->NeedRedraw(te);
00434    }
00435 }
00436 
00437 //______________________________________________________________________________
00438 Bool_t TGTab::IsEnabled(Int_t tabIndex) const
00439 {
00440    // Returns true if tab is enabled.
00441 
00442    TGTabElement *te = GetTabTab(tabIndex);
00443 
00444    return te ? te->IsEnabled() : kFALSE;
00445 }
00446 
00447 //______________________________________________________________________________
00448 void TGTab::ChangeTab(Int_t tabIndex, Bool_t emit)
00449 {
00450    // Make tabIdx the current tab. Utility method called by SetTab and
00451    // HandleButton().
00452 
00453    TGTabElement *te = GetTabTab(tabIndex);
00454    if (!te || !te->IsEnabled()) return;
00455 
00456    if (tabIndex != fCurrent) {
00457       if (GetTabTab(fCurrent)) {
00458          GetTabTab(fCurrent)->SetActive(kFALSE);
00459          fClient->NeedRedraw(GetTabTab(fCurrent));
00460       }
00461       TGFrameElement *el, *elnxt;
00462       UInt_t tw;
00463       Int_t  xtab  = 2;
00464       Int_t  count = 0;
00465 
00466       TIter next(fList);
00467       next();           // skip first container
00468 
00469       fCurrent = tabIndex;
00470       while ((el = (TGFrameElement *) next())) {
00471          elnxt = (TGFrameElement *) next();
00472          tw = el->fFrame->GetDefaultWidth();
00473          if (count == fCurrent) {
00474             el->fFrame->MoveResize(xtab-2, 0, tw+3, fTabh+1);
00475             elnxt->fFrame->RaiseWindow();
00476             el->fFrame->RaiseWindow();
00477          } else {
00478             el->fFrame->MoveResize(xtab, 2, tw, fTabh-1);
00479             el->fFrame->LowerWindow();
00480          }
00481          xtab += tw;
00482          count++;
00483       }
00484       if (emit) {
00485          SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_TAB), fCurrent, 0);
00486          fClient->ProcessLine(fCommand, MK_MSG(kC_COMMAND, kCM_TAB), fCurrent, 0);
00487          Selected(fCurrent);
00488       }
00489       GetTabTab(fCurrent)->SetActive(kTRUE);
00490       fClient->NeedRedraw(GetTabTab(fCurrent));
00491    }
00492 }
00493 
00494 //______________________________________________________________________________
00495 Bool_t TGTab::SetTab(Int_t tabIndex, Bool_t emit)
00496 {
00497    // Brings the composite frame with the index tabIndex to the
00498    // front and generate the following event if the front tab has changed:
00499    // kC_COMMAND, kCM_TAB, tab id, 0.
00500    // Returns kFALSE if tabIndex is a not valid index
00501 
00502    // check if tabIndex is a valid index
00503    if (tabIndex < 0)
00504       return kFALSE;
00505 
00506    // count the tabs
00507    TIter next(fList);
00508    Int_t count = 0;
00509    while (next())
00510       count++;
00511 
00512    count = count / 2 - 1;
00513    if (tabIndex > count)
00514       return kFALSE;
00515 
00516    // change tab and generate event
00517    ChangeTab(tabIndex, emit);
00518 
00519    return kTRUE;
00520 }
00521 
00522 //______________________________________________________________________________
00523 Bool_t TGTab::SetTab(const char *name, Bool_t emit)
00524 {
00525    // Brings the composite frame with the name to the
00526    // front and generate the following event if the front tab has changed:
00527    // kC_COMMAND, kCM_TAB, tab id, 0.
00528    // Returns kFALSE if tab with name does not exist.
00529 
00530    TGFrameElement *el;
00531    Int_t  count = 0;
00532    TGTabElement *tab = 0;
00533 
00534    TIter next(fList);
00535    next();           // skip first container
00536 
00537    while ((el = (TGFrameElement *) next())) {
00538       next();        // skip tab containter
00539       tab = (TGTabElement *)el->fFrame;
00540 
00541       if (*(tab->GetText()) == name) {
00542          // change tab and generate event
00543          ChangeTab(count, emit);
00544          return kTRUE;
00545       }
00546       count++;
00547    }
00548 
00549    return kFALSE;
00550 }
00551 
00552 //______________________________________________________________________________
00553 TGCompositeFrame *TGTab::GetTabContainer(Int_t tabIndex) const
00554 {
00555    // Return container of tab with index tabIndex.
00556    // Return 0 in case tabIndex is out of range.
00557 
00558    if (tabIndex < 0) return 0;
00559 
00560    TGFrameElement *el;
00561    Int_t  count = 0;
00562 
00563    TIter next(fList);
00564    next();           // skip first container
00565 
00566    while (next()) {
00567       el = (TGFrameElement *) next();
00568       if (count == tabIndex)
00569          return (TGCompositeFrame *) el->fFrame;
00570       count++;
00571    }
00572 
00573    return 0;
00574 }
00575 
00576 //______________________________________________________________________________
00577 TGCompositeFrame *TGTab::GetTabContainer(const char *name) const
00578 {
00579    // Return the tab container of tab with string name.
00580    // Returns 0 in case name is not found.
00581 
00582    TGFrameElement *el;
00583    TGTabElement *tab = 0;
00584    TGCompositeFrame *comp = 0;
00585 
00586    TIter next(fList);
00587    next();
00588 
00589    while ((el = (TGFrameElement *) next())) {
00590       tab  = (TGTabElement *) el->fFrame;
00591       el   = (TGFrameElement *) next();
00592       comp = (TGCompositeFrame *) el->fFrame;
00593       if (*tab->GetText() == name){
00594          return comp;
00595       }
00596    }
00597 
00598    return 0;
00599 }
00600 
00601 //______________________________________________________________________________
00602 TGTabElement *TGTab::GetTabTab(Int_t tabIndex) const
00603 {
00604    // Return the tab element of tab with index tabIndex.
00605    // Returns 0 in case tabIndex is out of range.
00606 
00607    if (tabIndex < 0) return 0;
00608 
00609    TGFrameElement *el;
00610    Int_t  count = 0;
00611 
00612    TIter next(fList);
00613    next();           // skip first container
00614 
00615    while ((el = (TGFrameElement *) next())) {
00616       next();
00617       if (count == tabIndex)
00618          return (TGTabElement *) el->fFrame;
00619       count++;
00620    }
00621 
00622    return 0;
00623 }
00624 
00625 //______________________________________________________________________________
00626 TGTabElement *TGTab::GetTabTab(const char *name) const
00627 {
00628    // Return the tab element of tab with string name.
00629    // Returns 0 in case name is not found.
00630 
00631    TGFrameElement *el;
00632    TGTabElement *tab = 0;
00633 
00634    TIter next(fList);
00635    next();
00636 
00637    while ((el = (TGFrameElement *) next())) {
00638       tab = (TGTabElement *)el->fFrame;
00639       if (name == *(tab->GetText())) {
00640          return tab;
00641       }
00642       next();
00643    }
00644 
00645    return tab;
00646 }
00647 
00648 //______________________________________________________________________________
00649 Int_t TGTab::GetNumberOfTabs() const
00650 {
00651    // Return number of tabs.
00652 
00653    Int_t count = 0;
00654 
00655    TIter next(fList);
00656    next();           // skip first container
00657 
00658    while (next()) {
00659       next();
00660       count++;
00661    }
00662 
00663    return count;
00664 }
00665 
00666 //______________________________________________________________________________
00667 FontStruct_t TGTab::GetDefaultFontStruct()
00668 {
00669    // Return default font structure in use.
00670 
00671    if (!fgDefaultFont)
00672       fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
00673    return fgDefaultFont->GetFontStruct();
00674 }
00675 
00676 //______________________________________________________________________________
00677 const TGGC &TGTab::GetDefaultGC()
00678 {
00679    // Return default graphics context in use.
00680 
00681    if (!fgDefaultGC)
00682       fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
00683    return *fgDefaultGC;
00684 }
00685 
00686 //______________________________________________________________________________
00687 void TGTab::NewTab(const char *text)
00688 {
00689    // Create new tab. Used in context menu.
00690 
00691    TString name;
00692    if (text)
00693       name = text;
00694    else
00695       name = TString::Format("tab%d", GetNumberOfTabs()+1);
00696    AddTab(name.Data());
00697 
00698    GetLayoutManager()->Layout();
00699 }
00700 
00701 //______________________________________________________________________________
00702 void TGTab::SetText(const char *text)
00703 {
00704    // Set text to current tab.
00705 
00706    GetCurrentTab()->SetText(new TGString(text));
00707    GetLayoutManager()->Layout();
00708 }
00709 
00710 //______________________________________________________________________________
00711 TGLayoutManager *TGTab::GetLayoutManager() const
00712 {
00713    // Return layout manager.
00714 
00715    TGTab *tab = (TGTab*)this;
00716 
00717    if (tab->fLayoutManager->IsA() != TGTabLayout::Class()) {
00718       tab->SetLayoutManager(new TGTabLayout(tab));
00719    }
00720 
00721    return tab->fLayoutManager;
00722 }
00723 
00724 //______________________________________________________________________________
00725 void TGTab::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00726 {
00727    // Save a tab widget as a C++ statement(s) on output stream out.
00728 
00729    char quote = '"';
00730 
00731    // font + GC
00732    option = GetName()+5;         // unique digit id of the name
00733    TString parGC, parFont;
00734    parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
00735    parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
00736 
00737    if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
00738       TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
00739       if (ufont) {
00740          ufont->SavePrimitive(out, option);
00741          parFont.Form("ufont->GetFontStruct()");
00742       }
00743 
00744       TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
00745       if (userGC) {
00746          userGC->SavePrimitive(out, option);
00747          parGC.Form("uGC->GetGC()");
00748       }
00749    }
00750 
00751    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00752 
00753    out << endl << "   // tab widget" << endl;
00754 
00755    out << "   TGTab *";
00756    out << GetName() << " = new TGTab(" << fParent->GetName()
00757        << "," << GetWidth() << "," << GetHeight();
00758 
00759    if (fBackground == GetDefaultFrameBackground()) {
00760       if (GetOptions() == kChildFrame) {
00761          if (fFontStruct == GetDefaultFontStruct()) {
00762             if (fNormGC == GetDefaultGC()()) {
00763                out <<");" << endl;
00764             } else {
00765                out << "," << parGC.Data() <<");" << endl;
00766             }
00767          } else {
00768             out << "," << parGC.Data() << "," << parFont.Data() <<");" << endl;
00769          }
00770       } else {
00771          out << "," << parGC.Data() << "," << parFont.Data() << "," << GetOptionString() <<");" << endl;
00772       }
00773    } else {
00774       out << "," << parGC.Data() << "," << parFont.Data() << "," << GetOptionString()  << ",ucolor);" << endl;
00775    }
00776    if (option && strstr(option, "keep_names"))
00777       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00778 
00779    TGCompositeFrame *cf;
00780    TGLayoutManager * lm;
00781    for (Int_t i=0; i<GetNumberOfTabs(); i++) {
00782       cf = GetTabContainer(i);
00783       out << endl << "   // container of " << quote
00784           << GetTabTab(i)->GetString() << quote << endl;
00785       out << "   TGCompositeFrame *" << cf->GetName() << ";" << endl;
00786       out << "   " << cf->GetName() << " = " << GetName()
00787                    << "->AddTab(" << quote << GetTabTab(i)->GetString()
00788                    << quote << ");" << endl;
00789       lm = cf->GetLayoutManager();
00790       if (lm) {
00791          if ((cf->GetOptions() & kHorizontalFrame) &&
00792             (lm->InheritsFrom(TGHorizontalLayout::Class()))) {
00793             ;
00794          } else if ((GetOptions() & kVerticalFrame) &&
00795             (lm->InheritsFrom(TGVerticalLayout::Class()))) {
00796             ;
00797          } else {
00798             out << "   " << cf->GetName() <<"->SetLayoutManager(";
00799             lm->SavePrimitive(out, option);
00800             out << ");" << endl;
00801          }
00802          if (!IsEnabled(i)) {
00803             out << "   " << GetName() << "->SetEnabled(" << i << ", kFALSE);" << endl;
00804          }
00805       }
00806       cf->SavePrimitiveSubframes(out, option);
00807 
00808       if (GetTabTab(i)->IsCloseShown()) {
00809          out << "   TGTabElement *tab" << i << " = "
00810              << GetName() << "->GetTabTab(" << i << ");" << endl;
00811          out << "   tab" << i << "->ShowClose(kTRUE);" << endl;
00812       }
00813       if (GetTabTab(i)->GetBackground() != GetTabTab(i)->GetDefaultFrameBackground()) {
00814          GetTabTab(i)->SaveUserColor(out, option);
00815          out << "   TGTabElement *tab" << i << " = "
00816              << GetName() << "->GetTabTab(" << i << ");" << endl;
00817          out << "   tab" << i << "->ChangeBackground(ucolor);" << endl;
00818       }
00819 
00820    }
00821    out << endl << "   " << GetName() << "->SetTab(" << GetCurrent() << ");" << endl;
00822    out << endl << "   " << GetName() << "->Resize(" << GetName()
00823        << "->GetDefaultSize());" << endl;
00824 }
00825 
00826 // __________________________________________________________________________
00827 void TGTabLayout::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00828 {
00829    // Save tab layout manager as a C++ statement(s) on out stream.
00830 
00831    out << "new TGTabLayout(" << fMain->GetName() << ")";
00832 
00833 }

Generated on Tue Jul 5 14:22:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1