00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00044
00045
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
00067 gSystem->NotifyApplicationCreated();
00068
00069
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
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
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
00108
00109
00110 TColor::InitializeColors();
00111
00112
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
00123
00124 gInterpreter->InitializeDictionaries();
00125 gInterpreter->UpdateListOfTypes();
00126
00127
00128 gInterpreter->SaveContext();
00129 gInterpreter->SaveGlobalsContext();
00130
00131
00132 gROOT->SetLineHasBeenProcessed();
00133 }
00134
00135
00136 TGApplication::~TGApplication()
00137 {
00138
00139
00140 delete fDisplay;
00141 delete fClient;
00142 }
00143
00144
00145 void TGApplication::LoadGraphicsLibs()
00146 {
00147
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
00183
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