Logo ROOT   6.12/07
Reference Guide
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 
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor of the base GUI attribute frame.
35 
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 = "";
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Destructor of the base GUI attribute frame.
53 
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 
74 {
75  fGedEditor->Update(this);
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Get draw options of the selected object.
80 
82 {
83  if (!fGedEditor->GetPad()) return "";
84 
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 {
99  kFitWidth |
100  kFixedWidth |
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 
113 {
114  if (fExtraTabs == 0) fExtraTabs = new TList();
115  fExtraTabs->Add(sf);
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 
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 
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 
146 {
147  if (!fGedEditor->GetPad() || !option) return;
148 
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 
169 {
170  // printf("%s::FillListOfBaseEditors %s\n", IsA()->GetName(), cl->GetName());
171  if (cl->GetListOfBases()->IsEmpty() == kFALSE) {
173  }
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Create the frame containing the selected object name.
178 
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 |
188  f1->AddFrame(new TGLabel(f1,"Name"),
189  new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
191  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
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 
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Destructor.
212 
214 {
215  delete fTip;
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Handle mouse crossing event for tooltip.
220 
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 
235 {
236  if (fTip) fTip->Hide();
237 
238  return kFALSE;
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Sets text for the label.
243 
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;
268  canvas->GetWidth() - 10 - hscrollw);
269  f2->SetWidth(TMath::Max(labwidth, 80));
270  }
271 }
TGedNameFrame(const TGedNameFrame &)
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3507
virtual TGCompositeFrame * GetEditorTab(const char *name)
Find or create tab with name.
Definition: TGedEditor.cxx:188
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
const char Option_t
Definition: RtypesCore.h:62
virtual ~TGedNameFrame()
Destructor.
Definition: TGedFrame.cxx:213
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition: TGedFrame.cxx:81
virtual void SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition: TGLabel.cxx:359
TGedFrame(const TGedFrame &)
void Reset()
Reset tool tip popup delay timer.
Definition: TGToolTip.cxx:259
virtual void Update()=0
void SetText(const char *new_text)
Set new tool tip text.
Definition: TGToolTip.cxx:386
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
void ActivateEditors(TList *bcl, Bool_t recurse)
Searches GedFrames for classes in the given list.
Definition: TGedEditor.cxx:564
virtual void SetModel(TObject *obj)
Sets text for the label.
Definition: TGedFrame.cxx:244
Basic string class.
Definition: TString.h:125
#define gClient
Definition: TGClient.h:166
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:246
static TGedEditor * GetFrameCreator()
Returns TGedEditor that currently creates TGedFrames.
Definition: TGedEditor.cxx:85
UInt_t GetWidth() const
Definition: TGFrame.h:271
Iterator of linked list.
Definition: TList.h:197
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGedFrame.cxx:234
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2365
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event for tooltip.
Definition: TGedFrame.cxx:221
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGCompositeFrame(const TGCompositeFrame &)
virtual TGVerticalFrame * CreateEditorTabSubFrame(const char *name)
Create a vertical frame to be used by 'owner' in extra tab 'name'.
Definition: TGedFrame.cxx:123
TGCanvas * GetTGCanvas() const
Definition: TGedEditor.h:83
A doubly linked list.
Definition: TList.h:44
const Mask_t kButtonPressMask
Definition: GuiTypes.h:160
const Mask_t kKeyPressMask
Definition: GuiTypes.h:158
virtual ~TGedFrame()
Destructor of the base GUI attribute frame.
Definition: TGedFrame.cxx:54
TGCompositeFrame * f2
Definition: TGedFrame.h:99
UInt_t fWidth
Definition: TGDimension.h:29
TGToolTip * fTip
Definition: TGedFrame.h:100
virtual void Update(TGedFrame *frame=0)
Virtual method that is called on any change in the dependent frames.
Definition: TGedEditor.cxx:177
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:321
EGEventType fType
Definition: GuiTypes.h:174
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Refresh(TObject *model)
Refresh the GUI info about the object attributes.
Definition: TGedFrame.cxx:135
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual TList * GetListOfPrimitives() const =0
TString fName
Definition: TGWindow.h:39
TGCompositeFrame * fFrame
Definition: TGedFrame.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:88
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
virtual void Modified(Bool_t flag=1)=0
virtual void SetWidth(UInt_t w)
Definition: TGFrame.h:293
TGLabel * fLabel
Definition: TGedFrame.h:98
virtual Bool_t IsEmpty() const
Definition: TCollection.h:184
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TGedFrame.cxx:145
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void SetModel(TObject *obj)=0
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:180
virtual Option_t * GetOption() const
Definition: TObject.h:120
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void AddExtraTab(TGedSubFrame *sf)
Adds tab container to list of extra tabs.
Definition: TGedFrame.cxx:112
TGClient * fClient
Definition: TGObject.h:37
TGCompositeFrame * f1
Definition: TGedFrame.h:99
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
TF1 * f1
Definition: legend1.C:11
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual TGDimension GetDefaultSize() const
Return default size.
Definition: TGLabel.cxx:165
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
TGVScrollBar * GetVScrollbar() const
Definition: TGCanvas.h:229
char name[80]
Definition: TGX11.cxx:109
TList * fExtraTabs
Definition: TGedFrame.h:58
Int_t fPriority
Definition: TGedFrame.h:59
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
Definition: TGedFrame.cxx:168