TGedFrame.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TGedFrame.cxx 35527 2010-09-21 12:27:01Z brun $
00002 // Author: Ilka Antcheva   10/05/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, 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 //  TGedFrame                                                           //
00015 //                                                                      //
00016 //  Base frame for implementing GUI - a service class.                  //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 #include "TGedFrame.h"
00021 #include "TGedEditor.h"
00022 #include "TG3DLine.h"
00023 #include "TClass.h"
00024 #include "TCanvas.h"
00025 #include "TGLabel.h"
00026 #include "TGToolTip.h"
00027 #include "TGCanvas.h"
00028 #include "TGScrollBar.h"
00029 
00030 
00031 ClassImp(TGedFrame)
00032 
00033 //______________________________________________________________________________
00034 TGedFrame::TGedFrame(const TGWindow *p, Int_t width,
00035                      Int_t height, UInt_t options, Pixel_t back)
00036       : TGCompositeFrame(p, width, height, options, back),
00037         fInit(kTRUE),
00038         fGedEditor(0),
00039         fModelClass(0),
00040         fAvoidSignal(kFALSE),
00041         fExtraTabs(0),
00042         fPriority(50)
00043 {
00044    // Constructor of the base GUI attribute frame.
00045 
00046    fName = "";
00047    fGedEditor = TGedEditor::GetFrameCreator();
00048    SetCleanup(kDeepCleanup);
00049 }
00050 
00051 //______________________________________________________________________________
00052 TGedFrame::~TGedFrame()
00053 {
00054    // Destructor of the base GUI attribute frame.
00055 
00056    if (fExtraTabs) {
00057       TGedSubFrame* sf;
00058       TIter next(fExtraTabs);
00059       while ((sf = (TGedSubFrame*) next()) != 0) {
00060          delete sf->fFrame;
00061          fExtraTabs->Remove(sf);
00062          delete sf;
00063       }
00064       delete fExtraTabs;
00065    }
00066 
00067    // Destructor of TGCompositeFrame will do the rest.
00068 }
00069 
00070 //______________________________________________________________________________
00071 void TGedFrame::Update()
00072 {
00073    // Update the current pad when an attribute is changed via GUI.
00074 
00075    fGedEditor->Update(this);
00076 }
00077 
00078 //______________________________________________________________________________
00079 Option_t *TGedFrame::GetDrawOption() const
00080 {
00081    // Get draw options of the selected object.
00082 
00083    if (!fGedEditor->GetPad()) return "";
00084 
00085    TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
00086    TObject *obj;
00087    while ((obj = next())) {
00088       if (obj == fGedEditor->GetModel()) return next.GetOption();
00089    }
00090    return "";
00091 }
00092 
00093 //______________________________________________________________________________
00094 void TGedFrame::MakeTitle(const char *title)
00095 {
00096    // Create attribute frame title.
00097 
00098    TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
00099                                                               kFitWidth |
00100                                                               kFixedWidth |
00101                                                               kOwnBackground);
00102    f1->AddFrame(new TGLabel(f1, title),
00103                 new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00104    f1->AddFrame(new TGHorizontal3DLine(f1),
00105                 new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00106    AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00107 }
00108 
00109 //______________________________________________________________________________
00110 void TGedFrame::AddExtraTab(TGedSubFrame* sf)
00111 {
00112   // Adds tab container to list of extra tabs.
00113 
00114    if (fExtraTabs == 0) fExtraTabs = new TList();
00115    fExtraTabs->Add(sf);
00116    sf->fFrame->SetCleanup(kDeepCleanup);
00117 }
00118 
00119 //______________________________________________________________________________
00120 TGVerticalFrame* TGedFrame::CreateEditorTabSubFrame(const char* name)
00121 {
00122    // Create a vertical frame to be used by 'owner' in extra tab 'name'.
00123    // The new frame is registered into the sub-frame list.
00124 
00125    TGCompositeFrame* tabcont  = fGedEditor->GetEditorTab(name);
00126 
00127    TGVerticalFrame* newframe = new TGVerticalFrame(tabcont);
00128    AddExtraTab(new TGedFrame::TGedSubFrame(TString(name), newframe));
00129    return newframe;
00130 }
00131 
00132 //______________________________________________________________________________
00133 void TGedFrame::Refresh(TObject* model)
00134 {
00135    // Refresh the GUI info about the object attributes.
00136 
00137    SetModel(model);
00138 }
00139 
00140 //______________________________________________________________________________
00141 void TGedFrame::SetDrawOption(Option_t *option)
00142 {
00143    // Set drawing option for object. This option only affects
00144    // the drawing style and is stored in the option field of the
00145    // TObjOptLink supporting a TPad's primitive list (TList).
00146 
00147    if (!fGedEditor->GetPad() || !option) return;
00148 
00149    TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
00150    delete fGedEditor->GetPad()->FindObject("Tframe");
00151    TObject *obj;
00152    while ((obj = next())) {
00153       if (obj == fGedEditor->GetModel()) {
00154          next.SetOption(option);
00155          fGedEditor->GetPad()->Modified();
00156          fGedEditor->GetPad()->Update();
00157          return;
00158       }
00159    }
00160 }
00161 
00162 //______________________________________________________________________________
00163 void TGedFrame::ActivateBaseClassEditors(TClass* cl)
00164 {
00165    // Provide list of editors for base-classes.
00166    // In this class we return all classed with editors found via recursive
00167    // descent into list of base classes.
00168    // Override to control which editors are actually shown (see TH2Editor).
00169 
00170    // printf("%s::FillListOfBaseEditors %s\n", IsA()->GetName(), cl->GetName());
00171    if (cl->GetListOfBases()->IsEmpty() == kFALSE) {
00172       fGedEditor->ActivateEditors(cl->GetListOfBases(), kTRUE);
00173    }
00174 }
00175 
00176 //______________________________________________________________________________
00177 TGedNameFrame::TGedNameFrame(const TGWindow *p, Int_t width,
00178                               Int_t height, UInt_t options, Pixel_t back)
00179    : TGedFrame(p, width, height, options | kVerticalFrame, back)
00180 {
00181    // Create the frame containing the selected object name.
00182 
00183    fPriority = 0;
00184 
00185    f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
00186                                             kFixedWidth      |
00187                                             kOwnBackground);
00188    f1->AddFrame(new TGLabel(f1,"Name"),
00189                 new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00190    f1->AddFrame(new TGHorizontal3DLine(f1),
00191                 new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00192    AddFrame(f1, new TGLayoutHints(kLHintsTop));
00193 
00194    f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame | kFixedWidth);
00195    fLabel = new TGLabel(f2, "");
00196    f2->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00197    AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00198 
00199    // Set red color for the name.
00200    Pixel_t color;
00201    gClient->GetColorByName("#ff0000", color);
00202    fLabel->SetTextColor(color, kFALSE);
00203 
00204    // create tool tip with delay 300 ms
00205    fTip = new TGToolTip(fClient->GetDefaultRoot(), this, "TGedNameFrame", 500);
00206 
00207    AddInput(kEnterWindowMask | kLeaveWindowMask | kKeyPressMask | kButtonPressMask);
00208 }
00209 
00210 //______________________________________________________________________________
00211 TGedNameFrame::~TGedNameFrame()
00212 {
00213    // Destructor.
00214 
00215    delete fTip;
00216 }
00217 
00218 //______________________________________________________________________________
00219 Bool_t TGedNameFrame::HandleCrossing(Event_t *event)
00220 {
00221    // Handle mouse crossing event for tooltip.
00222 
00223    if (event->fType == kEnterNotify)
00224       fTip->Reset();
00225    else
00226       fTip->Hide();
00227 
00228    return kFALSE;
00229 }
00230 
00231 //______________________________________________________________________________
00232 Bool_t TGedNameFrame::HandleButton(Event_t * /*event*/)
00233 {
00234    // Handle mouse button event.
00235 
00236    if (fTip) fTip->Hide();
00237 
00238    return kFALSE;
00239 }
00240 
00241 //______________________________________________________________________________
00242 void TGedNameFrame::SetModel(TObject* obj)
00243 {
00244    // Sets text for the label.
00245 
00246    TString string;
00247 
00248    if (obj == 0) {
00249       fLabel->SetText(new TGString("Object not selected"));
00250       return;
00251    }
00252    string.Append(obj->GetName());
00253    string.Append("::");
00254    string.Append(obj->ClassName());
00255 
00256    fLabel->SetText(new TGString(string));
00257    string = TString::Format("Name: %s\nTitle:   %s\nClass: %s",
00258                             obj->GetName(), obj->GetTitle(), obj->ClassName());
00259    fTip->SetText(string);
00260 
00261    // Resize label-frame to a reasonable width.
00262    {
00263       TGCanvas     *canvas = fGedEditor->GetTGCanvas();
00264       TGVScrollBar *vsb    = canvas->GetVScrollbar();
00265 
00266       Int_t hscrollw = (vsb && vsb->IsMapped()) ? vsb->GetWidth() : 0;
00267       Int_t labwidth = TMath::Min(fLabel->GetDefaultSize().fWidth,
00268                                   canvas->GetWidth() - 10 - hscrollw);
00269       f2->SetWidth(TMath::Max(labwidth, 80));
00270    }
00271 }

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