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