00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "TBrowser.h"
00026 #include "TGuiFactory.h"
00027 #include "TROOT.h"
00028 #include "TSystem.h"
00029 #include "TStyle.h"
00030 #include "TTimer.h"
00031 #include "TContextMenu.h"
00032 #include "TInterpreter.h"
00033 #include "TVirtualMutex.h"
00034 #include "TClass.h"
00035 #include "TApplication.h"
00036
00037
00038
00039
00040
00041
00042
00043 class TBrowserTimer : public TTimer {
00044
00045 protected:
00046 TBrowser *fBrowser;
00047 Bool_t fActivate;
00048
00049 public:
00050 TBrowserTimer(TBrowser *b, Long_t ms = 1000)
00051 : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
00052 Bool_t Notify();
00053 };
00054
00055
00056
00057
00058
00059
00060
00061 class TBrowserObject : public TNamed
00062 {
00063
00064
00065
00066 public:
00067
00068 TBrowserObject(void *obj, TClass *cl, const char *brname);
00069 ~TBrowserObject(){;}
00070
00071 void Browse(TBrowser* b);
00072 Bool_t IsFolder() const;
00073 TClass *IsA() const { return fClass; }
00074
00075 private:
00076 void *fObj;
00077 TClass *fClass;
00078
00079 };
00080
00081
00082 ClassImp(TBrowser)
00083
00084
00085 TBrowser::TBrowser(const char *name, const char *title, TBrowserImp *extimp,
00086 Option_t *opt)
00087 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0),
00088 fContextMenu(0), fNeedRefresh(kFALSE)
00089 {
00090
00091
00092
00093
00094
00095
00096 TApplication::NeedGraphicsLibs();
00097 gApplication->InitializeGraphics();
00098 if (TClass::IsCallingNew() != TClass::kRealNew) {
00099 fImp = 0;
00100 } else {
00101 Float_t cx = gStyle->GetScreenFactor();
00102 UInt_t w = UInt_t(cx*800);
00103 UInt_t h = UInt_t(cx*500);
00104 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
00105 Create();
00106 }
00107 }
00108
00109
00110 TBrowser::TBrowser(const char *name, const char *title, UInt_t width,
00111 UInt_t height, TBrowserImp *extimp, Option_t *opt)
00112 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
00113 fNeedRefresh(kFALSE)
00114 {
00115
00116
00117
00118 TApplication::NeedGraphicsLibs();
00119 gApplication->InitializeGraphics();
00120 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
00121 Create();
00122 }
00123
00124
00125 TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y,
00126 UInt_t width, UInt_t height, TBrowserImp *extimp, Option_t *opt)
00127 : TNamed(name, title), fLastSelectedObject(0), fImp(extimp), fTimer(0), fContextMenu(0),
00128 fNeedRefresh(kFALSE)
00129 {
00130
00131
00132
00133 TApplication::NeedGraphicsLibs();
00134 gApplication->InitializeGraphics();
00135 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
00136 Create();
00137 }
00138
00139
00140 TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Option_t *opt)
00141 : TNamed(name, title), fLastSelectedObject(0), fImp(0), fTimer(0), fContextMenu(0),
00142 fNeedRefresh(kFALSE)
00143 {
00144
00145
00146
00147 TApplication::NeedGraphicsLibs();
00148 gApplication->InitializeGraphics();
00149 Float_t cx = gStyle->GetScreenFactor();
00150 UInt_t w = UInt_t(cx*800);
00151 UInt_t h = UInt_t(cx*500);
00152
00153 if (!fImp) fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
00154 Create(obj);
00155 }
00156
00157
00158 TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
00159 UInt_t width, UInt_t height, Option_t *opt)
00160 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
00161 fNeedRefresh(kFALSE)
00162 {
00163
00164
00165
00166 TApplication::NeedGraphicsLibs();
00167 gApplication->InitializeGraphics();
00168 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
00169 Create(obj);
00170 }
00171
00172
00173 TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
00174 Int_t x, Int_t y,
00175 UInt_t width, UInt_t height, Option_t *opt)
00176 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
00177 fNeedRefresh(kFALSE)
00178 {
00179
00180
00181
00182 TApplication::NeedGraphicsLibs();
00183 gApplication->InitializeGraphics();
00184 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
00185 Create(obj);
00186 }
00187
00188
00189 TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
00190 const char *objname, const char *title, Option_t *opt)
00191 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
00192 fNeedRefresh(kFALSE)
00193 {
00194
00195
00196
00197 TApplication::NeedGraphicsLibs();
00198 gApplication->InitializeGraphics();
00199 Float_t cx = gStyle->GetScreenFactor();
00200 UInt_t w = UInt_t(cx*800);
00201 UInt_t h = UInt_t(cx*500);
00202
00203 fImp = gGuiFactory->CreateBrowserImp(this, title, w, h, opt);
00204
00205 Create(new TBrowserObject(obj,cl,objname));
00206 }
00207
00208
00209 TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
00210 const char *objname, const char *title,
00211 UInt_t width, UInt_t height, Option_t *opt)
00212 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
00213 fNeedRefresh(kFALSE)
00214 {
00215
00216
00217
00218 TApplication::NeedGraphicsLibs();
00219 gApplication->InitializeGraphics();
00220 fImp = gGuiFactory->CreateBrowserImp(this, title, width, height, opt);
00221 Create(new TBrowserObject(obj,cl,objname));
00222 }
00223
00224
00225 TBrowser::TBrowser(const char *name,void *obj, TClass *cl,
00226 const char *objname, const char *title,
00227 Int_t x, Int_t y,
00228 UInt_t width, UInt_t height, Option_t *opt)
00229 : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
00230 fNeedRefresh(kFALSE)
00231 {
00232
00233
00234
00235 TApplication::NeedGraphicsLibs();
00236 gApplication->InitializeGraphics();
00237 fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height, opt);
00238 Create(new TBrowserObject(obj,cl,objname));
00239 }
00240
00241
00242 TBrowser::~TBrowser()
00243 {
00244
00245
00246 R__LOCKGUARD2(gROOTMutex);
00247 gROOT->GetListOfBrowsers()->Remove(this);
00248 delete fContextMenu;
00249 delete fTimer;
00250 delete fImp;
00251 }
00252
00253
00254 void TBrowser::Add(TObject *obj, const char *name, Int_t check)
00255 {
00256
00257
00258
00259
00260 if (obj && fImp) {
00261 fImp->Add(obj, name, check);
00262 obj->SetBit(kMustCleanup);
00263 }
00264 }
00265
00266
00267 void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
00268 {
00269
00270
00271
00272
00273
00274
00275
00276
00277 if (!obj || !cl) return;
00278 TObject *to;
00279 if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
00280 else to = new TBrowserObject(obj,cl,name);
00281
00282 if (!to) return;
00283 Add(to,name,check);
00284 }
00285
00286
00287 void TBrowser::AddCheckBox(TObject *obj, Bool_t check)
00288 {
00289
00290
00291 if (obj && fImp) {
00292 fImp->AddCheckBox(obj, check);
00293 }
00294 }
00295
00296
00297 void TBrowser::CheckObjectItem(TObject *obj, Bool_t check)
00298 {
00299
00300
00301 if (obj && fImp) {
00302 fImp->CheckObjectItem(obj, check);
00303 }
00304 }
00305
00306
00307 void TBrowser::RemoveCheckBox(TObject *obj)
00308 {
00309
00310
00311 if (obj && fImp) {
00312 fImp->RemoveCheckBox(obj);
00313 }
00314 }
00315
00316
00317 void TBrowser::Create(TObject *obj)
00318 {
00319
00320
00321 fNeedRefresh = kFALSE;
00322
00323 fTimer = new TBrowserTimer(this);
00324 gSystem->AddTimer(fTimer);
00325
00326 R__LOCKGUARD2(gROOTMutex);
00327 gROOT->GetListOfBrowsers()->Add(this);
00328
00329
00330 gROOT->GetListOfGlobals(kTRUE);
00331 gROOT->GetListOfGlobalFunctions(kTRUE);
00332
00333 fContextMenu = new TContextMenu("BrowserContextMenu") ;
00334
00335
00336 if (obj) {
00337 Add(obj);
00338 if (fImp) fImp->BrowseObj(obj);
00339 } else if (fImp) {
00340
00341 fImp->BrowseObj(gROOT);
00342 }
00343
00344
00345
00346 }
00347
00348
00349 void TBrowser::ExecuteDefaultAction(TObject *obj)
00350 {
00351
00352
00353
00354 if (obj && fImp)
00355 fImp->ExecuteDefaultAction(obj);
00356 }
00357
00358
00359 void TBrowser::RecursiveRemove(TObject *obj)
00360 {
00361
00362
00363 if (fImp && obj) {
00364 fImp->RecursiveRemove(obj);
00365 fNeedRefresh = kTRUE;
00366 }
00367 }
00368
00369
00370 void TBrowser::Refresh()
00371 {
00372
00373
00374 fNeedRefresh = kTRUE;
00375 if (fImp) fImp->Refresh();
00376 fNeedRefresh = kFALSE;
00377 }
00378
00379
00380 void TBrowser::SetSelected(TObject *clickedObject)
00381 {
00382
00383
00384 fLastSelectedObject = clickedObject;
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394 Bool_t TBrowserTimer::Notify()
00395 {
00396
00397
00398 if (fBrowser) {
00399 if (fBrowser->GetRefreshFlag()) {
00400 fBrowser->SetRefreshFlag(kFALSE);
00401 fActivate = kTRUE;
00402 } else if (fActivate) {
00403 fActivate = kFALSE;
00404 fBrowser->Refresh();
00405 }
00406 }
00407 Reset();
00408
00409 return kFALSE;
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 TBrowserObject::TBrowserObject(void *obj, TClass *cl, const char *brname)
00423 : TNamed(brname, cl ? cl->GetName() : ""), fObj(obj), fClass(cl)
00424 {
00425
00426
00427 if (cl==0) Fatal("Constructor","Class parameter should not be null");
00428 SetBit(kCanDelete);
00429 }
00430
00431
00432 Bool_t TBrowserObject::IsFolder() const
00433 {
00434
00435
00436 return fClass->IsFolder(fObj);
00437 }
00438
00439
00440 void TBrowserObject::Browse(TBrowser* b)
00441 {
00442
00443
00444 fClass->Browse(fObj, b);
00445 }