#ifdef R__HAVE_CONFIG
#include "RConfigure.h"
#endif
#include "TGApplication.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TGClient.h"
#include "TPluginManager.h"
#include "TError.h"
#include "TEnv.h"
#include "TVirtualX.h"
#include "TStyle.h"
#include "TInterpreter.h"
#include "TColor.h"
ClassImp(TGApplication)
TGApplication::TGApplication(const char *appClassName,
                             int *argc, char **argv, void*, int)
   : TApplication(), fDisplay(0), fClient(0)
{
   
   
   
   if (gApplication) {
      Error("TGApplication", "only one instance of TGApplication allowed");
      return;
   }
   if (!gROOT)
      ::Fatal("TGApplication::TGApplication", "ROOT system not initialized");
   if (!gSystem)
      ::Fatal("TGApplication::TGApplication", "gSystem not initialized");
   gApplication = this;
   gROOT->SetApplication(this);
   gROOT->SetName(appClassName);
   GetOptions(argc, argv);
   if (argv && argv[0])
      gSystem->SetProgname(argv[0]);
   
   gInterpreter->EnableAutoLoading();
   LoadGraphicsLibs();
   if (!fDisplay) gSystem->SetDisplay();
   fClient = new TGClient(fDisplay);
   if (fClient->IsZombie()) {
      Error("TGApplication", "cannot switch to batch mode, exiting...");
      gSystem->Exit(1);
   }
   
   gROOT->SetBatch(kFALSE);
   if (strcmp(appClassName, "proofserv")) {
      const char *ttpath = gEnv->GetValue("Root.TTFontPath",
#ifdef TTFFONTDIR
                                          TTFFONTDIR);
#else
                                          "$(ROOTSYS)/fonts");
#endif
      char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
      
      if (!ttfont)
         ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
      if (ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
         TPluginHandler *h;
         if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
            h->LoadPlugin();
      }
      delete [] ttfont;
   }
   
   
   
   TColor::InitializeColors();
   
   if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
      Int_t  x, y;
      UInt_t w, h;
      if (gVirtualX) {
         gVirtualX->GetGeometry(-1, x, y, w, h);
         if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
      }
   }
   
   
   gInterpreter->InitializeDictionaries();
   gInterpreter->UpdateListOfTypes();
   
   gInterpreter->SaveContext();
   gInterpreter->SaveGlobalsContext();
   
   gROOT->SetLineHasBeenProcessed();
}
TGApplication::~TGApplication()
{
   
   delete fDisplay;
   delete fClient;
}
void TGApplication::LoadGraphicsLibs()
{
   
   TString name;
   TString title1 = "ROOT interface to ";
   TString nativex, title;
#ifndef R__WIN32
   nativex = "x11";
   name    = "X11";
   title   = title1 + "X11";
#else
   nativex = "win32gdk";
   name    = "Win32gdk";
   title   = title1 + "Win32gdk";
#endif
   TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
   guiBackend.ToLower();
   if (guiBackend == "native") {
      guiBackend = nativex;
   } else {
      name   = guiBackend;
      title  = title1 + guiBackend;
   }
   TPluginHandler *h;
   if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
      if (h->LoadPlugin() == -1)
         return;
      gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
   }
}
void TGApplication::GetOptions(Int_t *argc, char **argv)
{
   
   
   if (!argc) return;
   int i, j;
   for (i = 0; i < *argc; i++) {
      if (!strcmp(argv[i], "-display")) {
         if (argv[i+1] && strlen(argv[i+1]) && argv[i+1][0] != '-') {
            fDisplay = StrDup(argv[i+1]);
            argv[i]   = 0;
            argv[i+1] = 0;
            i++;
         }
      }
   }
   j = 0;
   for (i = 0; i < *argc; i++) {
      if (argv[i]) {
         argv[j] = argv[i];
         j++;
      }
   }
   *argc = j;
}
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.