ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TBrowser.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 25/10/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 /** \class TBrowser
13 Using a TBrowser one can browse all ROOT objects. It shows in a list
14 on the left side of the window all browsable ROOT classes. Selecting
15 one of the classes displays, in the icon-box on the right side, all
16 objects in the class. Selecting one of the objects in the icon-box,
17 will place all browsable objects in a new list and draws the
18 contents of the selected class in the icon-box. And so on....
19 
20 \image html base_browser.png
21 */
22 
23 #include "TBrowser.h"
24 #include "TGuiFactory.h"
25 #include "TROOT.h"
26 #include "TSystem.h"
27 #include "TStyle.h"
28 #include "TTimer.h"
29 #include "TContextMenu.h"
30 #include "TInterpreter.h"
31 #include "TVirtualMutex.h"
32 #include "TClass.h"
33 #include "TApplication.h"
34 
35 /** \class TBrowserTimer
36 */
37 
38 class TBrowserTimer : public TTimer {
39 
40 protected:
41  TBrowser *fBrowser;
42  Bool_t fActivate;
43 
44 public:
45  TBrowserTimer(TBrowser *b, Long_t ms = 1000)
46  : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
47  Bool_t Notify();
48 };
49 
50 /** \class TBrowserObject
51 This class is designed to wrap a Foreign object in order to
52 inject it into the Browse sub-system.
53 */
54 
55 class TBrowserObject : public TNamed
56 {
57 
58 public:
59 
60  TBrowserObject(void *obj, TClass *cl, const char *brname);
61  ~TBrowserObject(){;}
62 
63  void Browse(TBrowser* b);
64  Bool_t IsFolder() const;
65  TClass *IsA() const { return fClass; }
66 
67 private:
68  void *fObj; //! pointer to the foreign object
69  TClass *fClass; //! pointer to class of the foreign object
70 
71 };
72 
73 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Create a new browser with a name, title. Width and height are by
78 /// default set to 640x400 and (optionally) adjusted by the screen factor
79 /// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
80 /// is true).
81 
82 TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp,
83  Option_t *opt)
84  : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0),
85  fContextMenu(0), fNeedRefresh(kFALSE)
86 {
87  // make sure that the Gpad and GUI libs are loaded
91  fImp = 0;
92  } else {
94  UInt_t w = UInt_t(cx*800);
95  UInt_t h = UInt_t(cx*500);
96  if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
97  Create();
98  }
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Create a new browser with a name, title, width and height.
103 
104 TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
105  UInt_t height, TBrowserImp *extimp, Option_t *opt)
106  : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
107  fNeedRefresh(kFALSE)
108 {
109  // make sure that the Gpad and GUI libs are loaded
112  if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
113  Create();
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Create a new browser with a name, title, position, width and height.
118 
119 TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
120  UInt_t width, UInt_t height, TBrowserImp *extimp, Option_t *opt)
121  : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
122  fNeedRefresh(kFALSE)
123 {
124  // make sure that the Gpad and GUI libs are loaded
127  fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
128  Create();
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Create a new browser with a name, title, width and height for TObject *obj.
133 
134 TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
135  : TNamed(name, title), fLastSelectedObject(0), fImp(0), fTimer(0), fContextMenu(0),
136  fNeedRefresh(kFALSE)
137 {
138  // make sure that the Gpad and GUI libs are loaded
142  UInt_t w = UInt_t(cx*800);
143  UInt_t h = UInt_t(cx*500);
144 
145  if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
146  Create(obj);
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Create a new browser with a name, title, width and height for TObject *obj.
151 
152 TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
153  UInt_t width, UInt_t height, Option_t *opt)
154  : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
155  fNeedRefresh(kFALSE)
156 {
157  // make sure that the Gpad and GUI libs are loaded
160  fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
161  Create(obj);
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Create a new browser with a name, title, width and height for TObject *obj.
166 
167 TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
168  Int_t x, Int_t y,
169  UInt_t width, UInt_t height, Option_t *opt)
170  : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
171  fNeedRefresh(kFALSE)
172 {
173  // make sure that the Gpad and GUI libs are loaded
176  fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
177  Create(obj);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Create a new browser with a name, title, width and height for TObject *obj.
182 
183 TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
184  const char *objname, const char *title, Option_t *opt)
185  : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
186  fNeedRefresh(kFALSE)
187 {
188  // make sure that the Gpad and GUI libs are loaded
192  UInt_t w = UInt_t(cx*800);
193  UInt_t h = UInt_t(cx*500);
194 
195  fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
196 
197  Create(new TBrowserObject(obj,cl,objname));
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Create a new browser with a name, title, width and height for TObject *obj.
202 
203 TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
204  const char *objname, const char *title,
205  UInt_t width, UInt_t height, Option_t *opt)
206  : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
207  fNeedRefresh(kFALSE)
208 {
209  // make sure that the Gpad and GUI libs are loaded
212  fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
213  Create(new TBrowserObject(obj,cl,objname));
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Create a new browser with a name, title, width and height for TObject *obj.
218 
219 TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
220  const char *objname, const char *title,
221  Int_t x, Int_t y,
222  UInt_t width, UInt_t height, Option_t *opt)
223  : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
224  fNeedRefresh(kFALSE)
225 {
226  // make sure that the Gpad and GUI libs are loaded
229  fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
230  Create(new TBrowserObject(obj,cl,objname));
231 }
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 /// Delete the browser.
235 
237 {
238  Destructor();
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Actual browser destructor.
243 
245 {
246  fImp->CloseTabs();
248  gROOT->GetListOfBrowsers()->Remove(this);
249  delete fContextMenu;
250  delete fTimer;
251  delete fImp;
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Add object with name to browser. If name not set the objects GetName()
256 /// is used. If check < 0 (default) no check box is drawn, if 0 then
257 /// unchecked checkbox is added, if 1 checked checkbox is added.
258 
259 void TBrowser::Add(TObject *obj, const char *name, Int_t check)
260 {
261  if (obj && fImp) {
262  fImp->Add(obj, name, check);
263  obj->SetBit(kMustCleanup);
264  }
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// Add foreign object with name to browser.
269 /// 'cl' is the type use to store the value of obj.
270 /// So literally the following pseudo code should be correct:
271 ///~~~ {.cpp}
272 /// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
273 ///~~~
274 /// and the value of obj is not necessarily the start of the object.
275 /// If check < 0 (default) no check box is drawn, if 0 then
276 /// unchecked checkbox is added, if 1 checked checkbox is added.
277 
278 void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
279 {
280  if (!obj || !cl) return;
281  TObject *to;
282  if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
283  else to = new TBrowserObject(obj,cl,name);
284 
285  if (!to) return;
286  Add(to,name,check);
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Add checkbox for this item.
291 
293 {
294  if (obj && fImp) {
295  fImp->AddCheckBox(obj, check);
296  }
297 }
298 
299 ////////////////////////////////////////////////////////////////////////////////
300 /// Change status of checkbox for this item.
301 
303 {
304  if (obj && fImp) {
305  fImp->CheckObjectItem(obj, check);
306  }
307 }
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 /// Remove checkbox for this item.
311 
313 {
314  if (obj && fImp) {
315  fImp->RemoveCheckBox(obj);
316  }
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// Create the browser, called by the ctors.
321 
323 {
325 
326  fTimer = new TBrowserTimer(this);
328 
330  gROOT->GetListOfBrowsers()->Add(this);
331 
332  // Get the list of globals
333  gROOT->GetListOfGlobals(kTRUE);
334  gROOT->GetListOfGlobalFunctions(kTRUE);
335 
336  fContextMenu = new TContextMenu("BrowserContextMenu") ;
337 
338  // Fill the first list from the present TObject obj
339  if (obj) {
340  Add(obj);
341  if (fImp) fImp->BrowseObj(obj);
342  } else if (fImp) {
343  // Fill the first list with all browsable classes from TROOT
344  fImp->BrowseObj(gROOT);
345  }
346 
347  // The first list will be filled by TWin32BrowserImp ctor
348  // with all browsable classes from TROOT
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Execute default action for selected object (action is specified
353 /// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
354 
356 {
357  if (obj && fImp)
359 }
360 
361 ////////////////////////////////////////////////////////////////////////////////
362 /// Recursively remove obj from browser.
363 
365 {
366  if (fImp && obj) {
367  fImp->RecursiveRemove(obj);
369  }
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 /// Refresh browser contents.
374 
376 {
378  if (fImp) fImp->Refresh();
380 }
381 
382 ////////////////////////////////////////////////////////////////////////////////
383 /// Assign the last selected object.
384 
385 void TBrowser::SetSelected(TObject *clickedObject)
386 {
387  fLastSelectedObject = clickedObject;
388 }
389 
390 /** \class TBrowserTimer
391 Called whenever timer times out.
392 */
393 
395 {
396  if (fBrowser) {
397  if (fBrowser->GetRefreshFlag()) {
398  fBrowser->SetRefreshFlag(kFALSE);
399  fActivate = kTRUE;
400  } else if (fActivate) {
401  fActivate = kFALSE;
402  fBrowser->Refresh();
403  }
404  }
405  Reset();
406 
407  return kFALSE;
408 }
409 
410 /** \class TBrowserObject
411 This is a wrapper class to emulate the TObject interface
412 around an object of a non-TObject class
413 */
414 
415 ////////////////////////////////////////////////////////////////////////////////
416 /// Constructor.
417 
418 TBrowserObject::TBrowserObject(void *obj, TClass *cl, const char *brname)
419  : TNamed(brname, cl ? cl->GetName() : ""), fObj(obj), fClass(cl)
420 {
421  if (cl==0) Fatal("Constructor","Class parameter should not be null");
423 }
424 
425 ////////////////////////////////////////////////////////////////////////////////
426 /// Return kTRUE if the object is a folder (contains browsable objects).
427 
428 Bool_t TBrowserObject::IsFolder() const
429 {
430  return fClass->IsFolder(fObj);
431 }
432 
433 ////////////////////////////////////////////////////////////////////////////////
434 /// Browse the content of the underlying object.
435 
436 void TBrowserObject::Browse(TBrowser* b)
437 {
438  fClass->Browse(fObj, b);
439 }
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:259
virtual void CheckObjectItem(TObject *, Bool_t=kFALSE)
Definition: TBrowserImp.h:51
virtual TBrowserImp * CreateBrowserImp(TBrowser *b, const char *title, UInt_t width, UInt_t height, Option_t *opt="")
Create a batch version of TBrowserImp.
Definition: TGuiFactory.cxx:71
void * fObj
virtual ~TBrowser()
Delete the browser.
Definition: TBrowser.cxx:236
TBrowserTimer * fTimer
Window system specific browser implementation.
Definition: TBrowser.h:51
virtual void BrowseObj(TObject *)
Definition: TBrowserImp.h:53
float Float_t
Definition: RtypesCore.h:53
TObject * fLastSelectedObject
Definition: TBrowser.h:44
const char Option_t
Definition: RtypesCore.h:62
TBrowser(const TBrowser &)
The last TObject selected by user.
virtual void ExecuteDefaultAction(TObject *)
Definition: TBrowserImp.h:56
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TH1 * h
Definition: legend2.C:5
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition: TClass.cxx:5462
Bool_t Notify()
Definition: TTimer.cxx:65
#define gROOT
Definition: TROOT.h:344
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:178
void ExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file).
Definition: TBrowser.cxx:355
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TObject.cxx:517
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
const Bool_t kFALSE
Definition: Rtypes.h:92
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition: TBrowser.cxx:302
virtual void CloseTabs()
Definition: TBrowserImp.h:55
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
ClassImp(TBrowser) TBrowser
Create a new browser with a name, title.
Definition: TBrowser.cxx:74
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition: TBrowser.cxx:385
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition: TBrowser.cxx:292
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
virtual void Create(TObject *obj=0)
Create the browser, called by the ctors.
Definition: TBrowser.cxx:322
Double_t x[n]
Definition: legend1.C:17
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void Class()
Definition: Class.C:29
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual void RecursiveRemove(TObject *)
Definition: TBrowserImp.h:58
TClass * fClass
pointer to the foreign object
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition: TClass.cxx:5426
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:68
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:141
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
static void NeedGraphicsLibs()
Static method.
Bool_t fNeedRefresh
Context menu pointer.
Definition: TBrowser.h:53
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
TClass * IsA() const
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:44
unsigned int UInt_t
Definition: RtypesCore.h:42
tuple w
Definition: qtexample.py:51
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual void Browse(TBrowser *b)
This method is called by a browser to get the class information.
Definition: TClass.cxx:1912
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void Reset(Detail::TBranchProxy *x)
virtual void Refresh(Bool_t=kFALSE)
Definition: TBrowserImp.h:59
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition: TBrowser.cxx:312
void InitializeGraphics()
Initialize the graphics environment.
long Long_t
Definition: RtypesCore.h:50
virtual void Add(TObject *, const char *, Int_t)
Definition: TBrowserImp.h:49
Double_t y[n]
Definition: legend1.C:17
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Destructor()
Actual browser destructor.
Definition: TBrowser.cxx:244
Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TClass.h:458
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:475
virtual void AddCheckBox(TObject *, Bool_t=kFALSE)
Definition: TBrowserImp.h:50
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
Definition: TClass.cxx:4539
TBrowserImp * fImp
Definition: TBrowser.h:50
TContextMenu * fContextMenu
Browser's timer.
Definition: TBrowser.h:52
const Bool_t kTRUE
Definition: Rtypes.h:91
Float_t GetScreenFactor() const
Definition: TStyle.h:264
void Refresh()
Refresh browser contents.
Definition: TBrowser.cxx:375
virtual void RemoveCheckBox(TObject *)
Definition: TBrowserImp.h:52
virtual void RecursiveRemove(TObject *obj)
Recursively remove obj from browser.
Definition: TBrowser.cxx:364
ABC describing GUI independent browser implementation protocol.
Definition: TBrowserImp.h:31