TGButtonGroup.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGButtonGroup.cxx 36152 2010-10-07 13:52:30Z rdm $
00002 // Author: Valeriy Onuchin & Fons Rademakers   16/10/2000
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 //                                                                      //
00014 // The TGButtonGroup widget organizes TGButton widgets in a group.      //
00015 //                                                                      //
00016 // A button group widget makes it easier to deal with groups of buttons.//
00017 // A button in a button group is associated with a unique identifier.   //
00018 // The button group emits a Clicked() signal with this identifier when  //
00019 // the button is clicked. Thus, a button group is an ideal solution     //
00020 // when you have several similar buttons and want to connect all their  //
00021 // Clicked() signals, for example, to one slot.                         //
00022 //                                                                      //
00023 // An exclusive button group switches off all toggle buttons except     //
00024 // the one that was clicked. A button group is by default non-exclusive.//
00025 // All radio buttons that are inserted, will be mutually exclusive even //
00026 // if the button group is non-exclusive.                                //
00027 //                                                                      //
00028 //                                                                      //
00029 // There are two ways of using a button group:                          //
00030 //                                                                      //
00031 //    The button group is a parent widget of a number of buttons,       //
00032 //    i.e. the button group is the parent argument in the button        //
00033 //    constructor. The buttons are assigned identifiers 1, 2, 3 etc.    //
00034 ///   in the order they are created or you can specify button id in     //
00035 //    the button constructor. A TGButtonGroup can display a frame and   //
00036 //    a title because it inherits from TGGroupFrame.                    //
00037 //                                                                      //
00038 // Example:                                                             //
00039 //                                                                      //
00040 //    // vertical frame without border and title                        //
00041 //    TGVButtonGroup *bg = new TGVButtonGroup(main_frame);              //
00042 //                                                                      //
00043 //    // create text button with id=1                                   //
00044 //    TGTextButton *button1 = new TGTextButton(bg,"some text");         //
00045 //                                                                      //
00046 //    // create another text button with id=2                           //
00047 //    TGTextButton *button2 = new TGTextButton(bg,"another text");      //
00048 //                                                                      //
00049 //    // map all buttons                                                //
00050 //    bg->Show();                                                       //
00051 //                                                                      //
00052 // NOTE: there is no need to call AddFrame() since the buttons are      //
00053 // automatically added with a default layout hint to their parent,      //
00054 // i.e. the buttongroup. To override the default layout hints use the   //
00055 // SetLayoutHints() method.                                             //
00056 //                                                                      //
00057 //  ButtonGroup Signals:                                                //
00058 //                                                                      //
00059 //    Pressed(Int_t id)  -->  is emitted when a button in the group is  //
00060 //                            pressed down. The id argument is the      //
00061 //                            button's identifier.                      //
00062 //    Released(Int_t id) -->  is emitted when a button in the group is  //
00063 //                            released. The id argument is the button's //
00064 //                            identifier.                               //
00065 //    Clicked(Int_t id)  -->  is emitted when a button in the group is  //
00066 //                            clicked. The id argument is the button's  //
00067 //                            identifier.                               //
00068 //                                                                      //
00069 //                                                                      //
00070 // The TGHButtonGroup widget organizes TGButton widgets in a group      //
00071 // with one horizontal row. TGHButtonGroup is a convenience class that  //
00072 // offers a thin layer on top of TGButtonGroup. It inherits from        //
00073 // TGButtonGroup.                                                       //
00074 //                                                                      //
00075 // The TGVButtonGroup widget organizes TGButton widgets in a group      //
00076 // with one vertical column. TGVButtonGroup is a convenience class that //
00077 // offers a thin layer on top of TGButtonGroup. It inherits from        //
00078 // TGButtonGroup.                                                       //
00079 //                                                                      //
00080 //////////////////////////////////////////////////////////////////////////
00081 
00082 #include "TGButtonGroup.h"
00083 #include "TGButton.h"
00084 #include "TClass.h"
00085 #include "TGLayout.h"
00086 #include "TList.h"
00087 #include "TGResourcePool.h"
00088 #include "Riostream.h"
00089 
00090 
00091 ClassImp(TGButtonGroup)
00092 ClassImp(TGHButtonGroup)
00093 ClassImp(TGVButtonGroup)
00094 
00095 //______________________________________________________________________________
00096 TGButtonGroup::TGButtonGroup(const TGWindow *parent,
00097                              const TString &title,
00098                              UInt_t options,
00099                              GContext_t norm,
00100                              FontStruct_t font,
00101                              ULong_t back) :
00102    TGGroupFrame(parent, new TGString(title), options, norm, font, back)
00103 {
00104    // Constructor. Layout 1 row or 1 column.
00105 
00106    Init();
00107    if (options & kVerticalFrame) {
00108       SetLayoutManager(new TGVerticalLayout(this));
00109    } else {
00110       SetLayoutManager(new TGHorizontalLayout(this));
00111    }
00112 
00113    fDrawBorder = !title.IsNull();
00114 }
00115 
00116 //______________________________________________________________________________
00117 TGButtonGroup::TGButtonGroup(const TGWindow *parent,
00118                              UInt_t r, UInt_t c,
00119                              Int_t s, Int_t h,
00120                              const TString &title,
00121                              GContext_t norm ,
00122                              FontStruct_t font ,
00123                              ULong_t back) :
00124    TGGroupFrame(parent, new TGString(title), 0, norm, font, back)
00125 {
00126    // Constructor. Layout defined by TGMatrixLayout:
00127    //    r = number of rows
00128    //    c = number of columns
00129    //    s = interval between frames
00130    //    h = layout hints
00131 
00132    Init();
00133    fDrawBorder = !title.IsNull();
00134    SetLayoutManager(new TGMatrixLayout(this,r,c,s,h));
00135 }
00136 
00137 //______________________________________________________________________________
00138 void TGButtonGroup::Init()
00139 {
00140    // Default init.
00141 
00142    fState        = kTRUE;
00143    fMapOfButtons = new TMap();  // map of button/id pairs
00144    fExclGroup    = kFALSE;
00145    fRadioExcl    = kFALSE;
00146    fDrawBorder   = kTRUE;
00147 
00148    SetWindowName();
00149 }
00150 
00151 //______________________________________________________________________________
00152 TGButtonGroup::~TGButtonGroup()
00153 {
00154    // Destructor, we do not delete the buttons.
00155 
00156    TIter next(fMapOfButtons);
00157    register TGButton *item = 0;
00158 
00159    while ((item = (TGButton*)next())) {
00160       item->SetGroup(0);
00161    }
00162 
00163    SafeDelete(fMapOfButtons);
00164 }
00165 
00166 //______________________________________________________________________________
00167 void TGButtonGroup::DoRedraw()
00168 {
00169    // Redraw the group frame. Need special DoRedraw() since we need to
00170    // redraw with fBorderWidth=0.
00171 
00172    gVirtualX->ClearArea(fId, 0, 0, fWidth, fHeight);
00173 
00174    DrawBorder();
00175 }
00176 
00177 //______________________________________________________________________________
00178 void TGButtonGroup::DrawBorder()
00179 {
00180    // Draw border of around the group frame.
00181    //
00182    // if frame is kRaisedFrame  - a frame border is of "wall style",
00183    // otherwise of "groove style".
00184 
00185    if (!fDrawBorder) return;
00186 
00187    Int_t x, y, l, t, r, b, gl, gr, sep, max_ascent, max_descent;
00188 
00189    UInt_t tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
00190    gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
00191 
00192    l = 0;
00193    t = (max_ascent + max_descent + 2) >> 1;
00194    r = fWidth - 1;
00195    // next three lines are for backward compatibility in case of horizontal layout
00196    TGLayoutManager * lm = GetLayoutManager();
00197    if ((lm->InheritsFrom(TGHorizontalLayout::Class())) ||
00198        (lm->InheritsFrom(TGMatrixLayout::Class())))
00199       b = fHeight - 1;
00200    else
00201       b = fHeight - t;
00202 
00203    sep = 3;
00204    UInt_t rr = 5 + (sep << 1) + tw;
00205 
00206    switch (fTitlePos) {
00207       case kRight:
00208          gl = fWidth>rr ? Int_t(fWidth - rr) : 5 + sep;
00209          break;
00210       case kCenter:
00211          gl = fWidth>tw ? Int_t((fWidth - tw)>>1) - sep : 5 + sep;
00212          break;
00213       case kLeft:
00214       default:
00215          gl = 5 + sep;
00216    }
00217    gr = gl + tw + (sep << 1);
00218 
00219    switch (fOptions & (kSunkenFrame | kRaisedFrame)) {
00220       case kRaisedFrame:
00221          gVirtualX->DrawLine(fId, GetHilightGC()(),  l,   t,   gl,  t);
00222          gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, t+1, gl,  t+1);
00223 
00224          gVirtualX->DrawLine(fId, GetHilightGC()(),  gr,  t,   r-1, t);
00225          gVirtualX->DrawLine(fId, GetShadowGC()(), gr,  t+1, r-2, t+1);
00226 
00227          gVirtualX->DrawLine(fId, GetHilightGC()(),  r-1, t,   r-1, b-1);
00228          gVirtualX->DrawLine(fId, GetShadowGC()(), r,   t,   r,   b);
00229 
00230          gVirtualX->DrawLine(fId, GetHilightGC()(),  r-1, b-1, l,   b-1);
00231          gVirtualX->DrawLine(fId, GetShadowGC()(), r,   b,   l,   b);
00232 
00233          gVirtualX->DrawLine(fId, GetHilightGC()(),  l,   b-1, l,   t);
00234          gVirtualX->DrawLine(fId, GetShadowGC()(), l+1, b-2, l+1, t+1);
00235          break;
00236       case kSunkenFrame:
00237       default:
00238          gVirtualX->DrawLine(fId, GetShadowGC()(),  l,   t,   gl,  t);
00239          gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, t+1, gl,  t+1);
00240 
00241          gVirtualX->DrawLine(fId, GetShadowGC()(),  gr,  t,   r-1, t);
00242          gVirtualX->DrawLine(fId, GetHilightGC()(), gr,  t+1, r-2, t+1);
00243 
00244          gVirtualX->DrawLine(fId, GetShadowGC()(),  r-1, t,   r-1, b-1);
00245          gVirtualX->DrawLine(fId, GetHilightGC()(), r,   t,   r,   b);
00246 
00247          gVirtualX->DrawLine(fId, GetShadowGC()(),  r-1, b-1, l,   b-1);
00248          gVirtualX->DrawLine(fId, GetHilightGC()(), r,   b,   l,   b);
00249 
00250          gVirtualX->DrawLine(fId, GetShadowGC()(),  l,   b-1, l,   t);
00251          gVirtualX->DrawLine(fId, GetHilightGC()(), l+1, b-2, l+1, t+1);
00252          break;
00253    }
00254 
00255    x = gl + sep;
00256    y = 1;
00257 
00258    if (fState) {
00259       fText->Draw(fId, fNormGC, x, y + max_ascent);
00260    } else {
00261       fText->Draw(fId, GetHilightGC()(), x, y + 1 + max_ascent);
00262       fText->Draw(fId, GetShadowGC()(), x, y + max_ascent);
00263    }
00264 }
00265 
00266 //______________________________________________________________________________
00267 void TGButtonGroup::SetBorderDrawn(Bool_t enable)
00268 {
00269    // Makes border to be visible/invisible.
00270 
00271    if (enable != IsBorderDrawn()) {
00272       fDrawBorder = enable;
00273       ChangedBy("SetBorderDrawn");        // emit signal
00274    }
00275 }
00276 
00277 //______________________________________________________________________________
00278 void TGButtonGroup::SetExclusive(Bool_t enable)
00279 {
00280    // Sets the button group to be exclusive if enable is kTRUE,
00281    // or to be non-exclusive if enable is kFALSE.
00282    // An exclusive button group switches off all other toggle buttons when
00283    // one is switched on. This is ideal for groups of radio-buttons
00284    // A non-exclusive group allow many buttons to be switched on at the same
00285    // time. The default setting is kFALSE.
00286 
00287    if (enable != IsExclusive()) {
00288       fExclGroup = enable;
00289       ChangedBy("SetExclusive");  // emit signal
00290    }
00291 }
00292 
00293 //______________________________________________________________________________
00294 void TGButtonGroup::SetRadioButtonExclusive(Bool_t enable)
00295 {
00296    // If enable is kTRUE, this button group will treat radio buttons as
00297    // mutually exclusive, and other buttons according to IsExclusive().
00298    // This function is called automatically whenever a TGRadioButton
00299    // is inserted, so you should normally never have to call it.
00300 
00301    if (enable != IsRadioButtonExclusive()) {
00302       fRadioExcl = enable;
00303       ChangedBy("SetRadioButtonExclusive"); // emit signal
00304    }
00305 }
00306 
00307 //______________________________________________________________________________
00308 void TGButtonGroup::SetState(Bool_t state)
00309 {
00310    // Sets the state of all the buttons in the group to enable or disable.
00311 
00312    fState = state;
00313 
00314    TIter next(fMapOfButtons);
00315    register TGButton *item = 0;
00316 
00317    while ((item = (TGButton*)next())) {    // loop over all buttons
00318       if (state) {
00319          item->SetState(kButtonUp);
00320       } else {
00321          item->SetState(kButtonDisabled);
00322       }
00323    }
00324    DoRedraw();
00325 }
00326 //______________________________________________________________________________
00327 void TGButtonGroup::SetButton(Int_t id, Bool_t down)
00328 {
00329    // Sets the button with id to be on/down, and if this is an
00330    // exclusive group, all other button in the group to be off/up.
00331 
00332    TGButton *b = Find(id);
00333 
00334    if (b && (b->IsDown() != down)) {
00335       b->SetState(kButtonDown, kTRUE);
00336    }
00337 }
00338 
00339 //______________________________________________________________________________
00340 Int_t TGButtonGroup::Insert(TGButton *button, Int_t id)
00341 {
00342    // Inserts a button with the identifier id into the button group.
00343    // Returns the button identifier.
00344    //
00345    // It is not necessary to manually insert buttons that have this button
00346    // group as their parent widget. An exception is when you want custom
00347    // identifiers instead of the default 1, 2, 3 etc.
00348    //
00349    // The button is assigned the identifier id or an automatically
00350    // generated identifier.  It works as follows: If id > 0, this
00351    // identifier is assigned.  If id == -1 (default), the identifier is
00352    // equal to the number of buttons in the group+1.  If id is any other
00353    // negative integer, for instance -2, a unique identifier (negative
00354    // integer <= -2) is generated.
00355    //
00356    // Inserting several buttons with id = -1 assigns the identifiers 1,
00357    // 2, 3, etc.
00358 
00359    if (button->fGroup && button->fGroup != this)
00360       button->fGroup->Remove(button);
00361 
00362    if (button->fGroup == this) {
00363       if (id == -1)
00364          return GetId(button);    // the button is already in group
00365       else
00366          button->fGroup->Remove(button);  // want to set a new id
00367    }
00368 
00369    button->fGroup = this;
00370    button->Associate(this);
00371 
00372    static Int_t seq_no = -2;
00373    Long_t bid;
00374 
00375    if (id < -1)       bid = seq_no--;
00376    else if (id == -1) bid = GetCount()+1;
00377    else               bid = id;
00378 
00379    fMapOfButtons->Add(button, (TObject*)bid);
00380    AddFrame(button);
00381 
00382    SetRadioButtonExclusive(button->IsA()->InheritsFrom(TGRadioButton::Class()));
00383 
00384    Connect(button, "Clicked()" , "TGButtonGroup", this, "ReleaseButtons()");
00385    Connect(button, "Pressed()" , "TGButtonGroup", this, "ButtonPressed()");
00386    Connect(button, "Released()", "TGButtonGroup", this, "ButtonReleased()");
00387    Connect(button, "Clicked()" , "TGButtonGroup", this, "ButtonClicked()");
00388 
00389    return (Int_t) bid;
00390 }
00391 
00392 //______________________________________________________________________________
00393 void TGButtonGroup::Remove(TGButton *button)
00394 {
00395    // Removes a button from the button group.
00396 
00397    TGButton *item = (TGButton*) fMapOfButtons->Remove(button);
00398    if (item) {
00399       button->SetGroup(0);
00400       button->Disconnect(this);
00401       button->DestroyWindow();
00402    }
00403 
00404    RemoveFrame(button);
00405 }
00406 
00407 //______________________________________________________________________________
00408 TGButton *TGButtonGroup::Find(Int_t id) const
00409 {
00410    // Finds and returns a pointer to the button with the specified
00411    // identifier id. Returns null if the button was not found.
00412 
00413    TIter next(fMapOfButtons);
00414    register TGButton *item = 0;
00415 
00416    while ((item = (TGButton*)next())) {
00417       if ((Long_t)fMapOfButtons->GetValue(item) == id) break;   // found
00418    }
00419 
00420    return item;
00421 }
00422 
00423 //______________________________________________________________________________
00424 Int_t TGButtonGroup::GetId(TGButton *button) const
00425 {
00426    // Finds and returns the id of the button.
00427    // Returns -1 if the button is not a member of this group.
00428 
00429    TPair *a = (TPair*) fMapOfButtons->FindObject(button);
00430    if (a)
00431       return (Int_t)Long_t(a->Value());
00432    else
00433       return -1;
00434 }
00435 
00436 //______________________________________________________________________________
00437 void TGButtonGroup::ButtonPressed()
00438 {
00439    // This slot is activated when one of the buttons in the group emits the
00440    // Pressed() signal.
00441 
00442 #if 0
00443    // Is here for historical purposes and example. Now this is not needed
00444    // anymore since TGButton has has its own GetSender() method returning
00445    // the TGButton proper.
00446 
00447    // This is needed since gTQSender points to TQObject part of TGButton
00448    TGButton *btn = dynamic_cast<TGButton*>((TQObject*)gTQSender);
00449 
00450    if (!btn) {
00451       Error("ButtonPressed", "gTQSender not a TGButton");
00452       return;
00453    }
00454 #else
00455       TGButton *btn = (TGButton*)gTQSender;
00456 #endif
00457 
00458    TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
00459    if (a) {
00460       Int_t id = (Int_t)Long_t(a->Value());
00461       Pressed(id);
00462    }
00463 }
00464 
00465 //______________________________________________________________________________
00466 void TGButtonGroup::ButtonReleased()
00467 {
00468    // This slot is activated when one of the buttons in the group emits the
00469    // Released() signal.
00470 
00471    TGButton *btn = (TGButton*)gTQSender;
00472 
00473    TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
00474    if (a) {
00475       Int_t id = (Int_t)Long_t(a->Value());
00476       Released(id);
00477    }
00478 }
00479 
00480 //______________________________________________________________________________
00481 void TGButtonGroup::ButtonClicked()
00482 {
00483    // This slot is activated when one of the buttons in the group emits the
00484    // Clicked() signal.
00485 
00486    TGButton *btn = (TGButton*)gTQSender;
00487 
00488    TPair *a = (TPair*) fMapOfButtons->FindObject(btn);
00489    if (a) {
00490       Int_t id = (Int_t)Long_t(a->Value());
00491       Clicked(id);
00492    }
00493 }
00494 
00495 //______________________________________________________________________________
00496 void TGButtonGroup::ReleaseButtons()
00497 {
00498    // This slot is activated when one of the buttons in the
00499    // exclusive group emits the Pressed() signal.
00500 
00501    if (!fExclGroup && !fRadioExcl) return;
00502 
00503    TGButton *btn = (TGButton*)gTQSender;
00504 
00505    if (!fExclGroup && !btn)
00506       return;
00507 
00508    TIter next(fMapOfButtons);
00509    register TGButton *item = 0;
00510 
00511    while ((item = (TGButton*)next())) {    // loop over all buttons
00512       if (btn != item && item->IsToggleButton() && item->IsOn() &&
00513           (fExclGroup || (item->IsA()->InheritsFrom(TGRadioButton::Class())
00514                           && btn->IsA()->InheritsFrom(TGRadioButton::Class())))) {
00515          item->SetOn(kFALSE);
00516       }
00517    }
00518 }
00519 
00520 //______________________________________________________________________________
00521 void TGButtonGroup::Show()
00522 {
00523    // Show group of buttons.
00524 
00525    MapSubwindows();
00526    Resize();
00527    MapRaised();
00528    fClient->NeedRedraw(this);
00529 }
00530 
00531 //______________________________________________________________________________
00532 void TGButtonGroup::Hide()
00533 {
00534    // Hide group of buttons.
00535 
00536    UnmapWindow();
00537 }
00538 
00539 //______________________________________________________________________________
00540 void TGButtonGroup::SetTitle(TGString *title)
00541 {
00542    // Set or change title.
00543 
00544    if (!title) {
00545       Error("SetTitle", "title cannot be 0, try \"\"");
00546       return;
00547    }
00548 
00549    if (strcmp(fText->GetString(), title->GetString())) {
00550       SetBorderDrawn(title->GetLength() ? kTRUE : kFALSE);
00551       TGGroupFrame::SetTitle(title);
00552       ChangedBy("SetTitle");
00553    }
00554 }
00555 
00556 //______________________________________________________________________________
00557 void TGButtonGroup::SetTitle(const char *title)
00558 {
00559    // Set or change title.
00560 
00561    if (!title) {
00562       Error("SetTitle", "title cannot be 0, try \"\"");
00563       return;
00564    }
00565 
00566    if (strcmp(fText->GetString(), title)) {
00567       SetBorderDrawn(title && strlen(title));
00568       TGGroupFrame::SetTitle(title);
00569       ChangedBy("SetTitle");
00570    }
00571 }
00572 
00573 //______________________________________________________________________________
00574 void TGButtonGroup::SetLayoutHints(TGLayoutHints *l, TGButton *button)
00575 {
00576    // Set layout hints for the specified button or if button=0 for all
00577    // buttons.
00578 
00579    TGFrameElement *el;
00580    TIter next(fList);
00581 
00582    while ((el = (TGFrameElement *)next())) {
00583       if ((el->fFrame==(TGFrame*)button) || !button) {
00584          el->fLayout = l ? l : fgDefaultHints;
00585       }
00586    }
00587    Layout();
00588 }
00589 
00590 //______________________________________________________________________________
00591 void TGButtonGroup::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00592 {
00593    // Save a button group widget as a C++ statement(s) on output stream out.
00594 
00595    char quote ='"';
00596 
00597    // font + GC
00598    option = GetName()+5;         // unique digit id of the name
00599    TString parGC, parFont;
00600    parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
00601    parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
00602 
00603    if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
00604       TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
00605       if (ufont) {
00606          ufont->SavePrimitive(out, option);
00607          parFont.Form("ufont->GetFontStruct()");
00608       }
00609 
00610       TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
00611       if (userGC) {
00612          userGC->SavePrimitive(out, option);
00613          parGC.Form("uGC->GetGC()");
00614       }
00615    }
00616 
00617    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00618 
00619    out << endl << "   // buttongroup frame" << endl;
00620 
00621    out << "   TGButtonGroup *";
00622    out << GetName() << " = new TGButtonGroup(" << fParent->GetName()
00623        << ","<< quote << fText->GetString() << quote;
00624 
00625    if (fBackground == GetDefaultFrameBackground()) {
00626       if (fFontStruct == GetDefaultFontStruct()) {
00627          if (fNormGC == GetDefaultGC()()) {
00628             if (!GetOptions()) {
00629                out <<");" << endl;
00630             } else {
00631                out << "," << GetOptionString() <<");" << endl;
00632             }
00633          } else {
00634             out << "," << GetOptionString() << "," << parGC.Data() <<");" << endl;
00635          }
00636       } else {
00637          out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() <<");" << endl;
00638       }
00639    } else {
00640       out << "," << GetOptionString() << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << endl;
00641    }
00642    if (option && strstr(option, "keep_names"))
00643       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00644 
00645    // setting layout manager
00646    out << "   " << GetName() <<"->SetLayoutManager(";
00647    GetLayoutManager()->SavePrimitive(out, option);
00648    out << ");"<< endl;
00649 
00650    TGFrameElement *f;
00651    TIter next(GetList());
00652    while ((f = (TGFrameElement *)next())) {
00653       f->fFrame->SavePrimitive(out,option);
00654       if (f->fFrame->InheritsFrom("TGButton")) continue;
00655       else {
00656          out << "   " << GetName() << "->AddFrame(" << f->fFrame->GetName();
00657          f->fLayout->SavePrimitive(out, option);
00658          out << ");"<< endl;
00659       }
00660    }
00661 
00662    if (IsExclusive())
00663       out << "   " << GetName() <<"->SetExclusive(kTRUE);" << endl;
00664 
00665    if (IsRadioButtonExclusive())
00666       out << "   " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << endl;
00667 
00668    if (!IsBorderDrawn())
00669       out << "   " << GetName() <<"->SetBorderDrawn(kFALSE);" << endl;
00670 
00671 
00672    out << "   " << GetName() << "->Resize(" << GetWidth()
00673        << "," << GetHeight() << ");" << endl;
00674 
00675    if (!IsEnabled())
00676       out << "   " << GetName() <<"->SetState(kFALSE);" << endl;
00677 
00678    out << "   " << GetName() << "->Show();" << endl;
00679 }
00680 
00681 //______________________________________________________________________________
00682 void TGHButtonGroup::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00683 {
00684    // Save a button group widget as a C++ statement(s) on output stream out.
00685 
00686    char quote ='"';
00687 
00688    // font + GC
00689    option = GetName()+5;         // unique digit id of the name
00690    TString parGC, parFont;
00691    parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
00692    parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
00693 
00694    if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
00695       TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
00696       if (ufont) {
00697          ufont->SavePrimitive(out, option);
00698          parFont.Form("ufont->GetFontStruct()");
00699       }
00700 
00701       TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
00702       if (userGC) {
00703          userGC->SavePrimitive(out, option);
00704          parGC.Form("uGC->GetGC()");
00705       }
00706    }
00707 
00708    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00709 
00710    out << endl << "   // horizontal buttongroup frame" << endl;
00711 
00712    out << "   TGHButtonGroup *";
00713    out << GetName() << " = new TGHButtonGroup(" << fParent->GetName()
00714        << "," << quote << fText->GetString() << quote;
00715    if (fBackground == GetDefaultFrameBackground()) {
00716 
00717       if (fFontStruct == GetDefaultFontStruct()) {
00718 
00719          if (fNormGC == GetDefaultGC()()) {
00720             out << ");" << endl;
00721          } else {
00722             out << "," << parGC.Data() <<");" << endl;
00723          }
00724       } else {
00725          out << "," << parGC.Data() << "," << parFont.Data() <<");" << endl;
00726       }
00727    } else {
00728       out << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << endl;
00729    }
00730    if (option && strstr(option, "keep_names"))
00731       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00732 
00733    TGFrameElement *f;
00734    TIter next(GetList());
00735    while ((f = (TGFrameElement *)next())) {
00736       f->fFrame->SavePrimitive(out,option);
00737       if (f->fFrame->InheritsFrom("TGButton")){
00738          out << "   " << GetName() << "->SetLayoutHints(";
00739          f->fLayout->SavePrimitive(out, "nocoma");
00740          out << "," << f->fFrame->GetName();
00741          out << ");"<< endl;
00742       }
00743       else {
00744          out << "   " << GetName() << "->AddFrame(" << f->fFrame->GetName();
00745          f->fLayout->SavePrimitive(out, option);
00746          out << ");"<< endl;
00747       }
00748    }
00749 
00750    if (!IsEnabled())
00751       out << "   " << GetName() <<"->SetState(kFALSE);" << endl;
00752 
00753    if (IsExclusive())
00754       out << "   " << GetName() <<"->SetExclusive(kTRUE);" << endl;
00755 
00756    if (IsRadioButtonExclusive())
00757       out << "   " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << endl;
00758 
00759    if (!IsBorderDrawn())
00760       out << "   " << GetName() <<"->SetBorderDrawn(kFALSE);" << endl;
00761 
00762    out << "   " << GetName() <<"->Resize(" << GetWidth() << ","
00763        << GetHeight() << ");" << endl;
00764 
00765    out << "   " << GetName() << "->Show();" << endl;
00766 }
00767 
00768 //______________________________________________________________________________
00769 void TGVButtonGroup::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00770 {
00771    // Save a button group widget as a C++ statement(s) on output stream out.
00772 
00773    char quote ='"';
00774 
00775    // font + GC
00776    option = GetName()+5;         // unique digit id of the name
00777    TString parGC, parFont;
00778    parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
00779    parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
00780 
00781    if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC)) {
00782       TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
00783       if (ufont) {
00784          ufont->SavePrimitive(out, option);
00785          parFont.Form("ufont->GetFontStruct()");
00786       }
00787 
00788       TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
00789       if (userGC) {
00790          userGC->SavePrimitive(out, option);
00791          parGC.Form("uGC->GetGC()");
00792       }
00793    }
00794 
00795    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00796 
00797    out << endl << "   // vertical buttongroup frame" << endl;
00798 
00799    out << "   TGVButtonGroup *";
00800    out << GetName() << " = new TGVButtonGroup(" << fParent->GetName()
00801        << "," << quote << fText->GetString() << quote;
00802 
00803    if (fBackground == GetDefaultFrameBackground()) {
00804       if (fFontStruct == GetDefaultFontStruct()) {
00805          if (fNormGC == GetDefaultGC()()) {
00806             out <<");" << endl;
00807          } else {
00808             out << "," << parGC.Data() <<");" << endl;
00809          }
00810       } else {
00811          out << "," << parGC.Data() << "," << parFont.Data() <<");" << endl;
00812       }
00813    } else {
00814       out << "," << parGC.Data() << "," << parFont.Data() << ",ucolor);" << endl;
00815    }
00816    if (option && strstr(option, "keep_names"))
00817       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00818 
00819    TGFrameElement *f;
00820    TIter next(GetList());
00821    while ((f = (TGFrameElement *)next())) {
00822       f->fFrame->SavePrimitive(out,option);
00823       if (f->fFrame->InheritsFrom("TGButton")) continue;
00824       else {
00825          out << "   " << GetName() << "->AddFrame(" << f->fFrame->GetName();
00826          f->fLayout->SavePrimitive(out, option);
00827          out << ");"<< endl;
00828       }
00829    }
00830 
00831    if (!IsEnabled())
00832       out << "   " << GetName() <<"->SetState(kFALSE);" << endl;
00833 
00834    if (IsExclusive())
00835       out << "   " << GetName() <<"->SetExclusive(kTRUE);" << endl;
00836 
00837    if (IsRadioButtonExclusive())
00838       out << "   " << GetName() <<"->SetRadioButtonExclusive(kTRUE);" << endl;
00839 
00840    if (!IsBorderDrawn())
00841       out << "   " << GetName() <<"->SetBorderDrawn(kFALSE);" << endl;
00842 
00843    out << "   " << GetName() << "->Resize(" << GetWidth()
00844        << "," << GetHeight() << ");"<< endl;
00845 
00846    out << "   " << GetName() << "->Show();" << endl;
00847 }

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