#include "TBrowser.h"
#include "TGuiFactory.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TTimer.h"
#include "TContextMenu.h"
#include "TInterpreter.h"
#include "TVirtualMutex.h"
#include "TClass.h"
#include "TApplication.h"
class TBrowserTimer : public TTimer {
protected:
   TBrowser *fBrowser;
   Bool_t    fActivate;
public:
   TBrowserTimer(TBrowser *b, Long_t ms = 1000)
      : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
   Bool_t Notify();
};
class TBrowserObject : public TNamed
{
   
   
public:
   TBrowserObject(void *obj, TClass *cl, const char *brname);
   ~TBrowserObject(){;}
   void    Browse(TBrowser* b);
   Bool_t  IsFolder() const;
   TClass *IsA() const { return fClass; }
private:
   void     *fObj;   
   TClass   *fClass; 
};
ClassImp(TBrowser)
TBrowser::TBrowser(const char *name, const char *title)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0),
     fContextMenu(0), fNeedRefresh(kFALSE)
{
   
   
   
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   if (TClass::IsCallingNew()) {
      fImp = 0;
   } else {
      Float_t cx = gStyle->GetScreenFactor();
      UInt_t w = UInt_t(cx*800);
      UInt_t h = UInt_t(cx*500);
      fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
      Create();
   }
}
TBrowser::TBrowser(const char *name, const char *title,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create();
}
TBrowser::TBrowser(const char *name, const char *title,
                   Int_t x, Int_t y,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create();
}
TBrowser::TBrowser(const char *name, TObject *obj, const char *title)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*800);
   UInt_t h = UInt_t(cx*500);
   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create(obj);
}
TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create(obj);
}
TBrowser::TBrowser(const char *name, TObject *obj, const char *title,
                   Int_t x, Int_t y,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create(obj);
}
TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
                   const char *objname, const char *title)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*800);
   UInt_t h = UInt_t(cx*500);
   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create(new TBrowserObject(obj,cl,objname));
}
TBrowser::TBrowser(const char *name, void *obj, TClass *cl,
                   const char *objname, const char *title,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create(new TBrowserObject(obj,cl,objname));
}
TBrowser::TBrowser(const char *name,void *obj,  TClass *cl,
                   const char *objname, const char *title,
                   Int_t x, Int_t y,
                   UInt_t width, UInt_t height)
   : TNamed(name, title), fLastSelectedObject(0), fTimer(0), fContextMenu(0),
     fNeedRefresh(kFALSE)
{
   
   
   TApplication::NeedGraphicsLibs();
   gApplication->InitializeGraphics();
   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create(new TBrowserObject(obj,cl,objname));
}
TBrowser::TBrowser(const TBrowser& br) :
   TNamed(br),
   fLastSelectedObject(br.fLastSelectedObject),
   fImp(br.fImp),
   fTimer(br.fTimer),
   fContextMenu(br.fContextMenu),
   fNeedRefresh(br.fNeedRefresh)
{
   
}
TBrowser& TBrowser::operator=(const TBrowser& br)
{
   
   if (this != &br) {
      TNamed::operator=(br);
      fLastSelectedObject=br.fLastSelectedObject;
      fImp=br.fImp;
      fTimer=br.fTimer;
      fContextMenu=br.fContextMenu;
      fNeedRefresh=br.fNeedRefresh;
   }
   return *this;
}
TBrowser::~TBrowser()
{
   
   R__LOCKGUARD2(gROOTMutex);
   gROOT->GetListOfBrowsers()->Remove(this);
   delete fContextMenu;
   delete fTimer;
   delete fImp;
}
void TBrowser::Add(TObject *obj, const char *name, Int_t check)
{
   
   
   
   if (obj && fImp) {
      fImp->Add(obj, name, check);
      obj->SetBit(kMustCleanup);
   }
}
void TBrowser::Add(void *obj, TClass *cl, const char *name, Int_t check)
{
   
   
   
   
   
   
   
   if (!obj || !cl) return;
   TObject *to;
   if (cl->IsTObject()) to = (TObject*)cl->DynamicCast(TObject::Class(),obj,kTRUE);
   else                 to = new TBrowserObject(obj,cl,name);
   if (!to) return;
   Add(to,name,check);
}
void TBrowser::AddCheckBox(TObject *obj, Bool_t check)
{
   
   if (obj && fImp) {
      fImp->AddCheckBox(obj, check);
   }
}
void TBrowser::CheckObjectItem(TObject *obj, Bool_t check)
{
   
   if (obj && fImp) {
      fImp->CheckObjectItem(obj, check);
   }
}
void TBrowser::RemoveCheckBox(TObject *obj)
{
   
   if (obj && fImp) {
      fImp->RemoveCheckBox(obj);
   }
}
void TBrowser::Create(TObject *obj)
{
   
   fNeedRefresh = kFALSE;
   fTimer = new TBrowserTimer(this);
   gSystem->AddTimer(fTimer);
   R__LOCKGUARD2(gROOTMutex);
   gROOT->GetListOfBrowsers()->Add(this);
   
   gROOT->GetListOfGlobals(kTRUE);
   gROOT->GetListOfGlobalFunctions(kTRUE);
   fContextMenu = new TContextMenu("BrowserContextMenu") ;
   
   if (obj) {
      Add(obj);
      if (fImp) fImp->BrowseObj(obj);
   } else if (fImp) {
      
      fImp->BrowseObj(gROOT);
   }
   
   
}
void TBrowser::ExecuteDefaultAction(TObject *obj)
{
   
   
   if (obj && fImp)
      fImp->ExecuteDefaultAction(obj);
}
void TBrowser::RecursiveRemove(TObject *obj)
{
   
   if (fImp && obj) {
      fImp->RecursiveRemove(obj);
      fNeedRefresh = kTRUE;
   }
}
void TBrowser::Refresh()
{
   
   fNeedRefresh = kTRUE;
   if (fImp) fImp->Refresh();
   fNeedRefresh = kFALSE;
}
void TBrowser::SetSelected(TObject *clickedObject)
{
   
   fLastSelectedObject = clickedObject;
}
Bool_t TBrowserTimer::Notify()
{
   
   if (fBrowser) {
      if (fBrowser->GetRefreshFlag()) {
         fBrowser->SetRefreshFlag(kFALSE);
         fActivate = kTRUE;
      } else if (fActivate) {
         fActivate = kFALSE;
         fBrowser->Refresh();
      }
   }
   Reset();
   return kFALSE;
}
TBrowserObject::TBrowserObject(void *obj, TClass *cl, const char *brname)
   : TNamed(brname,cl->GetName()), fObj(obj), fClass(cl)
{
   
   if (cl==0) Fatal("Constructor","Class parameter should not be null");
   SetBit(kCanDelete);
}
Bool_t TBrowserObject::IsFolder() const
{
   
   return fClass->IsFolder(fObj);
}
void TBrowserObject::Browse(TBrowser* b)
{
   
   fClass->Browse(fObj, b);
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.