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
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
103
104////////////////////////////////////////////////////////////////////////////////
105// Make sure the application environment exists and the GUI libs are loaded
106
108{
109 // Make sure the application environment exists. It is need for graphics
110 // (colors are initialized in the TApplication ctor).
111 if (!gApplication)
113 // make sure that the Gpad and GUI libs are loaded
115
116 TString hname = gEnv->GetValue("Browser.Name", "TRootBrowserLite");
117
118 Bool_t isweb = gROOT->IsWebDisplay() || (hname == "ROOT::RWebBrowserImp");
119
120 if (gApplication)
122
123 if (!gROOT->IsBatch() || (isweb && !gROOT->IsWebDisplayBatch()))
124 return kTRUE;
125
126 Warning("TBrowser", "The ROOT browser cannot run in batch mode");
127 return kFALSE;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Create a new browser with a name, title. Width and height are by
132/// default set to 640x400 and (optionally) adjusted by the screen factor
133/// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
134/// is true).
135
136TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp, Option_t *opt)
137 : TNamed(name, title), fImp(extimp)
138{
139 if (!InitGraphics())
140 return;
142 fImp = nullptr;
143 } else {
145 UInt_t w = UInt_t(cx*800);
146 UInt_t h = UInt_t(cx*500);
147 if (!fImp)
148 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
149 Create();
150 }
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Create a new browser with a name, title, width and height.
155
156TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
157 UInt_t height, TBrowserImp *extimp, Option_t *opt)
158 : TNamed(name, title), fImp(extimp)
159{
160 if (!InitGraphics())
161 return;
162 if (!fImp)
163 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
164 Create();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Create a new browser with a name, title, position, width and height.
169
170TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
172 : TNamed(name, title), fImp(extimp)
173{
174 if (!InitGraphics())
175 return;
176 if (!fImp)
177 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
178 Create();
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Create a new browser with a name, title, width and height for TObject *obj.
183
184TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
185 : TNamed(name, title)
186{
187 if (!InitGraphics())
188 return;
190 UInt_t w = UInt_t(cx*800);
191 UInt_t h = UInt_t(cx*500);
192
193 if (!fImp)
194 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
195 Create(obj);
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Create a new browser with a name, title, width and height for TObject *obj.
200
201TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
203 : TNamed(name, title)
204{
205 if (!InitGraphics())
206 return;
207 if (!fImp)
208 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
209 Create(obj);
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Create a new browser with a name, title, width and height for TObject *obj.
214
215TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
216 Int_t x, Int_t y,
218 : TNamed(name, title)
219{
220 if (!InitGraphics())
221 return;
222 if (!fImp)
223 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
224 Create(obj);
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Create a new browser with a name, title, width and height for TObject *obj.
229
230TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
231 const char *objname, const char *title, Option_t *opt)
232 : TNamed(name, title)
233{
234 if (!InitGraphics())
235 return;
237 UInt_t w = UInt_t(cx*800);
238 UInt_t h = UInt_t(cx*500);
239
240 if (!fImp)
241 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
242
243 Create(new TBrowserObject(obj,cl,objname));
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Create a new browser with a name, title, width and height for TObject *obj.
248
249TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
250 const char *objname, const char *title,
252 : TNamed(name, title)
253{
254 if (!InitGraphics())
255 return;
256 if (!fImp)
257 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
258 Create(new TBrowserObject(obj,cl,objname));
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Create a new browser with a name, title, width and height for TObject *obj.
263
264TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
265 const char *objname, const char *title,
266 Int_t x, Int_t y,
268 : TNamed(name, title)
269{
270 if (!InitGraphics())
271 return;
272 if (!fImp)
273 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
274 Create(new TBrowserObject(obj,cl,objname));
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Delete the browser.
279
281{
282 Destructor();
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Actual browser destructor.
287
289{
290 if (fImp) fImp->CloseTabs();
292 gROOT->GetListOfBrowsers()->Remove(this);
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Add object with name to browser. If name not set the objects GetName()
300/// is used. If check < 0 (default) no check box is drawn, if 0 then
301/// unchecked checkbox is added, if 1 checked checkbox is added.
302
303void TBrowser::Add(TObject *obj, const char *name, Int_t check)
304{
305 if (obj && fImp) {
306 fImp->Add(obj, name, check);
307 obj->SetBit(kMustCleanup);
308 }
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Add foreign object with name to browser.
313/// 'cl' is the type use to store the value of obj.
314/// So literally the following pseudo code should be correct:
315///~~~ {.cpp}
316/// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
317///~~~
318/// and the value of obj is not necessarily the start of the object.
319/// If check < 0 (default) no check box is drawn, if 0 then
320/// unchecked checkbox is added, if 1 checked checkbox is added.
321
322void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
323{
324 if (!obj || !cl) return;
325 TObject *to;
326 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
327 else to = new TBrowserObject(obj,cl,name);
328
329 if (!to) return;
330 Add(to,name,check);
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Add checkbox for this item.
335
337{
338 if (obj && fImp) {
339 fImp->AddCheckBox(obj, check);
340 }
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Change status of checkbox for this item.
345
347{
348 if (obj && fImp) {
349 fImp->CheckObjectItem(obj, check);
350 }
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Remove checkbox for this item.
355
357{
358 if (obj && fImp) {
359 fImp->RemoveCheckBox(obj);
360 }
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Create the browser, called by the ctors.
365
367{
369
370 fTimer = new TBrowserTimer(this);
372
374 gROOT->GetListOfBrowsers()->Add(this);
375
376 // Get the list of globals
377 gROOT->GetListOfGlobals(kTRUE);
378 gROOT->GetListOfGlobalFunctions(kTRUE);
379
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/// Execute default action for selected object (action is specified
397/// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
398
400{
401 if (obj && fImp)
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// Recursively remove obj from browser.
407
409{
410 if (fImp && obj) {
411 fImp->RecursiveRemove(obj);
413 }
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Refresh browser contents.
418
420{
422 if (fImp) fImp->Refresh();
424}
425
426////////////////////////////////////////////////////////////////////////////////
427/// Assign the last selected object.
428
429void TBrowser::SetSelected(TObject *clickedObject)
430{
431 fLastSelectedObject = clickedObject;
432}
#define SafeDelete(p)
Definition RConfig.hxx:525
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
R__EXTERN TApplication * gApplication
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:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
#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 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
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:408
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition TBrowser.cxx:346
TBrowserImp * fImp
Definition TBrowser.h:46
TObject * fLastSelectedObject
Definition TBrowser.h:40
void SetRefreshFlag(Bool_t flag)
Definition TBrowser.h:99
virtual ~TBrowser()
Delete the browser.
Definition TBrowser.cxx:280
TContextMenu * fContextMenu
Browser's timer.
Definition TBrowser.h:48
virtual void Destructor()
Actual browser destructor.
Definition TBrowser.cxx:288
Bool_t InitGraphics()
Definition TBrowser.cxx:107
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition TBrowser.cxx:356
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:366
void Refresh()
Refresh browser contents.
Definition TBrowser.cxx:419
TBrowser(const TBrowser &)=delete
The last TObject selected by user.
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition TBrowser.cxx:429
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:399
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition TBrowser.cxx:336
void Add(TObject *obj, const char *name=nullptr, Int_t check=-1)
Add object with name to browser.
Definition TBrowser.cxx:303
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
void Browse(TBrowser *b) override
This method is called by a browser to get the class information.
Definition TClass.cxx:2010
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:4915
@ kRealNew
Definition TClass.h:107
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition TClass.cxx:5902
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:5938
Bool_t IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TClass.h:517
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:491
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:47
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:979
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:786
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1021
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:64
Basic string class.
Definition TString.h:139
Float_t GetScreenFactor() const
Definition TStyle.h:256
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:471
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:159
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17