TGApplication.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGApplication.cxx 35204 2010-09-08 13:26:21Z bellenot $
00002 // Author: Guy Barrand   30/05/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 2001, Guy Barrand.                                      *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TGApplication                                                        //
00015 //                                                                      //
00016 // This class initialize the ROOT GUI toolkit.                          //
00017 // This class must be instantiated exactly once in any given            //
00018 // application.                                                         //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include "RConfigure.h"
00023 
00024 #include "TGApplication.h"
00025 #include "TROOT.h"
00026 #include "TSystem.h"
00027 #include "TGClient.h"
00028 #include "TPluginManager.h"
00029 #include "TError.h"
00030 #include "TEnv.h"
00031 #include "TVirtualX.h"
00032 #include "TStyle.h"
00033 #include "TInterpreter.h"
00034 #include "TColor.h"
00035 
00036 ClassImp(TGApplication)
00037 
00038 //_____________________________________________________________________________
00039 TGApplication::TGApplication(const char *appClassName,
00040                              int *argc, char **argv, void*, int)
00041    : TApplication(), fDisplay(0), fClient(0)
00042 {
00043    // Create a GUI application environment. Use this class if you only
00044    // want to use the ROOT GUI and no other services. In all other cases
00045    // use either TApplication or TRint.
00046 
00047    if (gApplication) {
00048       Error("TGApplication", "only one instance of TGApplication allowed");
00049       return;
00050    }
00051 
00052    if (!gROOT)
00053       ::Fatal("TGApplication::TGApplication", "ROOT system not initialized");
00054 
00055    if (!gSystem)
00056       ::Fatal("TGApplication::TGApplication", "gSystem not initialized");
00057 
00058    gApplication = this;
00059    gROOT->SetApplication(this);
00060    gROOT->SetName(appClassName);
00061 
00062    GetOptions(argc, argv);
00063    if (argv && argv[0])
00064       gSystem->SetProgname(argv[0]);
00065 
00066    // Tell TSystem the TApplication has been created
00067    gSystem->NotifyApplicationCreated();
00068 
00069    // Enable autoloading
00070    gInterpreter->EnableAutoLoading();
00071 
00072    LoadGraphicsLibs();
00073 
00074    if (!fDisplay) gSystem->SetDisplay();
00075    fClient = new TGClient(fDisplay);
00076 
00077    if (fClient->IsZombie()) {
00078       Error("TGApplication", "cannot switch to batch mode, exiting...");
00079       gSystem->Exit(1);
00080    }
00081 
00082    // a GUI application is never run in batch mode
00083    gROOT->SetBatch(kFALSE);
00084 
00085    if (strcmp(appClassName, "proofserv")) {
00086       const char *ttpath = gEnv->GetValue("Root.TTFontPath",
00087 #ifdef TTFFONTDIR
00088                                           TTFFONTDIR);
00089 #else
00090                                           "$(ROOTSYS)/fonts");
00091 #endif
00092 
00093       char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
00094       // Added by cholm for use of DFSG - fonts - based on fix by Kevin
00095       if (!ttfont)
00096          ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
00097       if (ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
00098          TPluginHandler *h;
00099          if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
00100             if (h->LoadPlugin() == -1)
00101                Info("TGApplication", "no TTF support");
00102       }
00103 
00104       delete [] ttfont;
00105    }
00106 
00107    // Create the canvas colors early so they are allocated before
00108    // any color table expensive bitmaps get allocated in GUI routines (like
00109    // creation of XPM bitmaps).
00110    TColor::InitializeColors();
00111 
00112    // Set default screen factor (if not disabled in rc file)
00113    if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
00114       Int_t  x, y;
00115       UInt_t w, h;
00116       if (gVirtualX) {
00117          gVirtualX->GetGeometry(-1, x, y, w, h);
00118          if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
00119       }
00120    }
00121 
00122    // Make sure all registered dictionaries have been initialized
00123    // and that all types have been loaded
00124    gInterpreter->InitializeDictionaries();
00125    gInterpreter->UpdateListOfTypes();
00126 
00127    // Save current interpreter context
00128    gInterpreter->SaveContext();
00129    gInterpreter->SaveGlobalsContext();
00130 
00131    // to allow user to interact with TCanvas's under WIN32
00132    gROOT->SetLineHasBeenProcessed();
00133 }
00134 
00135 //_____________________________________________________________________________
00136 TGApplication::~TGApplication()
00137 {
00138    // TGApplication dtor.
00139 
00140    delete fDisplay;
00141    delete fClient;
00142 }
00143 
00144 //_____________________________________________________________________________
00145 void TGApplication::LoadGraphicsLibs()
00146 {
00147    // Load shared libs necessary for GUI.
00148 
00149    TString name;
00150    TString title1 = "ROOT interface to ";
00151    TString nativex, title;
00152 #ifndef R__WIN32
00153    nativex = "x11";
00154    name    = "X11";
00155    title   = title1 + "X11";
00156 #else
00157    nativex = "win32gdk";
00158    name    = "Win32gdk";
00159    title   = title1 + "Win32gdk";
00160 #endif
00161 
00162    TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
00163    guiBackend.ToLower();
00164    if (guiBackend == "native") {
00165       guiBackend = nativex;
00166    } else {
00167       name   = guiBackend;
00168       title  = title1 + guiBackend;
00169    }
00170 
00171    TPluginHandler *h;
00172    if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
00173       if (h->LoadPlugin() == -1)
00174          return;
00175       gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
00176    }
00177 }
00178 
00179 //______________________________________________________________________________
00180 void TGApplication::GetOptions(Int_t *argc, char **argv)
00181 {
00182    // Handle command line arguments. Arguments handled are removed from the
00183    // argument array. Currently only option "-display xserver" is considered.
00184 
00185    if (!argc) return;
00186 
00187    int i, j;
00188    for (i = 0; i < *argc; i++) {
00189       if (!strcmp(argv[i], "-display")) {
00190          if (argv[i+1] && strlen(argv[i+1]) && argv[i+1][0] != '-') {
00191             fDisplay = StrDup(argv[i+1]);
00192             argv[i]   = 0;
00193             argv[i+1] = 0;
00194             i++;
00195          }
00196       }
00197    }
00198 
00199    j = 0;
00200    for (i = 0; i < *argc; i++) {
00201       if (argv[i]) {
00202          argv[j] = argv[i];
00203          j++;
00204       }
00205    }
00206 
00207    *argc = j;
00208 }
00209 

Generated on Tue Jul 5 14:21:56 2011 for ROOT_528-00b_version by  doxygen 1.5.1