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::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 "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 Bool_t isweb = gROOT->IsWebDisplay();
117
118 if (gApplication)
120
121 if (!gROOT->IsBatch() || (isweb && !gROOT->IsWebDisplayBatch()))
122 return kTRUE;
123
124 Warning("TBrowser", "The ROOT browser cannot run in batch mode");
125 return kFALSE;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Create a new browser with a name, title. Width and height are by
130/// default set to 640x400 and (optionally) adjusted by the screen factor
131/// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
132/// is true).
133
134TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp, Option_t *opt)
135 : TNamed(name, title), fImp(extimp)
136{
137 if (!InitGraphics())
138 return;
140 fImp = nullptr;
141 } else {
143 UInt_t w = UInt_t(cx*800);
144 UInt_t h = UInt_t(cx*500);
145 if (!fImp)
146 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
147 Create();
148 }
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Create a new browser with a name, title, width and height.
153
154TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
155 UInt_t height, TBrowserImp *extimp, Option_t *opt)
156 : TNamed(name, title), fImp(extimp)
157{
158 if (!InitGraphics())
159 return;
160 if (!fImp)
161 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
162 Create();
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Create a new browser with a name, title, position, width and height.
167
168TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
170 : TNamed(name, title), fImp(extimp)
171{
172 if (!InitGraphics())
173 return;
174 if (!fImp)
175 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
176 Create();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Create a new browser with a name, title, width and height for TObject *obj.
181
182TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
183 : TNamed(name, title)
184{
185 if (!InitGraphics())
186 return;
188 UInt_t w = UInt_t(cx*800);
189 UInt_t h = UInt_t(cx*500);
190
191 if (!fImp)
192 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
193 Create(obj);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Create a new browser with a name, title, width and height for TObject *obj.
198
199TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
201 : TNamed(name, title)
202{
203 if (!InitGraphics())
204 return;
205 if (!fImp)
206 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
207 Create(obj);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Create a new browser with a name, title, width and height for TObject *obj.
212
213TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
214 Int_t x, Int_t y,
216 : TNamed(name, title)
217{
218 if (!InitGraphics())
219 return;
220 if (!fImp)
221 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
222 Create(obj);
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Create a new browser with a name, title, width and height for TObject *obj.
227
228TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
229 const char *objname, const char *title, Option_t *opt)
230 : TNamed(name, title)
231{
232 if (!InitGraphics())
233 return;
235 UInt_t w = UInt_t(cx*800);
236 UInt_t h = UInt_t(cx*500);
237
238 if (!fImp)
239 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
240
241 Create(new TBrowserObject(obj,cl,objname));
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Create a new browser with a name, title, width and height for TObject *obj.
246
247TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
248 const char *objname, const char *title,
250 : TNamed(name, title)
251{
252 if (!InitGraphics())
253 return;
254 if (!fImp)
255 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
256 Create(new TBrowserObject(obj,cl,objname));
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Create a new browser with a name, title, width and height for TObject *obj.
261
262TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
263 const char *objname, const char *title,
264 Int_t x, Int_t y,
266 : TNamed(name, title)
267{
268 if (!InitGraphics())
269 return;
270 if (!fImp)
271 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
272 Create(new TBrowserObject(obj,cl,objname));
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Delete the browser.
277
279{
280 Destructor();
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Actual browser destructor.
285
287{
288 if (fImp) fImp->CloseTabs();
290 gROOT->GetListOfBrowsers()->Remove(this);
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Add object with name to browser. If name not set the objects GetName()
298/// is used. If check < 0 (default) no check box is drawn, if 0 then
299/// unchecked checkbox is added, if 1 checked checkbox is added.
300
301void TBrowser::Add(TObject *obj, const char *name, Int_t check)
302{
303 if (obj && fImp) {
304 fImp->Add(obj, name, check);
305 obj->SetBit(kMustCleanup);
306 }
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Add foreign object with name to browser.
311/// 'cl' is the type use to store the value of obj.
312/// So literally the following pseudo code should be correct:
313///~~~ {.cpp}
314/// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
315///~~~
316/// and the value of obj is not necessarily the start of the object.
317/// If check < 0 (default) no check box is drawn, if 0 then
318/// unchecked checkbox is added, if 1 checked checkbox is added.
319
320void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
321{
322 if (!obj || !cl) return;
323 TObject *to;
324 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
325 else to = new TBrowserObject(obj,cl,name);
326
327 if (!to) return;
328 Add(to,name,check);
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Add checkbox for this item.
333
335{
336 if (obj && fImp) {
337 fImp->AddCheckBox(obj, check);
338 }
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Change status of checkbox for this item.
343
345{
346 if (obj && fImp) {
347 fImp->CheckObjectItem(obj, check);
348 }
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// Remove checkbox for this item.
353
355{
356 if (obj && fImp) {
357 fImp->RemoveCheckBox(obj);
358 }
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Create the browser, called by the ctors.
363
365{
367
368 fTimer = new TBrowserTimer(this);
370
372 gROOT->GetListOfBrowsers()->Add(this);
373
374 // Get the list of globals
375 gROOT->GetListOfGlobals(kTRUE);
376 gROOT->GetListOfGlobalFunctions(kTRUE);
377
378 fContextMenu = new TContextMenu("BrowserContextMenu") ;
379
380 // Fill the first list from the present TObject obj
381 if (obj) {
382 Add(obj);
383 if (fImp) fImp->BrowseObj(obj);
384 } else if (fImp) {
385 // Fill the first list with all browsable classes from TROOT
387 }
388
389 // The first list will be filled by TWin32BrowserImp ctor
390 // with all browsable classes from TROOT
391}
392
393////////////////////////////////////////////////////////////////////////////////
394/// Execute default action for selected object (action is specified
395/// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
396
398{
399 if (obj && fImp)
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Recursively remove obj from browser.
405
407{
408 if (fImp && obj) {
409 fImp->RecursiveRemove(obj);
411 }
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Refresh browser contents.
416
418{
420 if (fImp) fImp->Refresh();
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// Assign the last selected object.
426
427void TBrowser::SetSelected(TObject *clickedObject)
428{
429 fLastSelectedObject = clickedObject;
430}
#define SafeDelete(p)
Definition RConfig.hxx:540
#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:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TApplication * gApplication
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:405
R__EXTERN TStyle * gStyle
Definition TStyle.h:414
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
#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.
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:406
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition TBrowser.cxx:344
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:278
TContextMenu * fContextMenu
Browser's timer.
Definition TBrowser.h:48
virtual void Destructor()
Actual browser destructor.
Definition TBrowser.cxx:286
Bool_t InitGraphics()
Definition TBrowser.cxx:107
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition TBrowser.cxx:354
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:364
void Refresh()
Refresh browser contents.
Definition TBrowser.cxx:417
TBrowser(const TBrowser &)=delete
The last TObject selected by user.
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition TBrowser.cxx:427
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:397
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition TBrowser.cxx:334
void Add(TObject *obj, const char *name=nullptr, Int_t check=-1)
Add object with name to browser.
Definition TBrowser.cxx:301
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:108
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:513
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
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:956
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:774
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:998
@ 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:248
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:159
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17