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](ROOT::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 "TEnv.h"
38#include "TSystem.h"
39#include "TStyle.h"
40#include "TTimer.h"
41#include "TContextMenu.h"
42#include "TInterpreter.h"
43#include "TVirtualMutex.h"
44#include "TClass.h"
45#include "TApplication.h"
46
47/** \class TBrowserTimer
48Called whenever timer times out.
49*/
50
51class TBrowserTimer : public TTimer {
52
53protected:
54 TBrowser *fBrowser{nullptr};
56
57public:
59 Bool_t Notify() override
60 {
61 if (fBrowser) {
62 if (fBrowser->GetRefreshFlag()) {
65 } else if (fActivate) {
68 }
69 }
70 Reset();
71
72 return kFALSE;
73 }
74};
75
76/** \class TBrowserObject
77This class is designed to wrap a Foreign object in order to inject it into the Browse sub-system.
78*/
79
80class TBrowserObject : public TNamed {
81
82public:
83 TBrowserObject(void *obj, TClass *cl, const char *brname)
84 : TNamed(brname, cl ? cl->GetName() : ""), fObj(obj), fClass(cl)
85 {
86 if (!cl)
87 Fatal("Constructor", "Class parameter should not be null");
89 }
90
91 ~TBrowserObject() override {}
92
93 void Browse(TBrowser *b) override { fClass->Browse(fObj, b); }
94 Bool_t IsFolder() const override { return fClass->IsFolder(fObj); }
95 TClass *IsA() const override { return fClass; }
96
97private:
98 void *fObj; ///<! pointer to the foreign object
99 TClass *fClass; ///<! pointer to class of the foreign object
100};
101
102
103////////////////////////////////////////////////////////////////////////////////
104// Make sure the application environment exists and the GUI libs are loaded
105
107{
108 // Make sure the application environment exists. It is need for graphics
109 // (colors are initialized in the TApplication ctor).
110 if (!gApplication)
112 // make sure that the Gpad and GUI libs are loaded
114
115 TString hname = gEnv->GetValue("Browser.Name", "TRootBrowserLite");
116
117 Bool_t isweb = gROOT->IsWebDisplay() || (hname == "ROOT::RWebBrowserImp");
118
119 if (gApplication)
121
122 if (!gROOT->IsBatch() || (isweb && !gROOT->IsWebDisplayBatch()))
123 return kTRUE;
124
125 Warning("TBrowser", "The ROOT browser cannot run in batch mode");
126 return kFALSE;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Create a new browser with a name, title. Width and height are by
131/// default set to 640x400 and (optionally) adjusted by the screen factor
132/// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
133/// is true).
134
135TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp, Option_t *opt)
136 : TNamed(name, title), fImp(extimp)
137{
138 if (!InitGraphics())
139 return;
141 fImp = nullptr;
142 } else {
144 UInt_t w = UInt_t(cx*800);
145 UInt_t h = UInt_t(cx*500);
146 if (!fImp)
147 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
148 Create();
149 }
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Create a new browser with a name, title, width and height.
154
155TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
157 : TNamed(name, title), fImp(extimp)
158{
159 if (!InitGraphics())
160 return;
161 if (!fImp)
162 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
163 Create();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Create a new browser with a name, title, position, width and height.
168
169TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
171 : TNamed(name, title), fImp(extimp)
172{
173 if (!InitGraphics())
174 return;
175 if (!fImp)
176 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
177 Create();
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Create a new browser with a name, title, width and height for TObject *obj.
182
183TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
184 : TNamed(name, title)
185{
186 if (!InitGraphics())
187 return;
189 UInt_t w = UInt_t(cx*800);
190 UInt_t h = UInt_t(cx*500);
191
192 if (!fImp)
193 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
194 Create(obj);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Create a new browser with a name, title, width and height for TObject *obj.
199
200TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
202 : TNamed(name, title)
203{
204 if (!InitGraphics())
205 return;
206 if (!fImp)
207 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
208 Create(obj);
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Create a new browser with a name, title, width and height for TObject *obj.
213
214TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
215 Int_t x, Int_t y,
217 : TNamed(name, title)
218{
219 if (!InitGraphics())
220 return;
221 if (!fImp)
222 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
223 Create(obj);
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Create a new browser with a name, title, width and height for TObject *obj.
228
229TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
230 const char *objname, const char *title, Option_t *opt)
231 : TNamed(name, title)
232{
233 if (!InitGraphics())
234 return;
236 UInt_t w = UInt_t(cx*800);
237 UInt_t h = UInt_t(cx*500);
238
239 if (!fImp)
240 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
241
242 Create(new TBrowserObject(obj,cl,objname));
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Create a new browser with a name, title, width and height for TObject *obj.
247
248TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
249 const char *objname, const char *title,
251 : TNamed(name, title)
252{
253 if (!InitGraphics())
254 return;
255 if (!fImp)
256 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
257 Create(new TBrowserObject(obj,cl,objname));
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Create a new browser with a name, title, width and height for TObject *obj.
262
263TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
264 const char *objname, const char *title,
265 Int_t x, Int_t y,
267 : TNamed(name, title)
268{
269 if (!InitGraphics())
270 return;
271 if (!fImp)
272 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
273 Create(new TBrowserObject(obj,cl,objname));
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Delete the browser.
278
283
284////////////////////////////////////////////////////////////////////////////////
285/// Actual browser destructor.
286
288{
289 if (fImp) fImp->CloseTabs();
291 gROOT->GetListOfBrowsers()->Remove(this);
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Add object with name to browser. If name not set the objects GetName()
299/// is used. If check < 0 (default) no check box is drawn, if 0 then
300/// unchecked checkbox is added, if 1 checked checkbox is added.
301
302void TBrowser::Add(TObject *obj, const char *name, Int_t check)
303{
304 if (obj && fImp) {
305 fImp->Add(obj, name, check);
306 obj->SetBit(kMustCleanup);
307 }
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Add foreign object with name to browser.
312/// 'cl' is the type use to store the value of obj.
313/// So literally the following pseudo code should be correct:
314///~~~ {.cpp}
315/// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
316///~~~
317/// and the value of obj is not necessarily the start of the object.
318/// If check < 0 (default) no check box is drawn, if 0 then
319/// unchecked checkbox is added, if 1 checked checkbox is added.
320
321void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
322{
323 if (!obj || !cl) return;
324 TObject *to;
325 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
326 else to = new TBrowserObject(obj,cl,name);
327
328 if (!to) return;
329 Add(to,name,check);
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Add checkbox for this item.
334
336{
337 if (obj && fImp) {
338 fImp->AddCheckBox(obj, check);
339 }
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Change status of checkbox for this item.
344
346{
347 if (obj && fImp) {
349 }
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Remove checkbox for this item.
354
356{
357 if (obj && fImp) {
358 fImp->RemoveCheckBox(obj);
359 }
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Create the browser, called by the ctors.
364
366{
368
369 fTimer = new TBrowserTimer(this);
371
373 gROOT->GetListOfBrowsers()->Add(this);
374
375 // Get the list of globals
376 gROOT->GetListOfGlobals(kTRUE);
377 gROOT->GetListOfGlobalFunctions(kTRUE);
378
379 if (!IsWeb())
380 fContextMenu = new TContextMenu("BrowserContextMenu") ;
381
382 // Fill the first list from the present TObject obj
383 if (obj) {
384 Add(obj);
385 if (fImp) fImp->BrowseObj(obj);
386 } else if (fImp) {
387 // Fill the first list with all browsable classes from TROOT
389 }
390
391 // The first list will be filled by TWin32BrowserImp ctor
392 // with all browsable classes from TROOT
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Draw browser again if it was closed before
397/// If browser exists - just call Show method
398
400{
401 if (fImp) {
402 fImp->Show();
403 } else {
405 UInt_t w = UInt_t(cx*800);
406 UInt_t h = UInt_t(cx*500);
407 fImp = gGuiFactory->CreateBrowserImp(this, "ROOT Object Browser", w, h, "");
408 if (fImp)
410 }
411}
412
413
414////////////////////////////////////////////////////////////////////////////////
415/// Execute default action for selected object (action is specified
416/// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
417
419{
420 if (obj && fImp)
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// Recursively remove obj from browser.
426
428{
429 if (fImp && obj) {
430 fImp->RecursiveRemove(obj);
432 }
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// Refresh browser contents.
437
439{
441 if (fImp) fImp->Refresh();
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Assign the last selected object.
447
#define SafeDelete(p)
Definition RConfig.hxx:533
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
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:411
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD(mutex)
void InitializeGraphics(Bool_t only_web=kFALSE)
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 Show()
Definition TBrowserImp.h:55
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:80
TBrowserObject(void *obj, TClass *cl, const char *brname)
Definition TBrowser.cxx:83
TClass * IsA() const override
Definition TBrowser.cxx:95
~TBrowserObject() override
Definition TBrowser.cxx:91
Bool_t IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TBrowser.cxx:94
TClass * fClass
! pointer to class of the foreign object
Definition TBrowser.cxx:99
void * fObj
! pointer to the foreign object
Definition TBrowser.cxx:98
void Browse(TBrowser *b) override
Browse object. May be overridden for another default action.
Definition TBrowser.cxx:93
Called whenever timer times out.
Definition TBrowser.cxx:51
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
Definition TBrowser.cxx:59
TBrowserTimer(TBrowser *b, Long_t ms=1000)
Definition TBrowser.cxx:58
Bool_t fActivate
Definition TBrowser.cxx:55
TBrowser * fBrowser
Definition TBrowser.cxx:54
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
void RecursiveRemove(TObject *obj) override
Recursively remove obj from browser.
Definition TBrowser.cxx:427
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition TBrowser.cxx:345
TBrowserImp * fImp
Definition TBrowser.h:46
TObject * fLastSelectedObject
Definition TBrowser.h:40
void SetRefreshFlag(Bool_t flag)
Definition TBrowser.h:100
virtual ~TBrowser()
Delete the browser.
Definition TBrowser.cxx:279
TContextMenu * fContextMenu
Browser's timer.
Definition TBrowser.h:48
virtual void Destructor()
Actual browser destructor.
Definition TBrowser.cxx:287
Bool_t InitGraphics()
Definition TBrowser.cxx:106
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition TBrowser.cxx:355
TBrowserTimer * fTimer
Window system specific browser implementation.
Definition TBrowser.h:47
virtual void Create(TObject *obj=nullptr)
Create the browser, called by the ctors.
Definition TBrowser.cxx:365
void Refresh()
Refresh browser contents.
Definition TBrowser.cxx:438
TBrowser(const TBrowser &)=delete
The last TObject selected by user.
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition TBrowser.cxx:448
Bool_t fNeedRefresh
Context menu pointer.
Definition TBrowser.h:49
Bool_t GetRefreshFlag() const
Definition TBrowser.h:98
void ExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root....
Definition TBrowser.cxx:418
void Draw(Option_t *option="") override
Draw browser again if it was closed before If browser exists - just call Show method.
Definition TBrowser.cxx:399
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition TBrowser.cxx:335
Bool_t IsWeb() const
Definition TBrowser.h:95
void Add(TObject *obj, const char *name=nullptr, Int_t check=-1)
Add object with name to browser.
Definition TBrowser.cxx:302
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void Browse(TBrowser *b) override
This method is called by a browser to get the class information.
Definition TClass.cxx:2015
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:4942
@ kRealNew
Definition TClass.h:110
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition TClass.cxx:5944
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:5980
Bool_t IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TClass.h:530
This class provides an interface to context sensitive popup menus.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
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:1057
static TClass * Class()
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:70
Basic string class.
Definition TString.h:138
Float_t GetScreenFactor() const
Definition TStyle.h:258
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:469
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:162
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17