Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGedFrame.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 10/05/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGedFrame //
15 // //
16 // Base frame for implementing GUI - a service class. //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #include "TGedFrame.h"
21 #include "TGedEditor.h"
22 #include "TG3DLine.h"
23 #include "TClass.h"
24 #include "TCanvas.h"
25 #include "TGLabel.h"
26 #include "TGToolTip.h"
27 #include "TGCanvas.h"
28 #include "TGScrollBar.h"
29 
30 
31 ClassImp(TGedFrame);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor of the base GUI attribute frame.
35 
36 TGedFrame::TGedFrame(const TGWindow *p, Int_t width,
37  Int_t height, UInt_t options, Pixel_t back)
38  : TGCompositeFrame(p, width, height, options, back),
39  fInit(kTRUE),
40  fGedEditor(0),
41  fModelClass(0),
42  fAvoidSignal(kFALSE),
43  fExtraTabs(0),
44  fPriority(50)
45 {
46  fName = "";
47  fGedEditor = TGedEditor::GetFrameCreator();
48  SetCleanup(kDeepCleanup);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Destructor of the base GUI attribute frame.
53 
54 TGedFrame::~TGedFrame()
55 {
56  if (fExtraTabs) {
57  TGedSubFrame* sf;
58  TIter next(fExtraTabs);
59  while ((sf = (TGedSubFrame*) next()) != 0) {
60  delete sf->fFrame;
61  fExtraTabs->Remove(sf);
62  delete sf;
63  }
64  delete fExtraTabs;
65  }
66 
67  // Destructor of TGCompositeFrame will do the rest.
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Update the current pad when an attribute is changed via GUI.
72 
73 void TGedFrame::Update()
74 {
75  fGedEditor->Update(this);
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Get draw options of the selected object.
80 
81 Option_t *TGedFrame::GetDrawOption() const
82 {
83  if (!fGedEditor->GetPad()) return "";
84 
85  TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
86  TObject *obj;
87  while ((obj = next())) {
88  if (obj == fGedEditor->GetModel()) return next.GetOption();
89  }
90  return "";
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Create attribute frame title.
95 
96 void TGedFrame::MakeTitle(const char *title)
97 {
98  TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
99  kFitWidth |
100  kFixedWidth |
101  kOwnBackground);
102  f1->AddFrame(new TGLabel(f1, title),
103  new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
104  f1->AddFrame(new TGHorizontal3DLine(f1),
105  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
106  AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Adds tab container to list of extra tabs.
111 
112 void TGedFrame::AddExtraTab(TGedSubFrame* sf)
113 {
114  if (fExtraTabs == 0) fExtraTabs = new TList();
115  fExtraTabs->Add(sf);
116  sf->fFrame->SetCleanup(kDeepCleanup);
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Create a vertical frame to be used by 'owner' in extra tab 'name'.
121 /// The new frame is registered into the sub-frame list.
122 
123 TGVerticalFrame* TGedFrame::CreateEditorTabSubFrame(const char* name)
124 {
125  TGCompositeFrame* tabcont = fGedEditor->GetEditorTab(name);
126 
127  TGVerticalFrame* newframe = new TGVerticalFrame(tabcont);
128  AddExtraTab(new TGedFrame::TGedSubFrame(TString(name), newframe));
129  return newframe;
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Refresh the GUI info about the object attributes.
134 
135 void TGedFrame::Refresh(TObject* model)
136 {
137  SetModel(model);
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Set drawing option for object. This option only affects
142 /// the drawing style and is stored in the option field of the
143 /// TObjOptLink supporting a TPad's primitive list (TList).
144 
145 void TGedFrame::SetDrawOption(Option_t *option)
146 {
147  if (!fGedEditor->GetPad() || !option) return;
148 
149  TListIter next(fGedEditor->GetPad()->GetListOfPrimitives());
150  delete fGedEditor->GetPad()->FindObject("Tframe");
151  TObject *obj;
152  while ((obj = next())) {
153  if (obj == fGedEditor->GetModel()) {
154  next.SetOption(option);
155  fGedEditor->GetPad()->Modified();
156  fGedEditor->GetPad()->Update();
157  return;
158  }
159  }
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Provide list of editors for base-classes.
164 /// In this class we return all classed with editors found via recursive
165 /// descent into list of base classes.
166 /// Override to control which editors are actually shown (see TH2Editor).
167 
168 void TGedFrame::ActivateBaseClassEditors(TClass* cl)
169 {
170  // printf("%s::FillListOfBaseEditors %s\n", IsA()->GetName(), cl->GetName());
171  if (cl->GetListOfBases()->IsEmpty() == kFALSE) {
172  fGedEditor->ActivateEditors(cl->GetListOfBases(), kTRUE);
173  }
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Create the frame containing the selected object name.
178 
179 TGedNameFrame::TGedNameFrame(const TGWindow *p, Int_t width,
180  Int_t height, UInt_t options, Pixel_t back)
181  : TGedFrame(p, width, height, options | kVerticalFrame, back)
182 {
183  fPriority = 0;
184 
185  f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
186  kFixedWidth |
187  kOwnBackground);
188  f1->AddFrame(new TGLabel(f1,"Name"),
189  new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
190  f1->AddFrame(new TGHorizontal3DLine(f1),
191  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
192  AddFrame(f1, new TGLayoutHints(kLHintsTop));
193 
194  f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame | kFixedWidth);
195  fLabel = new TGLabel(f2, "");
196  f2->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
197  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
198 
199  // Set red color for the name.
200  Pixel_t color;
201  gClient->GetColorByName("#ff0000", color);
202  fLabel->SetTextColor(color, kFALSE);
203 
204  // create tool tip with delay 300 ms
205  fTip = new TGToolTip(fClient->GetDefaultRoot(), this, "TGedNameFrame", 500);
206 
207  AddInput(kEnterWindowMask | kLeaveWindowMask | kKeyPressMask | kButtonPressMask);
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Destructor.
212 
213 TGedNameFrame::~TGedNameFrame()
214 {
215  delete fTip;
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Handle mouse crossing event for tooltip.
220 
221 Bool_t TGedNameFrame::HandleCrossing(Event_t *event)
222 {
223  if (event->fType == kEnterNotify)
224  fTip->Reset();
225  else
226  fTip->Hide();
227 
228  return kFALSE;
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Handle mouse button event.
233 
234 Bool_t TGedNameFrame::HandleButton(Event_t * /*event*/)
235 {
236  if (fTip) fTip->Hide();
237 
238  return kFALSE;
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Sets text for the label.
243 
244 void TGedNameFrame::SetModel(TObject* obj)
245 {
246  TString string;
247 
248  if (obj == 0) {
249  fLabel->SetText(new TGString("Object not selected"));
250  return;
251  }
252  string.Append(obj->GetName());
253  string.Append("::");
254  string.Append(obj->ClassName());
255 
256  fLabel->SetText(new TGString(string));
257  string = TString::Format("Name: %s\nTitle: %s\nClass: %s",
258  obj->GetName(), obj->GetTitle(), obj->ClassName());
259  fTip->SetText(string);
260 
261  // Resize label-frame to a reasonable width.
262  {
263  TGCanvas *canvas = fGedEditor->GetTGCanvas();
264  TGVScrollBar *vsb = canvas->GetVScrollbar();
265 
266  Int_t hscrollw = (vsb && vsb->IsMapped()) ? vsb->GetWidth() : 0;
267  Int_t labwidth = TMath::Min(fLabel->GetDefaultSize().fWidth,
268  canvas->GetWidth() - 10 - hscrollw);
269  f2->SetWidth(TMath::Max(labwidth, 80));
270  }
271 }