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
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// Make sure the application environment exists and the GUI libs are loaded
80
82{
83 // Make sure the application environment exists. It is need for graphics
84 // (colors are initialized in the TApplication ctor).
85 if (!gApplication)
87 // make sure that the Gpad and GUI libs are loaded
89 if (gApplication)
91 if (gROOT->IsBatch()) {
92 Warning("TBrowser", "The ROOT browser cannot run in batch mode");
93 return kFALSE;
94 }
95 return kTRUE;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Create a new browser with a name, title. Width and height are by
100/// default set to 640x400 and (optionally) adjusted by the screen factor
101/// (depending on Rint.Canvas.UseScreenFactor to be true or false, default
102/// is true).
103
104TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp,
105 Option_t *opt)
106 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0),
107 fContextMenu(0), fNeedRefresh(kFALSE)
108{
109 if (!InitGraphics())
110 return;
112 fImp = 0;
113 } else {
115 UInt_t w = UInt_t(cx*800);
116 UInt_t h = UInt_t(cx*500);
117 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
118 Create();
119 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Create a new browser with a name, title, width and height.
124
125TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
126 UInt_t height, TBrowserImp *extimp, Option_t *opt)
127 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
128 fNeedRefresh(kFALSE)
129{
130 if (!InitGraphics())
131 return;
132 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
133 Create();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Create a new browser with a name, title, position, width and height.
138
139TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
140 UInt_t width, UInt_t height, TBrowserImp *extimp, Option_t *opt)
141 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
142 fNeedRefresh(kFALSE)
143{
144 if (!InitGraphics())
145 return;
146 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
147 Create();
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Create a new browser with a name, title, width and height for TObject *obj.
152
153TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
154 : TNamed(name, title), fLastSelectedObject(0), fImp(0), fTimer(0), fContextMenu(0),
155 fNeedRefresh(kFALSE)
156{
157 if (!InitGraphics())
158 return;
160 UInt_t w = UInt_t(cx*800);
161 UInt_t h = UInt_t(cx*500);
162
163 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
164 Create(obj);
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Create a new browser with a name, title, width and height for TObject *obj.
169
170TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
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 if (!InitGraphics())
176 return;
177 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
178 Create(obj);
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,
185 Int_t x, Int_t y,
186 UInt_t width, UInt_t height, Option_t *opt)
187 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
188 fNeedRefresh(kFALSE)
189{
190 if (!InitGraphics())
191 return;
192 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, 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, void *obj, TClass *cl,
200 const char *objname, const char *title, Option_t *opt)
201 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
202 fNeedRefresh(kFALSE)
203{
204 if (!InitGraphics())
205 return;
207 UInt_t w = UInt_t(cx*800);
208 UInt_t h = UInt_t(cx*500);
209
210 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
211
212 Create(new TBrowserObject(obj,cl,objname));
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Create a new browser with a name, title, width and height for TObject *obj.
217
218TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
219 const char *objname, const char *title,
220 UInt_t width, UInt_t height, Option_t *opt)
221 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
222 fNeedRefresh(kFALSE)
223{
224 if (!InitGraphics())
225 return;
226 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
227 Create(new TBrowserObject(obj,cl,objname));
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Create a new browser with a name, title, width and height for TObject *obj.
232
233TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
234 const char *objname, const char *title,
235 Int_t x, Int_t y,
236 UInt_t width, UInt_t height, Option_t *opt)
237 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
238 fNeedRefresh(kFALSE)
239{
240 if (!InitGraphics())
241 return;
242 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
243 Create(new TBrowserObject(obj,cl,objname));
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Delete the browser.
248
250{
251 Destructor();
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Actual browser destructor.
256
258{
259 if (fImp) fImp->CloseTabs();
261 gROOT->GetListOfBrowsers()->Remove(this);
262 delete fContextMenu;
263 delete fTimer;
264 if (fImp) delete fImp;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Add object with name to browser. If name not set the objects GetName()
269/// is used. If check < 0 (default) no check box is drawn, if 0 then
270/// unchecked checkbox is added, if 1 checked checkbox is added.
271
272void TBrowser::Add(TObject *obj, const char *name, Int_t check)
273{
274 if (obj && fImp) {
275 fImp->Add(obj, name, check);
276 obj->SetBit(kMustCleanup);
277 }
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Add foreign object with name to browser.
282/// 'cl' is the type use to store the value of obj.
283/// So literally the following pseudo code should be correct:
284///~~~ {.cpp}
285/// `cl->GetName()` * ptr = (`cl->GetName()`*) obj;
286///~~~
287/// and the value of obj is not necessarily the start of the object.
288/// If check < 0 (default) no check box is drawn, if 0 then
289/// unchecked checkbox is added, if 1 checked checkbox is added.
290
291void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
292{
293 if (!obj || !cl) return;
294 TObject *to;
295 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
296 else to = new TBrowserObject(obj,cl,name);
297
298 if (!to) return;
299 Add(to,name,check);
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Add checkbox for this item.
304
306{
307 if (obj && fImp) {
308 fImp->AddCheckBox(obj, check);
309 }
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Change status of checkbox for this item.
314
316{
317 if (obj && fImp) {
318 fImp->CheckObjectItem(obj, check);
319 }
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Remove checkbox for this item.
324
326{
327 if (obj && fImp) {
328 fImp->RemoveCheckBox(obj);
329 }
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Create the browser, called by the ctors.
334
336{
338
339 fTimer = new TBrowserTimer(this);
341
343 gROOT->GetListOfBrowsers()->Add(this);
344
345 // Get the list of globals
346 gROOT->GetListOfGlobals(kTRUE);
347 gROOT->GetListOfGlobalFunctions(kTRUE);
348
349 fContextMenu = new TContextMenu("BrowserContextMenu") ;
350
351 // Fill the first list from the present TObject obj
352 if (obj) {
353 Add(obj);
354 if (fImp) fImp->BrowseObj(obj);
355 } else if (fImp) {
356 // Fill the first list with all browsable classes from TROOT
358 }
359
360 // The first list will be filled by TWin32BrowserImp ctor
361 // with all browsable classes from TROOT
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// Execute default action for selected object (action is specified
366/// in the `$HOME/.root.mimes` or `$ROOTSYS/etc/root.mimes file`).
367
369{
370 if (obj && fImp)
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Recursively remove obj from browser.
376
378{
379 if (fImp && obj) {
380 fImp->RecursiveRemove(obj);
382 }
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// Refresh browser contents.
387
389{
391 if (fImp) fImp->Refresh();
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Assign the last selected object.
397
398void TBrowser::SetSelected(TObject *clickedObject)
399{
400 fLastSelectedObject = clickedObject;
401}
402
403/** \class TBrowserTimer
404Called whenever timer times out.
405*/
406
407Bool_t TBrowserTimer::Notify()
408{
409 if (fBrowser) {
410 if (fBrowser->GetRefreshFlag()) {
411 fBrowser->SetRefreshFlag(kFALSE);
412 fActivate = kTRUE;
413 } else if (fActivate) {
414 fActivate = kFALSE;
415 fBrowser->Refresh();
416 }
417 }
418 Reset();
419
420 return kFALSE;
421}
422
423/** \class TBrowserObject
424This is a wrapper class to emulate the TObject interface
425around an object of a non-TObject class
426*/
427
428////////////////////////////////////////////////////////////////////////////////
429/// Constructor.
430
431TBrowserObject::TBrowserObject(void *obj, TClass *cl, const char *brname)
432 : TNamed(brname, cl ? cl->GetName() : ""), fObj(obj), fClass(cl)
433{
434 if (cl==0) Fatal("Constructor","Class parameter should not be null");
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Return kTRUE if the object is a folder (contains browsable objects).
440
441Bool_t TBrowserObject::IsFolder() const
442{
443 return fClass->IsFolder(fObj);
444}
445
446////////////////////////////////////////////////////////////////////////////////
447/// Browse the content of the underlying object.
448
449void TBrowserObject::Browse(TBrowser* b)
450{
451 fClass->Browse(fObj, b);
452}
Cppyy::TCppType_t fClass
#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:92
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:91
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:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
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
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:335
void CheckObjectItem(TObject *obj, Bool_t check=kFALSE)
Change status of checkbox for this item.
Definition TBrowser.cxx:315
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:272
TObject * fLastSelectedObject
Definition TBrowser.h:40
virtual ~TBrowser()
Delete the browser.
Definition TBrowser.cxx:249
TContextMenu * fContextMenu
Browser's timer.
Definition TBrowser.h:48
virtual void Destructor()
Actual browser destructor.
Definition TBrowser.cxx:257
Bool_t InitGraphics()
Definition TBrowser.cxx:81
void RemoveCheckBox(TObject *obj)
Remove checkbox for this item.
Definition TBrowser.cxx:325
TBrowserTimer * fTimer
Window system specific browser implementation.
Definition TBrowser.h:47
void Refresh()
Refresh browser contents.
Definition TBrowser.cxx:388
TBrowser(const TBrowser &)=delete
The last TObject selected by user.
void SetSelected(TObject *clickedObject)
Assign the last selected object.
Definition TBrowser.cxx:398
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:368
virtual void RecursiveRemove(TObject *obj)
Recursively remove obj from browser.
Definition TBrowser.cxx:377
void AddCheckBox(TObject *obj, Bool_t check=kFALSE)
Add checkbox for this item.
Definition TBrowser.cxx:305
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
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:4892
@ kRealNew
Definition TClass.h:107
static ENewType IsCallingNew()
Static method returning the defConstructor flag passed to TClass::New().
Definition TClass.cxx:5879
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:5915
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:37
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TObject.cxx:475
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition TObject.cxx:121
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:921
@ 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:247
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:472
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