Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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\ingroup Base
14
15Using a TBrowser one can browse all ROOT objects. It shows in a list
16on the left side of the window all browsable ROOT classes. Selecting
17one of the classes displays, in the icon-box on the right side, all
18objects in the class. Selecting one of the objects in the icon-box,
19will place all browsable objects in a new list and draws the
20contents of the selected class in the icon-box. And so on....
21
22\image html base_browser.png
23
24\since **ROOT version 6.24/00**
25
26TBrowser invokes by default the Web-based %ROOT file browser [RBrowser](\ref ROOT::Experimental::RBrowser)
27To change this behaviour, and invoke the standard TBrowser, one should put
28the following directive in the `.rootrc` file:
29```
30Browser.Name: TRootBrowser
31```
32*/
33
34#include "TBrowser.h"
35#include "TGuiFactory.h"
36#include "TROOT.h"
37#include "TSystem.h"
38#include "TStyle.h"
39#include "TTimer.h"
40#include "TContextMenu.h"
41#include "TInterpreter.h"
42#include "TVirtualMutex.h"
43#include "TClass.h"
44#include "TApplication.h"
45
46/** \class TBrowserTimer
47Called whenever timer times out.
48*/
49
50class TBrowserTimer : public TTimer {
51
52protected:
55
56public:
58 : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
59 Bool_t Notify();
60};
61
62/** \class TBrowserObject
63This class is designed to wrap a Foreign object in order to inject it into the Browse sub-system.
64*/
65
66class TBrowserObject : public TNamed
67{
68
69public:
70
71 TBrowserObject(void *obj, TClass *cl, const char *brname);
73
74 void Browse(TBrowser* b);
75 Bool_t IsFolder() const;
76 TClass *IsA() const { return fClass; }
77
78private:
79 void *fObj; ///<! pointer to the foreign object
80 TClass *fClass; ///<! pointer to class of the foreign object
81
82};
83
84
86
87////////////////////////////////////////////////////////////////////////////////
88// Make sure the application environment exists and the GUI libs are loaded
89
91{
92 // Make sure the application environment exists. It is need for graphics
93 // (colors are initialized in the TApplication ctor).
94 if (!gApplication)
96 // make sure that the Gpad and GUI libs are loaded
98 if (gApplication)
100 if (gROOT->IsBatch()) {
101 Warning("TBrowser", "The ROOT browser cannot run in batch mode");
102 return kFALSE;
103 }
104 return kTRUE;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Create a new browser with a name, title. Width and height are by
109/// default set to 640x400 and (optionally) adjusted by the screen factor
110/// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
111/// is true).
112
113TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp,
114 Option_t *opt)
115 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0),
116 fContextMenu(0), fNeedRefresh(kFALSE)
117{
118 if (!InitGraphics())
119 return;
121 fImp = 0;
122 } else {
124 UInt_t w = UInt_t(cx*800);
125 UInt_t h = UInt_t(cx*500);
126 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
127 Create();
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Create a new browser with a name, title, width and height.
133
134TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
135 UInt_t height, TBrowserImp *extimp, Option_t *opt)
136 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
137 fNeedRefresh(kFALSE)
138{
139 if (!InitGraphics())
140 return;
141 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
142 Create();
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Create a new browser with a name, title, position, width and height.
147
148TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
149 UInt_t width, UInt_t height, TBrowserImp *extimp, Option_t *opt)
150 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
151 fNeedRefresh(kFALSE)
152{
153 if (!InitGraphics())
154 return;
155 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
156 Create();
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Create a new browser with a name, title, width and height for TObject *obj.
161
162TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
163 : TNamed(name, title), fLastSelectedObject(0), fImp(0), fTimer(0), fContextMenu(0),
164 fNeedRefresh(kFALSE)
165{
166 if (!InitGraphics())
167 return;
169 UInt_t w = UInt_t(cx*800);
170 UInt_t h = UInt_t(cx*500);
171
172 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
173 Create(obj);
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Create a new browser with a name, title, width and height for TObject *obj.
178
179TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
180 UInt_t width, UInt_t height, Option_t *opt)
181 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
182 fNeedRefresh(kFALSE)
183{
184 if (!InitGraphics())
185 return;
186 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
187 Create(obj);
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Create a new browser with a name, title, width and height for TObject *obj.
192
193TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
194 Int_t x, Int_t y,
195 UInt_t width, UInt_t height, Option_t *opt)
196 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
197 fNeedRefresh(kFALSE)
198{
199 if (!InitGraphics())
200 return;
201 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
202 Create(obj);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Create a new browser with a name, title, width and height for TObject *obj.
207
208TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
209 const char *objname, const char *title, Option_t *opt)
210 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
211 fNeedRefresh(kFALSE)
212{
213 if (!InitGraphics())
214 return;
216 UInt_t w = UInt_t(cx*800);
217 UInt_t h = UInt_t(cx*500);
218
219 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
220
221 Create(new TBrowserObject(obj,cl,objname));
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Create a new browser with a name, title, width and height for TObject *obj.
226
227TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
228 const char *objname, const char *title,
229 UInt_t width, UInt_t height, Option_t *opt)
230 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
231 fNeedRefresh(kFALSE)
232{
233 if (!InitGraphics())
234 return;
235 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
236 Create(new TBrowserObject(obj,cl,objname));
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Create a new browser with a name, title, width and height for TObject *obj.
241
242TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
243 const char *objname, const char *title,
244 Int_t x, Int_t y,
245 UInt_t width, UInt_t height, Option_t *opt)
246 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
247 fNeedRefresh(kFALSE)
248{
249 if (!InitGraphics())
250 return;
251 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
252 Create(new TBrowserObject(obj,cl,objname));
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Delete the browser.
257
259{
260 Destructor();
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Actual browser destructor.
265
267{
268 if (fImp) fImp->CloseTabs();
270 gROOT->GetListOfBrowsers()->Remove(this);
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Add object with name to browser. If name not set the objects GetName()
278/// is used. If check < 0 (default) no check box is drawn, if 0 then
279/// unchecked checkbox is added, if 1 checked checkbox is added.
280
281void TBrowser::Add(TObject *obj, const char *name, Int_t check)
282{
283 if (obj && fImp) {
284 fImp->Add(obj, name, check);
285 obj->SetBit(kMustCleanup);
286 }
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Add foreign object with name to browser.
291/// 'cl' is the type use to store the value of obj.
292/// So literally the following pseudo code should be correct:
293///~~~ {.cpp}
294/// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
295///~~~
296/// and the value of obj is not necessarily the start of the object.
297/// If check < 0 (default) no check box is drawn, if 0 then
298/// unchecked checkbox is added, if 1 checked checkbox is added.
299
300void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
301{
302 if (!obj || !cl) return;
303 TObject *to;
304 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
305 else to = new TBrowserObject(obj,cl,name);
306
307 if (!to) return;
308 Add(to,name,check);
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Add checkbox for this item.
313
315{
316 if (obj && fImp) {
317 fImp->AddCheckBox(obj, check);
318 }
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Change status of checkbox for this item.
323
325{
326 if (obj && fImp) {
327 fImp->CheckObjectItem(obj, check);
328 }
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Remove checkbox for this item.
333
335{
336 if (obj && fImp) {
337 fImp->RemoveCheckBox(obj);
338 }
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Create the browser, called by the ctors.
343
345{
347
348 fTimer = new TBrowserTimer(this);
350
352 gROOT->GetListOfBrowsers()->Add(this);
353
354 // Get the list of globals
355 gROOT->GetListOfGlobals(kTRUE);
356 gROOT->GetListOfGlobalFunctions(kTRUE);
357
358 fContextMenu = new TContextMenu("BrowserContextMenu") ;
359
360 // Fill the first list from the present TObject obj
361 if (obj) {
362 Add(obj);
363 if (fImp) fImp->BrowseObj(obj);
364 } else if (fImp) {
365 // Fill the first list with all browsable classes from TROOT
367 }
368
369 // The first list will be filled by TWin32BrowserImp ctor
370 // with all browsable classes from TROOT
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Execute default action for selected object (action is specified
375/// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
376
378{
379 if (obj && fImp)
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Recursively remove obj from browser.
385
387{
388 if (fImp && obj) {
389 fImp->RecursiveRemove(obj);
391 }
392}
393
394////////////////////////////////////////////////////////////////////////////////
395/// Refresh browser contents.
396
398{
400 if (fImp) fImp->Refresh();
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Assign the last selected object.
406
407void TBrowser::SetSelected(TObject *clickedObject)
408{
409 fLastSelectedObject = clickedObject;
410}
411
413{
414 if (fBrowser) {
415 if (fBrowser->GetRefreshFlag()) {
418 } else if (fActivate) {
420 fBrowser->Refresh();
421 }
422 }
423 Reset();
424
425 return kFALSE;
426}
427
428
429////////////////////////////////////////////////////////////////////////////////
430/// Constructor.
431
432TBrowserObject::TBrowserObject(void *obj, TClass *cl, const char *brname)
433 : TNamed(brname, cl ? cl->GetName() : ""), fObj(obj), fClass(cl)
434{
435 if (cl==0) Fatal("Constructor","Class parameter should not be null");
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Return kTRUE if the object is a folder (contains browsable objects).
441
443{
444 return fClass->IsFolder(fObj);
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Browse the content of the underlying object.
449
451{
452 fClass->Browse(fObj, b);
453}
Cppyy::TCppType_t fClass
#define SafeDelete(p)
Definition RConfig.hxx:537
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TApplication * gApplication
include TDocParser_001 C image html pict1_TDocParser_001 png width
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGuiFactory * gGuiFactory
Definition TGuiFactory.h:66
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:404
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define R__LOCKGUARD(mutex)
void InitializeGraphics()
Initialize the graphics environment.
static void CreateApplication()
Static function used to create a default application environment.
static void NeedGraphicsLibs()
Static method.
ABC describing GUI independent browser implementation protocol.
Definition TBrowserImp.h:29
virtual void ExecuteDefaultAction(TObject *)
Definition TBrowserImp.h:51
virtual void CloseTabs()
Definition TBrowserImp.h:50
virtual void RemoveCheckBox(TObject *)
Definition TBrowserImp.h:47
virtual void AddCheckBox(TObject *, Bool_t=kFALSE)
Definition TBrowserImp.h:45
virtual void BrowseObj(TObject *)
Definition TBrowserImp.h:48
virtual void RecursiveRemove(TObject *)
Definition TBrowserImp.h:53
virtual void Refresh(Bool_t=kFALSE)
Definition TBrowserImp.h:54
virtual void CheckObjectItem(TObject *, Bool_t=kFALSE)
Definition TBrowserImp.h:46
virtual void Add(TObject *, const char *, Int_t)
Definition TBrowserImp.h:44
This class is designed to wrap a Foreign object in order to inject it into the Browse sub-system.
Definition TBrowser.cxx:67
TBrowserObject(void *obj, TClass *cl, const char *brname)
Constructor.
Definition TBrowser.cxx:432
TClass * IsA() const
Definition TBrowser.cxx:76
TClass * fClass
! pointer to class of the foreign object
Definition TBrowser.cxx:80
void Browse(TBrowser *b)
Browse the content of the underlying object.
Definition TBrowser.cxx:450
void * fObj
! pointer to the foreign object
Definition TBrowser.cxx:79
Bool_t IsFolder() const
Return kTRUE if the object is a folder (contains browsable objects).
Definition TBrowser.cxx:442
Called whenever timer times out.
Definition TBrowser.cxx:50
TBrowserTimer(TBrowser *b, Long_t ms=1000)
Definition TBrowser.cxx:57
Bool_t fActivate
Definition TBrowser.cxx:54
Bool_t Notify()
Notify when timer times out.
Definition TBrowser.cxx:412
TBrowser * fBrowser
Definition TBrowser.cxx:53
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
virtual void Create(TObject *obj=0)
Create the browser, called by the ctors.
Definition TBrowser.cxx:344
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition TBrowser.cxx:324
TBrowserImp * fImp
Definition TBrowser.h:46
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition TBrowser.cxx:281
TObject * fLastSelectedObject
Definition TBrowser.h:40
void SetRefreshFlag(Bool_t flag)
Definition TBrowser.h:99
virtual ~TBrowser()
Delete the browser.
Definition TBrowser.cxx:258
TContextMenu * fContextMenu
Browser's timer.
Definition TBrowser.h:48
virtual void Destructor()
Actual browser destructor.
Definition TBrowser.cxx:266
Bool_t InitGraphics()
Definition TBrowser.cxx:90
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition TBrowser.cxx:334
TBrowserTimer * fTimer
Window system specific browser implementation.
Definition TBrowser.h:47
void Refresh()
Refresh browser contents.
Definition TBrowser.cxx:397
TBrowser(const TBrowser &)=delete
The last TObject selected by user.
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition TBrowser.cxx:407
Bool_t fNeedRefresh
Context menu pointer.
Definition TBrowser.h:49
Bool_t GetRefreshFlag() const
Definition TBrowser.h:97
void ExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root....
Definition TBrowser.cxx:377
virtual void RecursiveRemove(TObject *obj)
Recursively remove obj from browser.
Definition TBrowser.cxx:386
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition TBrowser.cxx:314
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TClass.h:512
virtual void Browse(TBrowser *b)
This method is called by a browser to get the class information.
Definition TClass.cxx:2008
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:4901
@ kRealNew
Definition TClass.h:107
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition TClass.cxx:5888
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:5924
This class provides an interface to context sensitive popup menus.
virtual TBrowserImp * CreateBrowserImp(TBrowser *b, const char *title, UInt_t width, UInt_t height, Option_t *opt="")
Create a batch version of TBrowserImp.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:949
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:766
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:991
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:64
Float_t GetScreenFactor() const
Definition TStyle.h:247
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:474
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:157
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17